Search in sources :

Example 1 with OSchemaProxy

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();
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OException(com.orientechnologies.common.exception.OException) OLiveResultListener(com.orientechnologies.orient.core.sql.query.OLiveResultListener) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OException(com.orientechnologies.common.exception.OException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OSchemaProxy(com.orientechnologies.orient.core.metadata.schema.OSchemaProxy) ORecordOperation(com.orientechnologies.orient.core.db.record.ORecordOperation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OLiveQuery(com.orientechnologies.orient.core.sql.query.OLiveQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 2 with OSchemaProxy

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");
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchemaProxy(com.orientechnologies.orient.core.metadata.schema.OSchemaProxy) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 3 with OSchemaProxy

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);
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchemaProxy(com.orientechnologies.orient.core.metadata.schema.OSchemaProxy) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Test(org.testng.annotations.Test)

Example 4 with OSchemaProxy

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);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchemaProxy(com.orientechnologies.orient.core.metadata.schema.OSchemaProxy) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Test(org.testng.annotations.Test)

Example 5 with OSchemaProxy

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);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchemaProxy(com.orientechnologies.orient.core.metadata.schema.OSchemaProxy) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Test(org.testng.annotations.Test)

Aggregations

OSchemaProxy (com.orientechnologies.orient.core.metadata.schema.OSchemaProxy)18 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)15 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)11 Test (org.testng.annotations.Test)11 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)8 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)7 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)4 Test (org.junit.Test)3 OException (com.orientechnologies.common.exception.OException)2 Date (java.util.Date)2 OCommandCacheSoftRefs (com.orientechnologies.orient.core.cache.OCommandCacheSoftRefs)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 ORecordOperation (com.orientechnologies.orient.core.db.record.ORecordOperation)1 OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)1 OIndexManager (com.orientechnologies.orient.core.index.OIndexManager)1 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)1 OIndexManagerRemote (com.orientechnologies.orient.core.index.OIndexManagerRemote)1 OIndexManagerShared (com.orientechnologies.orient.core.index.OIndexManagerShared)1 OFunctionLibrary (com.orientechnologies.orient.core.metadata.function.OFunctionLibrary)1