Search in sources :

Example 66 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class BetweenConversionTest method testBetweenRightLeftIncluded.

public void testBetweenRightLeftIncluded() {
    final String query = "select from BetweenConversionTest where a >= 1 and a <= 3";
    final List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 3);
    List<Integer> values = new ArrayList<Integer>(Arrays.asList(1, 2, 3));
    for (ODocument document : result) {
        Assert.assertTrue(values.remove((Integer) document.field("a")));
    }
    Assert.assertTrue(values.isEmpty());
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertEquals(explain.field("rangeQueryConvertedInBetween"), 1);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 67 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class CRUDObjectInheritanceTestSchemaFull method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    super.beforeClass();
    database.close();
    database = new OObjectDatabaseTx(url + "_objectschema");
    ODatabaseHelper.dropDatabase(database, getStorageType());
    ODatabaseHelper.createDatabase(database, url + "_objectschema", getStorageType());
    try {
        ODatabaseDocumentTx exportDatabase = new ODatabaseDocumentTx(url);
        exportDatabase.open("admin", "admin");
        OCommandOutputListener listener = new OCommandOutputListener() {

            @Override
            public void onMessage(String iText) {
            }
        };
        ODatabaseExport export = new ODatabaseExport(exportDatabase, EXPORT_DIR, listener);
        export.exportDatabase();
        export.close();
        exportDatabase.close();
        ODatabaseDocumentTx importDatabase = new ODatabaseDocumentTx(url + "_objectschema");
        if (url.startsWith("remote")) {
            importDatabase.open("root", ODatabaseHelper.getServerRootPassword());
        } else {
            importDatabase.open("admin", "admin");
        }
        ODatabaseImport impor = new ODatabaseImport(importDatabase, EXPORT_DIR, listener);
        // UNREGISTER ALL THE HOOKS
        for (ORecordHook hook : new ArrayList<ORecordHook>(importDatabase.getHooks().keySet())) {
            importDatabase.unregisterHook(hook);
        }
        impor.setDeleteRIDMapping(true);
        impor.importDatabase();
        impor.close();
        importDatabase.close();
        final File importDir = new File(EXPORT_DIR);
        importDir.delete();
    } catch (IOException e) {
        Assert.fail("Export import didn't go as expected", e);
    }
    database.open("admin", "admin");
    if (database.getMetadata().getSchema().existsClass("Company"))
        database.command(new OCommandSQL("delete from Company")).execute();
    if (database.getMetadata().getSchema().existsClass("Account"))
        database.command(new OCommandSQL("delete from Account")).execute();
    if (database.getMetadata().getSchema().existsClass("JavaComplexTestClass"))
        database.command(new OCommandSQL("delete from JavaComplexTestClass")).execute();
    if (database.getMetadata().getSchema().existsClass("Profile"))
        database.command(new OCommandSQL("delete from Profile")).execute();
    if (database.getMetadata().getSchema().existsClass("IdentityChild"))
        database.command(new OCommandSQL("delete from IdentityChild")).execute();
    database.close();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) ArrayList(java.util.ArrayList) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) IOException(java.io.IOException) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) File(java.io.File) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook) ODatabaseExport(com.orientechnologies.orient.core.db.tool.ODatabaseExport) BeforeClass(org.testng.annotations.BeforeClass)

Example 68 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class CRUDObjectInheritanceTestSchemaFull method testIdFieldInheritanceFirstSubClass.

@Test(dependsOnMethods = "testIdFieldInheritance")
public void testIdFieldInheritanceFirstSubClass() {
    database.setAutomaticSchemaGeneration(true);
    database.command(new OCommandSQL("delete from InheritanceTestBaseClass")).execute();
    database.command(new OCommandSQL("delete from InheritanceTestClass")).execute();
    database.getEntityManager().registerEntityClass(InheritanceTestClass.class);
    database.getEntityManager().registerEntityClass(InheritanceTestBaseClass.class);
    InheritanceTestBaseClass a = database.newInstance(InheritanceTestBaseClass.class);
    InheritanceTestBaseClass b = database.newInstance(InheritanceTestClass.class);
    database.save(a);
    database.save(b);
    final List<InheritanceTestBaseClass> result1 = database.query(new OSQLSynchQuery<InheritanceTestBaseClass>("select from InheritanceTestBaseClass"));
    Assert.assertEquals(2, result1.size());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) InheritanceTestBaseClass(com.orientechnologies.orient.test.domain.inheritance.InheritanceTestBaseClass) Test(org.testng.annotations.Test)

Example 69 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class CRUDDocumentPhysicalTest method testAny.

@Test
public void testAny() {
    database.command(new OCommandSQL("create class TestExport")).execute();
    database.command(new OCommandSQL("create property TestExport.anything ANY")).execute();
    database.command(new OCommandSQL("insert into TestExport set anything = 3")).execute();
    database.command(new OCommandSQL("insert into TestExport set anything = 'Jay'")).execute();
    database.command(new OCommandSQL("insert into TestExport set anything = 2.3")).execute();
    List<ODocument> result = database.command(new OCommandSQL("select count(*) from TestExport where anything = 3")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 1);
    result = database.command(new OCommandSQL("select count(*) from TestExport where anything = 'Jay'")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 1);
    result = database.command(new OCommandSQL("select count(*) from TestExport where anything = 2.3")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 1);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 70 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class BetweenConversionTest method testBetweenNotRangeQueryRight.

public void testBetweenNotRangeQueryRight() {
    final String query = "select from BetweenConversionTest where a >= 1 and a = 3";
    final List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 1);
    List<Integer> values = new ArrayList<Integer>(Arrays.asList(3));
    for (ODocument document : result) {
        Assert.assertTrue(values.remove((Integer) document.field("a")));
    }
    Assert.assertTrue(values.isEmpty());
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertNull(explain.field("rangeQueryConvertedInBetween"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)621 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)422 Test (org.junit.Test)97 Test (org.testng.annotations.Test)93 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)83 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)79 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)78 ORID (com.orientechnologies.orient.core.id.ORID)64 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)61 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)54 Set (java.util.Set)53 HashMap (java.util.HashMap)45 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)42 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)41 List (java.util.List)25 Before (org.junit.Before)24 OStorage (com.orientechnologies.orient.core.storage.OStorage)23 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)23 ORecordId (com.orientechnologies.orient.core.id.ORecordId)21 Vertex (com.tinkerpop.blueprints.Vertex)19