Class ODatabaseDocumentAbstract

java.lang.Object
com.orientechnologies.common.listener.OListenerManger<ODatabaseListener>
com.orientechnologies.orient.core.db.document.ODatabaseDocumentAbstract
All Implemented Interfaces:
ODatabaseDocument, ODatabase<ORecord>, ODatabaseDocumentInternal, ODatabaseInternal<ORecord>, ODatabaseSession, OBackupable, Closeable, AutoCloseable
Direct Known Subclasses:
ODatabaseDocumentEmbedded, ODatabaseDocumentRemote

public abstract class ODatabaseDocumentAbstract extends OListenerManger<ODatabaseListener> implements ODatabaseDocumentInternal
Document API entrypoint.
Author:
Luca Garulli (l.garulli--(at)--orientdb.com)
  • Field Details

  • Constructor Details

    • ODatabaseDocumentAbstract

      protected ODatabaseDocumentAbstract()
  • Method Details

    • getDefaultSerializer

      public static ORecordSerializer getDefaultSerializer()
      Returns:
      default serializer which is used to serialize documents. Default serializer is common for all database instances.
    • setDefaultSerializer

      public static void setDefaultSerializer(ORecordSerializer iDefaultSerializer)
      Sets default serializer. The default serializer is common for all database instances.
      Parameters:
      iDefaultSerializer - new default serializer value
    • callOnOpenListeners

      public void callOnOpenListeners()
      Specified by:
      callOnOpenListeners in interface ODatabaseDocumentInternal
    • loadMetadata

      protected abstract void loadMetadata()
    • callOnCloseListeners

      public void callOnCloseListeners()
      Specified by:
      callOnCloseListeners in interface ODatabaseDocumentInternal
    • callOnDropListeners

      public void callOnDropListeners()
      Specified by:
      callOnDropListeners in interface ODatabaseDocumentInternal
    • getRecord

      public <RET extends ORecord> RET getRecord(OIdentifiable iIdentifiable)
      Returns the record for a OIdentifiable instance. If the argument received already is a ORecord instance, then it's returned as is, otherwise a new ORecord is created with the identity received and returned.
      Specified by:
      getRecord in interface ODatabaseDocument
      Returns:
      A ORecord instance
    • load

      public <RET extends ORecord> RET load(ORID iRecordId, String iFetchPlan, boolean iIgnoreCache)
      Loads the entity by the Record ID using a fetch plan and specifying if the cache must be ignored.
      Specified by:
      load in interface ODatabase<ORecord>
      Parameters:
      iRecordId - The unique record id of the entity to load.
      iFetchPlan - Fetch plan used
      iIgnoreCache - Ignore cache or use it
      Returns:
      The loaded entity
    • delete

      public ODatabase<ORecord> delete(ORID iRecord, int iVersion)
      Deletes the record checking the version.
      Specified by:
      delete in interface ODatabase<ORecord>
      Parameters:
      iRecord - The RecordID to delete.
      iVersion - for MVCC
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • cleanOutRecord

      public ODatabaseDocumentInternal cleanOutRecord(ORID iRecord, int iVersion)
      Specified by:
      cleanOutRecord in interface ODatabaseDocumentInternal
    • getType

      public String getType()
      Specified by:
      getType in interface ODatabase<ORecord>
    • browseCluster

      public <REC extends ORecord> ORecordIteratorCluster<REC> browseCluster(String iClusterName, Class<REC> iClass)
      Description copied from interface: ODatabaseDocument
      Browses all the records of the specified cluster of the passed record type.
      Specified by:
      browseCluster in interface ODatabaseDocument
      Parameters:
      iClusterName - Cluster name to iterate
      iClass - The record class expected
      Returns:
      Iterator of ODocument instances
    • browseCluster

      public <REC extends ORecord> ORecordIteratorCluster<REC> browseCluster(String iClusterName, Class<REC> iRecordClass, long startClusterPosition, long endClusterPosition)
      Specified by:
      browseCluster in interface ODatabaseDocument
    • getRecordType

      public byte getRecordType()
      Returns the default record type for this kind of database.
      Specified by:
      getRecordType in interface ODatabaseDocument
    • getMetadata

      public OSessionMetadata getMetadata()
      Return the OMetadata instance. Cannot be null.
      Specified by:
      getMetadata in interface ODatabase<ORecord>
      Specified by:
      getMetadata in interface ODatabaseDocumentInternal
      Returns:
      The OMetadata instance.
    • getDatabaseOwner

      public ODatabaseInternal<?> getDatabaseOwner()
      Returns the database owner. Used in wrapped instances to know the up level ODatabase instance.
      Specified by:
      getDatabaseOwner in interface ODatabaseInternal<ORecord>
      Returns:
      Returns the database owner.
    • setDatabaseOwner

      public ODatabaseInternal<ORecord> setDatabaseOwner(ODatabaseInternal<?> iOwner)
      Internal. Sets the database owner.
      Specified by:
      setDatabaseOwner in interface ODatabaseInternal<ORecord>
    • setStatus

      public <DB extends ODatabase> DB setStatus(ODatabase.STATUS status)
      Set the current status of database. deprecated since 2.2
      Specified by:
      setStatus in interface ODatabase<ORecord>
    • setStatusInternal

      public void setStatusInternal(ODatabase.STATUS status)
    • setInternal

      public void setInternal(ODatabase.ATTRIBUTES iAttribute, Object iValue)
      Internal method. Don't call it directly unless you're building an internal component.
      Specified by:
      setInternal in interface ODatabaseInternal<ORecord>
    • getUser

      public OSecurityUser getUser()
      Returns the current user logged into the database.
      Specified by:
      getUser in interface ODatabase<ORecord>
      See Also:
    • setUser

      public void setUser(OSecurityUser user)
      Set user for current database instance.
      Specified by:
      setUser in interface ODatabaseInternal<ORecord>
    • reloadUser

      public void reloadUser()
      Specified by:
      reloadUser in interface ODatabaseDocumentInternal
    • getDictionary

      @Deprecated public ODictionary<ORecord> getDictionary()
      Deprecated.
      Returns the Dictionary manual index.
      Specified by:
      getDictionary in interface ODatabase<ORecord>
      Returns:
      ODictionary instance
    • registerHook

      public <DB extends ODatabase<?>> DB registerHook(ORecordHook iHookImpl, ORecordHook.HOOK_POSITION iPosition)
      Specified by:
      registerHook in interface ODatabase<ORecord>
    • registerHook

      public <DB extends ODatabase<?>> DB registerHook(ORecordHook iHookImpl)
      Registers a hook to listen all events for Records.
      Specified by:
      registerHook in interface ODatabase<ORecord>
      Parameters:
      iHookImpl - ORecordHook implementation
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • unregisterHook

      public <DB extends ODatabase<?>> DB unregisterHook(ORecordHook iHookImpl)
      Unregisters a previously registered hook.
      Specified by:
      unregisterHook in interface ODatabase<ORecord>
      Parameters:
      iHookImpl - ORecordHook implementation
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain. deprecated since 2.2
    • getLocalCache

      public OLocalRecordCache getLocalCache()
      Returns the level1 cache. Cannot be null.
      Specified by:
      getLocalCache in interface ODatabase<ORecord>
      Returns:
      Current cache.
    • getHooks

      Retrieves all the registered hooks.
      Specified by:
      getHooks in interface ODatabase<ORecord>
      Returns:
      A not-null unmodifiable map of ORecordHook and position instances. If there are no hooks registered, the Map is empty.
    • callbackHooks

      public ORecordHook.RESULT callbackHooks(ORecordHook.TYPE type, OIdentifiable id)
      Callback the registered hooks if any.
      Specified by:
      callbackHooks in interface ODatabaseDocumentInternal
      Parameters:
      type - Hook type. Define when hook is called.
      id - Record received in the callback
      Returns:
      True if the input record is changed, otherwise false
    • isValidationEnabled

      public boolean isValidationEnabled()
      Tells if validation of record is active. Default is true.
      Specified by:
      isValidationEnabled in interface ODatabaseDocument
      Returns:
      true if it's active, otherwise false.
    • setValidationEnabled

      public <DB extends ODatabaseDocument> DB setValidationEnabled(boolean iEnabled)
      Enables or disables the record validation.

      Since 2.2 this setting is persistent.

      Specified by:
      setValidationEnabled in interface ODatabaseDocument
      Parameters:
      iEnabled - True to enable, false to disable
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • getConfiguration

      public OContextConfiguration getConfiguration()
      Description copied from interface: ODatabase
      Returns the database configuration settings. If defined, any database configuration overwrites the global one.
      Specified by:
      getConfiguration in interface ODatabase<ORecord>
      Returns:
      OContextConfiguration
    • close

      public void close()
      Description copied from interface: ODatabase
      Closes an opened database, if the database is already closed does nothing, if a transaction is active will be rollback.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface ODatabase<ORecord>
    • getStatus

      public ODatabase.STATUS getStatus()
      Description copied from interface: ODatabase
      Returns the current status of database.
      Specified by:
      getStatus in interface ODatabase<ORecord>
    • getName

      public String getName()
      Description copied from interface: ODatabase
      Returns the database name.
      Specified by:
      getName in interface ODatabase<ORecord>
      Returns:
      Name of the database
    • getURL

      public String getURL()
      Description copied from interface: ODatabase
      Returns the database URL.
      Specified by:
      getURL in interface ODatabase<ORecord>
      Returns:
      URL of the database
    • getDefaultClusterId

      public int getDefaultClusterId()
      Description copied from interface: ODatabase
      Returns the default cluster id. If not specified all the new entities will be stored in the default cluster.
      Specified by:
      getDefaultClusterId in interface ODatabase<ORecord>
      Returns:
      The default cluster id
    • getClusters

      public int getClusters()
      Description copied from interface: ODatabase
      Returns the number of clusters.
      Specified by:
      getClusters in interface ODatabase<ORecord>
      Returns:
      Number of the clusters
    • existsCluster

      public boolean existsCluster(String iClusterName)
      Description copied from interface: ODatabase
      Returns true if the cluster exists, otherwise false.
      Specified by:
      existsCluster in interface ODatabase<ORecord>
      Parameters:
      iClusterName - Cluster name
      Returns:
      true if the cluster exists, otherwise false
    • getClusterNames

      public Collection<String> getClusterNames()
      Description copied from interface: ODatabase
      Returns all the names of the clusters.
      Specified by:
      getClusterNames in interface ODatabase<ORecord>
      Returns:
      Collection of cluster names.
    • getClusterIdByName

      public int getClusterIdByName(String iClusterName)
      Description copied from interface: ODatabase
      Returns the cluster id by name.
      Specified by:
      getClusterIdByName in interface ODatabase<ORecord>
      Parameters:
      iClusterName - Cluster name
      Returns:
      The id of searched cluster.
    • getClusterNameById

      public String getClusterNameById(int iClusterId)
      Description copied from interface: ODatabase
      Returns the cluster name by id.
      Specified by:
      getClusterNameById in interface ODatabase<ORecord>
      Parameters:
      iClusterId - Cluster id
      Returns:
      The name of searched cluster.
    • checkForClusterPermissions

      public void checkForClusterPermissions(String iClusterName)
      Specified by:
      checkForClusterPermissions in interface ODatabaseDocumentInternal
    • setProperty

      public Object setProperty(String iName, Object iValue)
      Description copied from interface: ODatabase
      Sets a property value
      Specified by:
      setProperty in interface ODatabase<ORecord>
      Parameters:
      iName - Property name
      iValue - new value to set
      Returns:
      The previous value if any, otherwise null
    • getProperty

      public Object getProperty(String iName)
      Description copied from interface: ODatabase
      Gets the property value.
      Specified by:
      getProperty in interface ODatabase<ORecord>
      Parameters:
      iName - Property name
      Returns:
      The previous value if any, otherwise null
    • getProperties

      public Iterator<Map.Entry<String,Object>> getProperties()
      Description copied from interface: ODatabase
      Returns an iterator of the property entries
      Specified by:
      getProperties in interface ODatabase<ORecord>
    • get

      public Object get(ODatabase.ATTRIBUTES iAttribute)
      Description copied from interface: ODatabase
      Returns a database attribute value
      Specified by:
      get in interface ODatabase<ORecord>
      Parameters:
      iAttribute - Attributes between #ATTRIBUTES enum
      Returns:
      The attribute value
    • getTransaction

      public OTransaction getTransaction()
      Description copied from interface: ODatabase
      Return active transaction. Cannot be null. If no transaction is active, then a OTransactionNoTx instance is returned.
      Specified by:
      getTransaction in interface ODatabase<ORecord>
      Returns:
      OTransaction implementation
    • load

      public <RET extends ORecord> RET load(ORecord iRecord, String iFetchPlan)
      Description copied from interface: ODatabase
      Loads a record using a fetch plan.
      Specified by:
      load in interface ODatabase<ORecord>
      Parameters:
      iRecord - Record to load
      iFetchPlan - Fetch plan used
      Returns:
      The record received
    • load

      public <RET extends ORecord> RET load(ORecord iRecord)
      Description copied from interface: ODatabase
      Loads the entity and return it.
      Specified by:
      load in interface ODatabase<ORecord>
      Parameters:
      iRecord - The entity to load. If the entity was already loaded it will be reloaded and all the changes will be lost.
      Returns:
    • load

      public <RET extends ORecord> RET load(ORID recordId)
      Description copied from interface: ODatabase
      Loads the entity by the Record ID.
      Specified by:
      load in interface ODatabase<ORecord>
      Parameters:
      recordId - The unique record id of the entity to load.
      Returns:
      The loaded entity
    • load

      public <RET extends ORecord> RET load(ORID iRecordId, String iFetchPlan)
      Description copied from interface: ODatabase
      Loads the entity by the Record ID using a fetch plan.
      Specified by:
      load in interface ODatabase<ORecord>
      Parameters:
      iRecordId - The unique record id of the entity to load.
      iFetchPlan - Fetch plan used
      Returns:
      The loaded entity
    • loadIfVersionIsNotLatest

      public <RET extends ORecord> RET loadIfVersionIsNotLatest(ORID rid, int recordVersion, String fetchPlan, boolean ignoreCache) throws ORecordNotFoundException
      Specified by:
      loadIfVersionIsNotLatest in interface ODatabaseDocumentInternal
      Throws:
      ORecordNotFoundException
    • reload

      public <RET extends ORecord> RET reload(ORecord iRecord)
    • reload

      public <RET extends ORecord> RET reload(ORecord iRecord, String iFetchPlan)
    • reload

      public <RET extends ORecord> RET reload(ORecord iRecord, String iFetchPlan, boolean iIgnoreCache)
      Description copied from interface: ODatabase
      Force the reloading of the entity.
      Specified by:
      reload in interface ODatabase<ORecord>
      Parameters:
      iRecord - The entity to load. If the entity was already loaded it will be reloaded and all the changes will be lost.
      iFetchPlan - Fetch plan used
      iIgnoreCache - Ignore cache or use it
      Returns:
      The loaded entity
    • reload

      public <RET extends ORecord> RET reload(ORecord record, String fetchPlan, boolean ignoreCache, boolean force)
      Description copied from interface: ODatabase
      Force the reloading of the entity.
      Specified by:
      reload in interface ODatabase<ORecord>
      Parameters:
      record - The entity to load. If the entity was already loaded it will be reloaded and all the changes will be lost.
      fetchPlan - Fetch plan used
      ignoreCache - Ignore cache or use it
      force - Force to reload record even if storage has the same record as reloaded record, it is useful if fetch plan is not null and alongside with root record linked records will be reloaded.
      Returns:
      The loaded entity
    • delete

      public ODatabaseDocument delete(ORID iRecord)
      Deletes the record without checking the version.
      Specified by:
      delete in interface ODatabase<ORecord>
      Parameters:
      iRecord - The RecordID to delete.
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • getSerializerFactory

      public OBinarySerializerFactory getSerializerFactory()
      Specified by:
      getSerializerFactory in interface ODatabaseDocumentInternal
      Returns:
      the factory of binary serializers.
    • swapTx

      public OTransaction swapTx(OTransaction newTx)
      Specified by:
      swapTx in interface ODatabaseDocumentInternal
    • rawBegin

      public void rawBegin(OTransaction iTx)
      Specified by:
      rawBegin in interface ODatabaseDocumentInternal
    • load

      public <RET extends ORecord> RET load(ORecord iRecord, String iFetchPlan, boolean iIgnoreCache)
      Loads a record using a fetch plan.
      Specified by:
      load in interface ODatabase<ORecord>
      Parameters:
      iRecord - Record to load
      iFetchPlan - Fetch plan used
      iIgnoreCache - Ignore cache or use it
      Returns:
      The record received
    • setPrefetchRecords

      public void setPrefetchRecords(boolean prefetchRecords)
      Specified by:
      setPrefetchRecords in interface ODatabaseDocumentInternal
    • isPrefetchRecords

      public boolean isPrefetchRecords()
      Specified by:
      isPrefetchRecords in interface ODatabaseDocumentInternal
    • executeReadRecord

      public abstract <RET extends ORecord> RET executeReadRecord(ORecordId rid, ORecord iRecord, int recordVersion, String fetchPlan, boolean ignoreCache, boolean iUpdateCache, RecordReader recordReader)
      This method is internal, it can be subject to signature change or be removed, do not use. @Internal
      Specified by:
      executeReadRecord in interface ODatabaseDocumentInternal
    • assignAndCheckCluster

      public int assignAndCheckCluster(ORecord record, String iClusterName)
      Specified by:
      assignAndCheckCluster in interface ODatabaseDocumentInternal
    • begin

      public ODatabaseDocumentAbstract begin()
      Description copied from interface: ODatabase
      Begins a new transaction. By default the type is OPTIMISTIC. If a previous transaction is running a nested call counter is incremented. A transaction once begun has to be closed by calling the ODatabase.commit() or ODatabase.rollback().
      Specified by:
      begin in interface ODatabase<ORecord>
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • begin

      Description copied from interface: ODatabase
      Begins a new transaction specifying the transaction type. If a previous transaction is running a nested call counter is incremented. A transaction once begun has to be closed by calling the ODatabase.commit() or ODatabase.rollback().
      Specified by:
      begin in interface ODatabase<ORecord>
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • setDefaultTransactionMode

      public void setDefaultTransactionMode(Map<ORID,OTransactionAbstract.LockedRecordMetadata> noTxLocks)
      Specified by:
      setDefaultTransactionMode in interface ODatabaseDocumentInternal
    • newInstance

      public ODocument newInstance()
      Creates a new ODocument.
      Specified by:
      newInstance in interface ODatabase<ORecord>
      Returns:
      The new instance.
    • newBlob

      public OBlob newBlob(byte[] bytes)
      Description copied from interface: ODatabaseDocument
      Create a new instance of a blob containing the given bytes.
      Specified by:
      newBlob in interface ODatabaseDocument
      Parameters:
      bytes - content of the OBlob
      Returns:
      the OBlob instance.
    • newBlob

      public OBlob newBlob()
      Description copied from interface: ODatabaseDocument
      Create a new empty instance of a blob.
      Specified by:
      newBlob in interface ODatabaseDocument
      Returns:
      the OBlob instance.
    • newInstance

      public ODocument newInstance(String iClassName)
      Creates a document with specific class.
      Specified by:
      newInstance in interface ODatabaseDocument
      Parameters:
      iClassName - the name of class that should be used as a class of created document.
      Returns:
      new instance of document.
    • newEmbeddedElement

      public OElement newEmbeddedElement()
      Specified by:
      newEmbeddedElement in interface ODatabaseDocument
    • newEmbeddedElement

      public OElement newEmbeddedElement(String className)
      Specified by:
      newEmbeddedElement in interface ODatabaseDocument
    • newElement

      public OElement newElement()
      Specified by:
      newElement in interface ODatabaseDocument
    • newElement

      public OElement newElement(String className)
      Specified by:
      newElement in interface ODatabaseDocument
    • newElement

      public OElement newElement(OClass clazz)
    • newVertex

      public OVertex newVertex(String iClassName)
      Description copied from interface: ODatabaseDocument
      Creates a new Vertex
      Specified by:
      newVertex in interface ODatabaseDocument
      Parameters:
      iClassName - the vertex type (class name)
      Returns:
    • newVertex

      public OVertex newVertex(OClass type)
      Description copied from interface: ODatabaseDocument
      Creates a new Vertex
      Specified by:
      newVertex in interface ODatabaseDocument
      Parameters:
      type - the vertex type
      Returns:
    • newEdge

      public OEdge newEdge(OVertex from, OVertex to, String type)
      Description copied from interface: ODatabaseDocument
      Creates a new Edge
      Specified by:
      newEdge in interface ODatabaseDocument
      Parameters:
      from - the starting point vertex
      to - the endpoint vertex
      type - the edge type
      Returns:
      the edge
    • newEdge

      public OEdge newEdge(OVertex from, OVertex to, OClass type)
      Description copied from interface: ODatabaseDocument
      Creates a new Edge
      Specified by:
      newEdge in interface ODatabaseDocument
      Parameters:
      from - the starting point vertex
      to - the endpoint vertex
      type - the edge type
      Returns:
      the edge
    • browseClass

      public ORecordIteratorClass<ODocument> browseClass(String iClassName)
      Browses all the records of the specified class and also all the subclasses. If you've a class Vehicle and Car that extends Vehicle then a db.browseClass("Vehicle", true) will return all the instances of Vehicle and Car. The order of the returned instance starts from record id with position 0 until the end. Base classes are worked at first.
      Specified by:
      browseClass in interface ODatabaseDocument
      Parameters:
      iClassName - Class name to iterate
      Returns:
      Iterator of ODocument instances
    • browseClass

      public ORecordIteratorClass<ODocument> browseClass(String iClassName, boolean iPolymorphic)
      Browses all the records of the specified class and if iPolymorphic is true also all the subclasses. If you've a class Vehicle and Car that extends Vehicle then a db.browseClass("Vehicle", true) will return all the instances of Vehicle and Car. The order of the returned instance starts from record id with position 0 until the end. Base classes are worked at first.
      Specified by:
      browseClass in interface ODatabaseDocument
      Parameters:
      iClassName - Class name to iterate
      iPolymorphic - Consider also the instances of the subclasses or not
      Returns:
      Iterator of ODocument instances
    • browseCluster

      public ORecordIteratorCluster<ODocument> browseCluster(String iClusterName)
      Browses all the records of the specified cluster.
      Specified by:
      browseCluster in interface ODatabaseDocument
      Parameters:
      iClusterName - Cluster name to iterate
      Returns:
      Iterator of ODocument instances
    • getListeners

      public Iterable<ODatabaseListener> getListeners()
      Retrieves all the registered listeners.
      Specified by:
      getListeners in interface ODatabase<ORecord>
      Returns:
      An iterable of ODatabaseListener instances.
    • save

      public <RET extends ORecord> RET save(ORecord iRecord)
      Saves a document to the database. Behavior depends by the current running transaction if any. If no transaction is running then changes apply immediately. If an Optimistic transaction is running then the record will be changed at commit time. The current transaction will continue to see the record as modified, while others not. If a Pessimistic transaction is running, then an exclusive lock is acquired against the record. Current transaction will continue to see the record as modified, while others cannot access to it since it's locked.

      If MVCC is enabled and the version of the document is different by the version stored in the database, then a OConcurrentModificationException exception is thrown.Before to save the document it must be valid following the constraints declared in the schema if any (can work also in schema-less mode). To validate the document the ODocument.validate() is called.

      Specified by:
      save in interface ODatabase<ORecord>
      Parameters:
      iRecord - Record to save.
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
      Throws:
      OConcurrentModificationException - if the version of the document is different by the version contained in the database.
      OValidationException - if the document breaks some validation constraints defined in the schema
    • save

      public <RET extends ORecord> RET save(ORecord iRecord, String iClusterName)
      Saves a document specifying a cluster where to store the record. Behavior depends by the current running transaction if any. If no transaction is running then changes apply immediately. If an Optimistic transaction is running then the record will be changed at commit time. The current transaction will continue to see the record as modified, while others not. If a Pessimistic transaction is running, then an exclusive lock is acquired against the record. Current transaction will continue to see the record as modified, while others cannot access to it since it's locked.

      If MVCC is enabled and the version of the document is different by the version stored in the database, then a OConcurrentModificationException exception is thrown. Before to save the document it must be valid following the constraints declared in the schema if any (can work also in schema-less mode). To validate the document the ODocument.validate() is called.

      Specified by:
      save in interface ODatabase<ORecord>
      Parameters:
      iRecord - Record to save
      iClusterName - Cluster name where to save the record
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
      Throws:
      OConcurrentModificationException - if the version of the document is different by the version contained in the database.
      OValidationException - if the document breaks some validation constraints defined in the schema
      See Also:
    • save

      public <RET extends ORecord> RET save(ORecord iRecord, String iClusterName, boolean iForceCreate)
      Saves a document specifying a cluster where to store the record. Behavior depends by the current running transaction if any. If no transaction is running then changes apply immediately. If an Optimistic transaction is running then the record will be changed at commit time. The current transaction will continue to see the record as modified, while others not. If a Pessimistic transaction is running, then an exclusive lock is acquired against the record. Current transaction will continue to see the record as modified, while others cannot access to it since it's locked.

      If MVCC is enabled and the version of the document is different by the version stored in the database, then a OConcurrentModificationException exception is thrown. Before to save the document it must be valid following the constraints declared in the schema if any (can work also in schema-less mode). To validate the document the ODocument.validate() is called.

      Specified by:
      save in interface ODatabaseInternal<ORecord>
      Parameters:
      iRecord - Record to save
      iClusterName - Cluster name where to save the record
      iMode - Mode of save: synchronous (default) or asynchronous
      iForceCreate - Flag that indicates that record should be created. If record with current rid already exists, exception is thrown
      iRecordCreatedCallback - callback that is called after creation of new record
      iRecordUpdatedCallback - callback that is called after record update
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
      Throws:
      OConcurrentModificationException - if the version of the document is different by the version contained in the database.
      OValidationException - if the document breaks some validation constraints defined in the schema
    • countView

      public long countView(String viewName)
      Returns the number of the records of the class iClassName.
      Specified by:
      countView in interface ODatabaseDocument
    • countClass

      public long countClass(String iClassName)
      Returns the number of the records of the class iClassName.
      Specified by:
      countClass in interface ODatabaseDocument
      Parameters:
      iClassName - Class name
      Returns:
      Total entities
    • countClass

      public long countClass(String iClassName, boolean iPolymorphic)
      Returns the number of the records of the class iClassName considering also sub classes if polymorphic is true.
      Specified by:
      countClass in interface ODatabaseDocument
      Parameters:
      iClassName - Class name
      iPolymorphic - True if consider also the sub classes, otherwise false
      Returns:
      Total entities
    • countClass

      protected long countClass(OImmutableClass cls, boolean iPolymorphic)
    • commit

      public ODatabase<ORecord> commit()
      Commits the current transaction. The approach is all or nothing. All changes will be permanent following the storage type. If the operation succeed all the entities changed inside the transaction context will be effective. If the operation fails, all the changed entities will be restored in the data store.
      Specified by:
      commit in interface ODatabase<ORecord>
      Returns:
    • commit

      public ODatabaseDocument commit(boolean force) throws OTransactionException
      Specified by:
      commit in interface ODatabase<ORecord>
      Throws:
      OTransactionException
    • beforeCommitOperations

      protected void beforeCommitOperations()
    • afterCommitOperations

      protected void afterCommitOperations()
    • beforeRollbackOperations

      protected void beforeRollbackOperations()
    • afterRollbackOperations

      protected void afterRollbackOperations()
    • rollback

      public ODatabase<ORecord> rollback()
      Aborts the current running transaction. All the pending changed entities will be restored in the data store.
      Specified by:
      rollback in interface ODatabase<ORecord>
      Returns:
    • rollback

      public ODatabaseDocument rollback(boolean force) throws OTransactionException
      Specified by:
      rollback in interface ODatabase<ORecord>
      Throws:
      OTransactionException
    • getUnderlying

      public <DB extends ODatabase> DB getUnderlying()
      This method is internal, it can be subject to signature change or be removed, do not use. @Internal
      Specified by:
      getUnderlying in interface ODatabaseInternal<ORecord>
      Returns:
      The underlying ODatabase implementation.
    • getStorageVersions

      public OCurrentStorageComponentsFactory getStorageVersions()
      Description copied from interface: ODatabaseDocumentInternal
      Internal. Returns the factory that defines a set of components that current database should use to be compatible to current version of storage. So if you open a database create with old version of OrientDB it defines a components that should be used to provide backward compatibility with that version of database.
      Specified by:
      getStorageVersions in interface ODatabaseDocumentInternal
    • getSerializer

      public ORecordSerializer getSerializer()
      Specified by:
      getSerializer in interface ODatabaseDocumentInternal
      Returns:
      serializer which is used for document serialization.
    • setSerializer

      public void setSerializer(ORecordSerializer serializer)
      Sets serializer for the database which will be used for document serialization.
      Specified by:
      setSerializer in interface ODatabaseDocumentInternal
      Parameters:
      serializer - the serializer to set.
    • resetInitialization

      public void resetInitialization()
      Specified by:
      resetInitialization in interface ODatabaseInternal<ORecord>
    • checkSecurity

      public void checkSecurity(int operation, OIdentifiable record, String cluster)
    • isPooled

      public boolean isPooled()
      Specified by:
      isPooled in interface ODatabaseDocument
      Returns:
      true if database is obtained from the pool and false otherwise.
    • setCurrentDatabaseInThreadLocal

      @Deprecated public void setCurrentDatabaseInThreadLocal()
      Deprecated.
      Use #activateOnCurrentThread instead.
    • activateOnCurrentThread

      public ODatabaseDocumentAbstract activateOnCurrentThread()
      Activates current database instance on current thread.
      Specified by:
      activateOnCurrentThread in interface ODatabase<ORecord>
    • isActiveOnCurrentThread

      public boolean isActiveOnCurrentThread()
      Description copied from interface: ODatabase
      Returns true if the current database instance is active on current thread, otherwise false.
      Specified by:
      isActiveOnCurrentThread in interface ODatabase<ORecord>
    • checkOpenness

      protected void checkOpenness()
    • callbackHookFailure

      protected void callbackHookFailure(ORecord record, boolean wasNew, byte[] stream)
    • callbackHookSuccess

      protected void callbackHookSuccess(ORecord record, boolean wasNew, byte[] stream, OStorageOperationResult<Integer> operationResult)
    • callbackHookFinalize

      protected void callbackHookFinalize(ORecord record, boolean wasNew, byte[] stream)
    • clearDocumentTracking

      protected void clearDocumentTracking(ORecord record)
    • checkRecordClass

      protected void checkRecordClass(OClass recordClass, String iClusterName, ORecordId rid)
    • init

      protected void init()
    • checkIfActive

      public void checkIfActive()
      Specified by:
      checkIfActive in interface ODatabaseDocumentInternal
    • getBlobClusterIds

      public Set<Integer> getBlobClusterIds()
      Description copied from interface: ODatabase
      Retrieve the set of defined blob cluster.
      Specified by:
      getBlobClusterIds in interface ODatabase<ORecord>
      Returns:
      the set of defined blob cluster ids.
    • getSharedContext

      public OSharedContext getSharedContext()
      Specified by:
      getSharedContext in interface ODatabaseInternal<ORecord>
    • executeWithRetries

      public static Object executeWithRetries(OCallable<Object,Integer> callback, int maxRetry)
    • executeWithRetries

      public static Object executeWithRetries(OCallable<Object,Integer> callback, int maxRetry, int waitBetweenRetry)
    • executeWithRetries

      public static Object executeWithRetries(OCallable<Object,Integer> callback, int maxRetry, int waitBetweenRetry, ORecord[] recordToReloadOnRetry)
    • isUseLightweightEdges

      public boolean isUseLightweightEdges()
      Specified by:
      isUseLightweightEdges in interface ODatabaseDocumentInternal
    • setUseLightweightEdges

      public void setUseLightweightEdges(boolean b)
      Specified by:
      setUseLightweightEdges in interface ODatabaseDocumentInternal
    • newLightweightEdge

      public OEdge newLightweightEdge(String iClassName, OVertex from, OVertex to)
      Specified by:
      newLightweightEdge in interface ODatabaseDocumentInternal
    • newRegularEdge

      public OEdge newRegularEdge(String iClassName, OVertex from, OVertex to)
      Specified by:
      newRegularEdge in interface ODatabaseDocumentInternal
    • queryStarted

      public void queryStarted(String id, OQueryDatabaseState state)
    • queryClosed

      public void queryClosed(String id)
    • closeActiveQueries

      protected void closeActiveQueries()
    • getActiveQueries

      public Map<String,OQueryDatabaseState> getActiveQueries()
      Specified by:
      getActiveQueries in interface ODatabaseDocumentInternal
    • getActiveQuery

      public OResultSet getActiveQuery(String id)
      Specified by:
      getActiveQuery in interface ODatabaseDocumentInternal
    • isClusterEdge

      public boolean isClusterEdge(int cluster)
      Specified by:
      isClusterEdge in interface ODatabaseDocumentInternal
    • isClusterVertex

      public boolean isClusterVertex(int cluster)
      Specified by:
      isClusterVertex in interface ODatabaseDocumentInternal
    • isClusterView

      public boolean isClusterView(int cluster)
      Specified by:
      isClusterView in interface ODatabaseDocumentInternal
    • getViewFromCluster

      public OView getViewFromCluster(int cluster)
      Specified by:
      getViewFromCluster in interface ODatabaseDocumentInternal
    • pessimisticLockChecks

      protected void pessimisticLockChecks(ORID recordId)
    • getCollectionsChanges

      public Map<UUID,OBonsaiCollectionPointer> getCollectionsChanges()
      Specified by:
      getCollectionsChanges in interface ODatabaseDocumentInternal