public boolean isAutomatic() { return indexDefinition != null && indexDefinition.getClassName() != null; }
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; }
public boolean isAutomatic() { acquireSharedLock(); try { return indexDefinition != null && indexDefinition.getClassName() != null; } finally { releaseSharedLock(); } }
@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; }
private boolean canCheck(OIndex index) { OIndexDefinition indexDef = index.getDefinition(); String className = indexDef.getClassName(); if (className == null) { return false; //manual index, not supported yet } List<String> fields = indexDef.getFields(); List<String> fieldDefs = indexDef.getFieldsToIndex(); //check if there are fields defined on maps (by key/value). Not supported yet for (int i = 0; i < fieldDefs.size(); i++) { if (!fields.get(i).equals(fieldDefs.get(i))) { return false; } } return true; }
/** * Checks if existing index consists of exactly the same fields. If not, error thrown to indicate * probable programmer error. * * @param fields new signature index fields */ public void checkFieldsCompatible(final String... fields) { final Set<String> indexFields = Sets.newHashSet(index.getDefinition().getFields()); final Joiner joiner = Joiner.on(","); check(indexFields.equals(Sets.newHashSet(fields)), "Existing index '%s' (class '%s') fields '%s' are different from '%s'.", index.getName(), index.getDefinition().getClassName(), joiner.join(indexFields), joiner.join(fields)); }
/** * 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); }
@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); } }
/** * Checks that current index type is equal to one of provided types. * If not, exception thrown. Type check is important for fulltext and lucene indexes because, * most likely, if existing index type is different from that specific index type then index name was set * by mistake and to avoid replacing existing index error should be thrown (programmer mistake). * * @param types allowed index types */ public void checkTypeCompatible(final OClass.INDEX_TYPE... types) { final Set<String> allowed = Sets.newHashSet(Iterables.transform(Arrays.asList(types), new Function<OClass.INDEX_TYPE, String>() { @Nonnull @Override public String apply(@Nonnull final OClass.INDEX_TYPE input) { return input.name(); } })); check(allowed.contains(index.getType()), "Existing index '%s' (class '%s') type '%s' is incompatible with '%s'. " + "Either drop existing index or rename index.", index.getName(), index.getDefinition().getClassName(), index.getType(), Joiner.on(',').join(allowed)); }
@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); } }
if (indexDefinition == null || indexDefinition.getClassName() == null) return; Map<OMultiKey, Set<OIndex<?>>> propertyIndex = getIndexOnProperty(indexDefinition.getClassName()); classPropertyIndex.put(indexDefinition.getClassName().toLowerCase(locale), copyPropertyMap(propertyIndex)); } finally { releaseExclusiveLock();
doc.add(createField(RID, value.getIdentity().toString(), Field.Store.YES)); doc.add(createField("_CLUSTER", "" + value.getIdentity().getClusterId(), Field.Store.YES)); doc.add(createField("_CLASS", definition.getClassName(), Field.Store.YES)); createFields(definition.getClassName() + "." + field, val, Field.Store.YES) .forEach(f -> doc.add(f));
public OLuceneClassIndexContext(OSchema schema, OIndexDefinition definition, String name, boolean automatic, ODocument metadata) { this.definition = definition; this.name = name; this.automatic = automatic; this.metadata = metadata; OLogManager.instance().info(this, "index definition:: " + definition); indexClass = schema.getClass(definition.getClassName()); updateFieldToStore(definition); }
private void checkCollectionIndex(OIndexDefinition indexDefinition) { List<String> fields = indexDefinition.getFields(); OClass aClass = getDatabase().getMetadata().getSchema().getClass(indexDefinition.getClassName()); for (String field : fields) { OProperty property = aClass.getProperty(field); if (property.getType().isEmbedded() && property.getLinkedType() != null) { collectionFields.put(field, true); } else { collectionFields.put(field, false); } } }
private void checkCollectionIndex(OIndexDefinition indexDefinition) { List<String> fields = indexDefinition.getFields(); OClass aClass = getDatabase().getMetadata().getSchema().getClass(indexDefinition.getClassName()); for (String field : fields) { OProperty property = aClass.getProperty(field); if (property.getType().isEmbedded() && property.getLinkedType() != null) { collectionFields.put(field, true); } else { collectionFields.put(field, false); } } }
@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])); }
@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])); }
protected Set<String> getInvolvedClustersOfIndex(final String iIndexName) { final ODatabaseDocumentInternal db = getDatabase(); final Set<String> clusters = new HashSet<String>(); final OMetadataInternal metadata = (OMetadataInternal) db.getMetadata(); final OIndex<?> idx = metadata.getIndexManager().getIndex(iIndexName); if (idx != null && idx.getDefinition() != null) { final String clazz = idx.getDefinition().getClassName(); if (clazz != null) { final OClass cls = metadata.getImmutableSchemaSnapshot().getClass(clazz); if (cls != null) for (int clId : cls.getClusterIds()) { final String clName = db.getClusterNameById(clId); if (clName != null) clusters.add(clName.toLowerCase(Locale.ENGLISH)); } } } return clusters; }
public SpatialStrategy createStrategy(SpatialContext ctx, ODatabaseDocumentInternal db, OIndexDefinition indexDefinition, ODocument metadata) { OClass aClass = db.getMetadata().getSchema().getClass(indexDefinition.getClassName()); OProperty property = aClass.getProperty(indexDefinition.getFields().get(0)); OClass linkedClass = property.getLinkedClass(); if ("OPoint".equalsIgnoreCase(linkedClass.getName())) { RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(new GeohashPrefixTree(ctx, 11), "location"); strategy.setDistErrPct(0); return strategy; } return BBoxStrategy.newInstance(ctx, "location"); } }
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); } }