Top Description Inners Fields Constructors Methods
org.hsqldb.jdbc

public Class JDBCPool

extends Object
implements DataSource, Referenceable, ConnectionEventListener, StatementEventListener, Wrapper
Class Inheritance
All Implemented Interfaces
java.sql.Wrapper, javax.sql.StatementEventListener, java.util.EventListener, javax.sql.ConnectionEventListener, javax.naming.Referenceable, javax.sql.DataSource, javax.sql.CommonDataSource
Annotations
@SuppressWarnings:serial
Imports
java.io.PrintWriter, java.sql.Connection, .SQLException, .SQLFeatureNotSupportedException, .Wrapper, java.util.Arrays, .Properties, java.util.concurrent.atomic.AtomicIntegerArray, javax.naming.NamingException, .Reference, .Referenceable, .StringRefAddr, javax.sql.ConnectionEvent, .ConnectionEventListener, .DataSource, .PooledConnection, .StatementEvent, .StatementEventListener, org.hsqldb.jdbc.pool.JDBCPooledConnection, .JDBCPooledDataSource

A fast connection pool.

HSQLDB-Specific Information:

A connection pool for HyperSQL connections. This implementation of DataSource is dedicated to HyperSQL and guarantees all connection states are automatically reset when a connection is reused.

The methods of the parent class, JDBCCommonDataSource are used to specify the database URL, user, password, and / or connection properties.

Author
Fred Toussi (fredt@users dot sourceforge.net)
Since
HSQLDB 2.2.9
Version
2.7.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface

Field Summary

Modifier and TypeField and Description
pack-priv volatile boolean
pack-priv JDBCPooledConnection[]
pack-priv JDBCPooledDataSource
pack-priv AtomicIntegerArray

Constructor Summary

AccessConstructor and Description
public
JDBCPool()

Creates a connection pool with the maximum size of 8.

public
JDBCPool(int
int maximum size of the pool
size
)

Creates a connection pool with the given maximum size.

Method Summary

Modifier and TypeMethod and Description
public void
close(int
int number of seconds to wait before closing the connections, maximum 60 seconds
wait
)

Closes the pool immediately.

public void
connectionClosed(ConnectionEvent event)

Implements javax.sql.ConnectionEventListener.connectionClosed.

Notifies this ConnectionEventListener that the application has called the method close on its representation of a pooled connection.

public void
connectionErrorOccurred(ConnectionEvent event)

Implements javax.sql.ConnectionEventListener.connectionErrorOccurred.

Notifies this ConnectionEventListener that a fatal error has occurred and the pooled connection can no longer be used.

public Connection

Returns:

a connection to the data source
getConnection
()

Implements javax.sql.DataSource.getConnection.

Retrieves a new connection using the properties that have already been set.

public Connection

Returns:

a connection to the data source
getConnection
(String
the database user on whose behalf the connection is being made
username
,
String
the user's password
password
)

Implements javax.sql.DataSource.getConnection.

Retrieves a new connection using the given username and password, and the database url that has been set.

public String

Returns:

the jdbc database connection url attribute
getDatabase
()

Synonym for getUrl().

public String

Returns:

the jdbc database connection url attribute
getDatabaseName
()

Synonym for getUrl().

public String

Returns:

the description
getDataSourceName
()

Retrieves the name of the data source.

public String

Returns:

the description
getDescription
()

Retrieves the description of the data source.

public int

Returns:

the data source login time limit
getLoginTimeout
()

Implements javax.sql.DataSource.getLoginTimeout.

Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.

public PrintWriter

Returns:

the log writer for this data source or null if logging is disabled
getLogWriter
()

Implements javax.sql.DataSource.getLogWriter.

Retrieves the log writer for this DataSource object.

public Logger

Returns:

the parent Logger for this data source
getParentLogger
()

Implements javax.sql.CommonDataSource.getParentLogger.

Return the parent Logger of all the Loggers used by this data source.

public Reference

Returns:

The non-null Reference of this object.
getReference
()

Implements javax.naming.Referenceable.getReference.

Retrieves the Reference of this object.

public String

Returns:

the jdbc database connection url attribute
getUrl
()

Retrieves the jdbc database connection url attribute.

public String

Returns:

the jdbc database connection url attribute
getURL
()

Retrieves the jdbc database connection url attribute.

public String

Returns:

the username for the connection
getUser
()

Retrieves the user name for the connection.

public boolean

Returns:

true if this implements the interface or directly or indirectly wraps an object that does.
isWrapperFor
(Class<?>
a Class defining an interface.
iface
)

Implements java.sql.Wrapper.isWrapperFor.

Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does.

public void
setDatabase(String
the new value for the attribute
database
)

Synonym for setUrl(String).

public void
setDatabaseName(String
the new value for the attribute
databaseName
)

Synonym for setUrl(String).

public void
setLoginTimeout(int
the data source login time limit
seconds
)

Implements javax.sql.DataSource.setLoginTimeout.

Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.

public void
setLogWriter(PrintWriter
the new log writer; to disable logging, set to null
out
)

Implements javax.sql.DataSource.setLogWriter.

Sets the log writer for this DataSource object to the given java.io.PrintWriter object.

public void
setPassword(String
the password
password
)

Sets the password for the username.

public void
setProperties(Properties
properties. If null, then existing properties will be cleared/replaced.
props
)

Sets connection properties.

public void
setUrl(String
the new value of this object's jdbc database connection url attribute
url
)

Sets the jdbc database URL.

public void
setURL(String
the new value of this object's jdbc database connection url attribute
url
)

Sets the jdbc database URL.

public void
setUser(String
the user id
user
)

Sets the user name.

public void
statementClosed(StatementEvent event)

Implements javax.sql.StatementEventListener.statementClosed.

The driver calls this method on all StatementEventListeners registered on the connection when it detects that a PreparedStatement is closed.

public void
statementErrorOccurred(StatementEvent event)

Implements javax.sql.StatementEventListener.statementErrorOccurred.

The driver calls this method on all StatementEventListeners registered on the connection when it detects that a PreparedStatement is invalid.

public <T> T

Returns:

an object that implements the interface. May be a proxy for the actual implementing object.
unwrap
(Class<T>
A Class defining an interface that the result must implement.
iface
)

Implements java.sql.Wrapper.unwrap.

Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closedback to summary
pack-priv volatile boolean closed
connectionsback to summary
pack-priv JDBCPooledConnection[] connections
sourceback to summary
pack-priv JDBCPooledDataSource source
statesback to summary
pack-priv AtomicIntegerArray states

Constructor Detail

JDBCPoolback to summary
public JDBCPool()

Creates a connection pool with the maximum size of 8. The database and connection settings are made before the getConnection() is called.

JDBCPoolback to summary
public JDBCPool(int size)

Creates a connection pool with the given maximum size. The database and connection settings are made before the getConnection() is called.

Parameters
size:int

int maximum size of the pool

Method Detail

closeback to summary
public void close(int wait) throws SQLException

Closes the pool immediately. Waits the given number of seconds before closing all existing connections in the pool.

Parameters
wait:int

int number of seconds to wait before closing the connections, maximum 60 seconds

Exceptions
SQLException:
on any error
connectionClosedback to summary
public void connectionClosed(ConnectionEvent event)

Implements javax.sql.ConnectionEventListener.connectionClosed.

Doc from javax.sql.ConnectionEventListener.connectionClosed.

Notifies this ConnectionEventListener that the application has called the method close on its representation of a pooled connection.

connectionErrorOccurredback to summary
public void connectionErrorOccurred(ConnectionEvent event)

Implements javax.sql.ConnectionEventListener.connectionErrorOccurred.

Doc from javax.sql.ConnectionEventListener.connectionErrorOccurred.

Notifies this ConnectionEventListener that a fatal error has occurred and the pooled connection can no longer be used. The driver makes this notification just before it throws the application the SQLException contained in the given ConnectionEvent object.

getConnectionback to summary
public Connection getConnection() throws SQLException

Implements javax.sql.DataSource.getConnection.

Retrieves a new connection using the properties that have already been set.

Returns:Connection

a connection to the data source

Exceptions
SQLException:
if a database access error occurs
getConnectionback to summary
public Connection getConnection(String username, String password) throws SQLException

Implements javax.sql.DataSource.getConnection.

Retrieves a new connection using the given username and password, and the database url that has been set. No other properties are used for the connection. This method can be used only with the same username and password used for the connection pool. The first call to this method sets the user name and password for the connection pool.

Parameters
username:String

the database user on whose behalf the connection is being made

password:String

the user's password

Returns:Connection

a connection to the data source

Exceptions
SQLException:
if a database access error occurs
getDatabaseback to summary
public String getDatabase()

Synonym for getUrl().

Returns:String

the jdbc database connection url attribute

getDatabaseNameback to summary
public String getDatabaseName()

Synonym for getUrl().

Returns:String

the jdbc database connection url attribute

getDataSourceNameback to summary
public String getDataSourceName()

Retrieves the name of the data source.

Returns:String

the description

getDescriptionback to summary
public String getDescription()

Retrieves the description of the data source.

Returns:String

the description

getLoginTimeoutback to summary
public int getLoginTimeout() throws SQLException

Implements javax.sql.DataSource.getLoginTimeout.

Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise, it means that there is no timeout. When a DataSource object is created, the login timeout is initially zero.

Returns:int

the data source login time limit

Exceptions
SQLException:
if a database access error occurs.
Since
1.4
See Also
setLoginTimeout
getLogWriterback to summary
public PrintWriter getLogWriter() throws SQLException

Implements javax.sql.DataSource.getLogWriter.

Retrieves the log writer for this DataSource object.

The log writer is a character output stream to which all logging and tracing messages for this data source will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.DriverManager class. When a DataSource object is created, the log writer is initially null; in other words, the default is for logging to be disabled.

Returns:PrintWriter

the log writer for this data source or null if logging is disabled

Exceptions
SQLException:
if a database access error occurs
Since
1.4
See Also
setLogWriter
getParentLoggerback to summary
public Logger getParentLogger() throws SQLFeatureNotSupportedException

Implements javax.sql.CommonDataSource.getParentLogger.

Return the parent Logger of all the Loggers used by this data source. This should be the Logger farthest from the root Logger that is still an ancestor of all of the Loggers used by this data source. Configuring this Logger will affect all of the log messages generated by the data source. In the worst case, this may be the root Logger.

Returns:Logger

the parent Logger for this data source

Exceptions
SQLFeatureNotSupportedException:
if the data source does not use java.util.logging.
Since
JDK 1.7, HSQLDB 2.2.9
getReferenceback to summary
public Reference getReference() throws NamingException

Implements javax.naming.Referenceable.getReference.

Retrieves the Reference of this object.

Returns:Reference

The non-null Reference of this object.

Exceptions
NamingException:
If a naming exception was encountered while retrieving the reference.
getUrlback to summary
public String getUrl()

Retrieves the jdbc database connection url attribute.

Returns:String

the jdbc database connection url attribute

getURLback to summary
public String getURL()

Retrieves the jdbc database connection url attribute.

Returns:String

the jdbc database connection url attribute

getUserback to summary
public String getUser()

Retrieves the user name for the connection.

Returns:String

the username for the connection

isWrapperForback to summary
public boolean isWrapperFor(Class<?> iface) throws SQLException

Implements java.sql.Wrapper.isWrapperFor.

Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. Returns false otherwise. If this implements the interface then return true, else if this is a wrapper then return the result of recursively calling isWrapperFor on the wrapped object. If this does not implement the interface and is not a wrapper, return false. This method should be implemented as a low-cost operation compared to unwrap so that callers can use this method to avoid expensive unwrap calls that may fail. If this method returns true then calling unwrap with the same argument should succeed.

Parameters
iface:Class<?>

a Class defining an interface.

Returns:boolean

true if this implements the interface or directly or indirectly wraps an object that does.

Exceptions
SQLException:
if an error occurs while determining whether this is a wrapper for an object with the given interface.
Since
JDK 1.6, HSQLDB 2.0
setDatabaseback to summary
public void setDatabase(String database)

Synonym for setUrl(String).

Parameters
database:String

the new value for the attribute

setDatabaseNameback to summary
public void setDatabaseName(String databaseName)

Synonym for setUrl(String).

Parameters
databaseName:String

the new value for the attribute

setLoginTimeoutback to summary
public void setLoginTimeout(int seconds) throws SQLException

Implements javax.sql.DataSource.setLoginTimeout.

Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise, it specifies that there is no timeout. When a DataSource object is created, the login timeout is initially zero.

Parameters
seconds:int

the data source login time limit

Exceptions
SQLException:
if a database access error occurs.
Since
1.4
See Also
getLoginTimeout
setLogWriterback to summary
public void setLogWriter(PrintWriter out) throws SQLException

Implements javax.sql.DataSource.setLogWriter.

Sets the log writer for this DataSource object to the given java.io.PrintWriter object.

The log writer is a character output stream to which all logging and tracing messages for this data source will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source- specific log writer are not printed to the log writer associated with the java.sql.DriverManager class. When a DataSource object is created the log writer is initially null; in other words, the default is for logging to be disabled.

Parameters
out:PrintWriter

the new log writer; to disable logging, set to null

Exceptions
SQLException:
if a database access error occurs
Since
1.4
See Also
getLogWriter
setPasswordback to summary
public void setPassword(String password)

Sets the password for the username.

Parameters
password:String

the password

setPropertiesback to summary
public void setProperties(Properties props)

Sets connection properties. If user / password / loginTimeout has been set with one of the setXXX() methods it will be added to the Properties object.

Parameters
props:Properties

properties. If null, then existing properties will be cleared/replaced.

setUrlback to summary
public void setUrl(String url)

Sets the jdbc database URL.

Parameters
url:String

the new value of this object's jdbc database connection url attribute

setURLback to summary
public void setURL(String url)

Sets the jdbc database URL.

Parameters
url:String

the new value of this object's jdbc database connection url attribute

setUserback to summary
public void setUser(String user)

Sets the user name.

Parameters
user:String

the user id

statementClosedback to summary
public void statementClosed(StatementEvent event)

Implements javax.sql.StatementEventListener.statementClosed.

Doc from javax.sql.StatementEventListener.statementClosed.

The driver calls this method on all StatementEventListeners registered on the connection when it detects that a PreparedStatement is closed.

statementErrorOccurredback to summary
public void statementErrorOccurred(StatementEvent event)

Implements javax.sql.StatementEventListener.statementErrorOccurred.

Doc from javax.sql.StatementEventListener.statementErrorOccurred.

The driver calls this method on all StatementEventListeners registered on the connection when it detects that a PreparedStatement is invalid. The driver calls this method just before it throws the SQLException, contained in the given event, to the application.

unwrapback to summary
public <T> T unwrap(Class<T> iface) throws SQLException

Implements java.sql.Wrapper.unwrap.

Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy. If the receiver implements the interface then the result is the receiver or a proxy for the receiver. If the receiver is a wrapper and the wrapped object implements the interface then the result is the wrapped object or a proxy for the wrapped object. Otherwise return the result of calling unwrap recursively on the wrapped object or a proxy for that result. If the receiver is not a wrapper and does not implement the interface, then an SQLException is thrown.

Parameters
iface:Class<T>

A Class defining an interface that the result must implement.

Returns:T

an object that implements the interface. May be a proxy for the actual implementing object.

Annotations
@SuppressWarnings:unchecked
Exceptions
SQLException:
If no object found that implements the interface
Since
JDK 1.6, HSQLDB 2.0
org.hsqldb.jdbc back to summary

pack-priv Interface JDBCPool.RefState


Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int

Field Detail

allocatedback to summary
public static final int allocated
availableback to summary
public static final int available
emptyback to summary
public static final int empty