@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 ODocument getODocumentByHostId(OrientGraph graph, String index, String host, String id) { ODocument doc = null; OIndex<?> hostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex(index); // this is a unique index, so it retrieves a OIdentifiable OCompositeKey key = new OCompositeKey(host, id); OIdentifiable oid = (OIdentifiable) hostIdIdx.get(key); if (oid != null) { doc = (ODocument)oid.getRecord(); } return doc; }
private boolean hasIndexClass(OIndex<?> idx) { final ODocument metadata = idx.getMetadata(); return (metadata != null && metadata.field(OrientIndex.CONFIG_CLASSNAME) != null) // compatibility with versions earlier 1.6.3 || idx.getConfiguration().field(OrientIndex.CONFIG_CLASSNAME) != null; }
/** * 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); }
OProperty property = newClass.createProperty("name", OType.STRING); OIndex<?> newIndex = OIndexPrototyper.newPrototype("NewClass", Arrays.asList("name")); assertTrue(property.getAllIndexes().size()==0); PropertyResolver.setValue("type", newIndex, "notunique", null); assertNotNull(newIndex.getDefinition()); assertTrue(newIndex.getDefinition().getFields().contains("name")); assertTrue(newIndex instanceof IPrototype); OIndex<?> realizedNewIndex = ((IPrototype<OIndex<?>>)newIndex).realizePrototype(); assertEquals(1, property.getAllIndexes().size()); assertEquals(1, newClass.getIndexes().size()); property = newClass.createProperty("description", OType.STRING); newIndex = OIndexPrototyper.newPrototype("NewClass", Arrays.asList("description")); PropertyResolver.setValue("type", newIndex, "notunique", null); assertEquals(0, property.getAllIndexes().size()); PropertyResolver.setValue("algorithm", newIndex, ODefaultIndexFactory.SBTREE_ALGORITHM, null); ODocument metadata = new ODocument(); metadata.field("test", "test123", OType.STRING); PropertyResolver.setValue("metadata", newIndex, metadata, null); realizedNewIndex = ((IPrototype<OIndex<?>>)newIndex).realizePrototype(); assertEquals(1, property.getAllIndexes().size()); assertEquals(2, newClass.getIndexes().size()); assertEquals("test123", realizedNewIndex.getMetadata().field("test")); wicket.getTester().getSchema().dropClass(newClass.getName());
private void updateMavenIndexFileAssetKind() { List<String> mavenRepositoryNames; try (ODatabaseDocumentTx db = configDatabaseInstance.get().connect()) { mavenRepositoryNames = db.<List<ODocument>>query(new OSQLSynchQuery<ODocument>(SELECT_MAVEN_REPOSITORIES)).stream() .map(d -> (String)d.field(P_REPOSITORY_NAME)) .collect(Collectors.toList()); } if (!mavenRepositoryNames.isEmpty()) { OCommandSQL updateAssetCommand = new OCommandSQL(UPDATE_ASSET_KIND); try (ODatabaseDocumentTx db = componentDatabaseInstance.get().connect()) { OIndex<?> bucketIdx = db.getMetadata().getIndexManager().getIndex(I_REPOSITORY_NAME); mavenRepositoryNames.forEach(repositoryName -> { log.info("Scanning maven2 repository {} for maven index file assets", repositoryName); OIdentifiable bucket = (OIdentifiable) bucketIdx.get(repositoryName); if (bucket == null) { log.warn("Unable to find bucket for {}", repositoryName); } else { int updates = db.command(updateAssetCommand).execute(bucket.getIdentity()); if (updates > 0) { log.info( "Updated {} maven index file asset(s) in repository {}: " + "set attributes.maven2.asset_kind='REPOSITORY_INDEX'", updates, repositoryName); } } }); } } } }
context.rawGraph = new ODatabaseDocumentTx(url); if (url.startsWith("remote:") || context.rawGraph.exists()) { context.rawGraph.open(username, password); for (OIndex<?> idx : context.rawGraph.getMetadata() .getIndexManager().getIndexes()) { if (idx.getConfiguration().field( OrientIndex.CONFIG_CLASSNAME) != null)
long totalRecords = 0; final List<OIndex<?>> indexes = new ArrayList<OIndex<?>>(currentDatabase.getMetadata().getIndexManager().getIndexes()); Collections.sort(indexes, new Comparator<OIndex<?>>() { public int compare(OIndex<?> o1, OIndex<?> o2) { final ODocument row = new ODocument(); resultSet.add(row); final long indexSize = index.getKeySize(); totalIndexedRecords += indexSize; row.field("NAME", index.getName()); row.field("TYPE", index.getType()); row.field("RECORDS", indexSize); final OIndexDefinition indexDefinition = index.getDefinition(); final long size = index.getKeySize(); if (indexDefinition != null) { row.field("CLASS", indexDefinition.getClassName());
private void create(final String indexName, final Class<? extends Element> indexClass, OType iKeyType) { this.indexClass = indexClass; if (iKeyType == null) iKeyType = OType.STRING; final OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY.toString(), null); this.recordKeyValueIndex = new OIndexTxAwareOneValue(graph.getRawGraph(), (OIndex<OIdentifiable>) graph .getRawGraph() .getMetadata() .getIndexManager() .createIndex("__@recordmap@___" + indexName, OClass.INDEX_TYPE.DICTIONARY.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.LINK, OType.STRING), null, null, null)); final String className; if (Vertex.class.isAssignableFrom(indexClass)) className = VERTEX; else if (Edge.class.isAssignableFrom(indexClass)) className = EDGE; else className = indexClass.getName(); final ODocument metadata = new ODocument(); metadata.field(CONFIG_CLASSNAME, className); metadata.field(CONFIG_RECORD_MAP_NAME, recordKeyValueIndex.getName()); final OIndexFactory nuFactory = OIndexes.getFactory(OClass.INDEX_TYPE.NOTUNIQUE.toString(), null); // CREATE THE MAP this.underlying = new OIndexTxAwareMultiValue(graph.getRawGraph(), (OIndex<Collection<OIdentifiable>>) graph .getRawGraph() .getMetadata() .getIndexManager() .createIndex(indexName, OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OSimpleKeyIndexDefinition(nuFactory.getLastVersion(), iKeyType), null, null, metadata)); }
private void updateIndexEntries(ODocument iDocument) { iDocument = checkForLoading(iDocument); final OClass cls = iDocument.getSchemaClass(); if (cls == null) return; final Collection<OIndex<?>> indexes = (Collection<OIndex<?>>) getDatabase().getMetadata().getIndexManager().getIndexes(); if (!indexes.isEmpty()) { final Set<String> dirtyFields = new HashSet<String>(Arrays.asList(iDocument.getDirtyFields())); if (!dirtyFields.isEmpty()) { for (final OIndex<?> index : indexes) { if (index.getInternal() instanceof OLuceneIndex && index.getConfiguration().field("metadata") != null) { if (index.getDefinition() instanceof OCompositeIndexDefinition) processCompositeIndexUpdate(index, dirtyFields, iDocument); else processSingleIndexUpdate(index, dirtyFields, iDocument); if (iDocument.isTrackingChanges()) { iDocument.setTrackingChanges(false); iDocument.setTrackingChanges(true); } } } } } }
private OIndex<?> buildKeyValueIndex(final ODocument metadata) { final OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY.toString(), null); final OIndex<?> recordKeyValueIndex = new OIndexTxAwareOneValue(graph.getRawGraph(), (OIndex<OIdentifiable>) graph .getRawGraph() .getMetadata() .getIndexManager() .createIndex("__@recordmap@___" + underlying.getName(), OClass.INDEX_TYPE.DICTIONARY.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.LINK, OType.STRING), null, null, null)); final List<ODocument> entries = graph.getRawGraph().query( new OSQLSynchQuery<Object>("select from index:" + underlying.getName())); for (ODocument entry : entries) { final OIdentifiable rid = entry.field("rid"); if (rid != null) recordKeyValueIndex.put(new OCompositeKey(rid, entry.field("key")), rid); } metadata.field(CONFIG_RECORD_MAP_NAME, recordKeyValueIndex.getName()); return recordKeyValueIndex; }
if (index.getName().equals(ODatabaseImport.EXPORT_IMPORT_MAP_NAME)) continue; final String clsName = index.getDefinition() != null ? index.getDefinition().getClassName() : null; listener.onMessage("\n- Index " + index.getName() + "..."); writer.beginObject(2, true, null); writer.writeAttribute(3, true, "name", index.getName()); writer.writeAttribute(3, true, "type", index.getType()); if (index.getAlgorithm() != null) writer.writeAttribute(3, true, "algorithm", index.getAlgorithm()); if (!index.getClusters().isEmpty()) writer.writeAttribute(3, true, "clustersToIndex", index.getClusters()); if (index.getDefinition() != null) { writer.beginObject(4, true, "definition"); writer.writeAttribute(5, true, "defClass", index.getDefinition().getClass().getName()); writer.writeAttribute(5, true, "stream", index.getDefinition().toStream()); final ODocument metadata = index.getMetadata(); if (metadata != null) writer.writeAttribute(4, true, "metadata", metadata); final ODocument configuration = index.getConfiguration(); if (configuration.field("blueprintsIndexClass") != null) writer.writeAttribute(4, true, "blueprintsIndexClass", configuration.field("blueprintsIndexClass"));
@Override public void afterRegistration(final ODatabaseObject db, final SchemeDescriptor descriptor, final CompositeLuceneIndex annotation) { db.getMetadata().getIndexManager().reload(); final String name = Strings.emptyToNull(annotation.name().trim()); Preconditions.checkArgument(name != null, "Index name required"); final String model = descriptor.schemeClass; final OClass clazz = db.getMetadata().getSchema().getClass(model); final OIndex<?> classIndex = clazz.getClassIndex(name); final OClass.INDEX_TYPE type = OClass.INDEX_TYPE.FULLTEXT; final String[] fields = annotation.fields(); if (!descriptor.initialRegistration && classIndex != null) { final IndexValidationSupport support = new IndexValidationSupport(classIndex, logger); support.checkTypeCompatible(type); support.checkFieldsCompatible(fields); final boolean correct = support .isIndexSigns(classIndex.getConfiguration().field("algorithm"), getAnalyzer(classIndex)) .matchRequiredSigns(type, OLuceneIndexFactory.LUCENE_ALGORITHM, annotation.analyzer().getName()); if (!correct) { support.dropIndex(db); } else { // index ok return; } } final ODocument metadata = createMetadata(annotation); SchemeUtils.command(db, "create index %s on %s (%s) %s engine %s metadata %s", name, model, Joiner.on(',').join(fields), type.name(), OLuceneIndexFactory.LUCENE_ALGORITHM, metadata.toJSON()); logger.info("Lucene fulltext index '{}' ({} [{}]) created", name, model, Joiner.on(',').join(fields)); }
private static boolean supportNullValues(OIndex<?> index) { final ODocument metadata = index.getMetadata(); if (metadata == null) return false; final Boolean ignoreNullValues = metadata.field("ignoreNullValues"); return Boolean.FALSE.equals(ignoreNullValues); }
protected void removeElement(final T element) { graph.setCurrentGraphInThreadLocal(); graph.autoStartTransaction(); final OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>("select from index:" + recordKeyValueIndex.getName() + " where key between [" + element.getIdentity() + "] and [" + element.getIdentity() + "]"); final Collection<ODocument> entries = (Collection<ODocument>) graph.getRawGraph().query(query); for (ODocument entry : entries) { final OCompositeKey key = entry.field("key"); final List<Object> keys = key.getKeys(); underlying.remove(keys.get(1).toString(), element.getIdentity()); recordKeyValueIndex.remove(key, element.getIdentity()); } }
private void create(final String indexName, final Class<? extends Element> indexClass, OType iKeyType) { this.indexClass = indexClass; if (iKeyType == null) iKeyType = OType.STRING; // CREATE THE MAP this.underlying = new OIndexTxAwareMultiValue(graph.getRawGraph(), (OIndex<Collection<OIdentifiable>>) graph.getRawGraph() .getMetadata().getIndexManager() .createIndex(indexName, OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OSimpleKeyIndexDefinition(iKeyType), null, null)); final String className; if (Vertex.class.isAssignableFrom(indexClass)) className = VERTEX; else if (Edge.class.isAssignableFrom(indexClass)) className = EDGE; else className = indexClass.getName(); // CREATE THE CONFIGURATION FOR THE NEW INDEX underlying.getConfiguration().field(CONFIG_CLASSNAME, className); }
@Override public Object call(OrientBaseGraph g) { try { final OIndexManager indexManager = getRawGraph().getMetadata().getIndexManager(); final OIndex index = indexManager.getIndex(indexName); ODocument metadata = index.getConfiguration().field("metadata"); String recordMapIndexName = null; if (metadata != null) { recordMapIndexName = metadata.field(OrientIndex.CONFIG_RECORD_MAP_NAME); } indexManager.dropIndex(indexName); if (recordMapIndexName != null) getRawGraph().getMetadata().getIndexManager().dropIndex(recordMapIndexName); saveIndexConfiguration(); return null; } catch (Exception e) { g.rollback(); throw new RuntimeException(e.getMessage(), e); } } }, "drop index '", indexName, "'");
sqlQuery = new OSQLSynchQuery<ODocument>(lookup); else { index = pipeline.getDocumentDatabase().getMetadata().getIndexManager().getIndex(lookup); if (index == null) { log(OETLProcessor.LOG_LEVELS.DEBUG, "WARNING: index %s not found. Lookups could be really slow", lookup); final OType idxFieldType = index.getDefinition().getTypes()[0]; joinValue = OType.convert(joinValue, idxFieldType.getDefaultJavaType()); result = index.get(joinValue); } else { if (sqlQuery instanceof OSQLSynchQuery) ((OSQLSynchQuery) sqlQuery).resetPagination(); result = pipeline.getDocumentDatabase().query(sqlQuery, joinValue);
private void addIndexesEntries(ODocument document) { document = checkForLoading(document); // STORE THE RECORD IF NEW, OTHERWISE ITS RID final OIdentifiable rid = document.getIdentity().isPersistent() ? document.placeholder() : document; final OClass cls = document.getSchemaClass(); if (cls != null) { final Collection<OIndex<?>> indexes = cls.getIndexes(); for (final OIndex<?> index : indexes) { final Object key = index.getDefinition().getDocumentValueToIndex(document); // SAVE A COPY TO AVOID PROBLEM ON RECYCLING OF THE RECORD if (key instanceof Collection) { for (final Object keyItem : (Collection<?>) key) if (keyItem != null) index.put(keyItem, rid); } else if (key != null) index.put(key, rid); } } }
private static RecordType getRecordType(OClass oClass) { RecordType type = new RecordType(oClass.getName()); for (OProperty oProperty : oClass.properties()) { OType oType = oProperty.getType(); Class javaType = oType.getDefaultJavaType(); if (oType == OType.LINK) { javaType = RecordId.class; } FieldDefinition field = new FieldDefinition(oProperty.getName(), javaType); field.withNotNull(oProperty.isNotNull()); for (OIndex oIndex : oProperty.getAllIndexes()) { OIndexDefinition def = oIndex.getDefinition(); if (def.isAutomatic() && def.getFields().size() == 1) { boolean unique = oIndex.getType().equalsIgnoreCase(INDEX_TYPE.UNIQUE.name()); field.withIndexed(true).withUnique(unique); } } type.withField(field); } type.withStrict(oClass.isStrictMode()); OClass oSuperClass = oClass.getSuperClass(); if (oSuperClass != null) { type.withSuperType(getRecordType(oSuperClass)); } type.withAbstract(oClass.isAbstract()); return type; }