protected void checkClass() { // FORCE EARLY UNMARSHALLING final ODocument doc = getRecord(); doc.deserializeFields(); final OClass cls = ODocumentInternal.getImmutableSchemaClass(doc); if (cls == null || !cls.isSubClassOf(getBaseClassName())) throw new IllegalArgumentException("The document received is not a " + getElementType() + ". Found class '" + cls + "'"); }
@Override public <T> T getProperty(final String key) { graph.setCurrentGraphInThreadLocal(); if (rawElement == null) // LIGHTWEIGHT EDGE return null; return super.getProperty(key); }
@Override public <T> T removeProperty(String key) { graph.setCurrentGraphInThreadLocal(); if (rawElement != null) // NON LIGHTWEIGHT EDGE return super.removeProperty(key); return null; }
protected <E extends Element> E setProperties(final E element, final Object... properties) { ((OrientElement) element).setProperties(properties); ((OrientElement) element).save(); return element; } }
/** * Sets a Property value. * * @param key Property name * @param value Property value */ @Override public void setProperty(final String key, final Object value) { if (checkDeletedInTx()) graph.throwRecordNotFoundException(getIdentity(), "The graph element " + getIdentity() + " has been deleted"); validateProperty(this, key, value); final OrientBaseGraph graph = getGraph(); if (graph != null) graph.autoStartTransaction(); getRecord().field(key, value); if (graph != null) save(); }
if (checkDeletedInTx()) graph.throwRecordNotFoundException(getIdentity(), "The graph element " + getIdentity() + " has been deleted"); setPropertiesInternal(fields); save(); return (T) this;
final String clsName = className != null ? className : (element instanceof OrientVertex ? element.getLabel() : element .getLabel()); if (clsName != null) cls = getOrCreateClass(clsName, element.getBaseClassName()); else throw new IllegalArgumentException("No class defined on graph element: " + input); for (String f : element.getPropertyKeys()) { final String newName = transformFieldName(f); final String fName = newName != null ? newName : f; final Object fValue = element.getProperty(f); createProperty(cls, fName, fValue); if (newName != null) { element.removeProperty(f); element.setProperty(newName, fValue);
public void reload() { final ODocument rec = getRecord(); if (rec != null) rec.reload(null, true); }
/** * Removes the Element from the Graph. In case the element is a Vertex, all the incoming and outgoing edges are automatically * removed too. */ void removeRecord() { checkIfAttached(); final OrientBaseGraph graph = getGraph(); graph.setCurrentGraphInThreadLocal(); graph.autoStartTransaction(); if (checkDeletedInTx()) graph.throwRecordNotFoundException(getIdentity(), "The graph element with id " + getIdentity() + " not found"); try { getRecord().load(); } catch (ORecordNotFoundException e) { graph.throwRecordNotFoundException(getIdentity(), e.getMessage()); } getRecord().delete(); }
public void remove(final String key, final Object value, final T element) { final String keyTemp = key + SEPARATOR + value; graph.setCurrentGraphInThreadLocal(); graph.autoStartTransaction(); try { underlying.remove(keyTemp, element.getRecord()); recordKeyValueIndex.remove(new OCompositeKey(element.getIdentity(), keyTemp), element.getIdentity()); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
protected boolean checkDeletedInTx() { OrientBaseGraph curGraph = getGraph(); if (curGraph == null) return false; ORID id; if (getRecord() != null) id = getRecord().getIdentity(); else return false; final ORecordOperation oper = curGraph.getRawGraph().getTransaction().getRecordEntry(id); if (oper == null) return id.isTemporary(); else return oper.type == ORecordOperation.DELETED; }
/** * Returns the Element Id assuring to save it if it's transient yet. */ public Object getId() { return getIdentity(); }
return null; OrientBaseGraph graph = getGraph(); if (graph == null) return className; }, "Committing the active transaction to create the new type '", className, "' as subclass of '", getBaseClassName(), "'. The transaction will be reopen right after that. To avoid this behavior create the classes outside the transaction"); if (!cls.isSubClassOf(getBaseClassName())) throw new IllegalArgumentException("Class '" + className + "' is not an instance of " + getBaseClassName());
@Override public void setProperty(final String key, final Object value) { graph.setCurrentGraphInThreadLocal(); if (rawElement == null) // LIGHTWEIGHT EDGE convertToDocument(); super.setProperty(key, value); }
@Override public OClass call(final OrientBaseGraph g) { return schema.createClass(className, schema.getClass(getBaseClassName())); } }, "Committing the active transaction to create the new type '", className, "' as subclass of '", getBaseClassName(),
/** * (Blueprints Extension) Saves current element. You don't need to call save() unless you're working against Temporary Vertices. */ public void save() { save(null); }
/** * (Blueprints Extension) Returns the record's identity. */ @Override public ORID getIdentity() { if (rawElement == null) return ORecordId.EMPTY_RECORD_ID; final ORID rid = rawElement.getIdentity(); if (!rid.isValid()) { final OrientBaseGraph graph = getGraph(); if (graph != null) { // SAVE THE RECORD TO OBTAIN A VALID RID graph.setCurrentGraphInThreadLocal(); graph.autoStartTransaction(); save(); } } return rid; }
@Override public boolean equals(final Object object) { if (rawElement == null && object instanceof OrientEdge) { final OrientEdge other = (OrientEdge) object; return vOut.equals(other.vOut) && vIn.equals(other.vIn) && (label == null && other.label == null || label .equals(other.label)); } return super.equals(object); }
@Override public Object getId() { if (rawElement == null) // CREATE A TEMPORARY ID return vOut.getIdentity() + "->" + vIn.getIdentity(); graph.setCurrentGraphInThreadLocal(); return super.getId(); }