@Override public Status insert(String table, String key, Map<String, ByteIterator> values) { try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODocument document = new ODocument(CLASS); for (Map.Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) { document.field(entry.getKey(), entry.getValue()); } document.save(); final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); dictionary.put(key, document); return Status.OK; } catch (Exception e) { e.printStackTrace(); } return Status.ERROR; }
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; }
@Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); final ODocument document = dictionary.get(key); if (document != null) { if (fields != null) { for (String field : fields) { result.put(field, new StringByteIterator((String) document.field(field))); } } else { for (String field : document.fieldNames()) { result.put(field, new StringByteIterator((String) document.field(field))); } } return Status.OK; } } catch (Exception e) { e.printStackTrace(); } return Status.ERROR; }
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)
public OIndex build(final ODatabaseDocumentTx db) { checkState(!propertyNames.isEmpty(), "At least one property is required"); checkState(propertyTypes.size() == propertyNames.size(), "A type must be defined for each property"); List<OCollate> collates = null; if (caseInsensitive) { collates = Lists.transform(propertyNames, n -> new OCaseInsensitiveCollate()); } ODocument metadata = new ODocument(); if (ignoreNullValues) { metadata.field("ignoreNullValues", true); } OIndexDefinition indexDefinition = OIndexDefinitionFactory.createIndexDefinition(type, propertyNames, propertyTypes, collates, indexType.name(), null); return db.getMetadata().getIndexManager().createIndex(name, indexType.name(), indexDefinition, type.getPolymorphicClusterIds(), null, metadata.fields() > 0 ? metadata : null); } }
switch (dbType) { case DOCUMENT: documentDatabase = new ODatabaseDocumentTx(dbURL); documentDatabase.open(dbUser, dbPassword); break; schemaClass = getOrCreateClass((String) cls.field("name"), (String) cls.field("extends")); Integer clusters = cls.field("clusters"); if (clusters != null) OClassImpl.addClusters(schemaClass, clusters); String idxName = (String) resolve(idx.field("name")); if (idxName != null) { index = documentDatabase.getMetadata().getIndexManager().getIndex(idxName); if (index != null) index = documentDatabase.getMetadata().getIndexManager().getIndex(idxName); if (index != null)
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 void createComponentIndex(final ODatabaseDocumentTx db, final OClass type) { if (db.getMetadata().getIndexManager().getIndex(I_COMPONENT) == null) { type.createIndex(I_COMPONENT, INDEX_TYPE.NOTUNIQUE, AssetEntityAdapter.P_COMPONENT); } }
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); }
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);
public Iterable<Vertex> getVertices(final String iKey, Object iValue) { if (iKey.equals("@class")) return getVerticesOfClass(iValue.toString()); final String indexName; final String key; int pos = iKey.indexOf('.'); if (pos > -1) { indexName = iKey; key = iKey.substring(iKey.indexOf('.') + 1); } else { indexName = OrientVertex.CLASS_NAME + "." + iKey; key = iKey; } final OIndex<?> idx = getContext(true).rawGraph.getMetadata() .getIndexManager().getIndex(indexName); if (idx != null) { iValue = convertKey(idx, iValue); Object indexValue = idx.get(iValue); if (indexValue != null && !(indexValue instanceof Iterable<?>)) indexValue = Arrays.asList(indexValue); return new OrientElementIterable<Vertex>(this, (Iterable<?>) indexValue); } // NO INDEX: EXECUTE A QUERY return query().has(key, iValue).vertices(); }
private void createBucketNameIndex() { try (ODatabaseDocumentTx db = componentDatabaseInstance.get().connect()) { if (db.getMetadata().getIndexManager().getIndex(I_BUCKET_NAME_VERSION) == null) { OSchema schema = db.getMetadata().getSchema(); OClass type = schema.getClass(COMPONENT_CLASS); if (type != null) { type.createIndex(I_BUCKET_NAME_VERSION, INDEX_TYPE.NOTUNIQUE, new String[] { P_BUCKET, P_NAME, P_VERSION }); } } } } }
public <T extends Element> Set<String> getIndexedKeys( final Class<T> elementClass) { final OSchema schema = getRawGraph().getMetadata().getSchema(); final String elementOClassName = getClassName(elementClass); Set<String> result = new HashSet<String>(); final Collection<? extends OIndex<?>> indexes = getRawGraph() .getMetadata().getIndexManager().getIndexes(); for (OIndex<?> index : indexes) { String indexName = index.getName(); int point = indexName.indexOf("."); if (point > 0) { String oClassName = indexName.substring(0, point); OClass oClass = schema.getClass(oClassName); if (oClass.isSubClassOf(elementOClassName)) result.add(index.getDefinition().getFields().get(0)); } } return result; }
@Override public Status delete(String table, String key) { while (true) { try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); dictionary.remove(key); return Status.OK; } catch (OConcurrentModificationException cme) { continue; } catch (Exception e) { e.printStackTrace(); return Status.ERROR; } } }
@Override public void onDrop(final ODatabaseInternal iDatabase) { OLogManager.instance().info(this, "Dropping Lucene indexes..."); for (OIndex idx : iDatabase.getMetadata().getIndexManager().getIndexes()) { if (idx.getInternal() instanceof OLuceneIndex) { OLogManager.instance().info(this, "- index '%s'", idx.getName()); idx.delete(); } } }
final OSchema schema = db.getMetadata().getSchema(); keyType = property.getType(); db.getMetadata() .getIndexManager() .createIndex(className + "." + key, indexType, new OPropertyIndexDefinition(className, key, keyType), cls.getPolymorphicClusterIds(), null);
@Override protected OIndex<?> doBackward(String b) { return OrientDbWebSession.get().getDatabase().getMetadata().getIndexManager().getIndex(b); }
@Override public void onUpdate(OrienteerWebApplication app, ODatabaseDocument db, int oldVersion, int newVersion) { int toVersion = oldVersion+1; switch (toVersion) { case 2: convertNameProperty(app, db, OCLASS_PERSPECTIVE); convertNameProperty(app, db, OCLASS_ITEM); break; case 3: onInstall(app, db); break; case 4: OIndex<?> index = db.getMetadata().getIndexManager().getIndex(OCLASS_PERSPECTIVE + ".name"); if(index!=null) index.delete(); onInstall(app, db); break; case 5: OSchemaHelper.bind(db) .oClass(OIdentity.CLASS_NAME) .oProperty("perspective", OType.LINK).linkedClass(OCLASS_PERSPECTIVE); break; default: break; } if(toVersion<newVersion) onUpdate(app, db, toVersion, newVersion); }
/** * {@inheritDoc} */ public ODictionary<ORecord> getDictionary() { checkOpenness(); return metadata.getIndexManager().getDictionary(); }