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