Class ODatabaseWrapperAbstract<DB extends ODatabaseInternal,T>

java.lang.Object
com.orientechnologies.orient.core.db.ODatabaseWrapperAbstract<DB,T>
All Implemented Interfaces:
ODatabase<T>, ODatabaseInternal<T>, OBackupable, Closeable, AutoCloseable
Direct Known Subclasses:
OObjectDatabaseTx

public abstract class ODatabaseWrapperAbstract<DB extends ODatabaseInternal,T> extends Object implements ODatabaseInternal<T>
  • Field Details

  • Constructor Details

    • ODatabaseWrapperAbstract

      public ODatabaseWrapperAbstract(DB iDatabase)
  • Method Details

    • activateOnCurrentThread

      public ODatabase activateOnCurrentThread()
      Description copied from interface: ODatabase
      Activate current database instance on current thread. Call this method before using the database if you switch between multiple databases instances on the same thread or if you pass them across threads.
      Specified by:
      activateOnCurrentThread in interface ODatabase<DB extends ODatabaseInternal>
    • 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<DB extends ODatabaseInternal>
    • reload

      public void reload()
      Description copied from interface: ODatabase
      Reloads the database information like the cluster list.
      Specified by:
      reload in interface ODatabase<DB extends ODatabaseInternal>
    • 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<DB extends ODatabaseInternal>
      Returns:
      OContextConfiguration
    • backup

      public List<String> backup(OutputStream out, Map<String,Object> options, Callable<Object> callable, OCommandOutputListener iListener, int compressionLevel, int bufferSize) throws IOException
      Executes a backup of the database. During the backup the database will be frozen in read-only mode.
      Specified by:
      backup in interface OBackupable
      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 0 (no compression) 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
      Executes a restore of a database backup. During the restore the database will be frozen in read-only mode.
      Specified by:
      restore in interface OBackupable
      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:
    • 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<DB extends ODatabaseInternal>
    • replaceStorage

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

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

      public <THISDB extends ODatabase> THISDB setStatus(ODatabase.STATUS iStatus)
      Description copied from interface: ODatabase
      Set the current status of database. deprecated since 2.2
      Specified by:
      setStatus in interface ODatabase<DB extends ODatabaseInternal>
    • getName

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

      public String getURL()
      Description copied from interface: ODatabase
      Returns the database URL.
      Specified by:
      getURL in interface ODatabase<DB extends ODatabaseInternal>
      Returns:
      URL of the database
    • getStorage

      public OStorage getStorage()
      Description copied from interface: ODatabaseInternal
      Returns the underlying storage implementation.
      Specified by:
      getStorage in interface ODatabaseInternal<DB extends ODatabaseInternal>
      Returns:
      The underlying storage implementation
      See Also:
    • getLocalCache

      public OLocalRecordCache getLocalCache()
      Description copied from interface: ODatabase
      Returns the level1 cache. Cannot be null.
      Specified by:
      getLocalCache in interface ODatabase<DB extends ODatabaseInternal>
      Returns:
      Current cache.
    • isClosed

      public boolean isClosed()
      Description copied from interface: ODatabase
      Checks if the database is closed.
      Specified by:
      isClosed in interface ODatabase<DB extends ODatabaseInternal>
      Returns:
      true if is closed, otherwise false.
    • countClusterElements

      public long countClusterElements(int iClusterId)
      Description copied from interface: ODatabase
      Counts all the entities in the specified cluster id.
      Specified by:
      countClusterElements in interface ODatabase<DB extends ODatabaseInternal>
      Parameters:
      iClusterId - Cluster id
      Returns:
      Total number of entities contained in the specified cluster
    • truncateCluster

      public void truncateCluster(String clusterName)
      Removes all data in the cluster with given name. As result indexes for this class will be rebuilt.
      Specified by:
      truncateCluster in interface ODatabase<DB extends ODatabaseInternal>
      Parameters:
      clusterName - Name of cluster to be truncated.
    • countClusterElements

      public long countClusterElements(int[] iClusterIds)
      Description copied from interface: ODatabase
      Counts all the entities in the specified cluster ids.
      Specified by:
      countClusterElements in interface ODatabase<DB extends ODatabaseInternal>
      Parameters:
      iClusterIds - Array of cluster ids Cluster id
      Returns:
      Total number of entities contained in the specified clusters
    • countClusterElements

      public long countClusterElements(String iClusterName)
      Description copied from interface: ODatabase
      Counts all the entities in the specified cluster name.
      Specified by:
      countClusterElements in interface ODatabase<DB extends ODatabaseInternal>
      Parameters:
      iClusterName - Cluster name
      Returns:
      Total number of entities contained in the specified cluster
    • getClusters

      public int getClusters()
      Description copied from interface: ODatabase
      Returns the number of clusters.
      Specified by:
      getClusters in interface ODatabase<DB extends ODatabaseInternal>
      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<DB extends ODatabaseInternal>
      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<DB extends ODatabaseInternal>
      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<DB extends ODatabaseInternal>
      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<DB extends ODatabaseInternal>
      Parameters:
      iClusterId - Cluster id
      Returns:
      The name of searched cluster.
    • getClusterRecordSizeById

      public long getClusterRecordSizeById(int iClusterId)
      Description copied from interface: ODatabase
      Returns the total size of records contained in the cluster defined by its id.
      Specified by:
      getClusterRecordSizeById in interface ODatabase<DB extends ODatabaseInternal>
      Parameters:
      iClusterId - Cluster id
      Returns:
      The name of searched cluster.
    • getClusterRecordSizeByName

      public long getClusterRecordSizeByName(String iClusterName)
      Description copied from interface: ODatabase
      Returns the total size of records contained in the cluster defined by its name.
      Specified by:
      getClusterRecordSizeByName in interface ODatabase<DB extends ODatabaseInternal>
      Parameters:
      iClusterName - Cluster name
      Returns:
      Total size of records contained.
    • addCluster

      public int addCluster(String iClusterName, int iRequestedId)
      Description copied from interface: ODatabase
      Adds a new cluster.
      Specified by:
      addCluster in interface ODatabase<DB extends ODatabaseInternal>
      Parameters:
      iClusterName - Cluster name
      iRequestedId - requested id of the cluster
      Returns:
      Cluster id
    • addCluster

      public int addCluster(String iClusterName, Object... iParameters)
      Description copied from interface: ODatabase
      Adds a new cluster.
      Specified by:
      addCluster in interface ODatabase<DB extends ODatabaseInternal>
      Parameters:
      iClusterName - Cluster name
      iParameters - Additional parameters to pass to the factories
      Returns:
      Cluster id
    • dropCluster

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

      public boolean dropCluster(int iClusterId)
      Description copied from interface: ODatabase
      Drops a cluster by its id. Physical clusters will be completely deleted.
      Specified by:
      dropCluster in interface ODatabase<DB extends ODatabaseInternal>
      Parameters:
      iClusterId - id of cluster to delete
      Returns:
      true if has been removed, otherwise false
    • 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<DB extends ODatabaseInternal>
      Returns:
      The default cluster id
    • getUnderlying

      public <DBTYPE extends ODatabase> DBTYPE getUnderlying()
      Description copied from interface: ODatabaseInternal
      Return the underlying database. Used in wrapper instances to know the down level ODatabase instance.
      Specified by:
      getUnderlying in interface ODatabaseInternal<DB extends ODatabaseInternal>
      Returns:
      The underlying ODatabase implementation.
    • getDatabaseOwner

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

      public ODatabaseInternal<?> setDatabaseOwner(ODatabaseInternal<?> iOwner)
      Description copied from interface: ODatabaseInternal
      Internal. Sets the database owner.
      Specified by:
      setDatabaseOwner in interface ODatabaseInternal<DB extends ODatabaseInternal>
    • equals

      public boolean equals(Object iOther)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setProperty

      public Object setProperty(String iName, Object iValue)
      Description copied from interface: ODatabase
      Sets a property value
      Specified by:
      setProperty in interface ODatabase<DB extends ODatabaseInternal>
      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<DB extends ODatabaseInternal>
      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<DB extends ODatabaseInternal>
    • get

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

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

      public void registerListener(ODatabaseListener iListener)
      Description copied from interface: ODatabase
      Registers a listener to the database events.
      Specified by:
      registerListener in interface ODatabase<DB extends ODatabaseInternal>
      Parameters:
      iListener - the listener to register
    • unregisterListener

      public void unregisterListener(ODatabaseListener iListener)
      Description copied from interface: ODatabase
      Unregisters a listener to the database events.
      Specified by:
      unregisterListener in interface ODatabase<DB extends ODatabaseInternal>
      Parameters:
      iListener - the listener to unregister
    • getRecordMetadata

      public ORecordMetadata getRecordMetadata(ORID rid)
      Specified by:
      getRecordMetadata in interface ODatabase<DB extends ODatabaseInternal>
    • getSize

      public long getSize()
      Description copied from interface: ODatabase
      Returns the total size of the records in the database.
      Specified by:
      getSize in interface ODatabase<DB extends ODatabaseInternal>
    • freeze

      public void freeze(boolean throwException)
      Description copied from interface: ODatabase
      Flush cached storage content to the disk.

      After this call users can perform only select queries. All write-related commands will queued till ODatabase.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.

      Specified by:
      freeze in interface ODatabase<DB extends ODatabaseInternal>
      Parameters:
      throwException - If true OModificationOperationProhibitedException exception will be thrown in case of write command will be performed.
    • freeze

      public void freeze()
      Description copied from interface: ODatabase
      Flush cached storage content to the disk.

      After this call users can perform only idempotent calls like read records and select/traverse queries. All write-related operations will queued till ODatabase.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.

      Specified by:
      freeze in interface ODatabase<DB extends ODatabaseInternal>
      See Also:
    • release

      public void release()
      Description copied from interface: ODatabase
      Allows to execute write-related commands on DB. Called after ODatabase.freeze() command.
      Specified by:
      release in interface ODatabase<DB extends ODatabaseInternal>
      See Also:
    • checkOpenness

      protected void checkOpenness()