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 Context object.
Note that the user's HTTPSession is an unrelated concept.
- Author:
- kevinvandevelde at atmire.com
-
Method Summary
Modifier and TypeMethodDescriptionvoidClose this session: close DBMS connection(s) and clean up resources.voidcommit()Commit the open transaction.voidDo a manual flush.longHow 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.getType()Some description of the DBMS used to persist entities.booleanHas this session been configured for large batches?booleanboolean<E extends ReloadableEntity>
EreloadEntity(E entity) Reload an entity from the database.voidrollback()Roll back the open transaction.voidsetConnectionMode(boolean batchOptimized, boolean readOnlyOptimized) Configure the connection for special uses.voidshutdown()Close all sessions.voidRemove all entities from the session cache.<E extends ReloadableEntity>
voiduncacheEntity(E entity) Remove an entity from the session cache.
-
Method Details
-
getSession
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
Commit the open transaction.- Throws:
SQLException- passed through.
-
rollback
Roll back the open transaction.- Throws:
SQLException- passed through.
-
closeDBConnection
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
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
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
How many entities are cached in this session?- Returns:
- number of cached entities.
- Throws:
SQLException- passed through.
-
reloadEntity
Reload an entity 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 entity to reload.- Returns:
- the reloaded entity.
- Throws:
SQLException- passed through.
-
uncacheEntities
Remove all entities from the session cache.Entities removed from cache are not saved in any way. Therefore, if you have modified any entities, you should be sure to
commit()changes before calling this method.- Throws:
SQLException- passed through.
-
uncacheEntity
Remove an entity from the session cache.Entities removed from cache are not saved in any way. Therefore, if you have modified the entity, you should be sure to
commit()changes before calling this method.- Type Parameters:
E- Type of entity.- Parameters:
entity- The entity to decache.- Throws:
SQLException- passed through.
-
flushSession
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.
-