use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy 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();
}
}
use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.
the class SQLSelectTest method testEmbeddedMapAndDotNotation.
@Test
public void testEmbeddedMapAndDotNotation() {
OSchemaProxy schema = database.getMetadata().getSchema();
OClass v = schema.getClass("V");
final OClass cls = schema.createClass("EmbeddedMapAndDotNotation", v);
database.command(new OCommandSQL("CREATE VERTEX EmbeddedMapAndDotNotation set name = 'foo'")).execute();
database.command(new OCommandSQL("CREATE VERTEX EmbeddedMapAndDotNotation set data = {\"bar\": \"baz\", \"quux\": 1}, name = 'bar'")).execute();
database.command(new OCommandSQL("CREATE EDGE E FROM (SELECT FROM EmbeddedMapAndDotNotation WHERE name = 'foo') to (SELECT FROM EmbeddedMapAndDotNotation WHERE name = 'bar')")).execute();
List<OIdentifiable> result = database.query(new OSQLSynchQuery<OIdentifiable>(" select out().data as result from (select from EmbeddedMapAndDotNotation where name = 'foo')"));
Assert.assertEquals(result.size(), 1);
ODocument doc = result.get(0).getRecord();
Assert.assertNotNull(doc);
List list = doc.field("result");
Assert.assertEquals(list.size(), 1);
Object first = list.get(0);
Assert.assertTrue(first instanceof Map);
Assert.assertEquals(((Map) first).get("bar"), "baz");
}
use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.
the class SQLSelectTest method testOutFilterInclude.
@Test
public void testOutFilterInclude() {
OSchemaProxy schema = database.getMetadata().getSchema();
schema.createClass("TestOutFilterInclude", schema.getClass("V"));
database.command(new OCommandSQL("create class linkedToOutFilterInclude extends E")).execute();
database.command(new OCommandSQL("insert into TestOutFilterInclude content { \"name\": \"one\" }")).execute();
database.command(new OCommandSQL("insert into TestOutFilterInclude content { \"name\": \"two\" }")).execute();
database.command(new OCommandSQL("create edge linkedToOutFilterInclude from (select from TestOutFilterInclude where name = 'one') to (select from TestOutFilterInclude where name = 'two')")).execute();
final List<OIdentifiable> result = database.query(new OSQLSynchQuery<OIdentifiable>("select expand(out('linkedToOutFilterInclude')[@class='TestOutFilterInclude'].include('@rid')) from TestOutFilterInclude where name = 'one'"));
Assert.assertEquals(result.size(), 1);
for (OIdentifiable r : result) {
Assert.assertEquals(((ODocument) r.getRecord()).field("name"), null);
}
}
use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.
the class SQLSelectTest method testIndexWithNullValues.
@Test
public void testIndexWithNullValues() {
OSchemaProxy schema = database.getMetadata().getSchema();
final OClass cls = schema.createClass("testIndexWithNullValues");
cls.createProperty("releaseDate", OType.DATE);
// cls.createIndex("testIndexWithNullValues_releaseDate", OClass.INDEX_TYPE.NOTUNIQUE, "releaseDate");
database.command(new OCommandSQL("insert into testIndexWithNullValues set name = 'foo', releaseDate = null")).execute();
database.command(new OCommandSQL("insert into testIndexWithNullValues set name = bar")).execute();
// test with index created from Java
List<OIdentifiable> result = database.query(new OSQLSynchQuery<OIdentifiable>("select count(*) from testIndexWithNullValues where releaseDate is null order by releaseDate"));
Assert.assertEquals(result.size(), 1);
Assert.assertEquals(((ODocument) result.get(0)).field("count"), 2L);
// test with index created from SQL
database.command(new OCommandSQL("drop index testIndexWithNullValues_releaseDate")).execute();
database.command(new OCommandSQL("CREATE INDEX testIndexWithNullValues_releaseDate On testIndexWithNullValues (releaseDate) NOTUNIQUE METADATA {ignoreNullValues: true}")).execute();
List<OIdentifiable> result2 = database.query(new OSQLSynchQuery<OIdentifiable>("select count(*) from testIndexWithNullValues where releaseDate is null order by releaseDate"));
Assert.assertEquals(result2.size(), 1);
Assert.assertEquals(((ODocument) result2.get(0)).field("count"), 2L);
}
use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.
the class SQLSelectTest method testLetWithQuotedValue.
@Test
public void testLetWithQuotedValue() {
OSchemaProxy schema = database.getMetadata().getSchema();
OClass v = schema.getClass("V");
final OClass cls = schema.createClass("LetWithQuotedValue", v);
database.command(new OCommandSQL("CREATE VERTEX LetWithQuotedValue set name = \"\\\"foo\\\"\"")).execute();
List<OIdentifiable> result = database.query(new OSQLSynchQuery<OIdentifiable>(" select expand($a) let $a = (select from LetWithQuotedValue where name = \"\\\"foo\\\"\")"));
Assert.assertEquals(result.size(), 1);
}
Aggregations