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;
}
}));
}
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;
}
});
}
}
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));
}
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();
}
}
Aggregations