use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class IndexTest method testCreateIndexAbstractClass.
public void testCreateIndexAbstractClass() {
final ODatabaseDocumentTx databaseDocumentTx = (ODatabaseDocumentTx) database.getUnderlying();
final OSchema schema = databaseDocumentTx.getMetadata().getSchema();
OClass abstractClass = schema.createAbstractClass("TestCreateIndexAbstractClass");
abstractClass.createProperty("value", OType.STRING).setMandatory(true).createIndex(INDEX_TYPE.UNIQUE);
schema.createClass("TestCreateIndexAbstractClassChildOne", abstractClass);
schema.createClass("TestCreateIndexAbstractClassChildTwo", abstractClass);
ODocument docOne = new ODocument("TestCreateIndexAbstractClassChildOne");
docOne.field("value", "val1");
docOne.save();
ODocument docTwo = new ODocument("TestCreateIndexAbstractClassChildTwo");
docTwo.field("value", "val2");
docTwo.save();
final String queryOne = "select from TestCreateIndexAbstractClass where value = 'val1'";
List<ODocument> resultOne = databaseDocumentTx.query(new OSQLSynchQuery<ODocument>(queryOne));
Assert.assertEquals(resultOne.size(), 1);
Assert.assertEquals((Object) resultOne.get(0), (Object) docOne);
ODocument explain = databaseDocumentTx.command(new OCommandSQL("explain " + queryOne)).execute();
Assert.assertTrue(explain.<Collection<String>>field("involvedIndexes").contains("TestCreateIndexAbstractClass.value"));
final String queryTwo = "select from TestCreateIndexAbstractClass where value = 'val2'";
List<ODocument> resultTwo = databaseDocumentTx.query(new OSQLSynchQuery<ODocument>(queryTwo));
Assert.assertEquals(resultTwo.size(), 1);
Assert.assertEquals((Object) resultTwo.get(0), (Object) docTwo);
explain = databaseDocumentTx.command(new OCommandSQL("explain " + queryTwo)).execute();
Assert.assertTrue(explain.<Collection<String>>field("involvedIndexes").contains("TestCreateIndexAbstractClass.value"));
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class IndexTest method testNullIndexKeysSupportInMiddleTx.
public void testNullIndexKeysSupportInMiddleTx() {
if (database.getURL().startsWith("remote:"))
return;
final ODatabaseDocumentTx databaseDocumentTx = (ODatabaseDocumentTx) database.getUnderlying();
final OSchema schema = databaseDocumentTx.getMetadata().getSchema();
final OClass clazz = schema.createClass("NullIndexKeysSupportInMiddleTx", 1, null);
clazz.createProperty("nullField", OType.STRING);
ODocument metadata = new ODocument();
metadata.field("ignoreNullValues", false);
clazz.createIndex("NullIndexKeysSupportInMiddleTxIndex", INDEX_TYPE.NOTUNIQUE.toString(), null, metadata, new String[] { "nullField" });
database.begin();
for (int i = 0; i < 20; i++) {
if (i % 5 == 0) {
ODocument document = new ODocument("NullIndexKeysSupportInMiddleTx");
document.field("nullField", (Object) null);
document.save();
} else {
ODocument document = new ODocument("NullIndexKeysSupportInMiddleTx");
document.field("nullField", "val" + i);
document.save();
}
}
List<ODocument> result = databaseDocumentTx.query(new OSQLSynchQuery<ODocument>("select from NullIndexKeysSupportInMiddleTx where nullField = 'val3'"));
Assert.assertEquals(result.size(), 1);
Assert.assertEquals(result.get(0).field("nullField"), "val3");
final String query = "select from NullIndexKeysSupportInMiddleTx where nullField is null";
result = databaseDocumentTx.query(new OSQLSynchQuery<ODocument>("select from NullIndexKeysSupportInMiddleTx 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("NullIndexKeysSupportInMiddleTxIndex"));
database.commit();
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class IndexTest method testNullIndexKeysSupportInTx.
public void testNullIndexKeysSupportInTx() {
final ODatabaseDocumentTx databaseDocumentTx = (ODatabaseDocumentTx) database.getUnderlying();
final OSchema schema = databaseDocumentTx.getMetadata().getSchema();
final OClass clazz = schema.createClass("NullIndexKeysSupportInTx", 1, null);
clazz.createProperty("nullField", OType.STRING);
ODocument metadata = new ODocument();
metadata.field("ignoreNullValues", false);
clazz.createIndex("NullIndexKeysSupportInTxIndex", INDEX_TYPE.NOTUNIQUE.toString(), null, metadata, new String[] { "nullField" });
database.begin();
for (int i = 0; i < 20; i++) {
if (i % 5 == 0) {
ODocument document = new ODocument("NullIndexKeysSupportInTx");
document.field("nullField", (Object) null);
document.save();
} else {
ODocument document = new ODocument("NullIndexKeysSupportInTx");
document.field("nullField", "val" + i);
document.save();
}
}
database.commit();
List<ODocument> result = databaseDocumentTx.query(new OSQLSynchQuery<ODocument>("select from NullIndexKeysSupportInTx where nullField = 'val3'"));
Assert.assertEquals(result.size(), 1);
Assert.assertEquals(result.get(0).field("nullField"), "val3");
final String query = "select from NullIndexKeysSupportInTx where nullField is null";
result = databaseDocumentTx.query(new OSQLSynchQuery<ODocument>("select from NullIndexKeysSupportInTx 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("NullIndexKeysSupportInTxIndex"));
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class MapIndexTest method testIndexMapRemoveItemInTx.
public void testIndexMapRemoveItemInTx() throws Exception {
Mapper mapper = new Mapper();
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key1", 10);
map.put("key2", 20);
map.put("key3", 30);
mapper.setIntMap(map);
mapper = database.save(mapper);
try {
database.begin();
Mapper loadedMapper = (Mapper) database.load(new ORecordId(mapper.getId()));
loadedMapper.getIntMap().remove("key2");
loadedMapper = database.save(loadedMapper);
database.commit();
} catch (Exception e) {
database.rollback();
throw e;
}
final List<ODocument> resultByKey = database.command(new OCommandSQL("select key, rid from index:mapIndexTestKey")).execute();
Assert.assertNotNull(resultByKey);
Assert.assertEquals(resultByKey.size(), 2);
for (ODocument d : resultByKey) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (!d.field("key").equals("key1") && !d.field("key").equals("key3")) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
final List<ODocument> resultByValue = database.command(new OCommandSQL("select key, rid from index:mapIndexTestValue")).execute();
Assert.assertNotNull(resultByValue);
Assert.assertEquals(resultByValue.size(), 2);
for (ODocument d : resultByValue) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (!d.field("key").equals(10) && !d.field("key").equals(30)) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class MapIndexTest method testIndexMapRemoveInTx.
public void testIndexMapRemoveInTx() throws Exception {
Mapper mapper = new Mapper();
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key1", 10);
map.put("key2", 20);
mapper.setIntMap(map);
mapper = database.save(mapper);
try {
database.begin();
database.delete(mapper);
database.commit();
} catch (Exception e) {
database.rollback();
throw e;
}
final List<ODocument> resultByKey = database.command(new OCommandSQL("select key, rid from index:mapIndexTestKey")).execute();
Assert.assertNotNull(resultByKey);
Assert.assertEquals(resultByKey.size(), 0);
final List<ODocument> resultByValue = database.command(new OCommandSQL("select key, rid from index:mapIndexTestValue")).execute();
Assert.assertNotNull(resultByValue);
Assert.assertEquals(resultByValue.size(), 0);
}
Aggregations