use of com.orientechnologies.orient.core.index.OIndexCursorSingleValue 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;
}
use of com.orientechnologies.orient.core.index.OIndexCursorSingleValue 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;
}
use of com.orientechnologies.orient.core.index.OIndexCursorSingleValue 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;
}
Aggregations