Class OrientElement

java.lang.Object
com.tinkerpop.blueprints.impls.orient.OrientElement
All Implemented Interfaces:
OIdentifiable, OSerializableStream, com.tinkerpop.blueprints.Element, Externalizable, Serializable, Comparable<OIdentifiable>, Comparator<OIdentifiable>
Direct Known Subclasses:
OrientEdge, OrientVertex

public abstract class OrientElement extends Object implements com.tinkerpop.blueprints.Element, OSerializableStream, Externalizable, OIdentifiable
Base Graph Element where OrientVertex and OrientEdge classes extends from. Labels are managed as OrientDB classes.
Author:
Luca Garulli (l.garulli--(at)--orientdb.com) (http://orientdb.com)
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getLabel

      public abstract String getLabel()
    • getBaseClassName

      public abstract String getBaseClassName()
    • getElementType

      public abstract String getElementType()
      (Blueprints Extension) Returns the element type in form of String between "Vertex" and "Edge".
    • getProperties

      public abstract Map<String,Object> getProperties()
      (Blueprints Extension) Gets all the properties from a Vertex or Edge in one shot.
      Returns:
      a map containing all the properties of the Vertex/Edge.
    • checkDeletedInTx

      protected boolean checkDeletedInTx()
    • setProperties

      public <T extends OrientElement> T setProperties(Object... fields)
      (Blueprints Extension) Sets multiple properties in one shot against Vertices and Edges. This improves performance avoiding to save the graph element at every property set.
      Example:

      vertex.setProperties( "name", "Jill", "age", 33, "city", "Rome", "born", "Victoria, TX" ); You can also pass a Map of values as first argument. In this case all the map entries will be set as element properties:

      Map<String,Object> props = new HashMap<String,Object>(); props.put("name", "Jill"); props.put("age", 33); props.put("city", "Rome"); props.put("born", "Victoria, TX"); vertex.setProperties(props);

      Parameters:
      fields - Odd number of fields to set as repeating pairs of key, value, or if one parameter is received and it's a Map, the Map entries are used as field key/value pairs.
    • setProperty

      public void setProperty(String key, Object value)
      Sets a Property value.
      Specified by:
      setProperty in interface com.tinkerpop.blueprints.Element
      Parameters:
      key - Property name
      value - Property value
    • setProperty

      public void setProperty(String key, Object value, OType iType)
      Sets a Property value specifying a type. This is useful when you don't have a schema on this property but you want to force the type.
      Parameters:
      key - Property name
      value - Property value
      iType - Type to set
    • removeProperty

      public <T> T removeProperty(String key)
      Removes a Property.
      Specified by:
      removeProperty in interface com.tinkerpop.blueprints.Element
      Parameters:
      key - Property name
      Returns:
      Old value if any
    • getProperty

      public <T> T getProperty(String key)
      Returns a Property value.
      Specified by:
      getProperty in interface com.tinkerpop.blueprints.Element
      Parameters:
      key - Property name
      Returns:
      Property value if any, otherwise NULL.
    • getId

      public Object getId()
      Returns the Element Id assuring to save it if it's transient yet.
      Specified by:
      getId in interface com.tinkerpop.blueprints.Element
    • save

      public void save()
      (Blueprints Extension) Saves current element. You don't need to call save() unless you're working against Temporary Vertices.
    • save

      public void save(String iClusterName)
      (Blueprints Extension) Saves current element to a particular cluster. You don't need to call save() unless you're working against Temporary Vertices.
      Parameters:
      iClusterName - Cluster name or null to use the default "E"
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toStream

      public byte[] toStream() throws OSerializationException
      (Blueprints Extension) Serializes the Element as byte[]
      Specified by:
      toStream in interface OSerializableStream
      Returns:
      The byte array representation of the object
      Throws:
      OSerializationException - if the marshalling does not succeed
      See Also:
    • fromStream

      public OSerializableStream fromStream(byte[] stream) throws OSerializationException
      (Blueprints Extension) Fills the Element from a byte[]
      Specified by:
      fromStream in interface OSerializableStream
      Parameters:
      stream - byte array representation of the object
      Returns:
      The Object instance itself giving a "fluent interface". Useful to call multiple methods in chain.
      Throws:
      OSerializationException - if the unmarshalling does not succeed
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • lock

      public void lock(boolean iExclusive)
      (Blueprints Extension) Locks current Element to prevent concurrent access. If lock is exclusive, then no concurrent threads can read/write it. If the lock is shared, then concurrent threads can only read Element properties, but can't change them. Locks can be freed by calling @unlock or when the current transaction is closed (committed or rollbacked).
      Specified by:
      lock in interface OIdentifiable
      Parameters:
      iExclusive - True = Exclusive Lock, False = Shared Lock
      See Also:
    • isLocked

      public boolean isLocked()
      (Blueprints Extension) Checks if an Element is locked
      Specified by:
      isLocked in interface OIdentifiable
    • lockingStrategy

      public OStorage.LOCKING_STRATEGY lockingStrategy()
      Specified by:
      lockingStrategy in interface OIdentifiable
    • unlock

      public void unlock()
      (Blueprints Extension) Unlocks previous acquired @lock against the Element.
      Specified by:
      unlock in interface OIdentifiable
      See Also:
    • getIdentity

      public ORID getIdentity()
      (Blueprints Extension) Returns the record's identity.
      Specified by:
      getIdentity in interface OIdentifiable
      Returns:
      ORID instance
    • getRecord

      public ODocument getRecord()
      (Blueprints Extension) Returns the underlying record.
      Specified by:
      getRecord in interface OIdentifiable
      Returns:
      ORecord instance
    • detach

      public OrientElement detach()
      (Blueprints Extension) Removes the reference to the current graph instance to let working offline. To reattach it use @attach.

      This methods works only in "classic detach/attach mode" when dettachment/attachment is done manually, by default it is done automatically, and currently active graph connection will be used as graph elements owner.

      Returns:
      Current object to allow chained calls.
    • switchToAutoAttachmentMode

      public void switchToAutoAttachmentMode()
      Switches to auto attachment mode, when graph element is automatically attached to currently open graph instance.
    • switchToManualAttachmentMode

      public void switchToManualAttachmentMode(OrientBaseGraph iNewGraph)
      Behavior is the same as for attach(OrientBaseGraph) method.
    • attach

      public OrientElement attach(OrientBaseGraph iNewGraph)
      (Blueprints Extension) Replaces current graph instance with new one on @detach -ed elements. Use this method to pass elements between graphs or to switch between Tx and NoTx instances.

      This methods works only in "classic detach/attach mode" when detachment/attachment is done manually, by default it is done automatically, and currently active graph connection will be used as graph elements owner.

      To set "classic detach/attach mode" please set custom database parameter classicDetachMode to true.

      Parameters:
      iNewGraph - The new Graph instance to use.
      Returns:
      Current object to allow chained calls.
    • isDetached

      public boolean isDetached()
      (Blueprints Extension) Tells if the current element has been @detach ed.

      This methods works only in "classic detach/attach mode" when detachment/attachment is done manually, by default it is done automatically, and currently active graph connection will be used as graph elements owner.

      To set "classic detach/attach mode" please set custom database parameter classicDetachMode to true.

      Returns:
      True if detached, otherwise false
    • equals

      public boolean equals(Object object)
      Specified by:
      equals in interface Comparator<OIdentifiable>
      Overrides:
      equals in class Object
    • compare

      public int compare(OIdentifiable iFirst, OIdentifiable iSecond)
      Specified by:
      compare in interface Comparator<OIdentifiable>
    • compareTo

      public int compareTo(OIdentifiable iOther)
      Specified by:
      compareTo in interface Comparable<OIdentifiable>
    • getGraph

      public OrientBaseGraph getGraph()
      (Blueprints Extension) Returns the Graph instance associated to the current element. On @detach ed elements returns NULL.
    • validateProperty

      public final void validateProperty(com.tinkerpop.blueprints.Element element, String key, Object value) throws IllegalArgumentException
      (Blueprints Extension) Validates an Element property.
      Parameters:
      element - Element instance
      key - Property name
      value - property value
      Throws:
      IllegalArgumentException
    • reload

      public void reload()
    • copyTo

      protected void copyTo(OrientElement iCopy)
    • checkClass

      protected void checkClass()
    • checkForClassInSchema

      protected String checkForClassInSchema(String className)
      Check if a class already exists, otherwise create it at the fly. If a transaction is running commit changes, create the class and begin a new transaction.
      Parameters:
      className - Class's name
    • setPropertyInternal

      protected void setPropertyInternal(com.tinkerpop.blueprints.Element element, ODocument doc, String key, Object value)
    • setCurrentGraphInThreadLocal

      protected OrientBaseGraph setCurrentGraphInThreadLocal()
    • checkIfAttached

      protected OrientBaseGraph checkIfAttached()
    • setPropertiesInternal

      protected <T extends OrientElement> T setPropertiesInternal(Object... fields)
      (Blueprints Extension) Sets multiple properties in one shot against Vertices and Edges without saving the element. This improves performance avoiding to save the graph element at every property set. Example:

      vertex.setProperties( "name", "Jill", "age", 33, "city", "Rome", "born", "Victoria, TX" ); You can also pass a Map of values as first argument. In this case all the map entries will be set as element properties:

      Map<String,Object> props = new HashMap<String,Object>(); props.put("name", "Jill"); props.put("age", 33); props.put("city", "Rome"); props.put("born", "Victoria, TX"); vertex.setProperties(props);

      Parameters:
      fields - Odd number of fields to set as repeating pairs of key, value, or if one parameter is received and it's a Map, the Map entries are used as field key/value pairs.