use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.
the class SQLCreateIndexTest method testCreateCompositeIndexWithTypes.
@Test
public void testCreateCompositeIndexWithTypes() throws Exception {
final String query = new StringBuilder("CREATE INDEX sqlCreateIndexCompositeIndex2 ON sqlCreateIndexTestClass (prop1, prop2) UNIQUE ").append(EXPECTED_PROP1_TYPE).append(", ").append(EXPECTED_PROP2_TYPE).toString();
database.command(new OCommandSQL(query)).execute();
database.getMetadata().getIndexManager().reload();
final OIndex<?> index = database.getMetadata().getSchema().getClass("sqlCreateIndexTestClass").getClassIndex("sqlCreateIndexCompositeIndex2");
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");
}
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 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 testOldIndexWithMetadata.
public void testOldIndexWithMetadata() {
database.command(new OCommandSQL("CREATE INDEX sqlCreateIndexTestClass.prop8 NOTUNIQUE metadata {v1:23, v2:\"val2\"}")).execute();
database.getMetadata().getIndexManager().reload();
final OIndex<?> index = database.getMetadata().getSchema().getClass("sqlCreateIndexTestClass").getClassIndex("sqlCreateIndexTestClass.prop8");
Assert.assertNotNull(index);
final OIndexDefinition indexDefinition = index.getDefinition();
Assert.assertTrue(indexDefinition instanceof OPropertyIndexDefinition);
Assert.assertEquals(indexDefinition.getFields(), Arrays.asList("prop8"));
Assert.assertEquals(indexDefinition.getTypes(), new OType[] { OType.INTEGER });
Assert.assertEquals(index.getType(), "NOTUNIQUE");
ODocument metadata = index.getMetadata();
Assert.assertEquals(metadata.field("v1"), 23);
Assert.assertEquals(metadata.field("v2"), "val2");
}
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");
}
Aggregations