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
DataSource
object represents. An alternative to the
DriverManager
facility, a DataSource
object
is the preferred means of getting a connection. An object that implements
the DataSource
interface will typically be
registered with a naming service based on the
JavaTM Naming and Directory (JNDI) API.
The DataSource
interface is implemented by a driver vendor.
There are three types of implementations:
Connection
object
Connection
object that will automatically participate in connection pooling. This
implementation works with a middle-tier connection pooling manager.
Connection
object 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 DataSource
object 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 DataSource
object does not
register itself with the DriverManager
. Rather, a
DataSource
object is retrieved though a lookup operation
and then used to create a Connection
object. With a basic
implementation, the connection obtained through a DataSource
object is identical to a connection obtained through the
DriverManager
facility.
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.
Constructor | Description |
---|---|
JDBCDataSource() |
Modifier and Type | Method | Description |
---|---|---|
java.sql.Connection |
getConnection() |
Retrieves a new connection using the properties that have already been
set.
|
java.sql.Connection |
getConnection(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.Reference |
getReference() |
Retrieves the Reference of this object.
|
boolean |
isWrapperFor(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> T |
unwrap(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.
|
createShardingKeyBuilder, getParentLogger
createConnectionBuilder, getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
getDatabase, getDatabaseName, getDataSourceName, getDescription, getLoginTimeout, getLogWriter, getNetworkProtocol, getParentLogger, getServerName, getUrl, getUser, setDatabase, setDatabaseName, setLoginTimeout, setLogWriter, setPassword, setProperties, setUrl, setURL, setUser
public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
- if a database access error occurspublic java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
username
- the database user on whose behalf the connection is
being madepassword
- the user's passwordjava.sql.SQLException
- if a database access error occurspublic <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
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.unwrap
in interface java.sql.Wrapper
iface
- A Class defining an interface that the result must implement.java.sql.SQLException
- If no object found that implements the interfacepublic boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
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.isWrapperFor
in interface java.sql.Wrapper
iface
- a Class defining an interface.java.sql.SQLException
- if an error occurs while determining whether this is a wrapper
for an object with the given interface.public javax.naming.Reference getReference() throws javax.naming.NamingException
getReference
in interface javax.naming.Referenceable
javax.naming.NamingException
- If a naming exception was encountered
while retrieving the reference.Copyright �� 2001 - 2013 HSQL Development Group.