Search in sources :

Example 6 with OSQLSynchQuery

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();
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 7 with OSQLSynchQuery

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();
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 8 with OSQLSynchQuery

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();
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 9 with OSQLSynchQuery

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();
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 10 with OSQLSynchQuery

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

Aggregations

OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)530 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)445 Test (org.testng.annotations.Test)287 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)83 Test (org.junit.Test)73 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)59 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)53 ORID (com.orientechnologies.orient.core.id.ORID)36 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)32 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)23 HashMap (java.util.HashMap)23 List (java.util.List)22 ORecordId (com.orientechnologies.orient.core.id.ORecordId)19 Profile (com.orientechnologies.orient.test.domain.whiz.Profile)19 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)16 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)15 Collection (java.util.Collection)15 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)14 OrientTest (com.orientechnologies.orient.test.database.base.OrientTest)13 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)12