use of com.orientechnologies.orient.core.command.OCommandResultListener in project orientdb by orientechnologies.
the class SQLSelectTest method queryAsynch.
@Test
public void queryAsynch() {
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 true;
}
@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, synchResultTwo, database, asynchResultTwo, null), "synchResultTwo=" + synchResultTwo.size() + " asynchResultTwo=" + asynchResultTwo.size());
Assert.assertTrue(ODocumentHelper.compareCollections(database, synchResultOne, database, asynchResultOne, null), "synchResultOne=" + synchResultOne.size() + " asynchResultOne=" + asynchResultOne.size());
}
use of com.orientechnologies.orient.core.command.OCommandResultListener in project orientdb by orientechnologies.
the class SQLAsynchQuerySpeedTest method cycle.
@Override
@SuppressWarnings("unchecked")
public void cycle() throws UnsupportedEncodingException {
System.out.println("1 -----------------------");
OrientTest.printRecords((List<? extends ORecord>) database.command(new OSQLAsynchQuery<ODocument>("select * from animal where column(0) < 5 or column(0) >= 3 and column(5) < 7", new OCommandResultListener() {
@Override
public boolean result(Object iRecord) {
OrientTest.printRecord(resultCount++, iRecord);
return true;
}
@Override
public void end() {
}
@Override
public Object getResult() {
return null;
}
})).execute());
}
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;
}
}));
}
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();
}
}
use of com.orientechnologies.orient.core.command.OCommandResultListener in project orientdb by orientechnologies.
the class AbstractSelectTest method executeQuery.
protected List<ODocument> executeQuery(String sql, ODatabaseDocumentInternal db, Object... args) {
final List<ODocument> synchResult = db.query(new OSQLSynchQuery<ODocument>(sql), args);
final List<ODocument> asynchResult = new ArrayList<ODocument>();
final AtomicBoolean endWasCalled = new AtomicBoolean();
db.query(new OSQLAsynchQuery<ODocument>(sql, new OCommandResultListener() {
@Override
public boolean result(Object iRecord) {
asynchResult.add((ODocument) iRecord);
return true;
}
@Override
public void end() {
endWasCalled.set(true);
}
@Override
public Object getResult() {
return null;
}
}), args);
Assert.assertTrue(endWasCalled.get());
Assert.assertTrue(ODocumentHelper.compareCollections(db, synchResult, db, asynchResult, null), "Synch: " + synchResult.toString() + ", but asynch: " + asynchResult.toString());
return synchResult;
}
Aggregations