use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class CollateTest method testCompositeIndexQueryCollateWasChanged.
public void testCompositeIndexQueryCollateWasChanged() {
final OSchema schema = database.getMetadata().getSchema();
OClass clazz = schema.createClass("CompositeIndexQueryCollateWasChangedTest");
OProperty csp = clazz.createProperty("csp", OType.STRING);
csp.setCollate(ODefaultCollate.NAME);
clazz.createProperty("cip", OType.STRING);
clazz.createIndex("collateCompositeIndexCollateWasChanged", OClass.INDEX_TYPE.NOTUNIQUE, "csp", "cip");
for (int i = 0; i < 10; i++) {
ODocument document = new ODocument("CompositeIndexQueryCollateWasChangedTest");
if (i % 2 == 0) {
document.field("csp", "VAL");
document.field("cip", "VAL");
} else {
document.field("csp", "val");
document.field("cip", "val");
}
document.save();
}
String query = "select from CompositeIndexQueryCollateWasChangedTest where csp = 'VAL'";
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 5);
for (ODocument document : result) Assert.assertEquals(document.field("csp"), "VAL");
ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateCompositeIndexCollateWasChanged"));
csp = clazz.getProperty("csp");
csp.setCollate(OCaseInsensitiveCollate.NAME);
query = "select from CompositeIndexQueryCollateWasChangedTest where csp = 'VaL'";
result = database.query(new OSQLSynchQuery<ODocument>(query));
Assert.assertEquals(result.size(), 10);
for (ODocument document : result) Assert.assertEquals(document.<String>field("csp").toUpperCase(), "VAL");
explain = database.command(new OCommandSQL("explain " + query)).execute();
Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateCompositeIndexCollateWasChanged"));
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassIndexManagerTest method testIndexOnPropertiesFromClassAndSuperclass.
public void testIndexOnPropertiesFromClassAndSuperclass() {
final ODocument docOne = new ODocument("classIndexManagerTestClass");
docOne.field("prop0", "doc1-prop0");
docOne.field("prop1", "doc1-prop1");
docOne.save();
final ODocument docTwo = new ODocument("classIndexManagerTestClass");
docTwo.field("prop0", "doc2-prop0");
docTwo.field("prop1", "doc2-prop1");
docTwo.save();
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.getClass("classIndexManagerTestClass");
final OIndex<?> oIndex = oClass.getClassIndex("classIndexManagerTestIndexOnPropertiesFromClassAndSuperclass");
Assert.assertEquals(oIndex.getSize(), 2);
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassIndexManagerTest method testUpdateDocumentIndexRecordUpdated.
public void testUpdateDocumentIndexRecordUpdated() {
final ODocument doc = new ODocument("classIndexManagerTestClass");
doc.field("prop0", "x");
doc.field("prop1", "a");
doc.field("prop2", 1);
doc.save();
final OSchema schema = database.getMetadata().getSchema();
final OClass oSuperClass = schema.getClass("classIndexManagerTestSuperClass");
final OClass oClass = schema.getClass("classIndexManagerTestClass");
final OIndex<?> propZeroIndex = oSuperClass.getClassIndex("classIndexManagerTestSuperClass.prop0");
final OIndex<?> propOneIndex = oClass.getClassIndex("classIndexManagerTestClass.prop1");
final OIndex<?> compositeIndex = oClass.getClassIndex("classIndexManagerComposite");
final OIndexDefinition compositeIndexDefinition = compositeIndex.getDefinition();
Assert.assertEquals(propOneIndex.getSize(), 1);
Assert.assertEquals(compositeIndex.getSize(), 1);
Assert.assertEquals(propZeroIndex.getSize(), 1);
doc.field("prop2", 2);
doc.field("prop0", "y");
doc.save();
Assert.assertEquals(propOneIndex.getSize(), 1);
Assert.assertEquals(compositeIndex.getSize(), 1);
Assert.assertEquals(propZeroIndex.getSize(), 1);
Assert.assertNotNull(propZeroIndex.get("y"));
Assert.assertNotNull(propOneIndex.get("a"));
Assert.assertNotNull(compositeIndex.get(compositeIndexDefinition.createValue("a", 2)));
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassIndexManagerTest method testUpdateDocumentIndexRecordRemoved.
public void testUpdateDocumentIndexRecordRemoved() {
final ODocument doc = new ODocument("classIndexManagerTestClass");
doc.field("prop0", "x");
doc.field("prop1", "a");
doc.field("prop2", 1);
doc.save();
final OSchema schema = database.getMetadata().getSchema();
final OClass oSuperClass = schema.getClass("classIndexManagerTestSuperClass");
final OClass oClass = schema.getClass("classIndexManagerTestClass");
final OIndex<?> propOneIndex = oClass.getClassIndex("classIndexManagerTestClass.prop1");
final OIndex<?> compositeIndex = oClass.getClassIndex("classIndexManagerComposite");
final OIndex<?> propZeroIndex = oSuperClass.getClassIndex("classIndexManagerTestSuperClass.prop0");
Assert.assertEquals(propOneIndex.getSize(), 1);
Assert.assertEquals(compositeIndex.getSize(), 1);
Assert.assertEquals(propZeroIndex.getSize(), 1);
doc.removeField("prop2");
doc.removeField("prop0");
doc.save();
Assert.assertEquals(propOneIndex.getSize(), 1);
Assert.assertEquals(compositeIndex.getSize(), 0);
Assert.assertEquals(propZeroIndex.getSize(), 0);
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassIndexManagerTest method testListUpdate.
public void testListUpdate() {
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.getClass("classIndexManagerTestClass");
final OIndex<?> propFourIndex = oClass.getClassIndex("classIndexManagerTestClass.prop4");
Assert.assertEquals(propFourIndex.getSize(), 0);
final ODocument doc = new ODocument("classIndexManagerTestClass");
final List<String> listProperty = new ArrayList<String>();
listProperty.add("value1");
listProperty.add("value2");
doc.field("prop4", listProperty);
doc.save();
Assert.assertEquals(propFourIndex.getSize(), 2);
Assert.assertNotNull(propFourIndex.get("value1"));
Assert.assertNotNull(propFourIndex.get("value2"));
List<String> trackedList = doc.field("prop4");
trackedList.set(0, "value3");
trackedList.add("value4");
trackedList.add("value4");
trackedList.add("value4");
trackedList.remove("value4");
trackedList.remove("value2");
trackedList.add("value5");
doc.save();
Assert.assertEquals(propFourIndex.getSize(), 3);
Assert.assertNotNull(propFourIndex.get("value3"));
Assert.assertNotNull(propFourIndex.get("value4"));
Assert.assertNotNull(propFourIndex.get("value5"));
}
Aggregations