Refine search
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); } } } }
private boolean matchesClass(ORecord record, String className) { ORecord doc = record.getRecord(); if (!(doc instanceof ODocument)) { return false; } OClass schema = ((ODocument) doc).getSchemaClass(); if (schema == null) return className == null; else if (schema.getName().equals(className)) { return true; } else if (schema.isSubClassOf(className)) { return true; } return false; }
private void invokeCallbacks() { for (ORecordOperation recordOperation : allEntries.values()) { final ORecord record = recordOperation.getRecord(); final ORID identity = record.getIdentity(); if (recordOperation.type == ORecordOperation.CREATED && recordOperation.createdCallback != null) recordOperation.createdCallback.call(new ORecordId(identity), identity.getClusterPosition()); else if (recordOperation.type == ORecordOperation.UPDATED && recordOperation.updatedCallback != null) recordOperation.updatedCallback.call(new ORecordId(identity), record.getVersion()); } }
/** * Creates a new object by the record received. */ public ORawBuffer(final ORecord iRecord) { this.buffer = iRecord.toStream(); this.version = iRecord.getVersion(); this.recordType = ORecordInternal.getRecordType(iRecord); }
public OPlaceholder(final ORecord iRecord) { rid = (ORecordId) iRecord.getIdentity().copy(); recordVersion = iRecord.getVersion(); }
@Override public String getRid(ORecord entity) { return entity.getRecord().getIdentity().toString(); }
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());
iRecord.clear(); iRecord = new ODocument(); iRecord.fromStream(OCommonConst.EMPTY_BYTE_ARRAY); else if (iRecord instanceof OBlob) { iRecord.fromStream(Base64.getDecoder().decode(fieldValueAsString)); } else if (iRecord instanceof ORecordStringable) { ((ORecordStringable) iRecord).value(fieldValueAsString); if (first != null && first instanceof ORecord && !((ORecord) first).getIdentity().isValid()) type = v instanceof Set<?> ? OType.EMBEDDEDSET : OType.EMBEDDEDLIST; doc.field(fieldName, v, type); continue; if (first != null && first instanceof ORecord && !((ORecord) first).getIdentity().isValid()) { doc.field(fieldName, v, OType.EMBEDDEDMAP); continue; if (iRecord.getIdentity().isValid()) throw OException.wrapException( new OSerializationException("Error on unmarshalling JSON content for record " + iRecord.getIdentity()), e); else throw OException.wrapException(new OSerializationException("Error on unmarshalling JSON content for record: " + iSource),
else if (currentRecord instanceof ODocument) { ODocument rec = (ODocument) currentRecord; if (rec.getClassName() != null || rec.getIdentity().isValid()) { message("\nDOCUMENT @class:%s @rid:%s @version:%d", rec.getClassName(), rec.getIdentity().toString(), rec.getVersion()); message("\n| %s - record id: %s v.%d", currentRecord.getClass().getSimpleName(), currentRecord.getIdentity().toString(), currentRecord.getVersion()); message("\n+-------------------------------------------------------------------------------------------------+");
ORecord record = (iRecord != null ? iRecord.getRecord() : null); if (ORecordBytes.RECORD_TYPE == ORecordInternal.getRecordType(record)) { for (Entry<String, Object> projection : iProjections.entrySet()) { if ("rid".equalsIgnoreCase(projection.getKey())) { iValue.field(projection.getKey(), record.getIdentity()); inputDocument.copyTo(iValue); else { iValue.field(prjName, (Object) null); continue; iValue.field(prjName, new ORidBag((ORidBag) projectionValue)); else if (projectionValue instanceof OIdentifiable && !(projectionValue instanceof ORID) && !(projectionValue instanceof ORecord)) iValue.field(prjName, ((OIdentifiable) projectionValue).<ORecord>getRecord()); else if (projectionValue instanceof Iterator) { boolean link = true; iValue.field(prjName, iteratorValues, link ? OType.LINKLIST : OType.EMBEDDEDLIST); } else if (projectionValue instanceof ODocument && ((ODocument) projectionValue).getIdentity().getClusterId() < 0) { iValue.field(prjName, projectionValue, OType.EMBEDDED); } else if (projectionValue instanceof Set<?>) { if (value instanceof OIdentifiable) { value = ((OIdentifiable) value).getRecord(); if (value != null && !((OIdentifiable) value).getIdentity().isPersistent()) link = false;
final List<Object> outIds = out.get(i); final List<Object> inIds = in.get(i); final ODocument doc = new ODocument(vClass); if (outIds == null && inIds == null) { db.save(doc, clusterName).delete(); } else { doc.field(idPropertyName, i); if (outIds != null) { final ORidBag outBag = new ORidBag(); rid = (ORecordId) l; } else { rid = new ORecordId(getClusterId((Long) l), getClusterPosition((Long) l)); doc.field(outField, outBag); rid = (ORecordId) l; } else { rid = new ORecordId(getClusterId((Long) l), getClusterPosition((Long) l));
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;
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())); } } }
private static void browseCluster(final ODatabaseDocument iDatabase, final Set<ORID> iSourceRIDs, final Map<ORID, Set<ORID>> map, final String iClusterName) { for (ORecord record : iDatabase.browseCluster(iClusterName)) { if (record instanceof ODocument) { try { for (String fieldName : ((ODocument) record).fieldNames()) { Object value = ((ODocument) record).field(fieldName); checkObject(iSourceRIDs, map, value, (ODocument) record); } } catch (Exception e) { OLogManager.instance().debug(null, "Error reading record " + record.getIdentity(), e); } } } }
ORecord rec = id.getRecord(); ((ODocument) rec).setLazyLoad(false); for (String fieldName : doc.fieldNames()) { columns.put(fieldName, getColumnSize(fetched, doc, fieldName, columns.get(fieldName))); if (!hasClass && doc.getClassName() != null) hasClass = true; if (!tempRids && !rec.getIdentity().isPersistent()) tempRids = true;
@Override public boolean result(final Object iRecord) { OClass oldClass = null; ORecord oldRecord = ((OIdentifiable) iRecord).getRecord(); if (oldRecord instanceof ODocument) { oldClass = ((ODocument) oldRecord).getSchemaClass(); final ORecord rec = oldRecord.copy(); rec.getIdentity().reset(); doc.setClassName(className); doc.setTrackingChanges(true); Object edges = doc.getProperty(field); if (edges instanceof OIdentifiable) { ODocument edgeRec = ((OIdentifiable) edges).getRecord(); if (edgeRec.getSchemaClass() != null && edgeRec.getSchemaClass().isSubClassOf("E")) { doc.removeProperty(field); for (Object edge : (Iterable) edges) { if (edge instanceof OIdentifiable) { OElement edgeRec = ((OIdentifiable) edge).getRecord(); if (edgeRec.getSchemaType().isPresent() && edgeRec.getSchemaType().get().isSubClassOf("E")) { doc.removeProperty(field); rec.setDirty(); synchronized (this) { saveRecord(rec);
if (record == null || record.getIdentity() == null) { OLogManager.instance().warn(this, "Broken record was detected and will be skipped"); return null; if (schemaImported && record.getIdentity().equals(schemaRecordId)) { if (!includeClusters.contains(database.getClusterNameById(record.getIdentity().getClusterId()))) { return null; if (excludeClusters.contains(database.getClusterNameById(record.getIdentity().getClusterId()))) return null; if (record.getIdentity().getClusterId() == 0 && record.getIdentity().getClusterPosition() == 1) if (record.getIdentity().getClusterId() == indexId || record.getIdentity().getClusterId() == oridsId) if (record.getIdentity().getClusterId() == manualIndexCluster) if (record.getIdentity().equals(indexMgrRecordId)) return null; final ORID rid = record.getIdentity(); ORecordInternal.setVersion(record, 0); record.setDirty(); ORecordInternal.setIdentity(record, new ORecordId()); record.save(); else
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) : if (!database.isRetainRecords()) resultRid = iLinkedRecord.getIdentity();
updatedRids.put(newRid.copy(), oldRid.copy()); if (!rec.getRecord().getIdentity().equals(newRid)) { ORecordInternal.onBeforeIdentityChanged(rec.getRecord()); final ORecordId recordId = (ORecordId) rec.getRecord().getIdentity(); if (recordId == null) { ORecordInternal.setIdentity(rec.getRecord(), new ORecordId(newRid)); } else { recordId.setClusterPosition(newRid.getClusterPosition()); recordId.setClusterId(newRid.getClusterId()); ORecordInternal.onAfterIdentityChanged(rec.getRecord());