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 static void checkRecord(final Set<ORID> iSourceRIDs, final Map<ORID, Set<ORID>> map, final OIdentifiable value, final ORecord iRootObject) { if (iSourceRIDs.contains(value.getIdentity())) { map.get(value.getIdentity()).add(iRootObject.getIdentity()); }else if(!value.getIdentity().isValid() && value.getRecord() instanceof ODocument){ //embedded document ODocument doc = value.getRecord(); for (String fieldName : doc.fieldNames()) { Object fieldValue = doc.field(fieldName); checkObject(iSourceRIDs, map, fieldValue, iRootObject); } } } }
public OIndexRemote<T> put(final Object iKey, final OIdentifiable iValue) { if (iValue instanceof ORecord && !iValue.getIdentity().isValid()) // SAVE IT BEFORE TO PUT ((ORecord) iValue).save(); if (iValue.getIdentity().isNew()) throw new OIndexException( "Cannot insert values in manual indexes against remote protocol during a transaction. Temporary RID cannot be managed at server side"); getDatabase().command(String.format(QUERY_PUT, name), iKey, iValue.getIdentity()).close(); return this; }
/** * {@inheritDoc} */ @Override public void serializeInByteBufferObject(OIdentifiable object, ByteBuffer buffer, Object... hints) { final ORID r = object.getIdentity(); buffer.putShort((short) r.getClusterId()); // Wrong implementation but needed for binary compatibility byte[] stream = new byte[OLongSerializer.LONG_SIZE]; OLongSerializer.INSTANCE.serialize(r.getClusterPosition(), stream, 0); buffer.put(stream); }
private static OIdentifiable readLinkOptimizedSBTree(final BytesContainer bytes) { ORID rid = new ORecordId(OVarIntSerializer.readAsInteger(bytes), OVarIntSerializer.readAsLong(bytes)); final OIdentifiable identifiable; if (rid.isTemporary() && rid.getRecord() != null) identifiable = rid.getRecord(); else identifiable = rid; return identifiable; }
public void setDirty(ORecord record) { ODirtyManager real = getReal(); if (record.getIdentity().isNew() && !record.getIdentity().isTemporary()) { if (real.newRecords == null) real.newRecords = Collections.newSetFromMap(new IdentityHashMap<ORecord, Boolean>()); real.newRecords.add(record); } else { if (real.updateRecords == null) real.updateRecords = Collections.newSetFromMap(new IdentityHashMap<ORecord, Boolean>()); real.updateRecords.add(record); } }
throw new ORecordNotFoundException(getIdentity(), "The vertex " + getIdentity() + " has been deleted"); final ORID oldIdentity = getIdentity().copy(); final ORecord oldRecord = oldIdentity.getRecord(); if (oldRecord == null) throw new ORecordNotFoundException(getIdentity(), "The vertex " + getIdentity() + " has been deleted"); final ODocument doc = ((ODocument) getRecord()).copy(); oldRecord.delete(); doc.setClassName(iClassName); doc.setDirty(); ORecordInternal.setIdentity(doc, new ORecordId());
protected ODocument serializeIndexChangeEntry(OTransactionIndexChangesPerKey entry, final ODocument indexDoc) { ODocument keyContainer = new ODocument(); keyContainer.setTrackingChanges(false); final List<Object> keys = ((OCompositeKey) entry.key).getKeys(); keyContainer.field("key", keys, OType.EMBEDDEDLIST); keyContainer.field("binary", false); } else { changeDoc.field("o", e.operation.ordinal()); if (e.value instanceof ORecord && e.value.getIdentity().isNew()) { final ORecord saved = getRecord(e.value.getIdentity()); if (saved != null) e.value = saved; else ((ORecord) e.value).save(); changeDoc.field("v", e.value != null ? e.value.getIdentity() : null);
@Override public void apply() throws Exception { try (ODatabaseDocumentTx db = databaseInstance.get().connect()) { OSchema schema = db.getMetadata().getSchema(); OClass type = schema.getClass("audit_data"); if (type != null) { type.setDefaultClusterId(primaryClusterId); log.info("Moving events to primary cluster {}", db.getClusterNameById(primaryClusterId)); for (ODocument document : db.browseClass(type.getName())) { ORID rid = document.getIdentity(); if (rid.getClusterId() != primaryClusterId) { db.save(new ODocument(document.toStream())); db.delete(rid); moveCount++;
return getElement().get(); ODocument doc = new ODocument(); for (String s : getPropertyNames()) { if (s == null) { Object newRid = getProperty(s); if (newRid instanceof OIdentifiable) { newRid = ((OIdentifiable) newRid).getIdentity(); } else { continue; ORecordId oldId = (ORecordId) doc.getIdentity(); oldId.setClusterId(((ORID) newRid).getClusterId()); oldId.setClusterPosition(((ORID) newRid).getClusterPosition()); } else if (s.equalsIgnoreCase("@version")) { Object v = getProperty(s); if (v instanceof Number) { ORecordInternal.setVersion(doc, ((Number) v).intValue()); } else { continue; doc.setClassName(getProperty(s)); } else { doc.setProperty(s, convertToElement(getProperty(s)));
/** * Atomic increment number field value * @param field * @param value */ public void incrementField(final String field, final Number value){ Number oldValue = document.field(field); document.field(field, oldValue.doubleValue()+value.doubleValue()); if(document.getIdentity().isPersistent()) { atomicChange(field,value,"INCREMENT "+field+"=?"); } }
return iCurrent.getRecord(); else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_RID)) return iCurrent.getIdentity(); else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_RID_ID)) return iCurrent.getIdentity().getClusterId(); else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_RID_POS)) return iCurrent.getIdentity().getClusterPosition(); else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_VERSION)) return iCurrent.getRecord().getVersion(); else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_CLASS)) return ((ODocument) iCurrent.getRecord()).getClassName(); else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_TYPE)) return Orient.instance().getRecordFactoryManager().getRecordTypeName(ORecordInternal.getRecordType(iCurrent.getRecord())); else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_SIZE)) { final byte[] stream = iCurrent.getRecord().toStream(); return stream != null ? stream.length : 0; } else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_FIELDS)) return ((ODocument) iCurrent.getRecord()).fieldNames(); else if (iFieldName.equalsIgnoreCase(ATTRIBUTE_RAW)) return new String(iCurrent.getRecord().toStream()); return null; doc.checkForFields(iFieldName); ODocumentEntry entry = doc._fields.get(iFieldName); return entry != null ? entry.value : null;
private boolean isEventAlreadyExecuted() { final ORecord rec = document.getIdentity().getRecord(); if (rec == null) // SKIP EXECUTION BECAUSE THE EVENT WAS DELETED return true; final ODocument updated = rec.reload(); final Long currentExecutionId = updated.field(PROP_EXEC_ID); if (currentExecutionId == null) return false; if (currentExecutionId >= nextExecutionId) { OLogManager.instance() .info(this, "Scheduled event '%s' with id %d is already running (current id=%d)", getName(), nextExecutionId, currentExecutionId); // ALREADY RUNNING return true; } return false; }
private int writeOptimizedLink(final BytesContainer bytes, OIdentifiable link) { if (!link.getIdentity().isPersistent()) { final ORecord real = link.getRecord(); if (real != null) link = real; } final int pos = OVarIntSerializer.write(bytes, link.getIdentity().getClusterId()); OVarIntSerializer.write(bytes, link.getIdentity().getClusterPosition()); return pos; }
@Override protected void readFields(final ODocument document, final T entity) { ORID bucketId = document.field(P_BUCKET, ORID.class); String format = document.field(P_FORMAT, OType.STRING); Date lastUpdated = document.field(P_LAST_UPDATED, OType.DATETIME); Map<String, Object> attributes = document.field(P_ATTRIBUTES, OType.EMBEDDEDMAP); entity.bucketId(new AttachedEntityId(bucketEntityAdapter, bucketId)); entity.format(format); entity.lastUpdated(new DateTime(lastUpdated)); entity.attributes(new NestedAttributesMap(P_ATTRIBUTES, detachable(attributes))); entity.newEntity(document.getIdentity().isNew()); }
protected OType getTypeFromValueEmbedded(final Object fieldValue) { OType type = OType.getTypeByValue(fieldValue); if (type == OType.LINK && fieldValue instanceof ODocument && !((ODocument) fieldValue).getIdentity().isValid()) type = OType.EMBEDDED; return type; }
assert rid.getIdentity().isValid() || (ODatabaseRecordThreadLocal.instance().get().getStorage() instanceof OStorageProxy) : "Impossible to serialize invalid link " + rid.getIdentity(); resultRid = rid; } else { if (iLinked instanceof String) iLinked = new ORecordId((String) iLinked); ORecord iLinkedRecord = ((OIdentifiable) iLinked).getRecord(); rid = iLinkedRecord.getIdentity(); assert rid.getIdentity().isValid() || (ODatabaseRecordThreadLocal.instance().get().getStorage() instanceof OStorageProxy) : "Impossible to serialize invalid link " + rid.getIdentity(); if (!database.isRetainRecords()) resultRid = iLinkedRecord.getIdentity(); if (rid.isValid()) rid.toString(buffer);
if (requireLogin == null || requireLogin.isEmpty() || !requireLogin.equalsIgnoreCase("true")) { IUser user = docToUser(db.browseClass("User").next()); String id = rememberMeRepository.validateTokenAndGetUserId(c.getValue()); if (id != null) { ORID oid = new ORecordId(id); if (oid.isValid()) { user = docToUser(db.getRecord(oid)); } finally { db.close();
public <T> T getProperty(String name) { T result = null; if (content.containsKey(name)) { result = (T) wrap(content.get(name)); } else if (element != null) { result = (T) wrap(((ODocument) element.getRecord()).getProperty(name)); } if (result instanceof OIdentifiable && ((OIdentifiable) result).getIdentity().isPersistent()) { result = (T) ((OIdentifiable) result).getIdentity(); } return result; }
private void addOwnerToEmbeddedDoc(T e) { if (embeddedCollection && e instanceof ODocument && !((ODocument) e).getIdentity().isValid()) ODocumentInternal.addOwner((ODocument) e, this); if (e instanceof ODocument) ORecordInternal.track(sourceRecord, (ODocument) e); }