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