use of com.orientechnologies.orient.core.metadata.schema.OSchema 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.metadata.schema.OSchema 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.metadata.schema.OSchema 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());
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema 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.metadata.schema.OSchema in project orientdb by orientechnologies.
the class IndexTxTest method beforeMethod.
@BeforeMethod
public void beforeMethod() throws Exception {
super.beforeMethod();
final OSchema schema = database.getMetadata().getSchema();
schema.reload();
database.getStorage().reload();
schema.getClass("IndexTxTestClass").truncate();
}
Aggregations