Search in sources :

Example 16 with ODirtyManager

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));
}
Also used : ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 17 with ODirtyManager

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));
}
Also used : ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 18 with ODirtyManager

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;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 19 with ODirtyManager

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();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 20 with ODirtyManager

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();
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager)

Aggregations

ODirtyManager (com.orientechnologies.orient.core.record.impl.ODirtyManager)33 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)32 Test (org.testng.annotations.Test)28 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)5 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)3 ORecord (com.orientechnologies.orient.core.record.ORecord)3 ORecordLazySet (com.orientechnologies.orient.core.db.record.ORecordLazySet)2 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)2 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)2 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)2 Test (org.junit.Test)2 OException (com.orientechnologies.common.exception.OException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)1 ORecordId (com.orientechnologies.orient.core.id.ORecordId)1