use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.
the class SQLCreateIndexTest method testCreateEmbeddedMapIndex.
@Test
public void testCreateEmbeddedMapIndex() throws Exception {
database.command(new OCommandSQL("CREATE INDEX sqlCreateIndexEmbeddedMapIndex ON sqlCreateIndexTestClass (prop3) UNIQUE")).execute();
database.getMetadata().getIndexManager().reload();
final OIndex<?> index = database.getMetadata().getSchema().getClass("sqlCreateIndexTestClass").getClassIndex("sqlCreateIndexEmbeddedMapIndex");
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 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;
}
use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.
the class OQueryOperatorBetween 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() || !internalIndex.hasRangeQuerySupport())
return null;
if (indexDefinition.getParamCount() == 1) {
final Object[] betweenKeys = (Object[]) keyParams.get(0);
final Object keyOne = indexDefinition.createValue(Collections.singletonList(OSQLHelper.getValue(betweenKeys[0])));
final Object keyTwo = indexDefinition.createValue(Collections.singletonList(OSQLHelper.getValue(betweenKeys[2])));
if (keyOne == null || keyTwo == null)
return null;
cursor = index.iterateEntriesBetween(keyOne, leftInclusive, keyTwo, rightInclusive, ascSortOrder);
} else {
final OCompositeIndexDefinition compositeIndexDefinition = (OCompositeIndexDefinition) indexDefinition;
final Object[] betweenKeys = (Object[]) keyParams.get(keyParams.size() - 1);
final Object betweenKeyOne = OSQLHelper.getValue(betweenKeys[0]);
if (betweenKeyOne == null)
return null;
final Object betweenKeyTwo = OSQLHelper.getValue(betweenKeys[2]);
if (betweenKeyTwo == null)
return null;
final List<Object> betweenKeyOneParams = new ArrayList<Object>(keyParams.size());
betweenKeyOneParams.addAll(keyParams.subList(0, keyParams.size() - 1));
betweenKeyOneParams.add(betweenKeyOne);
final List<Object> betweenKeyTwoParams = new ArrayList<Object>(keyParams.size());
betweenKeyTwoParams.addAll(keyParams.subList(0, keyParams.size() - 1));
betweenKeyTwoParams.add(betweenKeyTwo);
final Object keyOne = compositeIndexDefinition.createSingleValue(betweenKeyOneParams);
if (keyOne == null)
return null;
final Object keyTwo = compositeIndexDefinition.createSingleValue(betweenKeyTwoParams);
if (keyTwo == null)
return null;
cursor = index.iterateEntriesBetween(keyOne, leftInclusive, keyTwo, rightInclusive, ascSortOrder);
}
updateProfiler(iContext, index, keyParams, indexDefinition);
return cursor;
}
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;
}
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;
}
Aggregations