Search in sources :

Example 51 with OSchema

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"));
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 52 with OSchema

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);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 53 with OSchema

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);
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndex(com.orientechnologies.orient.core.index.OIndex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 54 with OSchema

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);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 55 with OSchema

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);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)203 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)165 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)122 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)54 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)46 Test (org.testng.annotations.Test)35 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)31 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)23 Test (org.junit.Test)19 Before (org.junit.Before)16 ORID (com.orientechnologies.orient.core.id.ORID)15 OIndex (com.orientechnologies.orient.core.index.OIndex)15 Collection (java.util.Collection)15 Set (java.util.Set)15 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)9 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 BeforeClass (org.testng.annotations.BeforeClass)9 OStorage (com.orientechnologies.orient.core.storage.OStorage)6 ArrayList (java.util.ArrayList)5 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)4