Top Description Inners Fields Constructors Methods
org.hibernate.engine.jdbc.connections.internal

public Class DriverManagerConnectionProviderImpl

extends Object
implements ConnectionProvider, Configurable, Stoppable, ServiceRegistryAwareService, ConnectionValidator
Class Inheritance
All Implemented Interfaces
org.hibernate.engine.jdbc.connections.internal.ConnectionValidator, org.hibernate.service.spi.ServiceRegistryAwareService, org.hibernate.service.spi.Stoppable, org.hibernate.service.spi.Configurable, org.hibernate.engine.jdbc.connections.spi.ConnectionProvider, org.hibernate.service.spi.Wrapped, org.hibernate.service.Service, java.io.Serializable
Imports
java.security.AccessController, .PrivilegedAction, java.sql.Connection, .Driver, .DriverManager, .SQLException, java.util.Enumeration, .Iterator, .Map, .Properties, java.util.concurrent.ConcurrentLinkedQueue, .Executors, .ScheduledExecutorService, .ThreadFactory, .TimeUnit, java.util.concurrent.locks.ReadWriteLock, .ReentrantReadWriteLock, org.hibernate.HibernateException, .Internal, org.hibernate.boot.registry.classloading.spi.ClassLoaderService, org.hibernate.cfg.AvailableSettings, org.hibernate.dialect.Database, org.hibernate.engine.jdbc.connections.spi.ConnectionProvider, org.hibernate.internal.util.config.ConfigurationHelper, org.hibernate.internal.util.securitymanager.SystemSecurityManager, org.hibernate.service.UnknownUnwrapTypeException, org.hibernate.service.spi.Configurable, .ServiceException, .ServiceRegistryAwareService, .ServiceRegistryImplementor, .Stoppable

A connection provider that uses the DriverManager directly to open connections and provides a very rudimentary connection pool.

Implementation Note

Not intended for use in production systems!

Authors
Gavin King, Steve Ebersole

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final String
public static final String
private volatile ServiceRegistryImplementor
private volatile DriverManagerConnectionProviderImpl.PoolState
public static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static ConnectionCreator
buildCreator(Map<String, Object> configurationValues, ServiceRegistryImplementor serviceRegistry)

private DriverManagerConnectionProviderImpl.PooledConnections
buildPool(Map<String, Object> configurationValues, ServiceRegistryImplementor serviceRegistry)

public void
closeConnection(Connection
The JDBC connection to release
conn
)

Implements org.hibernate.engine.jdbc.connections.spi.ConnectionProvider.closeConnection.

Release a connection from Hibernate use.
public void
configure(Map<String, Object>
The configuration properties.
configurationValues
)

Implements org.hibernate.service.spi.Configurable.configure.

Configure the service.
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
public Connection
getConnection()

Implements org.hibernate.engine.jdbc.connections.spi.ConnectionProvider.getConnection.

Obtains a connection for Hibernate use according to the underlying strategy of this provider.
public Properties
getConnectionProperties()

Exposed to facilitate testing only.

protected int
public void
injectServices(ServiceRegistryImplementor
The registry
serviceRegistry
)

Implements org.hibernate.service.spi.ServiceRegistryAwareService.injectServices.

Callback to inject the registry.
public boolean
isUnwrappableAs(Class<?>
The type to check.
unwrapType
)

Implements org.hibernate.service.spi.Wrapped.isUnwrappableAs.

Can this wrapped service be unwrapped as the indicated type?
public boolean
isValid(Connection connection)

Implements org.hibernate.engine.jdbc.connections.internal.ConnectionValidator.isValid.

Checks if the given connection is still valid.
private static ConnectionCreatorFactory
loadConnectionCreatorFactory(String connectionCreatorFactoryClassName, ServiceRegistryImplementor serviceRegistry)

private static Driver
loadDriverIfPossible(String driverClassName, ServiceRegistryImplementor serviceRegistry)

public void
public void
stop()

Implements org.hibernate.service.spi.Stoppable.stop.

Stop phase notification
public boolean
supportsAggressiveRelease()

Implements org.hibernate.engine.jdbc.connections.spi.ConnectionProvider.supportsAggressiveRelease.

Does this connection provider support aggressive release of JDBC connections and later re-acquisition of those connections if needed?
public <T> T
unwrap(Class<T>
The java type as which to unwrap this instance.
unwrapType
)

Implements org.hibernate.service.spi.Wrapped.unwrap.

Unproxy the service proxy
protected void
protected void
Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CONNECTION_CREATOR_FACTORYback to summary
public static final String CONNECTION_CREATOR_FACTORY
INIT_SQLback to summary
public static final String INIT_SQL
INITIAL_SIZEback to summary
public static final String INITIAL_SIZE
MIN_SIZEback to summary
public static final String MIN_SIZE
serviceRegistryback to summary
private volatile ServiceRegistryImplementor serviceRegistry
stateback to summary
private volatile DriverManagerConnectionProviderImpl.PoolState state
VALIDATION_INTERVALback to summary
public static final String VALIDATION_INTERVAL

Constructor Detail

DriverManagerConnectionProviderImplback to summary
public DriverManagerConnectionProviderImpl()

Method Detail

buildCreatorback to summary
private static ConnectionCreator buildCreator(Map<String, Object> configurationValues, ServiceRegistryImplementor serviceRegistry)
buildPoolback to summary
private DriverManagerConnectionProviderImpl.PooledConnections buildPool(Map<String, Object> configurationValues, ServiceRegistryImplementor serviceRegistry)
closeConnectionback to summary
public void closeConnection(Connection conn) throws SQLException

Implements org.hibernate.engine.jdbc.connections.spi.ConnectionProvider.closeConnection.

Doc from org.hibernate.engine.jdbc.connections.spi.ConnectionProvider.closeConnection.

Release a connection from Hibernate use.

Parameters
conn:Connection

The JDBC connection to release

Annotations
@Override
Exceptions
SQLException:
Indicates a problem closing the connection
configureback to summary
public void configure(Map<String, Object> configurationValues)

Implements org.hibernate.service.spi.Configurable.configure.

Doc from org.hibernate.service.spi.Configurable.configure.

Configure the service.

Parameters
configurationValues:Map<String, Object>

The configuration properties.

Annotations
@Override
finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method
getConnectionback to summary
public Connection getConnection() throws SQLException

Implements org.hibernate.engine.jdbc.connections.spi.ConnectionProvider.getConnection.

Doc from org.hibernate.engine.jdbc.connections.spi.ConnectionProvider.getConnection.

Obtains a connection for Hibernate use according to the underlying strategy of this provider.

Returns:Connection

The obtained JDBC connection

Annotations
@Override
Exceptions
SQLException:
Indicates a problem opening a connection
getConnectionPropertiesback to summary
public Properties getConnectionProperties()

Exposed to facilitate testing only.

getOpenConnectionsback to summary
protected int getOpenConnections()
injectServicesback to summary
public void injectServices(ServiceRegistryImplementor serviceRegistry)

Implements org.hibernate.service.spi.ServiceRegistryAwareService.injectServices.

Doc from org.hibernate.service.spi.ServiceRegistryAwareService.injectServices.

Callback to inject the registry.

Parameters
serviceRegistry:ServiceRegistryImplementor

The registry

Annotations
@Override
isUnwrappableAsback to summary
public boolean isUnwrappableAs(Class<?> unwrapType)

Implements org.hibernate.service.spi.Wrapped.isUnwrappableAs.

Doc from org.hibernate.service.spi.Wrapped.isUnwrappableAs.

Can this wrapped service be unwrapped as the indicated type?

Parameters
unwrapType:Class<?>

The type to check.

Returns:boolean

True/false.

Annotations
@Override
isValidback to summary
public boolean isValid(Connection connection) throws SQLException

Implements org.hibernate.engine.jdbc.connections.internal.ConnectionValidator.isValid.

Doc from org.hibernate.engine.jdbc.connections.internal.ConnectionValidator.isValid.

Checks if the given connection is still valid.

Returns:boolean

true if the connection is valid, false otherwise

Annotations
@Override
Exceptions
SQLException:
when an error happens due to the connection usage leading to a connection close
loadConnectionCreatorFactoryback to summary
private static ConnectionCreatorFactory loadConnectionCreatorFactory(String connectionCreatorFactoryClassName, ServiceRegistryImplementor serviceRegistry)
loadDriverIfPossibleback to summary
private static Driver loadDriverIfPossible(String driverClassName, ServiceRegistryImplementor serviceRegistry)
releasePooledConnectionsback to summary
public void releasePooledConnections()
Annotations
@Internal
stopback to summary
public void stop()

Implements org.hibernate.service.spi.Stoppable.stop.

Doc from org.hibernate.service.spi.Stoppable.stop.

Stop phase notification

Annotations
@Override
supportsAggressiveReleaseback to summary
public boolean supportsAggressiveRelease()

Implements org.hibernate.engine.jdbc.connections.spi.ConnectionProvider.supportsAggressiveRelease.

Doc from org.hibernate.engine.jdbc.connections.spi.ConnectionProvider.supportsAggressiveRelease.

Does this connection provider support aggressive release of JDBC connections and later re-acquisition of those connections if needed?

This is used in conjunction with org.hibernate.ConnectionReleaseMode#AFTER_STATEMENT to aggressively release JDBC connections. However, the configured ConnectionProvider must support re-acquisition of the same underlying connection for that semantic to work.

Typically, this is only true in managed environments where a container tracks connections by transaction or thread. Note that JTA semantic depends on the fact that the underlying connection provider does support aggressive release.

Returns:boolean

true if aggressive releasing is supported; false otherwise.

Annotations
@Override
unwrapback to summary
public <T> T unwrap(Class<T> unwrapType)

Implements org.hibernate.service.spi.Wrapped.unwrap.

Doc from org.hibernate.service.spi.Wrapped.unwrap.

Unproxy the service proxy

Parameters
unwrapType:Class<T>

The java type as which to unwrap this instance.

Returns:T

The unwrapped reference

Annotations
@Override
@SuppressWarnings:unchecked
validateConnectionsback to summary
protected void validateConnections(ConnectionValidator validator)
validateConnectionsReturnedback to summary
protected void validateConnectionsReturned()
org.hibernate.engine.jdbc.connections.internal back to summary

public Class DriverManagerConnectionProviderImpl.PooledConnections

extends Object
Class Inheritance
  • java.lang.Object
  • org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.PooledConnections

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final ConcurrentLinkedQueue<Connection>
private final boolean
private final ConcurrentLinkedQueue<Connection>
private final ConnectionCreator
private final ConnectionValidator
private final int
private final int
private volatile boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
protected void
addConnections(int numberOfConnections)

public void
protected void
public String
public Connection
poll()

protected Connection
protected Connection
public void
protected void
removeConnections(int numberToBeRemoved)

public int
size()

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allConnectionsback to summary
private final ConcurrentLinkedQueue<Connection> allConnections
autoCommitback to summary
private final boolean autoCommit
availableConnectionsback to summary
private final ConcurrentLinkedQueue<Connection> availableConnections
connectionCreatorback to summary
private final ConnectionCreator connectionCreator
connectionValidatorback to summary
private final ConnectionValidator connectionValidator
maxSizeback to summary
private final int maxSize
minSizeback to summary
private final int minSize
primedback to summary
private volatile boolean primed

Constructor Detail

PooledConnectionsback to summary
private PooledConnections(DriverManagerConnectionProviderImpl.PooledConnections.Builder builder)

Method Detail

addback to summary
public void add(Connection conn) throws SQLException
addConnectionsback to summary
protected void addConnections(int numberOfConnections)
closeback to summary
public void close() throws SQLException
closeConnectionback to summary
protected void closeConnection(Connection conn, Throwable t)
getUrlback to summary
public String getUrl()
pollback to summary
public Connection poll() throws SQLException
prepareConnectionback to summary
protected Connection prepareConnection(Connection conn)
releaseConnectionback to summary
protected Connection releaseConnection(Connection conn)
releasePooledConnectionsback to summary
public void releasePooledConnections()
Annotations
@Internal
removeConnectionsback to summary
protected void removeConnections(int numberToBeRemoved)
sizeback to summary
public int size()
validateback to summary
public void validate()
org.hibernate.engine.jdbc.connections.internal back to summary

public Class DriverManagerConnectionProviderImpl.PooledConnections.Builder

extends Object
Class Inheritance
  • java.lang.Object
  • org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.PooledConnections.Builder

Field Summary

Modifier and TypeField and Description
private final boolean
private final ConnectionCreator
private ConnectionValidator
private int
private int
private int

Constructor Summary

AccessConstructor and Description
public
Builder(ConnectionCreator connectionCreator, boolean autoCommit)

Field Detail

autoCommitback to summary
private final boolean autoCommit
connectionCreatorback to summary
private final ConnectionCreator connectionCreator
connectionValidatorback to summary
private ConnectionValidator connectionValidator
initialSizeback to summary
private int initialSize
maxSizeback to summary
private int maxSize
minSizeback to summary
private int minSize

Constructor Detail

Builderback to summary
public Builder(ConnectionCreator connectionCreator, boolean autoCommit)
org.hibernate.engine.jdbc.connections.internal back to summary

private Class DriverManagerConnectionProviderImpl.PoolState

extends Object
implements Runnable
Class Inheritance
  • java.lang.Object
  • org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.PoolState
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
private volatile boolean
private ScheduledExecutorService
private final DriverManagerConnectionProviderImpl.PooledConnections
private final ReadWriteLock
private final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public Connection
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
private void
public void
stop()

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activeback to summary
private volatile boolean active
executorServiceback to summary
private ScheduledExecutorService executorService
poolback to summary
private final DriverManagerConnectionProviderImpl.PooledConnections pool
statelockback to summary
private final ReadWriteLock statelock
validationIntervalback to summary
private final long validationInterval

Constructor Detail

PoolStateback to summary
public PoolState(DriverManagerConnectionProviderImpl.PooledConnections pool, long validationInterval)

Method Detail

closeConnectionback to summary
public void closeConnection(Connection conn) throws SQLException
getConnectionback to summary
public Connection getConnection() throws SQLException
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
startIfNeededback to summary
private void startIfNeeded()
stopback to summary
public void stop()
validateConnectionsback to summary
public void validateConnections(ConnectionValidator validator)
org.hibernate.engine.jdbc.connections.internal back to summary

private Class DriverManagerConnectionProviderImpl.ValidationThreadFactory

extends Object
implements ThreadFactory
Class Inheritance
  • java.lang.Object
  • org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.ValidationThreadFactory
All Implemented Interfaces
java.util.concurrent.ThreadFactory

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Thread
newThread(Runnable
a runnable to be executed by new thread instance
runnable
)

Implements java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ValidationThreadFactoryback to summary
private ValidationThreadFactory()

Method Detail

newThreadback to summary
public Thread newThread(Runnable runnable)

Implements java.util.concurrent.ThreadFactory.newThread.

Doc from java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

Parameters
runnable:Runnable

a runnable to be executed by new thread instance

Returns:Thread

constructed thread, or null if the request to create a thread is rejected

Annotations
@Override