Search in sources :

Example 96 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class CollateTest method testQueryNotNullCi.

public void testQueryNotNullCi() {
    final OSchema schema = database.getMetadata().getSchema();
    OClass clazz = schema.createClass("collateTestNotNull");
    OProperty csp = clazz.createProperty("bar", OType.STRING);
    csp.setCollate(OCaseInsensitiveCollate.NAME);
    ODocument document = new ODocument("collateTestNotNull");
    document.field("bar", "baz");
    document.save();
    document = new ODocument("collateTestNotNull");
    document.field("nobar", true);
    document.save();
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from collateTestNotNull where bar is null"));
    Assert.assertEquals(result.size(), 1);
    result = database.query(new OSQLSynchQuery<ODocument>("select from collateTestNotNull where bar is not null"));
    Assert.assertEquals(result.size(), 1);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) 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 97 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class CollateTest method testCompositeIndexQueryCS.

public void testCompositeIndexQueryCS() {
    final OSchema schema = database.getMetadata().getSchema();
    OClass clazz = schema.createClass("CompositeIndexQueryCSTest");
    OProperty csp = clazz.createProperty("csp", OType.STRING);
    csp.setCollate(ODefaultCollate.NAME);
    OProperty cip = clazz.createProperty("cip", OType.STRING);
    cip.setCollate(OCaseInsensitiveCollate.NAME);
    clazz.createIndex("collateCompositeIndexCS", OClass.INDEX_TYPE.NOTUNIQUE, "csp", "cip");
    for (int i = 0; i < 10; i++) {
        ODocument document = new ODocument("CompositeIndexQueryCSTest");
        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 CompositeIndexQueryCSTest 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("collateCompositeIndexCS"));
    query = "select from CompositeIndexQueryCSTest where csp = 'VAL' and cip = 'VaL'";
    result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 5);
    for (ODocument document : result) {
        Assert.assertEquals(document.field("csp"), "VAL");
        Assert.assertEquals((document.<String>field("cip")).toUpperCase(Locale.ENGLISH), "VAL");
    }
    explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateCompositeIndexCS"));
    result = database.query(new OSQLSynchQuery<ODocument>("select from index:collateCompositeIndexCS where key = ['VAL', 'VaL']"));
    Assert.assertEquals(result.size(), 5);
    for (ODocument document : result) {
        final OCompositeKey key = document.field("key");
        final List keys = key.getKeys();
        Assert.assertEquals(keys.get(0), "VAL");
        Assert.assertTrue("val".compareToIgnoreCase((String) keys.get(1)) == 0);
        final ODocument record = document.<OIdentifiable>field("rid").getRecord();
        Assert.assertEquals(record.field("csp"), "VAL");
        Assert.assertEquals((record.<String>field("cip")).toUpperCase(Locale.ENGLISH), "VAL");
    }
}
Also used : 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) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) List(java.util.List) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 98 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class CollateTest method testQuery.

public void testQuery() {
    final OSchema schema = database.getMetadata().getSchema();
    OClass clazz = schema.createClass("collateTest");
    OProperty csp = clazz.createProperty("csp", OType.STRING);
    csp.setCollate(ODefaultCollate.NAME);
    OProperty cip = clazz.createProperty("cip", OType.STRING);
    cip.setCollate(OCaseInsensitiveCollate.NAME);
    for (int i = 0; i < 10; i++) {
        ODocument document = new ODocument("collateTest");
        if (i % 2 == 0) {
            document.field("csp", "VAL");
            document.field("cip", "VAL");
        } else {
            document.field("csp", "val");
            document.field("cip", "val");
        }
        document.save();
    }
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from collateTest where csp = 'VAL'"));
    Assert.assertEquals(result.size(), 5);
    for (ODocument document : result) Assert.assertEquals(document.field("csp"), "VAL");
    result = database.query(new OSQLSynchQuery<ODocument>("select from collateTest where cip = 'VaL'"));
    Assert.assertEquals(result.size(), 10);
    for (ODocument document : result) Assert.assertEquals((document.<String>field("cip")).toUpperCase(Locale.ENGLISH), "VAL");
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) 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 99 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class DefaultValuesTrivialTest method testPrepopulationMultivalueIndex.

@Test
public void testPrepopulationMultivalueIndex() throws Exception {
    // create example schema
    OSchema schema = database.getMetadata().getSchema();
    OClass classA = schema.createClass("ClassA");
    OProperty prop = classA.createProperty("name", OType.STRING);
    prop.setDefaultValue("default name");
    OProperty prop2 = classA.createProperty("value", OType.STRING);
    OIndex<?> index = classA.createIndex("multi", OClass.INDEX_TYPE.NOTUNIQUE, "value", "name");
    {
        ODocument doc = new ODocument(classA);
        assertEquals("default name", doc.field("name"));
        doc.field("value", "1");
        database.save(doc);
        assertEquals(1, ((Collection) index.get(new OCompositeKey("1"))).size());
    }
    {
        ODocument doc = new ODocument(classA);
        assertEquals("default name", doc.field("name"));
        doc.field("value", "2");
        database.save(doc);
        assertEquals(1, ((Collection) index.get(new OCompositeKey("2"))).size());
    }
    assertEquals(0, ((Collection) index.get(new OCompositeKey("3"))).size());
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Collection(java.util.Collection) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 100 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.

the class DefaultValuesTrivialTest method testPrepopulationIndex.

@Test
public void testPrepopulationIndex() throws Exception {
    // create example schema
    OSchema schema = database.getMetadata().getSchema();
    OClass classA = schema.createClass("ClassA");
    OProperty prop = classA.createProperty("name", OType.STRING);
    prop.setDefaultValue("default name");
    OIndex<?> index = prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
    {
        ODocument doc = new ODocument(classA);
        assertEquals("default name", doc.field("name"));
        database.save(doc);
        assertEquals(1, ((Collection) index.get("default name")).size());
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Collection(java.util.Collection) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Aggregations

OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)121 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)84 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)41 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)32 Test (org.testng.annotations.Test)30 Test (org.junit.Test)28 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)25 OType (com.orientechnologies.orient.core.metadata.schema.OType)15 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11 FilterCriteriaManager (ru.ydn.wicket.wicketorientdb.utils.query.filter.FilterCriteriaManager)10 IFilterCriteriaManager (ru.ydn.wicket.wicketorientdb.utils.query.filter.IFilterCriteriaManager)10 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)8 OIndex (com.orientechnologies.orient.core.index.OIndex)8 Date (java.util.Date)8 Set (java.util.Set)8 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)7 Map (java.util.Map)7 ODatabaseObject (com.orientechnologies.orient.core.db.object.ODatabaseObject)6 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)6 Collection (java.util.Collection)6