Search in sources :

Example 46 with OSchema

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"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) Set(java.util.Set) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 47 with OSchema

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);
}
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 48 with OSchema

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)));
}
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 49 with OSchema

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);
}
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 50 with OSchema

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"));
}
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