public final class TempTableConnectionProvider
extends java.lang.Object
implements org.hibernate.service.jdbc.connections.spi.ConnectionProvider, org.hibernate.service.spi.Configurable
Another approach to solving this problem would have been to make the
persistence framework responsible for obtaining database connections for
temp tables and to supply these manually when opening new sessions via the
Hibernate SessionFactory.openSession(Connection connection)
method. However, using that approach we would have lost the ability to
use Hibernate's second level cache for temp table records, AND we would
have had to code specialized logic in Persistence
to differentially
handle temp tables and permanent tables. Thus, an implementation of
Hibernate's ConnectionProvider
interface was the preferred
approach.
This implementation wrappers a delegate connection provider whose
properties are specified in the directory. To enable this implementation,
the fully qualified name of this class (i.e.,
com.goldencode.p2j.persist.TempTableConnectionProvider
) is
specified for the hibernate.connection.provider_class
property
in the directory. The backing provider may be specified as well, using one
of the following mechanisms (see also the configure(java.util.Map)
method):
hibernate.connection.delegate_provider_class
(note this is a P2J extension, not a standard Hibernate property name).
This class effectively operates as a singleton, even though it is possible
to create multiple instances, since Hibernate requires a public, default
constructor. However, the implementation consists of only static
variables. One of these is a ContextLocal
variable
(context
), which maintains connection state specific to each
client context. This mechanism is used to ensure that even if multiple
instances of this class are created, requests to get and close JDBC
connections are managed at a client context level.
Modifier and Type | Class and Description |
---|---|
private static class |
TempTableConnectionProvider.Context
An instance of this class is created for each client context, in order
to manage connection data specific to that context.
|
Modifier and Type | Field and Description |
---|---|
private static ContextLocal<TempTableConnectionProvider.Context> |
context
Object which manages context local connection data
|
private static org.hibernate.service.jdbc.connections.spi.ConnectionProvider |
delegate
Connection provider to which actual work is delegated
|
(package private) static java.lang.String |
DELEGATE_CLASS_KEY
Property name in configuration for delegate provider class name
|
private static java.util.logging.Logger |
LOG
Logger
|
private static java.lang.String |
PROVIDER_CLASS_KEY
Property name in configuration for connection provider class name
|
Constructor and Description |
---|
TempTableConnectionProvider()
Default constructor used by Hibernate's
ConnectionProviderFactory
to instantiate this connection provider. |
Modifier and Type | Method and Description |
---|---|
void |
closeConnection(java.sql.Connection conn)
Return a JDBC connection which is no longer needed in the current
context, releasing it to the underlying delegate provider if it is no
longer needed by any active temp tables.
|
void |
configure(java.util.Map props)
Configure this connection provider using the specified properties.
|
java.sql.Connection |
getConnection()
Obtain a JDBC connection on demand.
|
boolean |
isUnwrappableAs(java.lang.Class unwrapType)
Can this wrapped service be unwrapped as the indicated type?
|
boolean |
supportsAggressiveRelease()
Returns
false to indicate JDBC connections will not be
released aggressively, regardless of how the delegate would handle such
requests. |
<T> T |
unwrap(java.lang.Class<T> unwrapType)
Unproxy the service proxy.
|
private static final java.util.logging.Logger LOG
static final java.lang.String DELEGATE_CLASS_KEY
private static final java.lang.String PROVIDER_CLASS_KEY
private static final ContextLocal<TempTableConnectionProvider.Context> context
private static volatile org.hibernate.service.jdbc.connections.spi.ConnectionProvider delegate
public TempTableConnectionProvider()
ConnectionProviderFactory
to instantiate this connection provider.public void configure(java.util.Map props)
hibernate.connection.provider_class
property either:
hibernate.connection.delegate_provider_class
(if
provided); or
hibernate.connection.delegate_provider_class
property
is not specified in the configuration.
In the latter case, Hibernate's internal logic determines which connection provider to create, based upon the remaining properties.
configure
in interface org.hibernate.service.spi.Configurable
props
- Hibernate configuration properties.public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface org.hibernate.service.jdbc.connections.spi.ConnectionProvider
java.sql.SQLException
- if there is an error establishing a connection with the
backing datastore.public void closeConnection(java.sql.Connection conn) throws java.sql.SQLException
closeConnection
in interface org.hibernate.service.jdbc.connections.spi.ConnectionProvider
conn
- The connection to be released.java.sql.SQLException
- if there is an error closing the connection with the backing
datastore.public boolean supportsAggressiveRelease()
false
to indicate JDBC connections will not be
released aggressively, regardless of how the delegate would handle such
requests.supportsAggressiveRelease
in interface org.hibernate.service.jdbc.connections.spi.ConnectionProvider
false
.public boolean isUnwrappableAs(java.lang.Class unwrapType)
isUnwrappableAs
in interface org.hibernate.service.spi.Wrapped
unwrapType
- The type to check.true
/false
public <T> T unwrap(java.lang.Class<T> unwrapType)
unwrap
in interface org.hibernate.service.spi.Wrapped
unwrapType
- The java type as which to unwrap this instance.org.hibernate.service.UnknownUnwrapTypeException
- if the service cannot be unwrapped as the indicated type.