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