use of com.orientechnologies.orient.core.record.impl.ODirtyManager in project orientdb by orientechnologies.
the class OTransactionNoTx method saveRecord.
/**
* Update the record.
*
* @param iRecord
* @param iForceCreate
* @param iRecordCreatedCallback
* @param iRecordUpdatedCallback
*/
public ORecord saveRecord(final ORecord iRecord, final String iClusterName, final OPERATION_MODE iMode, boolean iForceCreate, final ORecordCallback<? extends Number> iRecordCreatedCallback, ORecordCallback<Integer> iRecordUpdatedCallback) {
try {
ORecord toRet = null;
ODirtyManager dirtyManager = ORecordInternal.getDirtyManager(iRecord);
Set<ORecord> newRecord = dirtyManager.getNewRecords();
Set<ORecord> updatedRecord = dirtyManager.getUpdateRecords();
dirtyManager.clearForSave();
if (newRecord != null) {
for (ORecord rec : newRecord) {
if (rec.getIdentity().isNew() && rec instanceof ODocument) {
ORecord ret = saveNew((ODocument) rec, dirtyManager, iClusterName, iRecord, iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);
if (ret != null)
toRet = ret;
}
}
}
if (updatedRecord != null) {
for (ORecord rec : updatedRecord) {
if (rec == iRecord) {
toRet = database.executeSaveRecord(rec, iClusterName, rec.getVersion(), iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);
} else
database.executeSaveRecord(rec, getClusterName(rec), rec.getVersion(), OPERATION_MODE.SYNCHRONOUS, false, null, null);
}
}
if (toRet != null)
return toRet;
else
return database.executeSaveRecord(iRecord, iClusterName, iRecord.getVersion(), iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);
} catch (Exception e) {
// REMOVE IT FROM THE CACHE TO AVOID DIRTY RECORDS
final ORecordId rid = (ORecordId) iRecord.getIdentity();
if (rid.isValid())
database.getLocalCache().freeRecord(rid);
throw OException.wrapException(new ODatabaseException("Error during saving of record" + (iRecord != null ? " with rid " + iRecord.getIdentity() : "")), e);
}
}
use of com.orientechnologies.orient.core.record.impl.ODirtyManager in project orientdb by orientechnologies.
the class ODirtyManagerTest method testLinkMapOther.
@Test
public void testLinkMapOther() {
ODocument doc = new ODocument();
doc.field("test", "ddd");
Map<String, ODocument> map = new HashMap<String, ODocument>();
ODocument doc1 = new ODocument();
map.put("some", doc1);
doc.field("list", map);
ODocumentInternal.convertAllMultiValuesToTrackedVersions(doc);
ODirtyManager manager = ORecordInternal.getDirtyManager(doc1);
assertEquals(2, manager.getNewRecords().size());
assertEquals(1, manager.getPointed(doc).size());
assertTrue(manager.getPointed(doc).contains(doc1));
}
use of com.orientechnologies.orient.core.record.impl.ODirtyManager in project orientdb by orientechnologies.
the class ODirtyManagerTest method testBasic.
@Test
public void testBasic() {
ODocument doc = new ODocument();
doc.field("test", "ddd");
ODirtyManager manager = ORecordInternal.getDirtyManager(doc);
assertEquals(1, manager.getNewRecords().size());
}
use of com.orientechnologies.orient.core.record.impl.ODirtyManager in project orientdb by orientechnologies.
the class ODirtyManagerTest method testLinkMap.
@Test
public void testLinkMap() {
ODocument doc = new ODocument();
doc.field("test", "ddd");
Map<String, ODocument> map = new HashMap<String, ODocument>();
ODocument link = new ODocument();
map.put("bla", link);
doc.field("map", map, OType.LINKMAP);
ODocumentInternal.convertAllMultiValuesToTrackedVersions(doc);
ODirtyManager manager = ORecordInternal.getDirtyManager(doc);
assertEquals(2, manager.getNewRecords().size());
assertEquals(1, manager.getPointed(doc).size());
assertTrue(manager.getPointed(doc).contains(link));
}
use of com.orientechnologies.orient.core.record.impl.ODirtyManager in project orientdb by orientechnologies.
the class ODirtyManagerTest method testRidBag.
@Test
public void testRidBag() {
ODocument doc = new ODocument();
doc.field("test", "ddd");
ORidBag bag = new ORidBag();
ODocument doc1 = new ODocument();
bag.add(doc1);
doc.field("bag", bag);
ODocumentInternal.convertAllMultiValuesToTrackedVersions(doc);
ODirtyManager manager = ORecordInternal.getDirtyManager(doc1);
assertEquals(2, manager.getNewRecords().size());
}
Aggregations