|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface JpaDialect
SPI strategy that encapsulates certain functionality that standard JPA 1.0 does not offer, such as access to the underlying JDBC Connection. This strategy is mainly intended for standalone usage of a JPA provider; most of its functionality is not relevant when running with JTA transactions.
Also allows for the provision of value-added methods for portable yet more capable EntityManager and EntityManagerFactory subinterfaces offered by Spring.
In general, it is recommended to derive from DefaultJpaDialect instead of implementing this interface directly. This allows for inheriting common behavior (present and future) from DefaultJpaDialect, only overriding specific hooks to plug in concrete vendor-specific behavior.
DefaultJpaDialect
,
JpaAccessor.setJpaDialect(org.springframework.orm.jpa.JpaDialect)
,
JpaTransactionManager.setJpaDialect(org.springframework.orm.jpa.JpaDialect)
,
JpaVendorAdapter.getJpaDialect()
,
AbstractEntityManagerFactoryBean.setJpaDialect(org.springframework.orm.jpa.JpaDialect)
,
AbstractEntityManagerFactoryBean.setJpaVendorAdapter(org.springframework.orm.jpa.JpaVendorAdapter)
Method Summary | |
---|---|
Object |
beginTransaction(javax.persistence.EntityManager entityManager,
TransactionDefinition definition)
Begin the given JPA transaction, applying the semantics specified by the given Spring transaction definition (in particular, an isolation level and a timeout). |
void |
cleanupTransaction(Object transactionData)
Clean up the transaction via the given transaction data. |
EntityManagerFactoryPlusOperations |
getEntityManagerFactoryPlusOperations(javax.persistence.EntityManagerFactory rawEntityManager)
Return an EntityManagerFactoryPlusOperations implementation for the given raw EntityManagerFactory. |
EntityManagerPlusOperations |
getEntityManagerPlusOperations(javax.persistence.EntityManager rawEntityManager)
Return an EntityManagerPlusOperations implementation for the given raw EntityManager. |
ConnectionHandle |
getJdbcConnection(javax.persistence.EntityManager entityManager,
boolean readOnly)
Retrieve the JDBC Connection that the given JPA EntityManager uses underneath, if accessing a relational database. |
void |
releaseJdbcConnection(ConnectionHandle conHandle,
javax.persistence.EntityManager entityManager)
Release the given JDBC Connection, which has originally been retrieved via getJdbcConnection . |
boolean |
supportsEntityManagerFactoryPlusOperations()
Return whether the EntityManagerFactoryPlus(Operations) interface is supported by this provider. |
boolean |
supportsEntityManagerPlusOperations()
Return whether the EntityManagerPlus(Operations) interface is supported by this provider. |
Methods inherited from interface org.springframework.dao.support.PersistenceExceptionTranslator |
---|
translateExceptionIfPossible |
Method Detail |
---|
boolean supportsEntityManagerFactoryPlusOperations()
boolean supportsEntityManagerPlusOperations()
EntityManagerPlusOperations
,
EntityManagerPlus
EntityManagerFactoryPlusOperations getEntityManagerFactoryPlusOperations(javax.persistence.EntityManagerFactory rawEntityManager)
rawEntityManager
- the raw provider-specific EntityManagerFactory
EntityManagerPlusOperations getEntityManagerPlusOperations(javax.persistence.EntityManager rawEntityManager)
rawEntityManager
- the raw provider-specific EntityManagerFactory
Object beginTransaction(javax.persistence.EntityManager entityManager, TransactionDefinition definition) throws javax.persistence.PersistenceException, SQLException, TransactionException
An implementation can configure the JPA Transaction object and then
invoke begin
, or invoke a special begin method that takes,
for example, an isolation level.
An implementation can also apply read-only flag and isolation level to the
underlying JDBC Connection before beginning the transaction. In that case,
a transaction data object can be returned that holds the previous isolation
level (and possibly other data), to be reset in cleanupTransaction
.
Implementations can also use the Spring transaction name, as exposed by the passed-in TransactionDefinition, to optimize for specific data access use cases (effectively using the current transaction name as use case identifier).
entityManager
- the EntityManager to begin a JPA transaction ondefinition
- the Spring transaction definition that defines semantics
javax.persistence.PersistenceException
- if thrown by JPA methods
SQLException
- if thrown by JDBC methods
TransactionException
- in case of invalid argumentscleanupTransaction(java.lang.Object)
,
EntityTransaction.begin()
,
DataSourceUtils.prepareConnectionForTransaction(java.sql.Connection, org.springframework.transaction.TransactionDefinition)
void cleanupTransaction(Object transactionData)
An implementation can, for example, reset read-only flag and isolation level of the underlying JDBC Connection. Furthermore, an exposed data access use case can be reset here.
transactionData
- arbitrary object that holds transaction data, if any
(as returned by beginTransaction)beginTransaction(javax.persistence.EntityManager, org.springframework.transaction.TransactionDefinition)
,
DataSourceUtils.resetConnectionAfterTransaction(java.sql.Connection, java.lang.Integer)
ConnectionHandle getJdbcConnection(javax.persistence.EntityManager entityManager, boolean readOnly) throws javax.persistence.PersistenceException, SQLException
releaseJdbcConnection
method when not needed anymore.
This strategy is necessary as JPA 1.0 does not provide a standard way to retrieve the underlying JDBC Connection (due to the fact that a JPA implementation might not work with a relational database at all).
Implementations are encouraged to return an unwrapped Connection object, i.e. the Connection as they got it from the connection pool. This makes it easier for application code to get at the underlying native JDBC Connection, like an OracleConnection, which is sometimes necessary for LOB handling etc. We assume that calling code knows how to properly handle the returned Connection object.
In a simple case where the returned Connection will be auto-closed with the
EntityManager or can be released via the Connection object itself, an
implementation can return a SimpleConnectionHandle that just contains the
Connection. If some other object is needed in releaseJdbcConnection
,
an implementation should use a special handle that references that other object.
entityManager
- the current JPA EntityManager
releaseJdbcConnection
, or null
if no JDBC Connection can be retrieved
javax.persistence.PersistenceException
- if thrown by JPA methods
SQLException
- if thrown by JDBC methodsreleaseJdbcConnection(org.springframework.jdbc.datasource.ConnectionHandle, javax.persistence.EntityManager)
,
ConnectionHandle.getConnection()
,
SimpleConnectionHandle
,
JpaTransactionManager.setDataSource(javax.sql.DataSource)
,
NativeJdbcExtractor
void releaseJdbcConnection(ConnectionHandle conHandle, javax.persistence.EntityManager entityManager) throws javax.persistence.PersistenceException, SQLException
getJdbcConnection
. This should be invoked in any case,
to allow for proper release of the retrieved Connection handle.
An implementation might simply do nothing, if the Connection returned
by getJdbcConnection
will be implicitly closed when the JPA
transaction completes or when the EntityManager is closed.
conHandle
- the JDBC Connection handle to releaseentityManager
- the current JPA EntityManager
javax.persistence.PersistenceException
- if thrown by JPA methods
SQLException
- if thrown by JDBC methodsgetJdbcConnection(javax.persistence.EntityManager, boolean)
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |