com.orientechnologies.orient.core.db.record.OIdentifiable Java Examples
The following examples show how to use
com.orientechnologies.orient.core.db.record.OIdentifiable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OLuceneIndexType.java From orientdb-lucene with Apache License 2.0 | 6 votes |
public static Query createDeleteQuery(OIdentifiable value, List<String> fields, Object key) { BooleanQuery booleanQuery = new BooleanQuery(); booleanQuery.add(new TermQuery(new Term(OLuceneIndexManagerAbstract.RID, value.toString())), BooleanClause.Occur.MUST); Map<String, String> values = new HashMap<String, String>(); // TODO Implementation of Composite keys with Collection if (key instanceof OCompositeKey) { } else { values.put(fields.iterator().next(), key.toString()); } for (String s : values.keySet()) { booleanQuery.add(new TermQuery(new Term(s + OLuceneIndexManagerAbstract.STORED, values.get(s))), BooleanClause.Occur.MUST); } return booleanQuery; }
Example #2
Source File: OIndexHighLander.java From divide with Apache License 2.0 | 6 votes |
public OIndexOneValue put(final Object iKey, final OIdentifiable iSingleValue) { acquireExclusiveLock(); try { checkForKeyType(iKey); final OIdentifiable value = super.get(iKey); if (value != null){ // DELETE THE PREVIOUS INDEXED RECORD value.getRecord().delete(); } super.put(iKey, iSingleValue); return this; } finally { releaseExclusiveLock(); } }
Example #3
Source File: OLuceneWithinOperator.java From orientdb-lucene with Apache License 2.0 | 6 votes |
@Override public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) { OIndexDefinition definition = index.getDefinition(); int idxSize = definition.getFields().size(); int paramsSize = keyParams.size(); OIndexCursor cursor; Object indexResult = index.get(new OSpatialCompositeKey(keyParams).setOperation(SpatialOperation.IsWithin)); if (indexResult == null || indexResult instanceof OIdentifiable) cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, new OSpatialCompositeKey(keyParams)); else cursor = new OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult).iterator(), new OSpatialCompositeKey( keyParams)); iContext.setVariable("$luceneIndex", true); return cursor; }
Example #4
Source File: LuceneResultSet.java From orientdb-lucene with Apache License 2.0 | 6 votes |
@Override public OIdentifiable next() { if (localIndex == array.length) { localIndex = 0; fetchMoreResult(); } final ScoreDoc score = array[localIndex++]; Document ret = null; OContextualRecordId res = null; try { ret = queryContext.searcher.doc(score.doc); String rId = ret.get(OLuceneIndexManagerAbstract.RID); res = new OContextualRecordId(rId); manager.onRecordAddedToResultSet(queryContext, res, ret, score); } catch (IOException e) { e.printStackTrace(); } index++; return res; }
Example #5
Source File: ContentExpressionFunctionTest.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Before public void setup() { when(variableResolverAdapterManager.get(FORMAT)).thenReturn(assetVariableResolver); when(assetVariableResolver.fromDocument(assetDocument)).thenReturn(variableSource); when(bucketDocument.getRecord()).thenReturn(bucketDocument); when(bucketDocument.field("repository_name", String.class)).thenReturn(REPOSITORY_NAME); when(bucketDocument.getIdentity()).thenReturn(mock(ORID.class)); when(assetDocument.getClassName()).thenReturn("asset"); when(assetDocument.getRecord()).thenReturn(assetDocument); when(assetDocument.field("bucket", OIdentifiable.class)).thenReturn(bucketDocument); when(assetDocument.field("name", String.class)).thenReturn(PATH); when(assetDocument.field("format", String.class)).thenReturn(FORMAT); when(commandRequest.execute(any(Map.class))).thenReturn(Collections.singletonList(assetDocument)); when(database.command(any(OCommandRequest.class))).thenReturn(commandRequest); when(selectorManager.newSelectorConfiguration()).thenAnswer(invocation -> new OrientSelectorConfiguration()); underTest = new ContentExpressionFunction(variableResolverAdapterManager, selectorManager, contentAuthHelper); }
Example #6
Source File: OAbstractETLComponent.java From orientdb-etl with Apache License 2.0 | 6 votes |
protected boolean skip(final Object input) { final OSQLFilter ifFilter = getIfFilter(); if (ifFilter != null) { final ODocument doc = input instanceof OIdentifiable ? (ODocument) ((OIdentifiable) input).getRecord() : null; log(OETLProcessor.LOG_LEVELS.DEBUG, "Evaluating conditional expression if=%s...", ifFilter); final Object result = ifFilter.evaluate(doc, null, context); if (!(result instanceof Boolean)) throw new OConfigurationException("'if' expression in Transformer " + getName() + " returned '" + result + "' instead of boolean"); return !(Boolean) result; } return false; }
Example #7
Source File: AssetStoreImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Override @Guarded(by = STARTED) public <T> List<Entry<T, EntityId>> getNextPage(final OIndexCursor cursor, final int limit) { List<Entry<T, EntityId>> page = new ArrayList<>(limit); // For reasons unknown Orient needs the connection despite the code not using it try (ODatabaseDocumentTx db = databaseInstance.get().acquire()) { cursor.setPrefetchSize(limit); while (page.size() < limit) { Entry<Object, OIdentifiable> entry = cursor.nextEntry(); if (entry == null) { break; } @SuppressWarnings("unchecked") T key = (T) entry.getKey(); EntityId value = new AttachedEntityId(entityAdapter, entry.getValue().getIdentity()); page.add(new SimpleEntry<>(key, value)); } } return page; }
Example #8
Source File: PerspectivesModule.java From Orienteer with Apache License 2.0 | 6 votes |
public ODocument getDefaultPerspective(ODatabaseDocument db, OSecurityUser user) { if (user != null) { if (user.getDocument().field(PROP_PERSPECTIVE) != null) { return ((OIdentifiable) user.getDocument().field(PROP_PERSPECTIVE)).getRecord(); } Set<? extends OSecurityRole> roles = user.getRoles(); for (OSecurityRole oRole : roles) { ODocument perspective = getPerspectiveForORole(oRole); if (perspective != null) { return perspective; } } } return getPerspectiveByAliasAsDocument(db, ALIAS_PERSPECTIVE_DEFAULT) // Restore default perspective if it was not found .orElseGet(() -> DBClosure.sudo((adminDb)->createDefaultPerspective(OSchemaHelper.bind(adminDb)))); }
Example #9
Source File: OLuceneIndexNotUnique.java From orientdb-lucene with Apache License 2.0 | 6 votes |
@Override public boolean remove(Object key, OIdentifiable value) { checkForRebuild(); key = getCollatingValue(key); modificationLock.requestModificationLock(); try { acquireExclusiveLock(); try { if (indexEngine instanceof OLuceneIndexEngine) { return ((OLuceneIndexEngine) indexEngine).remove(key, value); } else { return false; } } finally { releaseExclusiveLock(); } } finally { modificationLock.releaseModificationLock(); } }
Example #10
Source File: OLuceneFullTextIndexManager.java From orientdb-lucene with Apache License 2.0 | 6 votes |
protected Document build(OIndexDefinition definition, Object key, OIdentifiable value, ODocument metadata) { Document doc = new Document(); int i = 0; if (value != null) { doc.add(OLuceneIndexType.createField(OLuceneIndexManagerAbstract.RID, value.getIdentity().toString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS)); } List<Object> formattedKey = formatKeys(definition, key); for (String f : definition.getFields()) { Object val = formattedKey.get(i); i++; doc.add(OLuceneIndexType.createField(f, val, Field.Store.NO, Field.Index.ANALYZED)); } return doc; }
Example #11
Source File: OLuceneFullTextIndexManager.java From orientdb-lucene with Apache License 2.0 | 6 votes |
@Override public Map.Entry<Object, OIdentifiable> nextEntry() { if (iterator.hasNext()) { final OIdentifiable next = iterator.next(); return new Map.Entry<Object, OIdentifiable>() { @Override public Object getKey() { return key; } @Override public OIdentifiable getValue() { return next; } @Override public OIdentifiable setValue(OIdentifiable value) { return null; } }; } return null; }
Example #12
Source File: ComponentDatabaseUpgrade_1_10.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private void fixComponentBatch(final ODatabaseDocumentTx db, final OIdentifiable bucket) { log.debug("Processing batch of {} yum component records...", BATCH_SIZE); OSQLSynchQuery<Object> query = new OSQLSynchQuery<>(SELECT_COMPONENT_BATCH_SQL); List<ODocument> components = db.query(query, bucket, new ORecordId()); while (!components.isEmpty()) { ORID last = components.get(components.size() - 1).getIdentity(); for (ODocument component : components) { fixComponent(db, component, bucket); } components = db.query(query, bucket, last); } }
Example #13
Source File: Lower.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Override public Object execute(final Object iThis, final OIdentifiable iCurrentRecord, final Object iCurrentResult, final Object[] iParams, final OCommandContext iContext) { checkArgument(iParams.length == 1); final Object param = iParams[0]; if (param == null) { return null; } checkArgument(param instanceof String, "lower() parameter must be a string"); return ((String) param).toLowerCase(Locale.ENGLISH); }
Example #14
Source File: OLuceneTextOperator.java From orientdb-lucene with Apache License 2.0 | 6 votes |
protected OLuceneFullTextIndex involvedIndex(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft, Object iRight) { ODocument doc = iRecord.getRecord(); Set<OIndex<?>> classInvolvedIndexes = getDatabase().getMetadata().getIndexManager() .getClassInvolvedIndexes(doc.getClassName(), fields(iCondition)); OLuceneFullTextIndex idx = null; for (OIndex<?> classInvolvedIndex : classInvolvedIndexes) { if (classInvolvedIndex.getInternal() instanceof OLuceneFullTextIndex) { idx = (OLuceneFullTextIndex) classInvolvedIndex.getInternal(); break; } } return idx; }
Example #15
Source File: EntityAdapter.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Read entity from document. */ public T readEntity(final OIdentifiable identifiable) { ODocument document = identifiable.getRecord(); // no-op if it's already a document checkNotNull(document); T entity = newEntity(); if (!partialLoading) { document.deserializeFields(); } try { readFields(document, entity); } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } attachMetadata(entity, document); return entity; }
Example #16
Source File: OLuceneSpatialIndexManager.java From orientdb-lucene with Apache License 2.0 | 6 votes |
private Document newGeoDocument(OIdentifiable oIdentifiable, Shape shape) { FieldType ft = new FieldType(); ft.setIndexed(true); ft.setStored(true); Document doc = new Document(); doc.add(OLuceneIndexType.createField(RID, oIdentifiable.getIdentity().toString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS)); for (IndexableField f : strategy.createIndexableFields(shape)) { doc.add(f); } doc.add(new StoredField(strategy.getFieldName(), ctx.toString(shape))); return doc; }
Example #17
Source File: OMergeTransformer.java From orientdb-etl with Apache License 2.0 | 5 votes |
@Override public Object executeTransform(final Object input) { Object joinValue = ((ODocument) ((OIdentifiable) input).getRecord()).field(joinFieldName); final Object result = lookup(joinValue, false); log(OETLProcessor.LOG_LEVELS.DEBUG, "joinValue=%s, lookupResult=%s", joinValue, result); if (result == null || OMultiValue.getSize(result) == 0) { // APPLY THE STRATEGY DEFINED IN unresolvedLinkAction switch (unresolvedLinkAction) { case NOTHING: break; case ERROR: processor.getStats().incrementErrors(); log(OETLProcessor.LOG_LEVELS.ERROR, "%s: ERROR Cannot resolve join for value '%s'", getName(), joinValue); break; case WARNING: processor.getStats().incrementWarnings(); log(OETLProcessor.LOG_LEVELS.INFO, "%s: WARN Cannot resolve join for value '%s'", getName(), joinValue); break; case SKIP: return null; case HALT: throw new OETLProcessHaltedException("[Merge transformer] Cannot resolve join for value '" + joinValue + "'"); } } else if (OMultiValue.getSize(result) > 1) throw new OETLProcessHaltedException("[Merge transformer] Multiple results returned from join for value '" + joinValue + "'"); else { final Object o = OMultiValue.getFirstValue(result); ((ODocument) o).merge((ODocument) ((OIdentifiable) input).getRecord(), true, false); log(OETLProcessor.LOG_LEVELS.DEBUG, "merged record %s with found record=%s", result, input); return o; } return input; }
Example #18
Source File: OClassIntrospector.java From Orienteer with Apache License 2.0 | 5 votes |
@Override public ODocument getParent(ODocument doc) { if(doc==null || doc.getSchemaClass()==null) return null; OClass oClass = doc.getSchemaClass(); OProperty parent = CustomAttribute.PROP_PARENT.getValue(oClass); if(parent!=null) { OType type = parent.getType(); Object value = doc.field(parent.getName()); if(value!=null) { switch (type) { case LINK: return ((OIdentifiable)value).getRecord(); case LINKLIST: case LINKBAG: case LINKSET: Collection<OIdentifiable> collection = (Collection<OIdentifiable>)value; return !collection.isEmpty()?(ODocument)collection.iterator().next().getRecord():null; case LINKMAP: Map<?, ?> map = (Map<?, ?>)value; value = map.isEmpty()?null:map.values().iterator().next(); return value instanceof OIdentifiable ? (ODocument)((OIdentifiable)value).getRecord():null; default: return null; } } } return null; }
Example #19
Source File: OrientDbWebApplication.java From wicket-orientdb with Apache License 2.0 | 5 votes |
@Override protected IConverterLocator newConverterLocator() { ConverterLocator locator = new ConverterLocator(); locator.set(OIdentifiable.class, new OIdentifiableConverter<OIdentifiable>()); locator.set(ODocument.class, new ODocumentConverter()); locator.set(byte[].class, new HexConverter()); return locator; }
Example #20
Source File: ODocumentNameModel.java From Orienteer with Apache License 2.0 | 5 votes |
@Override protected String load() { OIdentifiable id = documentModel!=null?documentModel.getObject():null; ORecord doc = id!=null?id.getRecord():null; return doc!=null && doc instanceof ODocument ?OrienteerWebApplication.get().getOClassIntrospector() .getDocumentName((ODocument)doc, namePropertyModel!=null?namePropertyModel.getObject():null) :null; }
Example #21
Source File: Concat.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public Object execute(final Object iThis, final OIdentifiable iCurrentRecord, final Object iCurrentResult, final Object[] iParams, final OCommandContext iContext) { StringBuilder b = new StringBuilder(); for (Object param : iParams) { b.append(param); } return b.toString(); }
Example #22
Source File: MavenUpgrade_1_1.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
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); } } }); } } }
Example #23
Source File: ComponentDatabaseUpgrade_1_10.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private void fixComponent(final ODatabaseDocumentTx db, final ODocument component, final OIdentifiable bucket) { String selectComponentAssetsSql = String.format(SELECT_COMPONENT_ASSETS_SQL, component.getIdentity()); List<ODocument> componentsAssets = db.query(new OSQLSynchQuery<>(selectComponentAssetsSql)); if (!componentsAssets.isEmpty()) { Map<String, String> formatAttributes = extractFormatAttributes(componentsAssets); if (formatAttributes != null && !formatAttributes.isEmpty()) { String name = formatAttributes.get("name"); String version = formatAttributes.get("version"); String release = formatAttributes.get("release"); String fullVersion = isNotBlank(release) ? version + "-" + release : version; //Skip if already correct if (component.field(P_NAME).equals(name) && component.field(P_VERSION).equals(fullVersion)) { return; } ODocument existingComponent = findComponent(db, name, fullVersion, bucket); if (existingComponent != null) { moveAssetsToComponent(componentsAssets, existingComponent); component.delete(); } else { component.field(P_NAME, name); component.field(P_VERSION, fullVersion); component.save(); } } else { log.warn("Unable to process Yum component because formatAttributes was null or empty. {}", component); } } }
Example #24
Source File: DynamicPropertyValueModel.java From wicket-orientdb with Apache License 2.0 | 5 votes |
@Override public void setObject(T object) { ODocument doc = docModel.getObject(); OProperty prop = propertyModel!=null?propertyModel.getObject():null; if(doc==null) return; if(prop==null) { if(object instanceof OIdentifiable) docModel.setObject((ODocument)object); } else { doc.field(prop.getName(), object); } super.setObject(object); }
Example #25
Source File: OrienteerUsersModule.java From Orienteer with Apache License 2.0 | 5 votes |
private ODocument updateAndGetUserReader(ODatabaseDocument db) { String sql = String.format("select from %s where name = ?", OUser.CLASS_NAME); List<ODocument> docs = db.query(new OSQLSynchQuery<>(sql, 1), "reader"); ODocument reader = docs.get(0); Set<OIdentifiable> users = reader.field(ORestrictedOperation.ALLOW_READ.getFieldName(), Set.class); if (users == null || users.isEmpty()) { reader.field(ORestrictedOperation.ALLOW_READ.getFieldName(), Collections.singleton(reader)); } else { users.add(reader); reader.field(ORestrictedOperation.ALLOW_READ.getFieldName(), users); } reader.save(); return reader; }
Example #26
Source File: ReferencesConsistencyHook.java From Orienteer with Apache License 2.0 | 5 votes |
@Override public void onRecordAfterCreate(ODocument doc) { if(enter(doc)) { try { OClass thisOClass = doc.getSchemaClass(); // if(thisOClass==null) return; Collection<OProperty> refProperties = getCache().get(doc.getSchemaClass()); for (OProperty oProperty : refProperties) { OProperty inverseProperty = CustomAttribute.PROP_INVERSE.getValue(oProperty); Object value = doc.field(oProperty.getName()); if(value instanceof OIdentifiable) value = Arrays.asList(value); if(inverseProperty!=null && value!=null && value instanceof Collection) { for(Object otherObj: (Collection<?>)value) { if(otherObj instanceof OIdentifiable) { ODocument otherDoc = ((OIdentifiable) otherObj).getRecord(); addLink(otherDoc, inverseProperty, doc); } } } } } catch (ExecutionException e) { LOG.error("Can't update reverse links onCreate", e); } finally { exit(doc); } } }
Example #27
Source File: GraphVerticesWidget.java From Orienteer with Apache License 2.0 | 5 votes |
@Override public String apply(ODocument vertex) { Object fieldIn = getModelObject().field("in"); String direction; if (fieldIn != null) { direction = ((OIdentifiable)fieldIn).getIdentity().equals(vertex.getIdentity()) ? "in":"out"; } else direction = "empty"; return getLocalizer().getString("widget.document.vertices.title." + direction, GraphVerticesWidget.this); }
Example #28
Source File: ReferencesConsistencyHook.java From Orienteer with Apache License 2.0 | 5 votes |
@Override public void onRecordAfterDelete(ODocument doc) { if(enter(doc)) { try { OClass thisOClass = doc.getSchemaClass(); // if(thisOClass==null) return; Collection<OProperty> refProperties = getCache().get(thisOClass); for (OProperty oProperty : refProperties) { OProperty inverseProperty = CustomAttribute.PROP_INVERSE.getValue(oProperty); Object value = doc.field(oProperty.getName()); if(value instanceof OIdentifiable) value = Arrays.asList(value); if(inverseProperty!=null && value!=null && value instanceof Collection) { for(Object otherObj: (Collection<?>)value) { if(otherObj instanceof OIdentifiable) { ODocument otherDoc = ((OIdentifiable) otherObj).getRecord(); removeLink(otherDoc, inverseProperty, doc); } } } } } catch (ExecutionException e) { LOG.error("Can't update reverse links onDelete", e); } finally { exit(doc); } } }
Example #29
Source File: OLuceneSpatialIndexManager.java From orientdb-lucene with Apache License 2.0 | 5 votes |
@Override public void put(Object key, Object value) { OCompositeKey compositeKey = (OCompositeKey) key; if (key instanceof OCompositeKey) { } Set<OIdentifiable> container = (Set<OIdentifiable>) value; for (OIdentifiable oIdentifiable : container) { addDocument(newGeoDocument(oIdentifiable, factory.makeShape(compositeKey, ctx))); } }
Example #30
Source File: OLuceneSpatialIndexManager.java From orientdb-lucene with Apache License 2.0 | 5 votes |
public Object searchWithin(OSpatialCompositeKey key, OCommandContext context) throws IOException { Set<OIdentifiable> result = new HashSet<OIdentifiable>(); Shape shape = factory.makeShape(key, ctx); if (shape == null) return null; SpatialArgs args = new SpatialArgs(SpatialOperation.IsWithin, shape); IndexSearcher searcher = getSearcher(); Filter filter = strategy.makeFilter(args); return new LuceneResultSet(this, new SpatialQueryContext(context, searcher, new MatchAllDocsQuery(), filter)); }