use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class JSONTest method testToJSONWithNoLazyLoadAndClosedDatabase.
@Test
public void testToJSONWithNoLazyLoadAndClosedDatabase() {
List<ODocument> result = database.command(new OSQLSynchQuery<ODocument>("select * from Profile where name = 'Barack' and surname = 'Obama'")).execute();
for (ODocument doc : result) {
doc.reload("*:0");
String jsonFull = doc.toJSON();
ORID rid = doc.getIdentity();
database.close();
database.open("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
doc.reload("*:0");
database.close();
String jsonLoaded = doc.toJSON();
Assert.assertEquals(jsonLoaded, jsonFull);
database.open("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
doc.load("*:0");
database.close();
jsonLoaded = doc.toJSON();
Assert.assertEquals(jsonLoaded, jsonFull);
}
if (database.isClosed())
database.open("admin", "admin");
for (ODocument doc : result) {
doc.reload("*:1");
String jsonFull = doc.toJSON();
ORID rid = doc.getIdentity();
database.close();
database.open("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
doc.reload("*:1");
database.close();
String jsonLoaded = doc.toJSON();
Assert.assertEquals(jsonFull, jsonLoaded);
database.open("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
doc.load("*:1");
database.close();
jsonLoaded = doc.toJSON();
Assert.assertEquals(jsonFull, jsonLoaded);
}
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class IndexTest method testUseOfIndex.
@Test(dependsOnMethods = "testDuplicatedIndexOnUnique")
public void testUseOfIndex() {
final List<Profile> result = database.command(new OSQLSynchQuery<Profile>("select * from Profile where nick = 'Jay'")).execute();
Assert.assertFalse(result.isEmpty());
Profile record;
for (int i = 0; i < result.size(); ++i) {
record = result.get(i);
OrientTest.printRecord(i, record);
Assert.assertTrue(record.getName().toString().equalsIgnoreCase("Jay"));
}
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class IndexTest method testIndexReturnOnlySpecifiedClass.
@Test(dependsOnMethods = "createInheritanceIndex")
public void testIndexReturnOnlySpecifiedClass() throws Exception {
List<ODocument> result;
ODatabaseDocument db = database.getUnderlying();
result = db.command(new OSQLSynchQuery("select * from ChildTestClass where testParentProperty = 10")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(10L, result.get(0).field("testParentProperty"));
result = db.command(new OCommandSQL("select * from AnotherChildTestClass where testParentProperty = 11")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(11L, result.get(0).field("testParentProperty"));
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class IndexTest method testNullIndexKeysSupport.
public void testNullIndexKeysSupport() {
final ODatabaseDocumentTx databaseDocumentTx = (ODatabaseDocumentTx) database.getUnderlying();
final OSchema schema = databaseDocumentTx.getMetadata().getSchema();
final OClass clazz = schema.createClass("NullIndexKeysSupport", 1, null);
clazz.createProperty("nullField", OType.STRING);
ODocument metadata = new ODocument();
metadata.field("ignoreNullValues", false);
clazz.createIndex("NullIndexKeysSupportIndex", INDEX_TYPE.NOTUNIQUE.toString(), null, metadata, new String[] { "nullField" });
for (int i = 0; i < 20; i++) {
if (i % 5 == 0) {
ODocument document = new ODocument("NullIndexKeysSupport");
document.field("nullField", (Object) null);
document.save();
} else {
ODocument document = new ODocument("NullIndexKeysSupport");
document.field("nullField", "val" + i);
document.save();
}
}
List<ODocument> result = databaseDocumentTx.query(new OSQLSynchQuery<ODocument>("select from NullIndexKeysSupport where nullField = 'val3'"));
Assert.assertEquals(result.size(), 1);
Assert.assertEquals(result.get(0).field("nullField"), "val3");
final String query = "select from NullIndexKeysSupport where nullField is null";
result = databaseDocumentTx.query(new OSQLSynchQuery<ODocument>("select from NullIndexKeysSupport where nullField is null"));
Assert.assertEquals(result.size(), 4);
for (ODocument document : result) Assert.assertNull(document.field("nullField"));
final ODocument explain = databaseDocumentTx.command(new OCommandSQL("explain " + query)).execute();
Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("NullIndexKeysSupportIndex"));
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class IndexTest method testIndexPaginationTest.
public void testIndexPaginationTest() {
ODatabaseDocumentTx databaseDocumentTx = (ODatabaseDocumentTx) database.getUnderlying();
final OSchema schema = databaseDocumentTx.getMetadata().getSchema();
final OClass indexPaginationTest = schema.createClass("IndexPaginationTestClass", 1, null);
indexPaginationTest.createProperty("prop", OType.INTEGER);
indexPaginationTest.createIndex("IndexPaginationTest", INDEX_TYPE.UNIQUE, "prop", "@rid");
List<ORID> rids = new ArrayList<ORID>();
for (int i = 99; i >= 0; i--) {
final ODocument document = new ODocument("IndexPaginationTestClass");
document.field("prop", i / 2);
document.save();
rids.add(document.getIdentity());
}
List<ODocument> result = databaseDocumentTx.query(new OSQLSynchQuery<ODocument>("select from index:IndexPaginationTest order by key limit 5"));
Assert.assertEquals(result.size(), 5);
int lastKey = -1;
ORID lastRid = null;
for (ODocument document : result) {
document.setLazyLoad(false);
if (lastKey > -1)
Assert.assertTrue(lastKey <= (Integer) document.<OCompositeKey>field("key").getKeys().get(0));
lastKey = (Integer) document.<OCompositeKey>field("key").getKeys().get(0);
lastRid = document.field("rid");
Assert.assertTrue(rids.remove(document.<OIdentifiable>field("rid").getIdentity()));
}
while (true) {
result = databaseDocumentTx.query(new OSQLSynchQuery<ODocument>("select from index:IndexPaginationTest where key > ? order by key limit 5"), new OCompositeKey(lastKey, lastRid));
if (result.isEmpty())
break;
Assert.assertEquals(result.size(), 5);
for (ODocument document : result) {
document.setLazyLoad(false);
if (lastKey > -1)
Assert.assertTrue(lastKey <= (Integer) document.<OCompositeKey>field("key").getKeys().get(0));
lastKey = (Integer) document.<OCompositeKey>field("key").getKeys().get(0);
lastRid = document.field("rid", OType.LINK);
Assert.assertTrue(rids.remove(document.<ORID>field("rid", OType.LINK)));
}
}
Assert.assertTrue(rids.isEmpty());
}
Aggregations