Search in sources :

Example 81 with OProperty

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);
    }
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Profile(com.orientechnologies.orient.test.domain.whiz.Profile) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest) OrientTest(com.orientechnologies.orient.test.database.base.OrientTest)

Example 82 with OProperty

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

Example 83 with OProperty

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

Example 84 with OProperty

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"));
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OIndex(com.orientechnologies.orient.core.index.OIndex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 85 with OProperty

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();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)87 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)69 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)32 Test (org.testng.annotations.Test)30 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)25 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)23 OType (com.orientechnologies.orient.core.metadata.schema.OType)14 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 OIndex (com.orientechnologies.orient.core.index.OIndex)7 ODatabaseObject (com.orientechnologies.orient.core.db.object.ODatabaseObject)6 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)6 Map (java.util.Map)6 Set (java.util.Set)6 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)5 Collection (java.util.Collection)5 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)4 Field (java.lang.reflect.Field)4 Test (org.junit.Test)4 OException (com.orientechnologies.common.exception.OException)3