@Override public <T extends ORecord> T getRecord() { return rid.getRecord(); }
@Override public Collection<ODocument> toChoices(final Collection<String> ids) { List<ODocument> documents = new ArrayList<ODocument>(); for (String id : ids) { ORecordId rid = new ORecordId(id); ODocument ret = rid.getRecord(); documents.add(ret); } return documents; } }
@Override public Collection<ODocument> toChoices(Collection<String> ids) { ArrayList<ODocument> documents = new ArrayList<ODocument>(); for (String id : ids) { ORecordId rid = new ORecordId(id); ODocument ret = rid.getRecord(); documents.add(ret); } return documents; } }
@Override public ODocument getObject(String id, IModel<? extends List<? extends ODocument>> choicesModel) { if(ORecordId.isA(id)) { ORecordId rid = new ORecordId(id); ODocument ret = rid.getRecord(); List<? extends ODocument> choices = choicesModel.getObject(); return choices!=null && choices.contains(ret)?ret:null; } return null; }
public Map<OIdentifiable, Change> deserializeChanges(final byte[] stream, int offset) { final int count = OIntegerSerializer.INSTANCE.deserializeLiteral(stream, offset); offset += OIntegerSerializer.INT_SIZE; final HashMap<OIdentifiable, Change> res = new HashMap<>(); for (int i = 0; i < count; i++) { ORecordId rid = OLinkSerializer.INSTANCE.deserialize(stream, offset); offset += OLinkSerializer.RID_SIZE; Change change = ChangeSerializationHelper.INSTANCE.deserializeChange(stream, offset); offset += Change.SIZE; final OIdentifiable identifiable; if (rid.isTemporary() && rid.getRecord() != null) identifiable = rid.getRecord(); else identifiable = rid; res.put(identifiable, change); } return res; }
public Object execute(Object iThis, OIdentifiable iCurrentRecord, Object iCurrentResult, final Object[] iParams, OCommandContext iContext) { final Object candidate = iParams[0]; final String format = iParams[1].toString(); byte[] data = null; if (candidate instanceof byte[]) { data = (byte[]) candidate; } else if (candidate instanceof ORecordId) { final ORecord rec = ((ORecordId) candidate).getRecord(); if (rec instanceof OBlob) { data = ((OBlob) rec).toStream(); } } else if (candidate instanceof OSerializableStream) { data = ((OSerializableStream) candidate).toStream(); } if (data == null) { return null; } if (FORMAT_BASE64.equalsIgnoreCase(format)) { return Base64.getEncoder().encodeToString(data); } else { throw new ODatabaseException("unknowned format :" + format); } }
@Override public ODocument apply(F input) { if(input==null) { return null; } else if(input instanceof ODocument) { return (ODocument)input; } else if(input instanceof ORID) { return ((ORID)input).getRecord(); } else if(input instanceof CharSequence) { return new ORecordId(input.toString()).getRecord(); } else { throw new WicketRuntimeException("Object '"+input+"' of type '"+input.getClass()+"' can't be converted to ODocument"); } }
@Override public ODocument apply(F input) { if(input==null) { return null; } else if(input instanceof ODocument) { return (ODocument)input; } else if(input instanceof ORID) { return ((ORID)input).getRecord(); } else if(input instanceof CharSequence) { return new ORecordId(input.toString()).getRecord(); } else { throw new WicketRuntimeException("Object '"+input+"' of type '"+input.getClass()+"' can't be converted to ODocument"); } }
public ODocument calculateODocument(ProcessEngine processEngine, String taskId) { if(rid!=null) return (ODocument)rid.getRecord(); if(variableName!=null) { Object recording = processEngine.getTaskService().getVariable(taskId, variableName); if(recording!=null) { return new ORecordId(recording.toString()).getRecord(); } } if(schemaClassName!=null) { return new ODocument(schemaClassName); } return null; }
private OIdentifiable readOptimizedLink(final BytesContainer bytes) { ORecordId id = new ORecordId(OVarIntSerializer.readAsInteger(bytes), OVarIntSerializer.readAsLong(bytes)); if (id.isTemporary()) { OIdentifiable persRef = id.getRecord(); if (persRef != null) return persRef; } return id; }
fieldValue = ((ORecordId) fieldValue).getRecord();
@SuppressWarnings("unchecked") public OIdentifiable next() { OIdentifiable value = underlying.next(); if (value == null) return null; if (value instanceof ORecordId && autoConvert2Record && ODatabaseRecordThreadLocal.instance().isDefined()) { try { final ORecord rec = ((ORecordId) value).getRecord(); if (sourceRecord != null && rec != null) ORecordInternal.track(sourceRecord, rec); if (underlying instanceof OLazyIterator<?>) ((OLazyIterator<OIdentifiable>) underlying).update(rec); value = rec; } catch (Exception e) { OLogManager.instance().error(this, "Error on iterating record collection", e); value = null; } } return value; }
@Override public Object execute(Object iThis, OIdentifiable iCurrentRecord, OCommandContext iContext, Object ioResult, Object[] iParams) { if (iThis != null) { if (iThis instanceof ORecordId) { iThis = ((ORecordId) iThis).getRecord(); } if (iThis instanceof ODocument) { // ACT ON SINGLE DOCUMENT return copy((ODocument) iThis, iParams); } else if (iThis instanceof Map) { // ACT ON SINGLE MAP return copy((Map) iThis, iParams); } else if (OMultiValue.isMultiValue(iThis)) { // ACT ON MULTIPLE DOCUMENTS final List<Object> result = new ArrayList<Object>(OMultiValue.getSize(iThis)); for (Object o : OMultiValue.getMultiValueIterable(iThis, false)) { if (o instanceof OIdentifiable) { result.add(copy((ODocument) ((OIdentifiable) o).getRecord(), iParams)); } } return result; } } // INVALID, RETURN NULL return null; }
@Override public byte[] onUpdate(OStorage storage, final byte iRecordType, final ORecordId rid, final int iRecordVersion, final byte[] iRecordContent, final AtomicInteger iDatabaseVersion) { final boolean hasSameContent; if (iRecordType == ODocument.RECORD_TYPE) { // No need lock, is already inside a lock. OStorageOperationResult<ORawBuffer> res = storage.readRecord(rid, null, false, false, null); final ODocument storedRecord = new ODocument(rid).fromStream(res.getResult().getBuffer()); final ODocument newRecord = new ODocument().fromStream(iRecordContent); final ODatabaseDocumentInternal currentDb = ODatabaseRecordThreadLocal.instance().get(); hasSameContent = ODocumentHelper.hasSameContentOf(storedRecord, currentDb, newRecord, currentDb, null, false); } else { // CHECK BYTE PER BYTE final ORecordAbstract storedRecord = rid.getRecord(); hasSameContent = Arrays.equals(storedRecord.toStream(), iRecordContent); } if (hasSameContent) // OK iDatabaseVersion.set(Math.max(iDatabaseVersion.get(), iRecordVersion)); else // NO DOCUMENT, CANNOT MERGE SO RELY TO THE VERSION CHECK checkVersions(rid, iRecordVersion, iDatabaseVersion.get()); return null; }
@Override public Iterable<OIdentifiable> searchFromTarget(OFromClause target, OBinaryCompareOperator operator, Object rightValue, OCommandContext ctx, OExpression... args) { OLuceneFullTextIndex index = this.searchForIndex(target, ctx); if (index == null) return Collections.emptySet(); IndexSearcher searcher = index.searcher(); OExpression expression = args[0]; ODocument metadata = parseMetadata(args); List<String> ridsAsString = parseRids(ctx, expression); List<ORecord> others = ridsAsString.stream().map(rid -> { ORecordId recordId = new ORecordId(); recordId.fromString(rid); return recordId; }).map(id -> id.<ORecord>getRecord()).collect(Collectors.toList()); MoreLikeThis mlt = buildMoreLikeThis(index, searcher, metadata); Builder queryBuilder = new Builder(); excludeOtherFromResults(ridsAsString, queryBuilder); addLikeQueries(others, mlt, queryBuilder); Query mltQuery = queryBuilder.build(); Set<OIdentifiable> luceneResultSet = index .get(new OLuceneKeyAndMetadata(new OLuceneCompositeKey(Arrays.asList(mltQuery.toString())).setContext(ctx), metadata)); return luceneResultSet; }
/** * Convert the item requested from link to record. * * @param iIndex Position of the item to convert */ private void convertLink2Record(final int iIndex) { if (ridOnly || !autoConvertToRecord) // PRECONDITIONS return; final OIdentifiable o = super.get(iIndex); if (contentType == MULTIVALUE_CONTENT_TYPE.ALL_RECORDS && !o.getIdentity().isNew()) // ALL RECORDS AND THE OBJECT IS NOT NEW, DO NOTHING return; if (o != null && o instanceof ORecordId) { final ORecordId rid = (ORecordId) o; marshalling = true; try { ORecord record = rid.getRecord(); if (record != null) { ORecordInternal.unTrack(sourceRecord, rid); ORecordInternal.track(sourceRecord, record); } super.set(iIndex, record); } catch (ORecordNotFoundException ignore) { // IGNORE THIS } finally { marshalling = false; } } }
protected void validateLink(final IValidatable<T> validatable, final OProperty p, final Object linkValue) { if (linkValue == null) validatable.error(newValidationError("nulllink")); else { ORecord linkedRecord = null; if (linkValue instanceof OIdentifiable) linkedRecord = ((OIdentifiable) linkValue).getRecord(); else if (linkValue instanceof String) linkedRecord = new ORecordId((String) linkValue).getRecord(); else validatable.error(newValidationError("linkwrong")); if (linkedRecord != null && p.getLinkedClass() != null) { if (!(linkedRecord instanceof ODocument)) validatable.error(newValidationError("linktypewrong", "linkedClass", p.getLinkedClass(), "identity", linkedRecord.getIdentity())); final ODocument doc = (ODocument) linkedRecord; // AT THIS POINT CHECK THE CLASS ONLY IF != NULL BECAUSE IN CASE // OF GRAPHS THE RECORD COULD BE PARTIAL if (doc.getSchemaClass() != null && !p.getLinkedClass().isSuperClassOf( doc.getSchemaClass())) validatable.error(newValidationError("linktypewrong", "linkedClass", p.getLinkedClass(), "identity", linkedRecord.getIdentity())); } } }
protected void validateLink(final IValidatable<T> validatable, final OProperty p, final Object linkValue) { if (linkValue == null) validatable.error(newValidationError("nulllink")); else { ORecord linkedRecord = null; if (linkValue instanceof OIdentifiable) linkedRecord = ((OIdentifiable) linkValue).getRecord(); else if (linkValue instanceof String) linkedRecord = new ORecordId((String) linkValue).getRecord(); else validatable.error(newValidationError("linkwrong")); if (linkedRecord != null && p.getLinkedClass() != null) { if (!(linkedRecord instanceof ODocument)) validatable.error(newValidationError("linktypewrong", "linkedClass", p.getLinkedClass(), "identity", linkedRecord.getIdentity())); final ODocument doc = (ODocument) linkedRecord; // AT THIS POINT CHECK THE CLASS ONLY IF != NULL BECAUSE IN CASE // OF GRAPHS THE RECORD COULD BE PARTIAL if (doc.getSchemaClass() != null && !p.getLinkedClass().isSuperClassOf( doc.getSchemaClass())) validatable.error(newValidationError("linktypewrong", "linkedClass", p.getLinkedClass(), "identity", linkedRecord.getIdentity())); } } }