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
DataSources 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 DriverDataSourcegetDataSource(String url, String username, String password) Returns a DriverDataSource created with the provided info.intReturns the password.getUrl()Get the connection URL.Returns the username used when connecting to the database.booleanisWrapperFor(Class<?> iface) voidsetLoginTimeout(int seconds) voidsetLogWriter(PrintWriter out) voidsetPassword(String password) Sets the password that will be used with the username when connecting.voidSets the connection URL.voidsetUsername(String username) Sets the username to use for connecting to the database.<T> TMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilderMethods 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:
getConnectionin 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:
getConnectionin 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:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Throws:
SQLException
-
setLogWriter
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Throws:
SQLException
-
setLoginTimeout
- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getLoginTimeout
- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getParentLogger
- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-