- java.lang.Object
-
- org.hsqldb.jdbc.JDBCCommonDataSource
-
- org.hsqldb.jdbc.JDBCDataSource
-
- All Implemented Interfaces:
java.io.Serializable,java.sql.Wrapper,javax.naming.Referenceable,javax.sql.CommonDataSource,javax.sql.DataSource
public class JDBCDataSource extends JDBCCommonDataSource implements javax.sql.DataSource, java.io.Serializable, javax.naming.Referenceable, java.sql.Wrapper
A factory for connections to the physical data source that this
DataSourceobject represents. An alternative to theDriverManagerfacility, aDataSourceobject is the preferred means of getting a connection. An object that implements theDataSourceinterface will typically be registered with a naming service based on the Java™ Naming and Directory (JNDI) API.The
DataSourceinterface is implemented by a driver vendor. There are three types of implementations:- Basic implementation -- produces a standard
Connectionobject - Connection pooling implementation -- produces a
Connectionobject that will automatically participate in connection pooling. This implementation works with a middle-tier connection pooling manager. - Distributed transaction implementation -- produces a
Connectionobject that may be used for distributed transactions and almost always participates in connection pooling. This implementation works with a middle-tier transaction manager and almost always with a connection pooling manager.
A
DataSourceobject has properties that can be modified when necessary. For example, if the data source is moved to a different server, the property for the server can be changed. The benefit is that because the data source's properties can be changed, any code accessing that data source does not need to be changed.A driver that is accessed via a
DataSourceobject does not register itself with theDriverManager. Rather, aDataSourceobject is retrieved though a lookup operation and then used to create aConnectionobject. With a basic implementation, the connection obtained through aDataSourceobject is identical to a connection obtained through theDriverManagerfacility.HSQLDB-Specific Information:
This implementation of data source is a basic implementation and does not perform connection pooling.The getter and setter methods of the parent class,
JDBCCommonDataSource, can be used.- Since:
- JDK 1.4, HSQLDB 1.7.2
- Author:
- Campbell Burnet (campbell-burnet@users dot sourceforge.net), Fred Toussi (fredt@users dot sourceforge.net)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description JDBCDataSource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.sql.ConnectiongetConnection()Retrieves a new connection using the properties that have already been set.java.sql.ConnectiongetConnection(java.lang.String username, java.lang.String password)Retrieves a new connection using the given username and password, and the database url that has been set.javax.naming.ReferencegetReference()Retrieves the Reference of this object.booleanisWrapperFor(java.lang.Class<?> iface)Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does.<T> Tunwrap(java.lang.Class<T> iface)Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.-
Methods inherited from class org.hsqldb.jdbc.JDBCCommonDataSource
getDatabase, getDatabaseName, getDataSourceName, getDescription, getLoginTimeout, getLogWriter, getNetworkProtocol, getParentLogger, getServerName, getUrl, getURL, getUser, setDatabase, setDatabaseName, setLoginTimeout, setLogWriter, setPassword, setProperties, setUrl, setURL, setUser
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Method Detail
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLExceptionRetrieves a new connection using the properties that have already been set.- Specified by:
getConnectionin interfacejavax.sql.DataSource- Returns:
- a connection to the data source
- Throws:
java.sql.SQLException- if a database access error occurs
-
getConnection
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLExceptionRetrieves 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- Specified by:
getConnectionin interfacejavax.sql.DataSource- Parameters:
username- the database user on whose behalf the connection is being madepassword- the user's password- Returns:
- a connection to the data source
- Throws:
java.sql.SQLException- if a database access error occurs
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLExceptionReturns 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 callingunwraprecursively on the wrapped object or a proxy for that result. If the receiver is not a wrapper and does not implement the interface, then anSQLExceptionis thrown.- Specified by:
unwrapin interfacejava.sql.Wrapper- Parameters:
iface- A Class defining an interface that the result must implement.- Returns:
- an object that implements the interface. May be a proxy for the actual implementing object.
- Throws:
java.sql.SQLException- If no object found that implements the interface- Since:
- JDK 1.6, HSQLDB 2.0
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLExceptionReturns 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 callingisWrapperForon 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 tounwrapso that callers can use this method to avoid expensiveunwrapcalls that may fail. If this method returns true then callingunwrapwith the same argument should succeed.- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Parameters:
iface- a Class defining an interface.- Returns:
- true if this implements the interface or directly or indirectly wraps an object that does.
- Throws:
java.sql.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
-
getReference
public javax.naming.Reference getReference() throws javax.naming.NamingExceptionRetrieves the Reference of this object.- Specified by:
getReferencein interfacejavax.naming.Referenceable- Returns:
- The non-null Reference of this object.
- Throws:
javax.naming.NamingException- If a naming exception was encountered while retrieving the reference.
-
-