| java.lang.Object com.uwyn.rife.database.Datasource
Datasource | public class Datasource implements Cloneable(Code) | | Contains all the information required to connect to a database and
centralizes the creation of connections to a database. These connections can
optionally be pooled.
The initial connection will only be made and the pool will only be
initialized when a connection is obtained for the first time. The
instantiation only stores the connection parameters.
A Datasource also defines the type of database that is used for
all database-independent logic such as sql to java and java to sql type
mappings, query builders, database-based authentication, database-based
scheduling, ... The key that identifies a supported type is the class name of
the jdbc driver.
A Datasource instance can be created through it's constructor,
but it's recommended to work with a Datasources collection
that is created and populated through XML. This can easily be achieved by
using a ParticipantDatasources which participates in the
application-wide repository.
Once a connection has been obtained from a pooled datasource, modifying its
connection parameters is not possible anymore, a new instance has to be
created to set the parameters to different values.
author: Geert Bevin (gbevin[remove] at uwyn dot com) version: $Revision: 3636 $ See Also: com.uwyn.rife.database.Datasources See Also: com.uwyn.rife.database.Xml2Datasources See Also: com.uwyn.rife.rep.Rep See Also: com.uwyn.rife.rep.participants.ParticipantDatasources since: 1.0 |
Constructor Summary | |
public | Datasource() Instantiates a new Datasource object with no connection
information. | public | Datasource(String driver, String url, String user, String password, int poolsize) Instantiates a new Datasource object with all the
connection parameters that are required. | public | Datasource(DataSource dataSource, int poolsize) Instantiates a new Datasource object from a standard
javax.sql.DataSource .
The driver will be detected from the connection that is provided by this
DataSource . | public | Datasource(DataSource dataSource, String driver, String user, String password, int poolsize) Instantiates a new Datasource object from a standard
javax.sql.DataSource . |
Method Summary | |
public void | cleanup() Cleans up all connections that have been reserved by this datasource. | public Datasource | clone() Simply clones the instance with the default clone method. | DbConnection | createConnection() Creates a new connection by using all the parameters that have been
defined in the Datasource . | public boolean | equals(Object object) Indicates whether some other object is "equal to" this one. | public String | getAliasedDriver() Retrieves the fully qualified class name of the jdbc driver that's used
by this Datasource . | public CapabilitiesCompensator | getCapabilitiesCompensator() | public DbConnection | getConnection() Retrieves a free database connection. | public DataSource | getDataSource() Retrieves the standard datasource that is used by this RIFE datasource
to obtain a database connection. | public String | getDriver() Retrieves the fully qualified class name of the jdbc driver that's used
by this Datasource . | public String | getPassword() Retrieves the password that's used by this Datasource . | public ConnectionPool | getPool() Retrieves the instance of the connection pool that is provided by this
dtaasource. | public int | getPoolsize() Retrieves the size of the pool that's used by this
Datasource . | public SqlConversion | getSqlConversion() Retrieves the sql to java and java to sql type mapping logic that
corresponds to the provide driver class name. | public String | getUrl() Retrieves the connection url that's used by this Datasource . | public String | getUser() Retrieves the user that's used by this Datasource . | public int | hashCode() Returns a hash code value for the Datasource . | public boolean | isPooled() | public void | setDataSource(DataSource dataSource) Sets the standard datasource that will be used to connect to the database. | public void | setDriver(String driver) Sets the jdbc driver that will be used to connect to the database. | public void | setPassword(String password) Sets the password that will be used to connect to the database. | public void | setPoolsize(int poolsize) Sets the size of the connection pool that will be used to connect to the
database. | public void | setUrl(String url) Sets the connection url that will be used to connect to the database. | public void | setUser(String user) Sets the user that will be used to connect to the database. |
Datasource | public Datasource(String driver, String url, String user, String password, int poolsize)(Code) | | Instantiates a new Datasource object with all the
connection parameters that are required.
Parameters: driver - the fully-qualified classname of the jdbc driver that willbe used to connect to the database Parameters: url - the connection url which identifies the database to which theconnection will be made, this is entirely driver-dependent Parameters: user - the user that will be used to connect to the database Parameters: password - the password that will be used to connect to the database Parameters: poolsize - the size of the connection pool, 0 meansthat the connections will not be pooled since: 1.0 |
Datasource | public Datasource(DataSource dataSource, int poolsize)(Code) | | Instantiates a new Datasource object from a standard
javax.sql.DataSource .
The driver will be detected from the connection that is provided by this
DataSource . If the driver couldn't be detected, an exception
will be thrown upon connect.
Parameters: dataSource - the standard datasource that will be used to obtain theconnection Parameters: poolsize - the size of the connection pool, 0 meansthat the connections will not be pooled since: 1.3 |
Datasource | public Datasource(DataSource dataSource, String driver, String user, String password, int poolsize)(Code) | | Instantiates a new Datasource object from a standard
javax.sql.DataSource .
Parameters: dataSource - the standard datasource that will be used to obtain theconnection Parameters: driver - the fully-qualified classname of the jdbc driver that willbe used to provide an identifier for the database abstraction functionalities,null will let RIFE try to figure it out by itself Parameters: user - the user that will be used to connect to the database Parameters: password - the password that will be used to connect to the database Parameters: poolsize - the size of the connection pool, 0 meansthat the connections will not be pooled since: 1.3 |
cleanup | public void cleanup() throws DatabaseException(Code) | | Cleans up all connections that have been reserved by this datasource.
throws: DatabaseException - when an error occured during the cleanup since: 1.0 |
clone | public Datasource clone()(Code) | | Simply clones the instance with the default clone method. This creates a
shallow copy of all fields and the clone will in fact just be another
reference to the same underlying data. The independence of each cloned
instance is consciously not respected since they rely on resources
that can't be cloned.
since: 1.0 |
createConnection | DbConnection createConnection() throws DatabaseException(Code) | | Creates a new connection by using all the parameters that have been
defined in the Datasource .
the newly created DbConnection instance throws: DatabaseException - when an error occured during the creation ofthe connection since: 1.0 |
equals | public boolean equals(Object object)(Code) | | Indicates whether some other object is "equal to" this one. Only the
real connection parameters will be taken into account. The size of the
pool is not used for the comparison.
Parameters: object - the reference object with which to compare. true if this object is the same as the objectargument; orfalse otherwise See Also: Datasource.hashCode() since: 1.0
|
getAliasedDriver | public String getAliasedDriver()(Code) | | Retrieves the fully qualified class name of the jdbc driver that's used
by this Datasource . Instead of straight retrieval of the
internal value, it looks for jdbc driver aliases and changes the driver
classname if it's not supported by RIFE, but its alias is.
a String with the name of the jdbc driver; ornull if the driver hasn't been set See Also: Datasource.getDriver() See Also: Datasource.setDriver(String) since: 1.0
|
getConnection | public DbConnection getConnection() throws DatabaseException(Code) | | Retrieves a free database connection. If no connection pool is used, a
new DbConnection will always be created, otherwise the first
available connection in the pool will be returned.
a free DbConnection instance which can be used tocreate an execute statements throws: DatabaseException - when errors occured during the creation of anew connection or during the obtainance of a connection from the pool since: 1.0 |
getDataSource | public DataSource getDataSource()(Code) | | Retrieves the standard datasource that is used by this RIFE datasource
to obtain a database connection.
a standard DataSource ; ornull if the standard datasource hasn't been set See Also: Datasource.setDataSource(DataSource) since: 1.3
|
getPassword | public String getPassword()(Code) | | Retrieves the password that's used by this Datasource .
a String>/code> with the password; ornull if the password hasn't been set See Also: Datasource.setPassword(String) since: 1.0
|
getPool | public ConnectionPool getPool()(Code) | | Retrieves the instance of the connection pool that is provided by this
dtaasource.
the requested instance of ConnectionPool |
getSqlConversion | public SqlConversion getSqlConversion() throws UnsupportedJdbcDriverException(Code) | | Retrieves the sql to java and java to sql type mapping logic that
corresponds to the provide driver class name.
a SqlConversion instance that is able to performthe required type conversions for the provided jdbc driver throws: UnsupportedJdbcDriverException - when the provided jdbc isn'tsupported since: 1.0 |
getUrl | public String getUrl()(Code) | | Retrieves the connection url that's used by this Datasource .
a String with the connection url; ornull if the url hasn't been set See Also: Datasource.setUrl(String) since: 1.0
|
getUser | public String getUser()(Code) | | Retrieves the user that's used by this Datasource .
a String>/code> with the user; ornull if the user hasn't been set See Also: Datasource.setUser(String) since: 1.0
|
hashCode | public int hashCode()(Code) | | Returns a hash code value for the Datasource . This method is
supported for the benefit of hashtables such as those provided by
java.util.Hashtable .
an int with the hash code value for thisDatasource . See Also: Datasource.equals(Object) since: 1.0 |
setDataSource | public void setDataSource(DataSource dataSource)(Code) | | Sets the standard datasource that will be used to connect to the database.
Parameters: dataSource - a standard DataSource that will be usedby this RIFE datasource to obtain a database connection. See Also: Datasource.getDataSource() since: 1.0 |
setDriver | public void setDriver(String driver)(Code) | | Sets the jdbc driver that will be used to connect to the database. This
has to be a fully qualified class name and will be looked up through
reflection. It's not possible to change the driver after a connection
has been obtained from a pooled datasource.
If the class name can't be resolved, an exception is thrown during the
creation of the first connection.
Parameters: driver - a String with the fully qualified class nameof the jdbc driver that will be used See Also: Datasource.getDriver() since: 1.0 |
setPassword | public void setPassword(String password)(Code) | | Sets the password that will be used to connect to the database.
It's not possible to change the password after a connection has been
obtained from a pooled datasource.
Parameters: password - a String with the password that will be used See Also: Datasource.getPassword() since: 1.0 |
setPoolsize | public void setPoolsize(int poolsize)(Code) | | Sets the size of the connection pool that will be used to connect to the
database.
Parameters: poolsize - a positive int with the size of the pool,providing 0 will disable the use of a connection pool forthis Datasource . See Also: Datasource.getPoolsize() See Also: Datasource.isPooled() since: 1.0 |
setUrl | public void setUrl(String url)(Code) | | Sets the connection url that will be used to connect to the database.
It's not possible to change the url after a connection has been obtained
from a pooled datasource.
Parameters: url - a String with the connection url that will beused See Also: Datasource.getUrl() since: 1.0 |
setUser | public void setUser(String user)(Code) | | Sets the user that will be used to connect to the database.
It's not possible to change the user after a connection has been obtained
from a pooled datasource.
Parameters: user - a String with the user that will be used See Also: Datasource.getUser() since: 1.0 |
|
|