/** * {@inheritDoc} */ public OIndexDefinition getDefinition() { return lastIndex.getDefinition(); }
private boolean isIndexByKey(OIndex<?> index, String field) { OIndexDefinition def = index.getDefinition(); for (String o : def.getFieldsToIndex()) { if (o.equalsIgnoreCase(field + " by key")) { return true; } } return false; }
public int compare(OIndex<?> o1, OIndex<?> o2) { return o1.getDefinition().getParamCount() - o2.getDefinition().getParamCount(); } });
private boolean isIndexByValue(OIndex<?> index, String field) { OIndexDefinition def = index.getDefinition(); for (String o : def.getFieldsToIndex()) { if (o.equalsIgnoreCase(field + " by value")) { return true; } } return false; }
public OIndex<?> getClassIndex(String className, String indexName) { final Locale locale = getServerLocale(); className = className.toLowerCase(locale); final OIndex<?> index = indexes.get(indexName); if (index != null && index.getDefinition() != null && index.getDefinition().getClassName() != null && className .equals(index.getDefinition().getClassName().toLowerCase(locale))) return preProcessBeforeReturn(getDatabase(), index); return null; }
@Override public OIndex<?> getClassAutoShardingIndex(String className) { final Locale locale = getServerLocale(); className = className.toLowerCase(locale); // LOOK FOR INDEX for (OIndex<?> index : indexes.values()) { if (index != null && OAutoShardingIndexFactory.AUTOSHARDING_ALGORITHM.equals(index.getAlgorithm()) && index.getDefinition() != null && index.getDefinition().getClassName() != null && className .equals(index.getDefinition().getClassName().toLowerCase(locale))) return preProcessBeforeReturn(getDatabase(), index); } return null; }
public Set<String> getIndexedKeys(String className) { Iterator<OIndex<?>> indexes = getIndexManager().getClassIndexes(className).iterator(); HashSet<String> indexedKeys = new HashSet<>(); indexes.forEachRemaining(index -> { index.getDefinition().getFields().forEach(indexedKeys::add); }); return indexedKeys; }
private static Dependency[] getIndexFieldRidDependencies(OIndex<?> index) { final OIndexDefinition definition = index.getDefinition(); if (definition == null) // type for untyped index is still not resolved return null; final OType[] types = definition.getTypes(); final Dependency[] dependencies = new Dependency[types.length]; for (int i = 0; i < types.length; ++i) dependencies[i] = getTypeRidDependency(types[i]); return dependencies; }
/** * Drops index. * * @param db database object */ public void dropIndex(final ODatabaseObject db) { final String name = index.getName(); logger.info("Dropping existing index '{}' (class '{}'), because of definition mismatch", name, index.getDefinition().getClassName()); SchemeUtils.dropIndex(db, name); }
public boolean isIndexChain(OCommandContext ctx, OClass clazz) { if (suffix != null && suffix.isBaseIdentifier()) { OProperty prop = clazz.getProperty(suffix.identifier.getStringValue()); if (prop == null) { return false; } Collection<OIndex<?>> allIndexes = prop.getAllIndexes(); return allIndexes != null && allIndexes.stream().anyMatch(idx -> idx.getDefinition().getFields().size() == 1); } return false; } }
@Override protected void handleObject(OIndex<?> object) { indexName = object.getName(); OIndexDefinition indexDefinition = object.getDefinition(); if(indexDefinition!=null) { String className = indexDefinition.getClassName(); if(className!=null) classModel = new OClassModel(className); } }
private void checkIndex(OIndex index) { List<String> fields = index.getDefinition().getFields(); String className = index.getDefinition().getClassName(); OClass clazz = database.getMetadata().getSchema().getClass(className); int[] clusterIds = clazz.getPolymorphicClusterIds(); for (int clusterId : clusterIds) { checkCluster(clusterId, index, fields); } }
private List<OIndex<?>> relatedIndexes(final String fieldName) { final List<OIndex<?>> result = new ArrayList<OIndex<?>>(); final ODatabaseDocument database = getDatabase(); for (final OIndex<?> oIndex : database.getMetadata().getIndexManager().getClassIndexes(className)) { if (OCollections.indexOf(oIndex.getDefinition().getFields(), fieldName, new OCaseInsentiveComparator()) > -1) { result.add(oIndex); } } return result; }
@Override protected OIndex<?> createInstance(OIndex proxy) { OSchema schema = OrientDbWebSession.get().getDatabase().getMetadata().getSchema(); OClass oClass = schema.getClass(proxy.getDefinition().getClassName()); String name = proxy.getName(); List<String> fields = proxy.getDefinition().getFields(); String type = proxy.getType(); if(name==null) name=oClass.getName()+"."+fields.get(0); ODocument metadata = proxy.getMetadata(); String algorithm = proxy.getAlgorithm(); values.keySet().retainAll(RW_ATTRS); return oClass.createIndex(name, type, null, metadata, algorithm, fields.toArray(new String[0])); }
private List<OIndex<?>> relatedIndexes(final String fieldName, ODatabase database) { final List<OIndex<?>> result = new ArrayList<OIndex<?>>(); for (final OIndex<?> oIndex : database.getMetadata().getIndexManager().getClassIndexes(className.getStringValue())) { if (OCollections.indexOf(oIndex.getDefinition().getFields(), fieldName, new OCaseInsentiveComparator()) > -1) { result.add(oIndex); } } return result; }
private static void deleteIndexKey(final OIndex<?> index, final ODocument iRecord, final Object origValue, List<IndexChange> changes) { final OIndexDefinition indexDefinition = index.getDefinition(); if (origValue instanceof Collection) { for (final Object valueItem : (Collection<?>) origValue) { if (!indexDefinition.isNullValuesIgnored() || valueItem != null) addRemove(changes, index, valueItem, iRecord); } } else if (!indexDefinition.isNullValuesIgnored() || origValue != null) { addRemove(changes, index, origValue, iRecord); } }
private OEdge getExistingEdge(OVertex currentFrom, OVertex currentTo) { Object key = uniqueIndex.getDefinition().createValue(currentFrom.getIdentity(), currentTo.getIdentity()); Object result = uniqueIndex.get(key); if (result instanceof ORID) { result = ((ORID) result).getRecord(); } if (result instanceof OElement) { return ((OElement) result).asEdge().get(); } return null; }
private void processBinaryCondition() { OIndexDefinition definition = index.getDefinition(); OBinaryCompareOperator operator = ((OBinaryCondition) condition).getOperator(); OExpression left = ((OBinaryCondition) condition).getLeft(); if (!left.toString().equalsIgnoreCase("key")) { throw new OCommandExecutionException("search for index for " + condition + " is not supported yet"); } Object rightValue = ((OBinaryCondition) condition).getRight().execute((OResult) null, ctx); cursor = createCursor(operator, definition, rightValue, ctx); }
private static void addIndexEntry(ODocument document, OIdentifiable rid, OIndex<?> index, List<IndexChange> changes) { final OIndexDefinition indexDefinition = index.getDefinition(); final Object key = indexDefinition.getDocumentValueToIndex(document); if (key instanceof Collection) { for (final Object keyItem : (Collection<?>) key) if (!indexDefinition.isNullValuesIgnored() || keyItem != null) addPut(changes, index, keyItem, rid); } else if (!indexDefinition.isNullValuesIgnored() || key != null) addPut(changes, index, key, rid); }
protected void checkForKeyType(final Object iKey) { if (delegate.getDefinition() == null) { // RECOGNIZE THE KEY TYPE AT RUN-TIME final OType type = OType.getTypeByClass(iKey.getClass()); if (type == null) return; OIndexManager indexManager = ODatabaseRecordThreadLocal.instance().get().getMetadata().getIndexManager(); getInternal().setType(type); indexManager.save(); } }