@Override public RESULT onRecordBeforeUpdate(ODocument iDocument) { iDocument.undo("b"); return RESULT.RECORD_CHANGED; }
private void reset() { for (ORecordOperation recordOperation : recordOperations.values()) { final ORecord record = recordOperation.record.getRecord(); if (record instanceof ODocument) { final ODocument document = (ODocument) record; if (document.isDirty()) document.undo(); changedDocuments.remove(document); } } for (ODocument changedDocument : changedDocuments) changedDocument.undo(); changedDocuments.clear(); updatedRids.clear(); recordOperations.clear(); indexOperations.clear(); recordIndexOperations.clear(); recordSerial = -2; customData.clear(); }
public void close() { super.close(); for (final ORecordOperation recordOperation : getRecordOperations()) { final ORecord record = recordOperation.getRecord(); if (record instanceof ODocument) { final ODocument document = (ODocument) record; if (document.isDirty()) { document.undo(); } changedDocuments.remove(document); } } for (ODocument changedDocument : changedDocuments) { changedDocument.undo(); } changedDocuments.clear(); updatedRids.clear(); allEntries.clear(); indexEntries.clear(); recordIndexOperations.clear(); newObjectCounter = -2; status = TXSTATUS.INVALID; database.setDefaultTransactionMode(); userData.clear(); }
@Override public RESULT onRecordBeforeUpdate(ODocument iDocument) { List<String> calcProperties = getCalcProperties(iDocument); if(calcProperties!=null && calcProperties.size()>0) { boolean wasChanged=false; String[] fieldNames = iDocument.fieldNames(); for (String field : fieldNames) { if(calcProperties.contains(field)) { boolean tracking = iDocument.isTrackingChanges(); if(tracking) iDocument.undo(field); // iDocument.removeField(field); wasChanged = true; } } return wasChanged?RESULT.RECORD_CHANGED:RESULT.RECORD_NOT_CHANGED; } return RESULT.RECORD_NOT_CHANGED; }
@Override public RESULT onRecordBeforeUpdate(ODocument iDocument) { System.out.println("onRecordAfterUpdate before undo: "+iDocument.field("a")); iDocument.undo("a"); System.out.println("onRecordAfterUpdate after undo: "+iDocument.field("a")); return RESULT.RECORD_CHANGED; }
@Override public RESULT onRecordBeforeUpdate(ODocument doc) { doc.undo("property2"); if(doc.field("property3")==null) doc.field("property3", "value3-update"); return RESULT.RECORD_CHANGED; }
private void doRollback() { storage.rollback(this); database.getLocalCache().clear(); for (ORecordOperation recordOperation : recordOperations.values()) { final ORecord record = recordOperation.record.getRecord(); if (record.isDirty()) if (record instanceof ODocument) { final ODocument document = (ODocument) record; if (document.isTrackingChanges()) document.undo(); } else record.unload(); } reset(); }
private <RET extends ORecord> RET saveInternal(ORecord iRecord, String iClusterName, OPERATION_MODE iMode, boolean iForceCreate, ORecordCallback<? extends Number> iRecordCreatedCallback, ORecordCallback<Integer> iRecordUpdatedCallback) { if (!(iRecord instanceof ODocument)) { assignAndCheckCluster(iRecord, iClusterName); return (RET) currentTx.saveRecord(iRecord, iClusterName, iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback); } ODocument doc = (ODocument) iRecord; ODocumentInternal.checkClass(doc, this); // IN TX THE VALIDATION MAY BE RUN TWICE BUT IS CORRECT BECAUSE OF DIFFERENT RECORD STATUS try { doc.validate(); } catch (OValidationException e) { doc.undo(); throw e; } ODocumentInternal.convertAllMultiValuesToTrackedVersions(doc); if (iForceCreate || !doc.getIdentity().isValid()) { if (doc.getClassName() != null) checkSecurity(ORule.ResourceGeneric.CLASS, ORole.PERMISSION_CREATE, doc.getClassName()); assignAndCheckCluster(doc, iClusterName); } else { // UPDATE: CHECK ACCESS ON SCHEMA CLASS NAME (IF ANY) if (doc.getClassName() != null) checkSecurity(ORule.ResourceGeneric.CLASS, ORole.PERMISSION_UPDATE, doc.getClassName()); } doc = (ODocument) currentTx .saveRecord(iRecord, iClusterName, iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback); return (RET) doc; }
@Test public void testRemovingReadonlyField() { ODatabaseDocument db = wicket.getTester().getDatabase(); OSchema schema = db.getMetadata().getSchema(); OClass classA = schema.createClass("TestRemovingField"); classA.createProperty("name", OType.STRING); OProperty property = classA.createProperty("property", OType.STRING); property.setReadonly(true); ODocument doc = new ODocument(classA); doc.field("name", "My Name"); doc.field("property", "value1"); doc.save(); doc.field("name", "My Name 2"); doc.field("property", "value2"); doc.undo("property"); doc.save(); }
@Test public void testRemovingReadonlyField2() { ODatabaseDocument db = wicket.getTester().getDatabase(); OSchema schema = db.getMetadata().getSchema(); OClass classA = schema.createClass("TestRemovingField2"); classA.createProperty("name", OType.STRING); OProperty property = classA.createProperty("property", OType.STRING); property.setReadonly(true); ODocument doc = new ODocument(classA); doc.field("name", "My Name"); doc.field("property", "value1"); doc.save(); doc.field("name", "My Name 2"); doc.field("property", "value2"); doc.undo(); doc.field("name", "My Name 3"); doc.save(); }