Search in sources :

Example 61 with OIndexDefinition

use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.

the class ClassIndexTest method testCreateCompositeEmbeddedMapIndex.

@Test
public void testCreateCompositeEmbeddedMapIndex() {
    final OIndex result = oClass.createIndex("ClassIndexTestCompositeEmbeddedMap", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fFifteen", "fEmbeddedMap" });
    assertEquals(result.getName(), "ClassIndexTestCompositeEmbeddedMap");
    assertEquals(oClass.getClassIndex("ClassIndexTestCompositeEmbeddedMap").getName(), result.getName());
    assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestCompositeEmbeddedMap").getName(), result.getName());
    final OIndexDefinition indexDefinition = result.getDefinition();
    assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
    assertEquals(indexDefinition.getFields().toArray(), new String[] { "fFifteen", "fEmbeddedMap" });
    assertEquals(indexDefinition.getTypes(), new OType[] { OType.INTEGER, OType.STRING });
    assertEquals(indexDefinition.getParamCount(), 2);
}
Also used : OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 62 with OIndexDefinition

use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.

the class OImmutableProperty method getAllIndexes.

@Override
public Collection<OIndex<?>> getAllIndexes() {
    final Set<OIndex<?>> indexes = owner.getIndexes();
    final List<OIndex<?>> indexList = new LinkedList<OIndex<?>>();
    for (final OIndex<?> index : indexes) {
        final OIndexDefinition indexDefinition = index.getDefinition();
        if (indexDefinition.getFields().contains(name))
            indexList.add(index);
    }
    return indexList;
}
Also used : OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) LinkedList(java.util.LinkedList)

Example 63 with OIndexDefinition

use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.

the class OQueryOperatorContainsKey method executeIndexQuery.

@Override
public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) {
    final OIndexDefinition indexDefinition = index.getDefinition();
    OIndexCursor cursor;
    final OIndexInternal<?> internalIndex = index.getInternal();
    if (!internalIndex.canBeUsedInEqualityOperators())
        return null;
    if (indexDefinition.getParamCount() == 1) {
        if (!((indexDefinition instanceof OPropertyMapIndexDefinition) && ((OPropertyMapIndexDefinition) indexDefinition).getIndexBy() == OPropertyMapIndexDefinition.INDEX_BY.KEY))
            return null;
        final Object key = ((OIndexDefinitionMultiValue) indexDefinition).createSingleValue(keyParams.get(0));
        if (key == null)
            return null;
        final Object indexResult = index.get(key);
        if (indexResult == null || indexResult instanceof OIdentifiable)
            cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, key);
        else
            cursor = new OIndexCursorCollectionValue((Collection<OIdentifiable>) indexResult, key);
    } else {
        // in case of composite keys several items can be returned in case of we perform search
        // using part of composite key stored in index.
        final OCompositeIndexDefinition compositeIndexDefinition = (OCompositeIndexDefinition) indexDefinition;
        if (!((compositeIndexDefinition.getMultiValueDefinition() instanceof OPropertyMapIndexDefinition) && ((OPropertyMapIndexDefinition) compositeIndexDefinition.getMultiValueDefinition()).getIndexBy() == OPropertyMapIndexDefinition.INDEX_BY.KEY))
            return null;
        final Object keyOne = compositeIndexDefinition.createSingleValue(keyParams);
        if (keyOne == null)
            return null;
        if (internalIndex.hasRangeQuerySupport()) {
            final Object keyTwo = compositeIndexDefinition.createSingleValue(keyParams);
            cursor = index.iterateEntriesBetween(keyOne, true, keyTwo, true, ascSortOrder);
        } else {
            if (indexDefinition.getParamCount() == keyParams.size()) {
                final Object indexResult = index.get(keyOne);
                if (indexResult == null || indexResult instanceof OIdentifiable)
                    cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, keyOne);
                else
                    cursor = new OIndexCursorCollectionValue((Collection<OIdentifiable>) indexResult, keyOne);
            } else
                return null;
        }
    }
    updateProfiler(iContext, index, keyParams, indexDefinition);
    return cursor;
}
Also used : OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OPropertyMapIndexDefinition(com.orientechnologies.orient.core.index.OPropertyMapIndexDefinition) OIndexCursorCollectionValue(com.orientechnologies.orient.core.index.OIndexCursorCollectionValue) OIndexCursorSingleValue(com.orientechnologies.orient.core.index.OIndexCursorSingleValue) OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) OIndexDefinitionMultiValue(com.orientechnologies.orient.core.index.OIndexDefinitionMultiValue) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 64 with OIndexDefinition

use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.

the class OQueryOperatorContainsText method executeIndexQuery.

@Override
public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) {
    final OIndexDefinition indexDefinition = index.getDefinition();
    if (indexDefinition.getParamCount() > 1)
        return null;
    final OIndex<?> internalIndex = index.getInternal();
    OIndexCursor cursor;
    if (internalIndex instanceof OIndexFullText) {
        final Object key = indexDefinition.createValue(keyParams);
        final Object indexResult = index.get(key);
        if (indexResult == null || indexResult instanceof OIdentifiable)
            cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, key);
        else
            cursor = new OIndexCursorCollectionValue((Collection<OIdentifiable>) indexResult, key);
    } else
        return null;
    updateProfiler(iContext, internalIndex, keyParams, indexDefinition);
    return cursor;
}
Also used : OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndexCursorCollectionValue(com.orientechnologies.orient.core.index.OIndexCursorCollectionValue) OIndexCursorSingleValue(com.orientechnologies.orient.core.index.OIndexCursorSingleValue) OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) OIndexFullText(com.orientechnologies.orient.core.index.OIndexFullText) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 65 with OIndexDefinition

use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.

the class OQueryOperatorIs method executeIndexQuery.

@Override
public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) {
    final OIndexDefinition indexDefinition = index.getDefinition();
    final OIndexInternal<?> internalIndex = index.getInternal();
    OIndexCursor cursor;
    if (!internalIndex.canBeUsedInEqualityOperators())
        return null;
    if (indexDefinition.getParamCount() == 1) {
        final Object key;
        if (indexDefinition instanceof OIndexDefinitionMultiValue)
            key = ((OIndexDefinitionMultiValue) indexDefinition).createSingleValue(keyParams.get(0));
        else
            key = indexDefinition.createValue(keyParams);
        final Object indexResult;
        indexResult = index.get(key);
        if (indexResult == null || indexResult instanceof OIdentifiable)
            cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, key);
        else
            cursor = new OIndexCursorCollectionValue((Collection<OIdentifiable>) indexResult, key);
    } else {
        // in case of composite keys several items can be returned in case we perform search
        // using part of composite key stored in index
        final OCompositeIndexDefinition compositeIndexDefinition = (OCompositeIndexDefinition) indexDefinition;
        final Object keyOne = compositeIndexDefinition.createSingleValue(keyParams);
        final Object keyTwo = compositeIndexDefinition.createSingleValue(keyParams);
        if (internalIndex.hasRangeQuerySupport()) {
            cursor = index.iterateEntriesBetween(keyOne, true, keyTwo, true, ascSortOrder);
        } else {
            if (indexDefinition.getParamCount() == keyParams.size()) {
                final Object indexResult;
                indexResult = index.get(keyOne);
                if (indexResult == null || indexResult instanceof OIdentifiable)
                    cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, keyOne);
                else
                    cursor = new OIndexCursorCollectionValue((Collection<OIdentifiable>) indexResult, keyOne);
            } else
                return null;
        }
    }
    updateProfiler(iContext, index, keyParams, indexDefinition);
    return cursor;
}
Also used : OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndexCursorCollectionValue(com.orientechnologies.orient.core.index.OIndexCursorCollectionValue) OIndexCursorSingleValue(com.orientechnologies.orient.core.index.OIndexCursorSingleValue) OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) OIndexDefinitionMultiValue(com.orientechnologies.orient.core.index.OIndexDefinitionMultiValue) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Aggregations

OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)68 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)29 OCompositeIndexDefinition (com.orientechnologies.orient.core.index.OCompositeIndexDefinition)26 OIndex (com.orientechnologies.orient.core.index.OIndex)26 Test (org.testng.annotations.Test)25 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)18 OPropertyMapIndexDefinition (com.orientechnologies.orient.core.index.OPropertyMapIndexDefinition)13 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)8 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)7 OIndexDefinitionMultiValue (com.orientechnologies.orient.core.index.OIndexDefinitionMultiValue)6 OIndexUnique (com.orientechnologies.orient.core.index.OIndexUnique)6 OPropertyIndexDefinition (com.orientechnologies.orient.core.index.OPropertyIndexDefinition)6 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)5 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 OPropertyListIndexDefinition (com.orientechnologies.orient.core.index.OPropertyListIndexDefinition)4 OPropertyRidBagIndexDefinition (com.orientechnologies.orient.core.index.OPropertyRidBagIndexDefinition)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)4 HashSet (java.util.HashSet)4 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)3 OSystemException (com.orientechnologies.common.exception.OSystemException)3