@Override public ORID getIdentity() { if (element == null) { return null; } return element.getIdentity(); }
/** * Override this method to declare a custom affinity for {@link EntityEvent}s. * * @since 3.11 */ public String eventAffinity(final ODocument document) { return document.getIdentity().toString(); }
@Override protected String getSql() { String sql = super.getSql(); ODocument doc = getModelObject(); sql = sql.replaceAll(":doc\\b", doc.getIdentity().toString()); return sql; }
private static void addIndexesEntries(ODatabaseDocumentInternal database, ODocument document, final Collection<OIndex<?>> indexes, List<IndexChange> changes) { // STORE THE RECORD IF NEW, OTHERWISE ITS RID final OIdentifiable rid = document.getIdentity(); for (final OIndex<?> index : indexes) { addIndexEntry(document, rid, getTransactionalIndex(database, index), changes); } }
private 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; }
public Object fetchLinkedCollectionValue(ODocument iRoot, Object iUserObject, String iFieldName, ODocument iLinked, OFetchContext iContext) throws OFetchException { if (iLinked.getIdentity().isValid()) { sendRecord(iLinked); return true; } return null; }
public Object fetchLinkedMapEntry(ODocument iRoot, Object iUserObject, String iFieldName, String iKey, ODocument iLinked, OFetchContext iContext) throws OFetchException { if (iLinked.getIdentity().isValid()) { sendRecord(iLinked); return true; } return null; }
private OType getTypeFromValueEmbedded(final Object fieldValue) { OType type = fieldValue instanceof OResult ? OType.EMBEDDED : OType.getTypeByValue(fieldValue); if (type == OType.LINK && fieldValue instanceof ODocument && !((ODocument) fieldValue).getIdentity().isValid()) type = OType.EMBEDDED; return type; }
public void onAfterCollection(final ODocument iRootRecord, final String iFieldName, final Object iUserObject) { try { jsonWriter.endCollection(settings.indentLevel--, true); collectionStack.pop(); } catch (IOException e) { throw OException.wrapException( new OFetchException("Error writing collection field " + iFieldName + " of record " + iRootRecord.getIdentity()), e); } }
/** * 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+"=?"); } }
@Nullable private EntityId findComponentId(final ODocument document) { if (document.containsField(P_COMPONENT)) { // get the owning component from the asset, might be null if asset is standalone return componentId(document.field(P_COMPONENT, ORID.class)); } else { // not an asset, must be a component itself return componentId(document.getIdentity()); } }
public void onBeforeCollection(final ODocument iRootRecord, final String iFieldName, final Object iUserObject, final Iterable<?> iterable) { try { manageTypes(iFieldName, iterable, null); jsonWriter.beginCollection(++settings.indentLevel, true, iFieldName); collectionStack.add(iRootRecord); } catch (IOException e) { throw OException.wrapException( new OFetchException("Error writing collection field " + iFieldName + " of record " + iRootRecord.getIdentity()), e); } }
public void onAfterDocument(final ODocument iRootRecord, final ODocument iDocument, final String iFieldName, final Object iUserObject) { try { jsonWriter.endObject(settings.indentLevel--, true); } catch (IOException e) { throw OException.wrapException( new OFetchException("Error writing link field " + iFieldName + " of record " + iRootRecord.getIdentity()), e); } }
@Override public RecordId getId() { session.checkOpen(); checkPersistent(); return session.getRecordId(document.getSchemaClass(), document.getIdentity()); }
private OrientVertex createVertex(OClass vertexClass, OClass edgeClass) { OrientGraph tx = orientGraphProvider.get(); OrientVertex newVertex = tx.addVertex(vertexClass.getName(), (String) null); OrientVertex vertex = tx.getVertex(documentModel.getObject().getIdentity()); tx.addEdge(null, vertex, newVertex, edgeClass.getName()); tx.commit();tx.begin(); return newVertex; }
private void createLinksForDocuments(List<ODocument> documents, List<ODocument> links) { Args.isTrue(documents.size() == links.size(), "documents.size() == linkedDocs.size()"); for (int i = 0; i < documents.size(); i++) { ODocument document = documents.get(i); document.field(LINK_FIELD, links.get(i).getIdentity().toString(), OType.LINK); document.save(); } }
private static ODocument checkForLoading(final ODocument iRecord) { if (iRecord.getInternalStatus() == ORecordElement.STATUS.NOT_LOADED) { try { return (ODocument) iRecord.load(); } catch (final ORecordNotFoundException e) { throw OException.wrapException(new OIndexException("Error during loading of record with id " + iRecord.getIdentity()), e); } } return iRecord; }
@Override protected void onConfigure() { super.onConfigure(); setVisible(getModelObject().getIdentity().isPersistent() || getModeObject().canModify()); }
private static OResultInternal calculateAfter(ODocument iDocument) { OResultInternal result = new OResultInternal(); for (String prop : iDocument.getPropertyNames()) { result.setProperty(prop, unboxRidbags(iDocument.getProperty(prop))); } result.setProperty("@rid", iDocument.getIdentity()); result.setProperty("@class", iDocument.getClassName()); result.setProperty("@version", iDocument.getVersion() + 1); return result; }
@Override protected void onConfigure() { super.onConfigure(); ODocument doc = getModelObject(); if(doc==null) throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND); //Support of case when metadata was changed in parallel else if(Strings.isEmpty(doc.getClassName()) && doc.getIdentity().isValid()) { getDatabase().reload(); if(Strings.isEmpty(doc.getClassName())) throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND); } }