Interface DBConnection<T>

Type Parameters:
T - type of the persistence provider's session object.
All Known Implementing Classes:
HibernateDBConnection

public interface DBConnection<T>
Interface representing a persistence provider "session". Implementations will wrap something like a JPA EntityManager or a Hibernate Session. The terms "database" and "connection" are historic and have no direct relationship to a JDBC Connection or even a connection pool.

This class should only be accessed by an enclosing Context object.

Note that the user's HTTPSession is an unrelated concept.

Author:
kevinvandevelde at atmire.com
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close this session: close DBMS connection(s) and clean up resources.
    void
    Commit the open transaction.
    void
    Do a manual flush.
    long
    How many entities are cached in this session?
    Identify certain characteristics of the DBMS being used to support persistence.
    The JDBC DataSource used by this session.
    Access to the underlying persistence provider's session object.
    Some description of the DBMS used to persist entities.
    boolean
    Has this session been configured for large batches? Typically this means that automatic flushing of updates to the database is suppressed, and thus one must take care to flush manually (or commit) at appropriate times.
    boolean
     
    boolean
     
    <E extends ReloadableEntity>
    E
    reloadEntity(E entity)
    Reload a DSpace object from the database.
    void
    Roll back the open transaction.
    void
    setConnectionMode(boolean batchOptimized, boolean readOnlyOptimized)
    Configure the connection for special uses.
    void
    Close all sessions.
    <E extends ReloadableEntity>
    void
    uncacheEntity(E entity)
    Remove a DSpace object from the session cache when batch processing a large number of objects.
  • Method Details

    • getSession

      T getSession() throws SQLException
      Access to the underlying persistence provider's session object.
      Returns:
      the provider's session object for this connection.
      Throws:
      SQLException - passed through.
    • isTransActionAlive

      boolean isTransActionAlive()
      Returns:
      true if this session has an uncommitted transaction.
    • isSessionAlive

      boolean isSessionAlive()
      Returns:
      true if the session is open, false if it has been closed.
    • commit

      void commit() throws SQLException
      Commit the open transaction.
      Throws:
      SQLException - passed through.
    • rollback

      void rollback() throws SQLException
      Roll back the open transaction.
      Throws:
      SQLException - passed through.
    • closeDBConnection

      void closeDBConnection() throws SQLException
      Close this session: close DBMS connection(s) and clean up resources.
      Throws:
      SQLException - passed through.
    • shutdown

      void shutdown()
      Close all sessions. Release all associated resources (cache, DBMS connections, etc.) To be used only when exiting the application.
    • getType

      String getType()
      Some description of the DBMS used to persist entities.
      Returns:
      Brand, version, dialect, etc. Implementation specific.
    • getDataSource

      DataSource getDataSource()
      The JDBC DataSource used by this session. Think carefully before using.
      Returns:
      the source of DBMS connections.
    • getDatabaseConfig

      DatabaseConfigVO getDatabaseConfig() throws SQLException
      Identify certain characteristics of the DBMS being used to support persistence.
      Returns:
      a collection of DBMS, database and connection information.
      Throws:
      SQLException - passed through.
    • setConnectionMode

      void setConnectionMode(boolean batchOptimized, boolean readOnlyOptimized) throws SQLException
      Configure the connection for special uses.
      Parameters:
      batchOptimized - if true, optimize for batch use. Typically this means suppressing automatic flushing of updates, thus requiring manual flushing at appropriate points in the process.
      readOnlyOptimized - if true, optimize for read-only use. Typically this suppresses all updating.
      Throws:
      SQLException
    • isOptimizedForBatchProcessing

      boolean isOptimizedForBatchProcessing()
      Has this session been configured for large batches? Typically this means that automatic flushing of updates to the database is suppressed, and thus one must take care to flush manually (or commit) at appropriate times.
      Returns:
      true if configured for batch.
    • getCacheSize

      long getCacheSize() throws SQLException
      How many entities are cached in this session?
      Returns:
      number of cached entities.
      Throws:
      SQLException - passed through.
    • reloadEntity

      <E extends ReloadableEntity> E reloadEntity(E entity) throws SQLException
      Reload a DSpace object from the database. This will make sure the object is valid and stored in the cache. The returned object should be used henceforth instead of the passed object.
      Type Parameters:
      E - type of entity
      Parameters:
      entity - The DSpace object to reload
      Returns:
      the reloaded entity.
      Throws:
      SQLException - passed through.
    • uncacheEntity

      <E extends ReloadableEntity> void uncacheEntity(E entity) throws SQLException
      Remove a DSpace object from the session cache when batch processing a large number of objects.

      Objects removed from cache are not saved in any way. Therefore, if you have modified an object, you should be sure to commit() changes before calling this method.

      Type Parameters:
      E - Type of entity
      Parameters:
      entity - The DSpace object to decache.
      Throws:
      SQLException - passed through.
    • flushSession

      void flushSession() throws SQLException
      Do a manual flush. This synchronizes the in-memory state of the Session with the database (write changes to the database)
      Throws:
      SQLException - passed through.