Package org.dspace.core
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
Contextobject.Note that the user's HTTPSession is an unrelated concept.
- Author:
- kevinvandevelde at atmire.com
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcloseDBConnection()Close this session: close DBMS connection(s) and clean up resources.voidcommit()Commit the open transaction.voidflushSession()Do a manual flush.longgetCacheSize()How many entities are cached in this session?DatabaseConfigVOgetDatabaseConfig()Identify certain characteristics of the DBMS being used to support persistence.DataSourcegetDataSource()The JDBC DataSource used by this session.TgetSession()Access to the underlying persistence provider's session object.StringgetType()Some description of the DBMS used to persist entities.booleanisOptimizedForBatchProcessing()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.booleanisSessionAlive()booleanisTransActionAlive()<E extends ReloadableEntity>
EreloadEntity(E entity)Reload a DSpace object from the database.voidrollback()Roll back the open transaction.voidsetConnectionMode(boolean batchOptimized, boolean readOnlyOptimized)Configure the connection for special uses.voidshutdown()Close all sessions.<E extends ReloadableEntity>
voiduncacheEntity(E entity)Remove a DSpace object from the session cache when batch processing a large number of objects.
-
-
-
Method Detail
-
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 SQLExceptionCommit the open transaction.- Throws:
SQLException- passed through.
-
rollback
void rollback() throws SQLExceptionRoll back the open transaction.- Throws:
SQLException- passed through.
-
closeDBConnection
void closeDBConnection() throws SQLExceptionClose 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 SQLExceptionConfigure 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 SQLExceptionHow 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 ofentity- 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 ofentity- Parameters:
entity- The DSpace object to decache.- Throws:
SQLException- passed through.
-
flushSession
void flushSession() throws SQLExceptionDo a manual flush. This synchronizes the in-memory state of the Session with the database (write changes to the database)- Throws:
SQLException- passed through.
-
-