Class ODatabaseDocumentRemote

All Implemented Interfaces:
ODatabaseDocument, ODatabase<ORecord>, ODatabaseDocumentInternal, ODatabaseInternal<ORecord>, ODatabaseSession, OBackupable, Closeable, AutoCloseable
Direct Known Subclasses:
ODatabaseDocumentRemotePooled

public class ODatabaseDocumentRemote extends ODatabaseDocumentAbstract
Created by tglman on 30/06/16.
  • Field Details

  • Constructor Details

  • Method Details

    • set

      public <DB extends ODatabase> DB set(ODatabase.ATTRIBUTES iAttribute, Object iValue)
      Description copied from interface: ODatabase
      Sets a database attribute value
      Parameters:
      iAttribute - Attributes between #ATTRIBUTES enum
      iValue - Value to set
      Returns:
      underlying
    • setCustom

      public <DB extends ODatabase> DB setCustom(String name, Object iValue)
    • copy

    • internalOpen

      public void internalOpen(String user, String password, OrientDBConfig config)
    • initPush

      public void initPush(OMetadataPushListener handler)
    • loadMetadata

      protected void loadMetadata()
      Specified by:
      loadMetadata in class ODatabaseDocumentAbstract
    • 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>
      Overrides:
      begin in class ODatabaseDocumentAbstract
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • getSession

      public ORemoteClientSession getSession()
    • setSessionMetadata

      public void setSessionMetadata(ORemoteClientSession sessionMetadata)
    • getStorage

      public OStorage getStorage()
      Description copied from interface: ODatabaseInternal
      Returns the underlying storage implementation.
      Returns:
      The underlying storage implementation
      See Also:
    • getRemoteClient

      public ORemoteClient getRemoteClient()
    • getStorageInfo

      public OStorageInfo getStorageInfo()
    • replaceStorage

      public void replaceStorage(OStorage iNewStorage)
      Description copied from interface: ODatabaseInternal
      Internal only: replace the storage with a new one.
      Parameters:
      iNewStorage - The new storage to use. Usually it's a wrapped instance of the current cluster.
    • query

      public OResultSet query(String query, Object... args)
      Description copied from interface: ODatabase
      Executes an SQL query. The result set has to be closed after usage

      Sample usage:

      OResultSet rs = db.query("SELECT FROM V where name = ?", "John"); while(rs.hasNext()){ OResult item = rs.next(); ... } rs.close();

      Parameters:
      query - the query string
      args - query parameters (positional)
      Returns:
      the query result set
    • query

      public OResultSet query(String query, Map args)
      Description copied from interface: ODatabase
      Executes an SQL query (idempotent). The result set has to be closed after usage

      Sample usage:

      Map<String, Object&gt params = new HashMapMap<&gt(); params.put("name", "John"); OResultSet rs = db.query("SELECT FROM V where name = :name", params); while(rs.hasNext()){ OResult item = rs.next(); ... } rs.close();

      Parameters:
      query - the query string
      args - query parameters (named)
      Returns:
    • indexQuery

      public OResultSet indexQuery(String indexName, String query, Object... args)
    • command

      public OResultSet command(String query, Object... args)
      Description copied from interface: ODatabase
      Executes a generic (idempotent or non idempotent) command. The result set has to be closed after usage

      Sample usage:

      OResultSet rs = db.command("INSERT INTO Person SET name = ?", "John"); ... rs.close();

      args - query arguments
      Returns:
    • command

      public OResultSet command(String query, Map args)
      Description copied from interface: ODatabase
      Executes a generic (idempotent or non idempotent) command. The result set has to be closed after usage

      Sample usage:

      Map<String, Object&gt params = new HashMapMap<&gt(); params.put("name", "John"); OResultSet rs = db.query("INSERT INTO Person SET name = :name", params); ... rs.close();

      Returns:
    • execute

      public OResultSet execute(String language, String script, Object... args) throws OCommandExecutionException, OCommandScriptException
      Description copied from interface: ODatabase
      Execute a script in a specified query language. The result set has to be closed after usage

      Sample usage:

      String script = "INSERT INTO Person SET name = 'foo', surname = ?;"+ "INSERT INTO Person SET name = 'bar', surname = ?;"+ "INSERT INTO Person SET name = 'baz', surname = ?;";

      OResultSet rs = db.execute("sql", script, "Surname1", "Surname2", "Surname3"); ... rs.close();

      Returns:
      Throws:
      OCommandExecutionException
      OCommandScriptException
    • execute

      public OResultSet execute(String language, String script, Map<String,?> args) throws OCommandExecutionException, OCommandScriptException
      Description copied from interface: ODatabase
      Execute a script of a specified query language The result set has to be closed after usage

      Sample usage:

      Map<String, Object&gt params = new HashMapMap<&gt(); params.put("surname1", "Jones"); params.put("surname2", "May"); params.put("surname3", "Ali");

      String script = "INSERT INTO Person SET name = 'foo', surname = :surname1;"+ "INSERT INTO Person SET name = 'bar', surname = :surname2;"+ "INSERT INTO Person SET name = 'baz', surname = :surname3;";

      OResultSet rs = db.execute("sql", script, params); ... rs.close();

      Returns:
      Throws:
      OCommandExecutionException
      OCommandScriptException
    • closeQuery

      public void closeQuery(String queryId)
    • fetchNextPage

      public void fetchNextPage(ORemoteResultSet rs)
    • live

      public OLiveQueryMonitor live(String query, OLiveQueryResultListener listener, Object... args)
      Description copied from interface: ODatabase
      Subscribe a query as a live query for future create/update event with the referred conditions
      Parameters:
      query - live query
      listener - the listener that receive the query results
      args - the live query args
    • live

      public OLiveQueryMonitor live(String query, OLiveQueryResultListener listener, Map<String,?> args)
      Description copied from interface: ODatabase
      Subscribe a query as a live query for future create/update event with the referred conditions
      Parameters:
      query - live query
      listener - the listener that receive the query results
      args - the live query args
    • addBlobCluster

      public int addBlobCluster(String iClusterName, Object... iParameters)
      Description copied from interface: ODatabaseDocument
      Add a cluster for blob records.
      Parameters:
      iClusterName - Cluster name
      iParameters - Additional parameters to pass to the factories
      Returns:
      Cluster id
    • executeDeleteRecord

      public void executeDeleteRecord(OIdentifiable record, int iVersion, boolean iRequired)
    • beforeCreateOperations

      public OIdentifiable beforeCreateOperations(OIdentifiable id, String iClusterName)
      Returns:
      null if nothing changed the instance if has been modified or replaced
    • beforeUpdateOperations

      public OIdentifiable beforeUpdateOperations(OIdentifiable id, String iClusterName)
      Returns:
      null if nothing changed the instance if has been modified or replaced
    • beforeDeleteOperations

      public void beforeDeleteOperations(OIdentifiable id, String iClusterName)
    • afterUpdateOperations

      public void afterUpdateOperations(OIdentifiable id)
    • afterCreateOperations

      public void afterCreateOperations(OIdentifiable id)
    • afterDeleteOperations

      public void afterDeleteOperations(OIdentifiable id)
    • beforeReadOperations

      public boolean beforeReadOperations(OIdentifiable identifiable)
      Returns:
      true if the record should be skipped
    • afterReadOperations

      public void afterReadOperations(OIdentifiable identifiable)
    • saveAll

      public ORecord saveAll(ORecord iRecord, String iClusterName, boolean iForceCreate)
    • executeReadRecord

      public <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
      Specified by:
      executeReadRecord in class ODatabaseDocumentAbstract
    • getClusterName

      public String getClusterName(ORecord record)
    • internalLockRecord

      public void internalLockRecord(OIdentifiable iRecord, OStorage.LOCKING_STRATEGY lockingStrategy)
    • internalUnlockRecord

      public void internalUnlockRecord(OIdentifiable iRecord)
    • lock

      public <RET extends ORecord> RET lock(ORID recordId) throws OLockException
      Description copied from interface: ODatabase
      Pessimistic lock a record.

      In case of lock inside the transaction the lock will be release by the commit operation, In case of lock outside a transaction unlock need to be call manually.

      Parameters:
      recordId - the id of the record that need to be locked
      Returns:
      the record updated to the last state after the lock.
      Throws:
      OLockException - In case of deadlock detected
    • lock

      public <RET extends ORecord> RET lock(ORID recordId, long timeout, TimeUnit timeoutUnit) throws OLockException
      Description copied from interface: ODatabase
      Pessimistic lock a record.
      Parameters:
      recordId - the id of the record that need to be locked
      timeout - for the record locking
      timeoutUnit - relative for the timeout
      Returns:
      the record updated to the last state after the lock.
      Throws:
      OLockException - In case of deadlock detected
    • unlock

      public void unlock(ORID recordId) throws OLockException
      Description copied from interface: ODatabase
      Pessimistic unlock
      Parameters:
      recordId - the id of the record to unlock
      Throws:
      OLockException - if the record is not locked.
    • sendSequenceAction

      public <T> T sendSequenceAction(OSequenceAction action) throws ExecutionException, InterruptedException
      Throws:
      ExecutionException
      InterruptedException
    • delete

      public ODatabaseDocumentAbstract delete(ORecord record)
      Description copied from interface: ODatabase
      Deletes an entity from the database in synchronous mode.
      Parameters:
      record - The entity to delete.
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • addCluster

      public int addCluster(String iClusterName, Object... iParameters)
      Description copied from interface: ODatabase
      Adds a new cluster.
      Parameters:
      iClusterName - Cluster name
      iParameters - Additional parameters to pass to the factories
      Returns:
      Cluster id
    • addCluster

      public int addCluster(String iClusterName, int iRequestedId)
      Description copied from interface: ODatabase
      Adds a new cluster.
      Parameters:
      iClusterName - Cluster name
      iRequestedId - requested id of the cluster
      Returns:
      Cluster id
    • getConflictStrategy

      public ORecordConflictStrategy getConflictStrategy()
      Description copied from interface: ODatabase
      Returns the current record conflict strategy.
    • setConflictStrategy

      public ODatabaseDocumentAbstract setConflictStrategy(String iStrategyName)
      Description copied from interface: ODatabase
      Overrides record conflict strategy selecting the strategy by name.
      Parameters:
      iStrategyName - ORecordConflictStrategy strategy name
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • setConflictStrategy

      public ODatabaseDocumentAbstract setConflictStrategy(ORecordConflictStrategy iResolver)
      Description copied from interface: ODatabase
      Overrides record conflict strategy.
      Parameters:
      iResolver - ORecordConflictStrategy implementation
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • countClusterElements

      public long countClusterElements(int iClusterId)
      Counts all the entities in the specified cluster id.
      Parameters:
      iClusterId - Cluster id
      Returns:
      Total number of entities contained in the specified cluster
    • countClusterElements

      public long countClusterElements(int[] iClusterIds)
      Counts all the entities in the specified cluster ids.
      Parameters:
      iClusterIds - Array of cluster ids Cluster id
      Returns:
      Total number of entities contained in the specified clusters
    • countClusterElements

      public long countClusterElements(String iClusterName)
      Counts all the entities in the specified cluster name.
      Parameters:
      iClusterName - Cluster name
      Returns:
      Total number of entities contained in the specified cluster
    • getClusterRecordSizeByName

      public long getClusterRecordSizeByName(String clusterName)
      Description copied from interface: ODatabase
      Returns the total size of records contained in the cluster defined by its name.
      Parameters:
      clusterName - Cluster name
      Returns:
      Total size of records contained.
    • dropCluster

      public boolean dropCluster(String iClusterName)
      Description copied from interface: ODatabase
      Drops a cluster by its name. Physical clusters will be completely deleted
      Parameters:
      iClusterName - the name of the cluster
      Returns:
      true if has been removed, otherwise false
    • dropCluster

      public boolean dropCluster(int clusterId)
      Description copied from interface: ODatabase
      Drops a cluster by its id. Physical clusters will be completely deleted.
      Parameters:
      clusterId - id of cluster to delete
      Returns:
      true if has been removed, otherwise false
    • dropClusterInternal

      public boolean dropClusterInternal(int clusterId)
    • getClusterRecordSizeById

      public long getClusterRecordSizeById(int clusterId)
      Description copied from interface: ODatabase
      Returns the total size of records contained in the cluster defined by its id.
      Parameters:
      clusterId - Cluster id
      Returns:
      The name of searched cluster.
    • getSize

      public long getSize()
      Description copied from interface: ODatabase
      Returns the total size of the records in the database.
    • checkSecurity

      public <DB extends ODatabaseDocument> DB checkSecurity(ORule.ResourceGeneric resourceGeneric, String resourceSpecific, int iOperation)
      Description copied from interface: ODatabaseDocument
      Checks if the operation on a resource is allowed for the current user.
      Parameters:
      resourceGeneric - Generic Resource where to execute the operation
      iOperation - Operation to execute against the resource
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • checkSecurity

      public <DB extends ODatabaseDocument> DB checkSecurity(ORule.ResourceGeneric iResourceGeneric, int iOperation, Object iResourceSpecific)
      Description copied from interface: ODatabaseDocument
      Checks if the operation on a resource is allowed for the current user. The check is made in two steps:
      1. Access to all the resource as *
      2. Access to the specific target resource
      Parameters:
      iResourceGeneric - Resource where to execute the operation, i.e.: database.clusters
      iOperation - Operation to execute against the resource
      iResourceSpecific - Target resource, i.e.: "employee" to specify the cluster name.
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • checkSecurity

      public <DB extends ODatabaseDocument> DB checkSecurity(ORule.ResourceGeneric iResourceGeneric, int iOperation, Object... iResourcesSpecific)
      Description copied from interface: ODatabaseDocument
      Checks if the operation against multiple resources is allowed for the current user. The check is made in two steps:
      1. Access to all the resource as *
      2. Access to the specific target resources
      Parameters:
      iResourceGeneric - Resource where to execute the operation, i.e.: database.clusters
      iOperation - Operation to execute against the resource
      iResourcesSpecific - Target resources as an array of Objects, i.e.: ["employee", 2] to specify cluster name and id.
      Returns:
      The Database instance itself giving a "fluent interface". Useful to call multiple methods in chain.
    • isRemote

      public boolean isRemote()
    • incrementalBackup

      public String incrementalBackup(String path) throws UnsupportedOperationException
      Description copied from interface: ODatabase
      Performs incremental backup of database content to the selected folder. This is thread safe operation and can be done in normal operational mode.

      If it will be first backup of data full content of database will be copied into folder otherwise only changes after last backup in the same folder will be copied.

      Parameters:
      path - Path to backup folder.
      Returns:
      File name of the backup
      Throws:
      UnsupportedOperationException
    • getRecordMetadata

      public ORecordMetadata getRecordMetadata(ORID rid)
    • freeze

      public void freeze(boolean throwException)
      Flush all indexes and cached storage content to the disk.

      After this call users can perform only select queries. All write-related commands will queued till ODatabaseDocument.release() command will be called or exception will be thrown on attempt to modify DB data. Concrete behaviour depends on throwException parameter.

      IMPORTANT: This command is not reentrant.

      Parameters:
      throwException - If true OModificationOperationProhibitedException exception will be thrown in case of write command will be performed.
    • freeze

      public void freeze()
      Flush all indexes and cached storage content to the disk.

      After this call users can perform only select queries. All write-related commands will queued till ODatabaseDocument.release() command will be called.

      Given command waits till all on going modifications in indexes or DB will be finished.

      IMPORTANT: This command is not reentrant.

      See Also:
    • release

      public void release()
      Allows to execute write-related commands on DB. Called after ODatabaseDocument.freeze() command.
      See Also:
    • backup

      public List<String> backup(OutputStream out, Map<String,Object> options, Callable<Object> callable, OCommandOutputListener iListener, int compressionLevel, int bufferSize) throws IOException
      Description copied from interface: OBackupable
      Executes a backup of the database. During the backup the database will be frozen in read-only mode.
      Parameters:
      out - OutputStream used to write the backup content. Use a FileOutputStream to make the backup persistent on disk
      options - Backup options as Map<String, Object> object
      callable - Callback to execute when the database is locked
      iListener - Listener called for backup messages
      compressionLevel - ZIP Compression level between 1 (the minimum) and 9 (maximum). The bigger is the compression, the smaller will be the final backup content, but will consume more CPU and time to execute
      bufferSize - Buffer size in bytes, the bigger is the buffer, the more efficient will be the compression
      Throws:
      IOException
      See Also:
    • restore

      public void restore(InputStream in, Map<String,Object> options, Callable<Object> callable, OCommandOutputListener iListener) throws IOException
      Description copied from interface: OBackupable
      Executes a restore of a database backup. During the restore the database will be frozen in read-only mode.
      Parameters:
      in - InputStream used to read the backup content. Use a FileInputStream to read a backup on a disk
      options - Backup options as Map<String, Object> object
      callable - Callback to execute when the database is locked
      iListener - Listener called for backup messages
      Throws:
      IOException
      See Also:
    • getSbTreeCollectionManager

      public OSBTreeCollectionManager getSbTreeCollectionManager()
      Internal. Gets an instance of sb-tree collection manager for current database.
    • reload

      public void reload()
      Description copied from interface: ODatabase
      Reloads the database information like the cluster list.
    • internalCommit

      public void internalCommit(OTransactionInternal transaction)
      Description copied from interface: ODatabaseDocumentInternal
      Executed the commit on the storage hiding away storage concepts from the transaction
    • isClosed

      public boolean isClosed()
      Description copied from interface: ODatabase
      Checks if the database is closed.
      Returns:
      true if is closed, otherwise false.
    • internalClose

      public void internalClose(boolean recycle)
    • getClusterDataRange

      public long[] getClusterDataRange(int currentClusterId)
    • setDefaultClusterId

      public void setDefaultClusterId(int addCluster)
    • getLastClusterPosition

      public long getLastClusterPosition(int clusterId)
    • getClusterRecordConflictStrategy

      public String getClusterRecordConflictStrategy(int clusterId)
    • getActiveTx

      public OTransactionOptimisticClient getActiveTx()
    • getClustersIds

      public int[] getClustersIds(Set<String> filterClusters)
    • truncateCluster

      public void truncateCluster(String clusterName)
      Removes all data in the cluster with given name. As result indexes for this class will be rebuilt.
      Parameters:
      clusterName - Name of cluster to be truncated.
    • truncateClass

      public void truncateClass(String name)
    • truncateClusterInternal

      public long truncateClusterInternal(String name)
    • truncateClass

      public long truncateClass(String name, boolean polimorfic)
    • commitPreallocate

      public void commitPreallocate()
    • internalCommitPreallocate

      public void internalCommitPreallocate(OTransactionOptimistic oTransactionOptimistic)
    • remoteRollback

      public void remoteRollback(OTransactionOptimistic oTransactionOptimistic)
    • higherPhysicalPositions

      public OPhysicalPosition[] higherPhysicalPositions(int clusterId, OPhysicalPosition physicalPosition)
    • lowerPhysicalPositions

      public OPhysicalPosition[] lowerPhysicalPositions(int clusterId, OPhysicalPosition physicalPosition)
    • ceilingPhysicalPositions

      public OPhysicalPosition[] ceilingPhysicalPositions(int clusterId, OPhysicalPosition physicalPosition)
    • floorPhysicalPositions

      public OPhysicalPosition[] floorPhysicalPositions(int clusterId, OPhysicalPosition physicalPosition)
    • countRecords

      public long countRecords()
    • isReusable

      public boolean isReusable()
    • createSBTree

      public OBonsaiCollectionPointer createSBTree(int clusterId, UUID ownerUUID)
    • directRead

      public ORawBuffer directRead(ORecordId rid, String fetchPlan, boolean ignoreCache, int recordVersion)
    • readIfVersionIsNotLatest

      public ORawBuffer readIfVersionIsNotLatest(ORecordId rid, String fetchPlan, boolean ignoreCache, int recordVersion)