use of com.orientechnologies.orient.core.record.impl.ODirtyManager in project orientdb by orientechnologies.
the class ODirtyManagerTest method testDoubleMapEmbedded.
@Test
public void testDoubleMapEmbedded() {
ODocument doc = new ODocument();
doc.field("test", "ddd");
List<ODocument> lst = new ArrayList<ODocument>();
ODocument embeddedInList = new ODocument();
ODocument link = new ODocument();
embeddedInList.field("link", link);
lst.add(embeddedInList);
Map<String, Object> map = new HashMap<String, Object>();
map.put("some", lst);
doc.field("set", map, OType.EMBEDDEDMAP);
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 testDoubleCollectionEmbedded.
@Test
public void testDoubleCollectionEmbedded() {
ODocument doc = new ODocument();
doc.field("test", "ddd");
List<ODocument> lst = new ArrayList<ODocument>();
ODocument embeddedInList = new ODocument();
ODocument link = new ODocument();
embeddedInList.field("link", link);
lst.add(embeddedInList);
Set<Object> set = new HashSet<Object>();
set.add(lst);
doc.field("set", set, OType.EMBEDDEDSET);
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 OTransactionOptimistic method saveRecord.
public ORecord saveRecord(final ORecord iRecord, final String iClusterName, final OPERATION_MODE iMode, final boolean iForceCreate, final ORecordCallback<? extends Number> iRecordCreatedCallback, final ORecordCallback<Integer> iRecordUpdatedCallback) {
this.recordCreatedCallback = (ORecordCallback<Long>) iRecordCreatedCallback;
this.recordUpdatedCallback = iRecordUpdatedCallback;
if (iRecord == null)
return null;
boolean originalSaved = false;
final ODirtyManager dirtyManager = ORecordInternal.getDirtyManager(iRecord);
do {
Set<ORecord> newRecord = dirtyManager.getNewRecords();
Set<ORecord> updatedRecord = dirtyManager.getUpdateRecords();
dirtyManager.clear();
if (newRecord != null) {
for (ORecord rec : newRecord) {
if (rec instanceof ODocument)
ODocumentInternal.convertAllMultiValuesToTrackedVersions((ODocument) rec);
if (rec == iRecord) {
addRecord(rec, ORecordOperation.CREATED, iClusterName);
originalSaved = true;
} else
addRecord(rec, ORecordOperation.CREATED, getClusterName(rec));
}
}
if (updatedRecord != null) {
for (ORecord rec : updatedRecord) {
if (rec instanceof ODocument)
ODocumentInternal.convertAllMultiValuesToTrackedVersions((ODocument) rec);
if (rec == iRecord) {
final byte operation = iForceCreate ? ORecordOperation.CREATED : iRecord.getIdentity().isValid() ? ORecordOperation.UPDATED : ORecordOperation.CREATED;
addRecord(rec, operation, iClusterName);
originalSaved = true;
} else
addRecord(rec, ORecordOperation.UPDATED, getClusterName(rec));
}
}
} while (dirtyManager.getNewRecords() != null || dirtyManager.getUpdateRecords() != null);
if (!originalSaved && iRecord.isDirty()) {
final byte operation = iForceCreate ? ORecordOperation.CREATED : iRecord.getIdentity().isValid() ? ORecordOperation.UPDATED : ORecordOperation.CREATED;
addRecord(iRecord, operation, iClusterName);
}
return iRecord;
}
use of com.orientechnologies.orient.core.record.impl.ODirtyManager in project orientdb by orientechnologies.
the class DirtyManagerGraph method testLoopOfNew.
@Test
public void testLoopOfNew() {
OrientGraph graph = new OrientGraph("memory:" + DirtyManagerGraph.class.getSimpleName());
try {
graph.createEdgeType("next");
OrientVertex vertex = graph.addVertex(null);
OrientVertex vertex1 = graph.addVertex(null);
OrientVertex vertex2 = graph.addVertex(null);
OrientVertex vertex3 = graph.addVertex(null);
OrientEdge edge1 = (OrientEdge) vertex.addEdge("next", vertex1);
OrientEdge edge2 = (OrientEdge) vertex1.addEdge("next", vertex2);
OrientEdge edge3 = (OrientEdge) vertex2.addEdge("next", vertex3);
OrientEdge edge4 = (OrientEdge) vertex3.addEdge("next", vertex);
ODocument rec = vertex.getRecord();
ODirtyManager manager = ORecordInternal.getDirtyManager(rec);
List<OIdentifiable> pointed = manager.getPointed(vertex.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(edge1.getRecord()));
assertTrue(pointed.contains(edge4.getRecord()));
pointed = manager.getPointed(vertex1.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(edge1.getRecord()));
assertTrue(pointed.contains(edge2.getRecord()));
pointed = manager.getPointed(vertex2.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(edge2.getRecord()));
assertTrue(pointed.contains(edge3.getRecord()));
pointed = manager.getPointed(vertex3.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(edge3.getRecord()));
assertTrue(pointed.contains(edge4.getRecord()));
pointed = manager.getPointed(edge1.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(vertex.getRecord()));
assertTrue(pointed.contains(vertex1.getRecord()));
pointed = manager.getPointed(edge2.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(vertex1.getRecord()));
assertTrue(pointed.contains(vertex2.getRecord()));
pointed = manager.getPointed(edge3.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(vertex2.getRecord()));
assertTrue(pointed.contains(vertex3.getRecord()));
pointed = manager.getPointed(edge4.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(vertex3.getRecord()));
assertTrue(pointed.contains(vertex.getRecord()));
} finally {
graph.drop();
}
}
use of com.orientechnologies.orient.core.record.impl.ODirtyManager in project orientdb by orientechnologies.
the class ODatabaseDocumentTx method updateStream.
private byte[] updateStream(final ORecord record) {
ORecordSerializationContext.pullContext();
ODirtyManager manager = ORecordInternal.getDirtyManager(record);
Set<ORecord> newRecords = manager.getNewRecords();
Set<ORecord> updatedRecords = manager.getUpdateRecords();
manager.clearForSave();
if (newRecords != null) {
for (ORecord newRecord : newRecords) {
if (newRecord != record)
getTransaction().saveRecord(newRecord, null, OPERATION_MODE.SYNCHRONOUS, false, null, null);
}
}
if (updatedRecords != null) {
for (ORecord updatedRecord : updatedRecords) {
if (updatedRecord != record)
getTransaction().saveRecord(updatedRecord, null, OPERATION_MODE.SYNCHRONOUS, false, null, null);
}
}
ORecordSerializationContext.pushContext();
ORecordInternal.unsetDirty(record);
record.setDirty();
return record.toStream();
}
Aggregations