Search in sources :

Example 6 with OFetchContext

use of com.orientechnologies.orient.core.fetch.OFetchContext in project orientdb by orientechnologies.

the class DepthFetchPlanTest method testFetchPlanDepth.

@Test
public void testFetchPlanDepth() {
    ODatabaseDocument database = new ODatabaseDocumentTx("memory:" + DepthFetchPlanTest.class.getSimpleName());
    database.create();
    try {
        database.getMetadata().getSchema().createClass("Test");
        ODocument doc = new ODocument("Test");
        ODocument doc1 = new ODocument("Test");
        ODocument doc2 = new ODocument("Test");
        doc.field("name", "name");
        database.save(doc);
        doc1.field("name", "name1");
        doc1.field("ref", doc);
        database.save(doc1);
        doc2.field("name", "name2");
        doc2.field("ref", doc1);
        database.save(doc2);
        OFetchContext context = new ORemoteFetchContext();
        CountFetchListener listener = new CountFetchListener();
        OFetchHelper.fetch(doc2, doc2, OFetchHelper.buildFetchPlan("ref:1 *:-2"), listener, context, "");
        assertEquals(1, listener.count);
    } finally {
        database.drop();
    }
}
Also used : OFetchContext(com.orientechnologies.orient.core.fetch.OFetchContext) ORemoteFetchContext(com.orientechnologies.orient.core.fetch.remote.ORemoteFetchContext) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 7 with OFetchContext

use of com.orientechnologies.orient.core.fetch.OFetchContext in project orientdb by orientechnologies.

the class OSyncCommandResultListener method linkdedBySimpleValue.

@Override
public void linkdedBySimpleValue(ODocument doc) {
    ORemoteFetchListener listener = new ORemoteFetchListener() {

        @Override
        protected void sendRecord(ORecord iLinked) {
            if (!alreadySent.contains(iLinked))
                fetchedRecordsToSend.add(iLinked);
        }

        @Override
        public void parseLinked(ODocument iRootRecord, OIdentifiable iLinked, Object iUserObject, String iFieldName, OFetchContext iContext) throws OFetchException {
            if (!(iLinked instanceof ORecordId)) {
                sendRecord(iLinked.getRecord());
            }
        }

        @Override
        public void parseLinkedCollectionValue(ODocument iRootRecord, OIdentifiable iLinked, Object iUserObject, String iFieldName, OFetchContext iContext) throws OFetchException {
            if (!(iLinked instanceof ORecordId)) {
                sendRecord(iLinked.getRecord());
            }
        }
    };
    final OFetchContext context = new ORemoteFetchContext();
    OFetchHelper.fetch(doc, doc, OFetchHelper.buildFetchPlan(""), listener, context, "");
}
Also used : OFetchContext(com.orientechnologies.orient.core.fetch.OFetchContext) ORemoteFetchListener(com.orientechnologies.orient.core.fetch.remote.ORemoteFetchListener) ORemoteFetchContext(com.orientechnologies.orient.core.fetch.remote.ORemoteFetchContext) ORecord(com.orientechnologies.orient.core.record.ORecord) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OFetchContext (com.orientechnologies.orient.core.fetch.OFetchContext)7 ORemoteFetchContext (com.orientechnologies.orient.core.fetch.remote.ORemoteFetchContext)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 ORecord (com.orientechnologies.orient.core.record.ORecord)5 ORemoteFetchListener (com.orientechnologies.orient.core.fetch.remote.ORemoteFetchListener)4 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3 IOException (java.io.IOException)3 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)2 OLockException (com.orientechnologies.common.concur.lock.OLockException)2 OException (com.orientechnologies.common.exception.OException)2 OIOException (com.orientechnologies.common.io.OIOException)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 OFetchListener (com.orientechnologies.orient.core.fetch.OFetchListener)2 OFetchPlan (com.orientechnologies.orient.core.fetch.OFetchPlan)2 OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)2 SocketException (java.net.SocketException)2 Test (org.testng.annotations.Test)2