Search in sources :

Example 1 with OCommandResultListener

use of com.orientechnologies.orient.core.command.OCommandResultListener in project orientdb by orientechnologies.

the class OClassImpl method firePropertyNameMigration.

public void firePropertyNameMigration(final ODatabaseDocument database, final String propertyName, final String newPropertyName, final OType type) {
    final boolean strictSQL = ((ODatabaseInternal) database).getStorage().getConfiguration().isStrictSql();
    database.query(new OSQLAsynchQuery<Object>("select from " + getEscapedName(name, strictSQL) + " where " + getEscapedName(propertyName, strictSQL) + " is not null ", new OCommandResultListener() {

        @Override
        public boolean result(Object iRecord) {
            final ODocument record = ((OIdentifiable) iRecord).getRecord();
            record.setFieldType(propertyName, type);
            record.field(newPropertyName, record.field(propertyName), type);
            database.save(record);
            return true;
        }

        @Override
        public void end() {
        }

        @Override
        public Object getResult() {
            return null;
        }
    }));
}
Also used : ODatabaseInternal(com.orientechnologies.orient.core.db.ODatabaseInternal) OCommandResultListener(com.orientechnologies.orient.core.command.OCommandResultListener) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 2 with OCommandResultListener

use of com.orientechnologies.orient.core.command.OCommandResultListener in project orientdb by orientechnologies.

the class OCommandExecutorSQLLiveSelect method onLiveResult.

public void onLiveResult(final ORecordOperation iOp) {
    ODatabaseDocumentInternal oldThreadLocal = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    execDb.activateOnCurrentThread();
    try {
        final OIdentifiable value = iOp.getRecord();
        if (!matchesTarget(value)) {
            return;
        }
        if (!matchesFilters(value)) {
            return;
        }
        if (!checkSecurity(value)) {
            return;
        }
    } finally {
        if (oldThreadLocal == null) {
            ODatabaseRecordThreadLocal.INSTANCE.remove();
        } else {
            ODatabaseRecordThreadLocal.INSTANCE.set(oldThreadLocal);
        }
    }
    final OCommandResultListener listener = request.getResultListener();
    if (listener instanceof OLiveResultListener) {
        execInSeparateDatabase(new OCallable() {

            @Override
            public Object call(Object iArgument) {
                execDb.activateOnCurrentThread();
                ((OLiveResultListener) listener).onLiveResult(token, iOp);
                return null;
            }
        });
    }
}
Also used : OCallable(com.orientechnologies.common.util.OCallable) OCommandResultListener(com.orientechnologies.orient.core.command.OCommandResultListener) OLiveResultListener(com.orientechnologies.orient.core.sql.query.OLiveResultListener) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 3 with OCommandResultListener

use of com.orientechnologies.orient.core.command.OCommandResultListener in project orientdb by orientechnologies.

the class SQLSelectTest method queryAsynchHalfForheFirstQuery.

@Test
public void queryAsynchHalfForheFirstQuery() {
    final String sqlOne = "select * from company where id between 4 and 7";
    final String sqlTwo = "select $names let $names = (select EXPAND( addresses.city ) as city from Account where addresses.size() > 0 )";
    final List<ODocument> synchResultOne = database.command(new OSQLSynchQuery<ODocument>(sqlOne)).execute();
    final List<ODocument> synchResultTwo = database.command(new OSQLSynchQuery<ODocument>(sqlTwo)).execute();
    Assert.assertTrue(synchResultOne.size() > 0);
    Assert.assertTrue(synchResultTwo.size() > 0);
    final List<ODocument> asynchResultOne = new ArrayList<ODocument>();
    final List<ODocument> asynchResultTwo = new ArrayList<ODocument>();
    final AtomicBoolean endOneCalled = new AtomicBoolean();
    final AtomicBoolean endTwoCalled = new AtomicBoolean();
    database.command(new OSQLAsynchQuery<ODocument>(sqlOne, new OCommandResultListener() {

        @Override
        public boolean result(Object iRecord) {
            asynchResultOne.add((ODocument) iRecord);
            return asynchResultOne.size() < synchResultOne.size() / 2;
        }

        @Override
        public void end() {
            endOneCalled.set(true);
            database.command(new OSQLAsynchQuery<ODocument>(sqlTwo, new OCommandResultListener() {

                @Override
                public boolean result(Object iRecord) {
                    asynchResultTwo.add((ODocument) iRecord);
                    return true;
                }

                @Override
                public void end() {
                    endTwoCalled.set(true);
                }

                @Override
                public Object getResult() {
                    return null;
                }
            })).execute();
        }

        @Override
        public Object getResult() {
            return null;
        }
    })).execute();
    Assert.assertTrue(endOneCalled.get());
    Assert.assertTrue(endTwoCalled.get());
    Assert.assertTrue(ODocumentHelper.compareCollections(database, synchResultOne.subList(0, synchResultOne.size() / 2), database, asynchResultOne, null));
    Assert.assertTrue(ODocumentHelper.compareCollections(database, synchResultTwo, database, asynchResultTwo, null));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OCommandResultListener(com.orientechnologies.orient.core.command.OCommandResultListener) OSQLAsynchQuery(com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 4 with OCommandResultListener

use of com.orientechnologies.orient.core.command.OCommandResultListener in project orientdb by orientechnologies.

the class OClassImpl method fireDatabaseMigration.

public void fireDatabaseMigration(final ODatabaseDocument database, final String propertyName, final OType type) {
    final boolean strictSQL = ((ODatabaseInternal) database).getStorage().getConfiguration().isStrictSql();
    database.query(new OSQLAsynchQuery<Object>("select from " + getEscapedName(name, strictSQL) + " where " + getEscapedName(propertyName, strictSQL) + ".type() <> \"" + type.name() + "\"", new OCommandResultListener() {

        @Override
        public boolean result(Object iRecord) {
            final ODocument record = ((OIdentifiable) iRecord).getRecord();
            record.field(propertyName, record.field(propertyName), type);
            database.save(record);
            return true;
        }

        @Override
        public void end() {
        }

        @Override
        public Object getResult() {
            return null;
        }
    }));
}
Also used : ODatabaseInternal(com.orientechnologies.orient.core.db.ODatabaseInternal) OCommandResultListener(com.orientechnologies.orient.core.command.OCommandResultListener) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with OCommandResultListener

use of com.orientechnologies.orient.core.command.OCommandResultListener in project orientdb by orientechnologies.

the class GraphNonBlockingQueryRemote method testNonBlockingClose.

@Test
public void testNonBlockingClose() throws ExecutionException, InterruptedException {
    OrientGraph database = new OrientGraph("remote:localhost:3064/" + GraphNonBlockingQueryRemote.class.getSimpleName());
    database.createVertexType("Prod").createProperty("something", OType.STRING);
    for (int i = 0; i < 21; i++) {
        OrientVertex vertex = database.addVertex("class:Prod");
        vertex.setProperty("something", "value");
        vertex.save();
    }
    database.commit();
    final CountDownLatch ended = new CountDownLatch(21);
    try {
        OSQLNonBlockingQuery<Object> test = new OSQLNonBlockingQuery<Object>("select * from Prod ", new OCommandResultListener() {

            int resultCount = 0;

            @Override
            public boolean result(Object iRecord) {
                resultCount++;
                ODocument odoc = ((ODocument) iRecord);
                for (String name : odoc.fieldNames()) {
                    // <----------- PROBLEM
                    assertEquals("something", name);
                }
                ended.countDown();
                return resultCount > 20 ? false : true;
            }

            @Override
            public void end() {
                ended.countDown();
            }

            @Override
            public Object getResult() {
                return resultCount;
            }
        });
        database.command(test).execute();
        assertTrue(ended.await(10, TimeUnit.SECONDS));
    } finally {
        database.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLNonBlockingQuery(com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery) OCommandResultListener(com.orientechnologies.orient.core.command.OCommandResultListener) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) CountDownLatch(java.util.concurrent.CountDownLatch) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OrientGraphRemoteTest(com.tinkerpop.blueprints.impls.orient.OrientGraphRemoteTest) Test(org.junit.Test)

Aggregations

OCommandResultListener (com.orientechnologies.orient.core.command.OCommandResultListener)10 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 Test (org.testng.annotations.Test)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)3 OSQLAsynchQuery (com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ODatabaseInternal (com.orientechnologies.orient.core.db.ODatabaseInternal)2 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)2 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)2 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 OCallable (com.orientechnologies.common.util.OCallable)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OLiveResultListener (com.orientechnologies.orient.core.sql.query.OLiveResultListener)1 OSQLNonBlockingQuery (com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery)1 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)1 OrientGraphRemoteTest (com.tinkerpop.blueprints.impls.orient.OrientGraphRemoteTest)1 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)1