Class DriverDataSource
java.lang.Object
com.invirgance.convirgance.jdbc.datasource.DriverDataSource
- All Implemented Interfaces:
Wrapper
,CommonDataSource
,DataSource
A JDBC DataSource implementation that wraps a database driver to provide connection services.
This class automates the process of establishing database connections using driver-based
connectivity. It determines the appropriate JDBC driver based on the connection URL
and manages connection credentials. This is particularly useful for scenarios where
you need to create
DataSource
s dynamically from existing login information.- Author:
- jbanes
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a connection to the database using the current username and password.getConnection
(String username, String password) Returns a connection to the database using the provided username and password.static DriverDataSource
getDataSource
(String url, String username, String password) Returns a DriverDataSource created with the provided info.int
Returns the password.getUrl()
Get the connection URL.Returns the username used when connecting to the database.boolean
isWrapperFor
(Class<?> iface) void
setLoginTimeout
(int seconds) void
setLogWriter
(PrintWriter out) void
setPassword
(String password) Sets the password that will be used with the username when connecting.void
Sets the connection URL.void
setUsername
(String username) Sets the username to use for connecting to the database.<T> T
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Constructor Details
-
DriverDataSource
public DriverDataSource()
-
-
Method Details
-
getDataSource
Returns a DriverDataSource created with the provided info.- Parameters:
url
- The connection URL.username
- The username.password
- The password.- Returns:
- A DriverDataSource.
-
getUrl
Get the connection URL.- Returns:
- The connection string URL.
-
setUrl
Sets the connection URL. Remember to include the connection prefix. Ex: "jdbc:oracle:thin:"- Parameters:
url
- The new connection URL.
-
getUsername
Returns the username used when connecting to the database.- Returns:
- The username.
-
setUsername
Sets the username to use for connecting to the database.- Parameters:
username
- The username.
-
getPassword
Returns the password.- Returns:
- The password.
-
setPassword
Sets the password that will be used with the username when connecting.- Parameters:
password
- The password.
-
getConnection
Returns a connection to the database using the current username and password. The password is optional when connecting with this method.- Specified by:
getConnection
in interfaceDataSource
- Returns:
- A connection.
- Throws:
SQLException
- When the username and password are incorrect or the something else.
-
getConnection
Returns a connection to the database using the provided username and password.- Specified by:
getConnection
in interfaceDataSource
- Parameters:
username
- The username.password
- The password.- Returns:
- A connection.
- Throws:
SQLException
- When the username and password are incorrect or the something else.
-
getLogWriter
- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceDataSource
- Throws:
SQLException
-
setLogWriter
- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceDataSource
- Throws:
SQLException
-
setLoginTimeout
- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Throws:
SQLException
-
getLoginTimeout
- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Throws:
SQLException
-
getParentLogger
- Specified by:
getParentLogger
in interfaceCommonDataSource
- Throws:
SQLFeatureNotSupportedException
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-