use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLUpdateTest method testUpdateContentParse.
@Test
public void testUpdateContentParse() throws Exception {
final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OCommandExecutorSQLUpdateTestContentParse");
db.create();
try {
db.command(new OCommandSQL("insert into V (name) values ('bar')")).execute();
db.command(new OCommandSQL("UPDATE V content {\"value\":\"foo\\\\\"}")).execute();
Iterable result = db.query(new OSQLSynchQuery<Object>("select from V"));
ODocument doc = (ODocument) result.iterator().next();
assertEquals(doc.field("value"), "foo\\");
db.command(new OCommandSQL("UPDATE V content {\"value\":\"foo\\\\\\\\\"}")).execute();
result = db.query(new OSQLSynchQuery<Object>("select from V"));
doc = (ODocument) result.iterator().next();
assertEquals(doc.field("value"), "foo\\\\");
} finally {
db.close();
}
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLUpdateTest method testUpdateAddOnNonExistingList2.
@Test
public void testUpdateAddOnNonExistingList2() throws Exception {
// issue #7194
final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:testUpdateAddOnNonExistingList2");
db.create();
try {
db.command(new OCommandSQL("CREATE class Foo")).execute();
db.command(new OCommandSQL("CREATE property Foo.tags EMBEDDEDLIST")).execute();
db.command(new OCommandSQL("insert into Foo set name = 'a'")).execute();
db.command(new OCommandSQL("update Foo add tags = 'foo'")).execute();
List<ODocument> result = db.query(new OSQLSynchQuery("SELECT FROM Foo"));
assertEquals(result.size(), 1);
ODocument doc = result.get(0);
List tags = doc.field("tags");
assertEquals(tags.size(), 1);
assertTrue(tags.contains("foo"));
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLUpdateTest method testUpdateAddOnNonExistingList1.
@Test
public void testUpdateAddOnNonExistingList1() throws Exception {
// issue #7194
final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:testUpdateAddOnNonExistingList1");
db.create();
try {
db.command(new OCommandSQL("CREATE class Foo")).execute();
db.command(new OCommandSQL("insert into Foo set name = 'a'")).execute();
db.command(new OCommandSQL("update Foo add tags = 'foo'")).execute();
List<ODocument> result = db.query(new OSQLSynchQuery("SELECT FROM Foo"));
assertEquals(result.size(), 1);
ODocument doc = result.get(0);
List tags = doc.field("tags");
assertEquals(tags.size(), 1);
assertTrue(tags.contains("foo"));
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLUpdateTest method testUpdateParamDate.
@Test
public void testUpdateParamDate() throws Exception {
final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OCommandExecutorSQLUpdateParamDate");
db.create();
try {
db.command(new OCommandSQL("CREATE CLASS test")).execute();
Date date = new Date();
db.command(new OCommandSQL("insert into test set birthDate = ?")).execute(date);
Iterable result = db.query(new OSQLSynchQuery<Object>("select from test"));
ODocument doc = (ODocument) result.iterator().next();
assertEquals(doc.field("birthDate"), date);
date = new Date();
db.command(new OCommandSQL("UPDATE test set birthDate = ?")).execute(date);
result = db.query(new OSQLSynchQuery<Object>("select from test"));
doc = (ODocument) result.iterator().next();
assertEquals(doc.field("birthDate"), date);
} finally {
db.close();
}
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OLiveQueryTest method testRestrictedLiveInsert.
@Test
public void testRestrictedLiveInsert() throws ExecutionException, InterruptedException {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OLiveQueryTest");
db.activateOnCurrentThread();
db.create();
try {
OSchemaProxy schema = db.getMetadata().getSchema();
OClass oRestricted = schema.getClass("ORestricted");
schema.createClass("test", oRestricted);
int liveMatch = 1;
List<ODocument> query = db.query(new OSQLSynchQuery("select from OUSer where name = 'reader'"));
final OIdentifiable reader = query.iterator().next().getIdentity();
final OIdentifiable current = db.getUser().getIdentity();
ExecutorService executorService = Executors.newSingleThreadExecutor();
final CountDownLatch latch = new CountDownLatch(1);
Future<Integer> future = executorService.submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OLiveQueryTest");
db.open("reader", "reader");
final AtomicInteger integer = new AtomicInteger(0);
db.query(new OLiveQuery<ODocument>("live select from test", new OLiveResultListener() {
@Override
public void onLiveResult(int iLiveToken, ORecordOperation iOp) throws OException {
integer.incrementAndGet();
}
@Override
public void onError(int iLiveToken) {
}
@Override
public void onUnsubscribe(int iLiveToken) {
}
}));
latch.countDown();
Thread.sleep(3000);
return integer.get();
}
});
latch.await();
db.command(new OCommandSQL("insert into test set name = 'foo', surname = 'bar'")).execute();
db.command(new OCommandSQL("insert into test set name = 'foo', surname = 'bar', _allow=?")).execute(new ArrayList<OIdentifiable>() {
{
add(current);
add(reader);
}
});
Integer integer = future.get();
Assert.assertEquals(integer.intValue(), liveMatch);
} finally {
db.drop();
}
}
Aggregations