use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassIndexManagerTest method testMapUpdate.
public void testMapUpdate() {
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.getClass("classIndexManagerTestClass");
final OIndex<?> propFiveIndexKey = oClass.getClassIndex("classIndexManagerTestIndexByKey");
final OIndex<?> propFiveIndexValue = oClass.getClassIndex("classIndexManagerTestIndexByValue");
Assert.assertEquals(propFiveIndexKey.getSize(), 0);
final ODocument doc = new ODocument("classIndexManagerTestClass");
final Map<String, String> mapProperty = new HashMap<String, String>();
mapProperty.put("key1", "value1");
mapProperty.put("key2", "value2");
doc.field("prop5", mapProperty);
doc.save();
Assert.assertEquals(propFiveIndexKey.getSize(), 2);
Assert.assertNotNull(propFiveIndexKey.get("key1"));
Assert.assertNotNull(propFiveIndexKey.get("key2"));
Map<String, String> trackedMap = doc.field("prop5");
trackedMap.put("key3", "value3");
trackedMap.put("key4", "value4");
trackedMap.remove("key1");
trackedMap.put("key1", "value5");
trackedMap.remove("key2");
trackedMap.put("key6", "value6");
trackedMap.put("key7", "value6");
trackedMap.put("key8", "value6");
trackedMap.put("key4", "value7");
trackedMap.remove("key8");
doc.save();
Assert.assertEquals(propFiveIndexKey.getSize(), 5);
Assert.assertNotNull(propFiveIndexKey.get("key1"));
Assert.assertNotNull(propFiveIndexKey.get("key3"));
Assert.assertNotNull(propFiveIndexKey.get("key4"));
Assert.assertNotNull(propFiveIndexKey.get("key6"));
Assert.assertNotNull(propFiveIndexKey.get("key7"));
Assert.assertEquals(propFiveIndexValue.getSize(), 4);
Assert.assertNotNull(propFiveIndexValue.get("value5"));
Assert.assertNotNull(propFiveIndexValue.get("value3"));
Assert.assertNotNull(propFiveIndexValue.get("value7"));
Assert.assertNotNull(propFiveIndexValue.get("value6"));
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassIndexManagerTest method testCreateDocumentIndexRecordAdded.
public void testCreateDocumentIndexRecordAdded() {
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 oClass = schema.getClass("classIndexManagerTestClass");
final OClass oSuperClass = schema.getClass("classIndexManagerTestSuperClass");
final OIndex<?> propOneIndex = oClass.getClassIndex("classIndexManagerTestClass.prop1");
Assert.assertNotNull(propOneIndex.get("a"));
Assert.assertEquals(propOneIndex.getSize(), 1);
final OIndex<?> compositeIndex = oClass.getClassIndex("classIndexManagerComposite");
final OIndexDefinition compositeIndexDefinition = compositeIndex.getDefinition();
Assert.assertNotNull(compositeIndex.get(compositeIndexDefinition.createValue("a", 1)));
Assert.assertEquals(compositeIndex.getSize(), 1);
final OIndex<?> propZeroIndex = oSuperClass.getClassIndex("classIndexManagerTestSuperClass.prop0");
Assert.assertNotNull(propZeroIndex.get("x"));
Assert.assertEquals(propZeroIndex.getSize(), 1);
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassIndexManagerTest method testNoClassIndexesUpdate.
public void testNoClassIndexesUpdate() {
final ODocument doc = new ODocument("classIndexManagerTestClassTwo");
doc.field("prop1", "a");
doc.save();
doc.field("prop1", "b");
doc.save();
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.getClass("classIndexManagerTestClass");
final Collection<OIndex<?>> indexes = oClass.getIndexes();
for (final OIndex<?> index : indexes) {
Assert.assertEquals(index.getSize(), 0);
}
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassIndexManagerTest method testSetDelete.
public void testSetDelete() {
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.getClass("classIndexManagerTestClass");
final OIndex<?> propSixIndex = oClass.getClassIndex("classIndexManagerTestClass.prop6");
Assert.assertEquals(propSixIndex.getSize(), 0);
final ODocument doc = new ODocument("classIndexManagerTestClass");
final Set<String> setProperty = new HashSet<String>();
setProperty.add("value1");
setProperty.add("value2");
doc.field("prop6", setProperty);
doc.save();
Assert.assertEquals(propSixIndex.getSize(), 2);
Assert.assertNotNull(propSixIndex.get("value1"));
Assert.assertNotNull(propSixIndex.get("value2"));
Set<String> trackedSet = doc.field("prop6");
trackedSet.add("value4");
trackedSet.add("value4");
trackedSet.add("value4");
trackedSet.remove("value4");
trackedSet.remove("value2");
trackedSet.add("value5");
doc.save();
Assert.assertEquals(propSixIndex.getSize(), 2);
Assert.assertNotNull(propSixIndex.get("value1"));
Assert.assertNotNull(propSixIndex.get("value5"));
trackedSet = doc.field("prop6");
trackedSet.remove("value1");
trackedSet.add("value6");
doc.delete();
Assert.assertEquals(propSixIndex.getSize(), 0);
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ClassIndexManagerTest method testUpdateDocumentNullKeyIndexRecordRemoved.
public void testUpdateDocumentNullKeyIndexRecordRemoved() {
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.field("prop2", (Object) null);
doc.field("prop0", (Object) null);
doc.save();
Assert.assertEquals(propOneIndex.getSize(), 1);
Assert.assertEquals(compositeIndex.getSize(), 0);
Assert.assertEquals(propZeroIndex.getSize(), 0);
}
Aggregations