use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.
the class SQLCreateIndexTest method testCreateRidBagIndex.
public void testCreateRidBagIndex() throws Exception {
database.command(new OCommandSQL("CREATE INDEX sqlCreateIndexRidBagIndex ON sqlCreateIndexTestClass (prop9) NOTUNIQUE")).execute();
database.getMetadata().getIndexManager().reload();
final OIndex<?> index = database.getMetadata().getSchema().getClass("sqlCreateIndexTestClass").getClassIndex("sqlCreateIndexRidBagIndex");
Assert.assertNotNull(index);
final OIndexDefinition indexDefinition = index.getDefinition();
Assert.assertTrue(indexDefinition instanceof OPropertyRidBagIndexDefinition);
Assert.assertEquals(indexDefinition.getFields(), Arrays.asList("prop9"));
Assert.assertEquals(indexDefinition.getTypes(), new OType[] { OType.LINK });
Assert.assertEquals(index.getType(), "NOTUNIQUE");
}
use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.
the class SQLCreateIndexTest method testOldSyntax.
@Test
public void testOldSyntax() throws Exception {
database.command(new OCommandSQL("CREATE INDEX sqlCreateIndexTestClass.prop1 UNIQUE")).execute();
database.getMetadata().getIndexManager().reload();
final OIndex<?> index = database.getMetadata().getSchema().getClass("sqlCreateIndexTestClass").getClassIndex("sqlCreateIndexTestClass.prop1");
Assert.assertNotNull(index);
final OIndexDefinition indexDefinition = index.getDefinition();
Assert.assertTrue(indexDefinition instanceof OPropertyIndexDefinition);
Assert.assertEquals(indexDefinition.getFields().get(0), "prop1");
Assert.assertEquals(indexDefinition.getTypes()[0], EXPECTED_PROP1_TYPE);
Assert.assertEquals(index.getType(), "UNIQUE");
}
use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.
the class SQLCreateIndexTest method testOldStileCreateEmbeddedMapIndex.
@Test
public void testOldStileCreateEmbeddedMapIndex() throws Exception {
database.command(new OCommandSQL("CREATE INDEX sqlCreateIndexTestClass.prop3 UNIQUE")).execute();
database.getMetadata().getIndexManager().reload();
final OIndex<?> index = database.getMetadata().getSchema().getClass("sqlCreateIndexTestClass").getClassIndex("sqlCreateIndexTestClass.prop3");
Assert.assertNotNull(index);
final OIndexDefinition indexDefinition = index.getDefinition();
Assert.assertTrue(indexDefinition instanceof OPropertyMapIndexDefinition);
Assert.assertEquals(indexDefinition.getFields(), Arrays.asList("prop3"));
Assert.assertEquals(indexDefinition.getTypes(), new OType[] { OType.STRING });
Assert.assertEquals(index.getType(), "UNIQUE");
Assert.assertEquals(((OPropertyMapIndexDefinition) indexDefinition).getIndexBy(), OPropertyMapIndexDefinition.INDEX_BY.KEY);
}
use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.
the class ClassIndexManagerTest method testUpdateDocumentIndexRecordUpdatedFromNullField.
public void testUpdateDocumentIndexRecordUpdatedFromNullField() {
final ODocument doc = new ODocument("classIndexManagerTestClass");
doc.field("prop1", "a");
doc.field("prop2", (Object) null);
doc.save();
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.getClass("classIndexManagerTestClass");
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(), 0);
doc.field("prop2", 2);
doc.save();
Assert.assertEquals(propOneIndex.getSize(), 1);
Assert.assertEquals(compositeIndex.getSize(), 1);
Assert.assertNotNull(propOneIndex.get("a"));
Assert.assertNotNull(compositeIndex.get(compositeIndexDefinition.createValue("a", 2)));
}
use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.
the class SQLDropPropertyIndexTest method testForcePropertyDisabledBrokenCase.
@Test
public void testForcePropertyDisabledBrokenCase() throws Exception {
database.command(new OCommandSQL("CREATE INDEX DropPropertyIndexCompositeIndex ON DropPropertyIndexTestClass (prop1, prop2) UNIQUE")).execute();
try {
database.command(new OCommandSQL("DROP PROPERTY DropPropertyIndextestclaSS.proP1")).execute();
Assert.fail();
} catch (OCommandExecutionException e) {
Assert.assertTrue(e.getMessage().contains("Property used in indexes (" + "DropPropertyIndexCompositeIndex" + "). Please drop these indexes before removing property or use FORCE parameter."));
}
database.getMetadata().getIndexManager().reload();
final OIndex<?> index = database.getMetadata().getSchema().getClass("DropPropertyIndexTestClass").getClassIndex("DropPropertyIndexCompositeIndex");
Assert.assertNotNull(index);
final OIndexDefinition indexDefinition = index.getDefinition();
Assert.assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
Assert.assertEquals(indexDefinition.getFields(), Arrays.asList("prop1", "prop2"));
Assert.assertEquals(indexDefinition.getTypes(), new OType[] { EXPECTED_PROP1_TYPE, EXPECTED_PROP2_TYPE });
Assert.assertEquals(index.getType(), "UNIQUE");
}
Aggregations