Class Datasource
- All Implemented Interfaces:
AutoCloseable,Cloneable
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.
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.
- Since:
- 1.0
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a newDatasourceobject with no connection information.Datasource(String driver, String url, String user, String password, int poolSize) Instantiates a newDatasourceobject with all the connection parameters that are required.Datasource(DataSource dataSource, int poolSize) Instantiates a newDatasourceobject from a standardjavax.sql.DataSource.Datasource(DataSource dataSource, String driver, String user, String password, int poolSize) Instantiates a newDatasourceobject from a standardjavax.sql.DataSource. -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanup()Cleans up all connections that have been reserved by this datasource.clone()Simply clones the instance with the default clone method.voidclose()static voidCloses all the active datasource.booleanIndicates whether some other object is "equal to" this one.Retrieves the fully qualified class name of the jdbc driver that's used by thisDatasource.rife.database.capabilities.CapabilitiesCompensatorRetrieves aCapabilitiesCompensatorinstance that is able to compensate for certain missing database featuresRetrieves a free database connection.Retrieves the standard datasource that is used by this RIFE datasource to obtain a database connection.Retrieves the fully qualified class name of the jdbc driver that's used by thisDatasource.Retrieves the password that's used by thisDatasource.getPool()Retrieves the instance of the connection pool that is provided by this datasource.intRetrieves the size of the pool that's used by thisDatasource.Retrieves the sql to java and java to sql type mapping logic that corresponds to the provide driver class name.getUrl()Retrieves the connection url that's used by thisDatasource.getUser()Retrieves the user that's used by thisDatasource.inthashCode()Returns a hash code value for theDatasource.booleanisPooled()Indicates whether theDatasourceuses a connection pool or notvoidsetDataSource(DataSource dataSource) Sets the standard datasource that will be used to connect to the database.voidSets the jdbc driver that will be used to connect to the database.voidsetPassword(String password) Sets the password that will be used to connect to the database.voidsetPoolSize(int poolSize) Sets the size of the connection pool that will be used to connect to the database.voidSets the connection url that will be used to connect to the database.voidSets the user that will be used to connect to the database.
-
Field Details
-
sDriverAliases
-
sDriverNames
-
DRIVER_NAME_DERBY
-
DRIVER_NAME_H2
-
DRIVER_NAME_HSQLDB
-
DRIVER_NAME_PGSQL
-
DRIVER_NAME_MYSQL
-
DRIVER_NAME_ORACLE
-
-
Constructor Details
-
Datasource
public Datasource()Instantiates a newDatasourceobject with no connection information. The setters need to be used afterward to provide each required parameter before theDatasourcecan be used. -
Datasource
Instantiates a newDatasourceobject with all the connection parameters that are required.- Parameters:
driver- the fully-qualified classname of the jdbc driver that will be used to connect to the databaseurl- the connection url which identifies the database to which the connection will be made, this is entirely driver-dependentuser- the user that will be used to connect to the databasepassword- the password that will be used to connect to the databasepoolSize- the size of the connection pool,0means that the connections will not be pooled- Since:
- 1.0
-
Datasource
Instantiates a newDatasourceobject from a standardjavax.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 the connectionpoolSize- the size of the connection pool,0means that the connections will not be pooled- Since:
- 1.0
-
Datasource
Instantiates a newDatasourceobject from a standardjavax.sql.DataSource.- Parameters:
dataSource- the standard datasource that will be used to obtain the connectiondriver- the fully-qualified classname of the jdbc driver that will be used to provide an identifier for the database abstraction functionalities,nullwill let RIFE try to figure it out by itselfuser- the user that will be used to connect to the databasepassword- the password that will be used to connect to the databasepoolSize- the size of the connection pool,0means that the connections will not be pooled- Since:
- 1.0
-
-
Method Details
-
getConnection
Retrieves a free database connection. If no connection pool is used, a newDbConnectionwill always be created, otherwise the first available connection in the pool will be returned.- Returns:
- a free
DbConnectioninstance which can be used to create an execute statements - Throws:
DatabaseException- when errors occured during the creation of a new connection or during the obtainance of a connection from the pool- Since:
- 1.0
-
getDriver
Retrieves the fully qualified class name of the jdbc driver that's used by thisDatasource.- Returns:
- a
Stringwith the name of the jdbc driver; ornullif the driver hasn't been set - Since:
- 1.0
- See Also:
-
getAliasedDriver
Retrieves the fully qualified class name of the jdbc driver that's used by thisDatasource. 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.- Returns:
- a
Stringwith the name of the jdbc driver; ornullif the driver hasn't been set - Since:
- 1.0
- See Also:
-
setDriver
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- aStringwith the fully qualified class name of the jdbc driver that will be used- Since:
- 1.0
- See Also:
-
getDataSource
Retrieves the standard datasource that is used by this RIFE datasource to obtain a database connection.- Returns:
- a standard
DataSource; ornullif the standard datasource hasn't been set - Since:
- 1.0
- See Also:
-
setDataSource
Sets the standard datasource that will be used to connect to the database.- Parameters:
dataSource- a standardDataSourcethat will be used by this RIFE datasource to obtain a database connection.- Since:
- 1.0
- See Also:
-
getUrl
Retrieves the connection url that's used by thisDatasource.- Returns:
- a
Stringwith the connection url; ornullif the url hasn't been set - Since:
- 1.0
- See Also:
-
setUrl
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- aStringwith the connection url that will be used- Since:
- 1.0
- See Also:
-
getUser
Retrieves the user that's used by thisDatasource.- Returns:
- a
Stringwith the user; ornullif the user hasn't been set - Since:
- 1.0
- See Also:
-
setUser
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- aStringwith the user that will be used- Since:
- 1.0
- See Also:
-
getPassword
Retrieves the password that's used by thisDatasource.- Returns:
- a
Stringwith the password; ornullif the password hasn't been set - Since:
- 1.0
- See Also:
-
setPassword
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- aStringwith the password that will be used- Since:
- 1.0
- See Also:
-
getPoolSize
public int getPoolSize()Retrieves the size of the pool that's used by thisDatasource.- Returns:
- a positive
intwith the size of the pool; or0if no pool is being used - Since:
- 1.0
- See Also:
-
isPooled
public boolean isPooled()Indicates whether theDatasourceuses a connection pool or not- Returns:
trueif a pool is being used by thisDatasource; orfalseotherwise- Since:
- 1.0
- See Also:
-
setPoolSize
public void setPoolSize(int poolSize) Sets the size of the connection pool that will be used to connect to the database.- Parameters:
poolSize- a positiveintwith the size of the pool, providing0will disable the use of a connection pool for thisDatasource.- Since:
- 1.0
- See Also:
-
getSqlConversion
Retrieves the sql to java and java to sql type mapping logic that corresponds to the provide driver class name.- Returns:
- a
SqlConversioninstance that is able to perform the required type conversions for the provided jdbc driver - Throws:
UnsupportedJdbcDriverException- when the provided jdbc isn't supported- Since:
- 1.0
-
getCapabilitiesCompensator
public rife.database.capabilities.CapabilitiesCompensator getCapabilitiesCompensator() throws UnsupportedJdbcDriverExceptionRetrieves aCapabilitiesCompensatorinstance that is able to compensate for certain missing database features- Returns:
- the requested
CapabilitiesCompensatorinstance - Throws:
UnsupportedJdbcDriverException- when the provided jdbc isn't supported- Since:
- 1.0
-
hashCode
public int hashCode()Returns a hash code value for theDatasource. This method is supported for the benefit of hashtables such as those provided byjava.util.Hashtable. -
equals
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. -
clone
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. -
cleanup
Cleans up all connections that have been reserved by this datasource.- Throws:
DatabaseException- when an error occurred during the cleanup- Since:
- 1.0
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
DatabaseException
-
getPool
Retrieves the instance of the connection pool that is provided by this datasource.- Returns:
- the requested instance of
ConnectionPool
-
closeAllActiveDatasources
public static void closeAllActiveDatasources()Closes all the active datasource.This can be used to ensure that no connections or drivers are dangling when an application shuts down. It's already used by the destroy method of the
RifeFilter.- Since:
- 1.6.1
-