Search in sources :

Example 41 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable 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 42 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable 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 43 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class TraverseTest method traverseSelectIterable.

@Test
public void traverseSelectIterable() {
    int cycles = 0;
    for (OIdentifiable id : new OSQLSynchQuery<ODocument>("select from ( traverse * from Movie while $depth < 2 )")) {
        cycles++;
    }
    Assert.assertTrue(cycles > 0);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Test(org.testng.annotations.Test)

Example 44 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class TruncateClassTest method testTruncateClass.

@SuppressWarnings("unchecked")
@Test
public void testTruncateClass() {
    OSchema schema = database.getMetadata().getSchema();
    OClass testClass = getOrCreateClass(schema);
    final OIndex<?> index = getOrCreateIndex(testClass);
    schema.save();
    database.command(new OCommandSQL("truncate class test_class")).execute();
    database.save(new ODocument(testClass).field("name", "x").field("data", Arrays.asList(1, 2)));
    database.save(new ODocument(testClass).field("name", "y").field("data", Arrays.asList(3, 0)));
    database.command(new OCommandSQL("truncate class test_class")).execute();
    database.save(new ODocument(testClass).field("name", "x").field("data", Arrays.asList(5, 6, 7)));
    database.save(new ODocument(testClass).field("name", "y").field("data", Arrays.asList(8, 9, -1)));
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from test_class"));
    Assert.assertEquals(result.size(), 2);
    Set<Integer> set = new HashSet<Integer>();
    for (ODocument document : result) {
        set.addAll((Collection<Integer>) document.field("data"));
    }
    Assert.assertTrue(set.containsAll(Arrays.asList(5, 6, 7, 8, 9, -1)));
    Assert.assertEquals(index.getSize(), 6);
    OIndexCursor cursor = index.cursor();
    Map.Entry<Object, OIdentifiable> entry = cursor.nextEntry();
    while (entry != null) {
        Assert.assertTrue(set.contains((Integer) entry.getKey()));
        entry = cursor.nextEntry();
    }
    schema.dropClass("test_class");
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 45 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class TransactionIsolationTest method testIsolationRepeatableReadScript.

@Test
public void testIsolationRepeatableReadScript() throws ExecutionException, InterruptedException {
    final ODatabaseDocumentTx db1 = new ODatabaseDocumentTx(url);
    db1.open("admin", "admin");
    final ODocument record1 = new ODocument();
    record1.field("name", "This is the first version").save();
    Future<List<OIdentifiable>> txFuture = Orient.instance().submit(new Callable<List<OIdentifiable>>() {

        @Override
        public List<OIdentifiable> call() throws Exception {
            String cmd = "";
            cmd += "begin isolation REPEATABLE_READ;";
            cmd += "let r1 = select from " + record1.getIdentity() + ";";
            cmd += "sleep 2000;";
            cmd += "let r2 = select from " + record1.getIdentity() + ";";
            cmd += "commit;";
            cmd += "return $r2;";
            db1.activateOnCurrentThread();
            return db1.command(new OCommandScript("sql", cmd)).execute();
        }
    });
    Thread.sleep(500);
    // CHANGE THE RECORD FROM DB2
    ODatabaseDocumentTx db2 = new ODatabaseDocumentTx(url);
    db2.open("admin", "admin");
    ODocument record2 = db2.load(record1.getIdentity());
    record2.field("name", "This is the second version").save();
    List<OIdentifiable> txRecord = txFuture.get();
    Assert.assertNotNull(txRecord);
    Assert.assertEquals(txRecord.size(), 1);
    Assert.assertEquals(((ODocument) txRecord.get(0).getRecord()).field("name"), "This is the first version");
    db1.activateOnCurrentThread();
    db1.close();
    db2.activateOnCurrentThread();
    db2.close();
}
Also used : OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) List(java.util.List) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Aggregations

OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)536 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)278 ORecordId (com.orientechnologies.orient.core.id.ORecordId)120 Test (org.testng.annotations.Test)104 HashSet (java.util.HashSet)89 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)79 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)70 ORID (com.orientechnologies.orient.core.id.ORID)56 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)47 Test (org.junit.Test)43 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)42 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)41 ArrayList (java.util.ArrayList)39 ORecord (com.orientechnologies.orient.core.record.ORecord)35 Map (java.util.Map)31 ByteBuffer (java.nio.ByteBuffer)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)26 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)22 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)22 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)21