use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.
the class IndexTest method testIndexInUniqueIndex.
@Test(dependsOnMethods = "populateIndexDocuments")
public void testIndexInUniqueIndex() {
final OProperty nickProperty = database.getMetadata().getSchema().getClass("Profile").getProperty("nick");
Assert.assertEquals(nickProperty.getIndexes().iterator().next().getType(), OClass.INDEX_TYPE.UNIQUE.toString());
final boolean localStorage = !(database.getStorage() instanceof OStorageProxy);
boolean oldRecording = true;
long indexQueries = 0L;
if (localStorage) {
oldRecording = Orient.instance().getProfiler().isRecording();
if (!oldRecording) {
Orient.instance().getProfiler().startRecording();
}
indexQueries = Orient.instance().getProfiler().getCounter("db.demo.query.indexUsed");
if (indexQueries < 0) {
indexQueries = 0;
}
}
final List<Profile> result = database.command(new OSQLSynchQuery<Profile>("SELECT * FROM Profile WHERE nick in ['ZZZJayLongNickIndex0' ,'ZZZJayLongNickIndex1', 'ZZZJayLongNickIndex2']")).execute();
final List<String> expectedSurnames = new ArrayList<String>(Arrays.asList("NolteIndex0", "NolteIndex1", "NolteIndex2"));
if (localStorage && !oldRecording) {
Orient.instance().getProfiler().stopRecording();
}
Assert.assertEquals(result.size(), 3);
for (final Profile profile : result) {
expectedSurnames.remove(profile.getSurname());
}
Assert.assertEquals(expectedSurnames.size(), 0);
if (localStorage) {
final long newIndexQueries = Orient.instance().getProfiler().getCounter("db.demo.query.indexUsed");
Assert.assertEquals(newIndexQueries, indexQueries + 1);
}
}
use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.
the class PropertyIndexTest method testIsIndexedIndexedField.
@Test(dependsOnMethods = { "testCreateUniqueIndex" })
public void testIsIndexedIndexedField() {
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.getClass("PropertyIndexTestClass");
final OProperty propOne = oClass.getProperty("prop1");
Assert.assertTrue(propOne.isIndexed());
}
use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.
the class PropertyIndexTest method testIsIndexedNonIndexedField.
@Test
public void testIsIndexedNonIndexedField() {
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.getClass("PropertyIndexTestClass");
final OProperty propThree = oClass.getProperty("prop3");
Assert.assertFalse(propThree.isIndexed());
}
use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.
the class PropertyIndexTest method testGetIndexes.
@Test(dependsOnMethods = "createAdditionalSchemas")
public void testGetIndexes() {
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.getClass("PropertyIndexTestClass");
final OProperty propOne = oClass.getProperty("prop1");
final Collection<OIndex<?>> indexes = propOne.getIndexes();
Assert.assertEquals(indexes.size(), 1);
Assert.assertNotNull(containsIndex(indexes, "PropertyIndexTestClass.prop1"));
}
use of com.orientechnologies.orient.core.metadata.schema.OProperty in project orientdb by orientechnologies.
the class PropertyIndexTest method testCreateUniqueIndex.
@Test
public void testCreateUniqueIndex() {
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.getClass("PropertyIndexTestClass");
final OProperty propOne = oClass.getProperty("prop1");
propOne.createIndex(OClass.INDEX_TYPE.UNIQUE, new ODocument().field("ignoreNullValues", true));
final Collection<OIndex<?>> indexes = propOne.getIndexes();
OIndexDefinition indexDefinition = null;
for (final OIndex<?> index : indexes) {
if (index.getName().equals("PropertyIndexTestClass.prop1")) {
indexDefinition = index.getDefinition();
break;
}
}
Assert.assertNotNull(indexDefinition);
Assert.assertEquals(indexDefinition.getParamCount(), 1);
Assert.assertEquals(indexDefinition.getFields().size(), 1);
Assert.assertTrue(indexDefinition.getFields().contains("prop1"));
Assert.assertEquals(indexDefinition.getTypes().length, 1);
Assert.assertEquals(indexDefinition.getTypes()[0], OType.STRING);
schema.save();
}
Aggregations