private void internalUnTrack(ORecord pointing, OIdentifiable pointed) { if (references == null) return; if (pointed.getIdentity().isNew()) { List<OIdentifiable> refs = references.get(pointing); if (refs == null) return; if (!(pointed instanceof ODocument) || !((ODocument) pointed).isEmbedded()) { refs.remove(pointed); } } }
public void setDirty(ORecord record) { ODirtyManager real = getReal(); if (record.getIdentity().isNew() && !record.getIdentity().isTemporary()) { if (real.newRecords == null) real.newRecords = Collections.newSetFromMap(new IdentityHashMap<ORecord, Boolean>()); real.newRecords.add(record); } else { if (real.updateRecords == null) real.updateRecords = Collections.newSetFromMap(new IdentityHashMap<ORecord, Boolean>()); real.updateRecords.add(record); } }
/** * adds an item to the unique result set * * @param o the result item to add * * @return true if the element is successfully added (it was not present yet), false otherwise (it was already present) */ public synchronized boolean addToUniqueResult(Object o) { Object toAdd = o; if (o instanceof ODocument && ((ODocument) o).getIdentity().isNew()) { toAdd = new ODocumentEqualityWrapper((ODocument) o); } return this.uniqueResult.add(toAdd); }
@Override public ORecord loadRecordIfVersionIsNotLatest(ORID rid, int recordVersion, String fetchPlan, boolean ignoreCache) throws ORecordNotFoundException { if (rid.isNew()) return null; return database.executeReadRecord((ORecordId) rid, null, recordVersion, fetchPlan, ignoreCache, !ignoreCache, false, OStorage.LOCKING_STRATEGY.NONE, new LatestVersionRecordReader()); }
@Deprecated public ORecord loadRecord(final ORID iRid, final ORecord iRecord, final String iFetchPlan, final boolean ignoreCache, final boolean iUpdateCache, final boolean loadTombstone, final OStorage.LOCKING_STRATEGY iLockingStrategy) { if (iRid.isNew()) return null; return database .executeReadRecord((ORecordId) iRid, iRecord, -1, iFetchPlan, ignoreCache, iUpdateCache, loadTombstone, iLockingStrategy, new SimpleRecordReader(database.isPrefetchRecords())); }
@Deprecated public ORecord loadRecord(final ORID iRid, final ORecord iRecord, final String iFetchPlan, final boolean ignoreCache, final boolean loadTombstone, final OStorage.LOCKING_STRATEGY iLockingStrategy) { if (iRid.isNew()) return null; return database .executeReadRecord((ORecordId) iRid, iRecord, -1, iFetchPlan, ignoreCache, !ignoreCache, loadTombstone, iLockingStrategy, new SimpleRecordReader(database.isPrefetchRecords())); }
/** * Add new entity. */ public ODocument addEntity(final ODatabaseDocumentTx db, final T entity) { checkNotNull(db); checkNotNull(entity); // new entity must either have no metadata or it should be a new record EntityMetadata metadata = entity.getEntityMetadata(); checkState(metadata == null || recordIdentity(metadata.getId()).isNew()); ODocument doc = db.newInstance(typeName); return writeEntity(doc, entity); }
public ORecord loadRecord(final ORID iRid, final ORecord iRecord, final String iFetchPlan, final boolean ignoreCache) { if (iRid.isNew()) return null; return database.executeReadRecord((ORecordId) iRid, iRecord, -1, iFetchPlan, ignoreCache, !ignoreCache, false, OStorage.LOCKING_STRATEGY.NONE, new SimpleRecordReader(database.isPrefetchRecords())); }
public static RequiredOrientResource[] getRequiredResources(ODocument doc) { ORID orid = doc.getIdentity(); OrientPermission permission = orid.isNew()?OrientPermission.CREATE:OrientPermission.UPDATE; return OSecurityHelper.requireOClass(doc.getSchemaClass(), permission); }
public void scheduleEvent(final OScheduledEvent event) { if (event.getDocument().getIdentity().isNew()) // FIST TIME: SAVE IT event.save(); if (events.putIfAbsent(event.getName(), event) == null) event.schedule(); }
protected void setDirtyManager(ODirtyManager dirtyManager) { if (this._dirtyManager != null && dirtyManager != null) { dirtyManager.merge(this._dirtyManager); } this._dirtyManager = dirtyManager; if (this.getIdentity().isNew() && getOwner() == null && this._dirtyManager != null) this._dirtyManager.setDirty(this); }
@Override public OIdentifiable put(final Object key, OIdentifiable value) { if (status == MULTIVALUE_CONTENT_TYPE.ALL_RIDS && value instanceof ORecord && !value.getIdentity().isNew()) // IT'S BETTER TO LEAVE ALL RIDS AND EXTRACT ONLY THIS ONE value = value.getIdentity(); else status = ORecordMultiValueHelper.updateContentType(status, value); return super.put(key, value); }
protected ODirtyManager getDirtyManager() { if (this._dirtyManager == null) { this._dirtyManager = new ODirtyManager(); if (this.getIdentity().isNew() && getOwner() == null) this._dirtyManager.setDirty(this); } return this._dirtyManager; }
@Override public void detach() { T ret = getObject(); if (ret != null && !ret.getDocument().getIdentity().isNew()) { needToReload = true; } super.detach(); }
@Override protected void onConfigure() { super.onConfigure(); IModel<? extends List<? extends OProperty>> propertiesModel = propertiesStructureTable.getCriteriesModel(); List<? extends OProperty> properties = propertiesModel.getObject(); setVisible((properties!=null && !properties.isEmpty()) ||getModel().getObject().getIdentity().isNew()); if(DisplayMode.EDIT.equals(getModeObject())) { saveODocumentCommand.configure(); if(!saveODocumentCommand.determineVisibility()) { setModeObject(DisplayMode.VIEW); } } }
public OIndexRemote<T> put(final Object iKey, final OIdentifiable iValue) { if (iValue instanceof ORecord && !iValue.getIdentity().isValid()) // SAVE IT BEFORE TO PUT ((ORecord) iValue).save(); if (iValue.getIdentity().isNew()) throw new OIndexException( "Cannot insert values in manual indexes against remote protocol during a transaction. Temporary RID cannot be managed at server side"); getDatabase().command(String.format(QUERY_PUT, name), iKey, iValue.getIdentity()).close(); return this; }
@Override protected void readFields(final ODocument document, final T entity) { ORID bucketId = document.field(P_BUCKET, ORID.class); String format = document.field(P_FORMAT, OType.STRING); Date lastUpdated = document.field(P_LAST_UPDATED, OType.DATETIME); Map<String, Object> attributes = document.field(P_ATTRIBUTES, OType.EMBEDDEDMAP); entity.bucketId(new AttachedEntityId(bucketEntityAdapter, bucketId)); entity.format(format); entity.lastUpdated(new DateTime(lastUpdated)); entity.attributes(new NestedAttributesMap(P_ATTRIBUTES, detachable(attributes))); entity.newEntity(document.getIdentity().isNew()); }
@Override public void onClick(Optional<AjaxRequestTarget> targetOptional) { ODocument doc = getModelObject(); if(doc.getIdentity().isNew()) realizeMandatory(doc); doc.save(); if(forceCommit) { ODatabaseDocument db = getDatabase(); boolean active = db.getTransaction().isActive(); db.commit(); if(active) db.begin(); } super.onClick(targetOptional); }
/** * helper method to convert entity to document * @param document to be converted * @param entity converted */ protected void populateODocumentWithCreatedModified(ODocument document, SegradaEntity entity) { // only set in new documents if (document.getIdentity().isNew()) { document.field("created", entity.getCreated()) .field("creator", entity.getCreator()==null?null:new ORecordId(entity.getCreator().getId())); } document.field("modified", entity.getModified()) .field("modifier", entity.getModifier() == null ? null : new ORecordId(entity.getModifier().getId())); }
@Test public void testOQueryModelDBTouch() { OClass classA = wicket.getTester().getSchema().getClass("ClassA"); ODocument doc = new ODocument(classA); doc.field("other", Arrays.asList(doc)); OQueryModel<ODocument> queryModel = new OQueryModel<ODocument>("select from ClassA where :doc in other"); queryModel.setParameter("doc", new ODocumentModel(doc)); long was = classA.count(); assertTrue(doc.getIdentity().isNew()); assertEquals(0, queryModel.size()); assertTrue(doc.getIdentity().isNew()); assertEquals(was, classA.count()); }