Package migratedb.core.internal.jdbc
Class DriverDataSource
- java.lang.Object
-
- migratedb.core.internal.jdbc.DriverDataSource
-
- All Implemented Interfaces:
Wrapper,CommonDataSource,DataSource
public class DriverDataSource extends Object implements DataSource
YAGNI: The simplest DataSource implementation that works for MigrateDB .
-
-
Constructor Summary
Constructors Constructor Description DriverDataSource(ClassLoader classLoader, String driverClass, String url, String user, String password, Map<String,String> additionalProperties, DatabaseTypeRegister databaseTypeRegister)DriverDataSource(ClassLoader classLoader, String driverClass, String url, String user, String password, Configuration configuration, Map<String,String> additionalProperties, DatabaseTypeRegister databaseTypeRegister)DriverDataSource(ClassLoader classLoader, String driverClass, String url, String user, String password, Configuration configuration, Properties defaultProperties, Map<String,String> additionalProperties, DatabaseTypeRegister databaseTypeRegister)Creates a new DriverDataSource.DriverDataSource(ClassLoader classLoader, String driverClass, String url, String user, String password, Configuration configuration, DatabaseTypeRegister databaseTypeRegister)DriverDataSource(ClassLoader classLoader, String driverClass, String url, String user, String password, DatabaseTypeRegister databaseTypeRegister)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,String>getAdditionalProperties()ConnectiongetConnection()This implementation delegates togetConnectionFromDriver, using the default user and password of this DataSource.ConnectiongetConnection(String username, String password)This implementation delegates togetConnectionFromDriver, using the given user and password.protected ConnectiongetConnectionFromDriver(String username, String password)Build properties for the Driver, including the given user and password (if any), and obtain a corresponding Connection.DrivergetDriver()intgetLoginTimeout()PrintWritergetLogWriter()LoggergetParentLogger()StringgetPassword()StringgetUrl()StringgetUser()booleanisAutoCommit()booleanisWrapperFor(Class<?> iface)voidsetAutoCommit(boolean autoCommit)voidsetLoginTimeout(int timeout)voidsetLogWriter(PrintWriter pw)voidshutdownDatabase()<T> Tunwrap(Class<T> iface)-
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 Detail
-
DriverDataSource
public DriverDataSource(ClassLoader classLoader, String driverClass, String url, String user, String password, DatabaseTypeRegister databaseTypeRegister) throws MigrateDbException
- Throws:
MigrateDbException
-
DriverDataSource
public DriverDataSource(ClassLoader classLoader, String driverClass, String url, String user, String password, Configuration configuration, DatabaseTypeRegister databaseTypeRegister) throws MigrateDbException
- Throws:
MigrateDbException
-
DriverDataSource
public DriverDataSource(ClassLoader classLoader, String driverClass, String url, String user, String password, Map<String,String> additionalProperties, DatabaseTypeRegister databaseTypeRegister) throws MigrateDbException
- Throws:
MigrateDbException
-
DriverDataSource
public DriverDataSource(ClassLoader classLoader, String driverClass, String url, String user, String password, Configuration configuration, Map<String,String> additionalProperties, DatabaseTypeRegister databaseTypeRegister) throws MigrateDbException
- Throws:
MigrateDbException
-
DriverDataSource
public DriverDataSource(ClassLoader classLoader, String driverClass, String url, String user, String password, Configuration configuration, Properties defaultProperties, Map<String,String> additionalProperties, DatabaseTypeRegister databaseTypeRegister) throws MigrateDbException
Creates a new DriverDataSource.- Parameters:
classLoader- The ClassLoader to use.driverClass- The name of the JDBC Driver class to use.nullfor url-based autodetection.url- The JDBC URL to use for connecting through the Driver. (required)user- The JDBC user to use for connecting through the Driver.password- The JDBC password to use for connecting through the Driver.configuration- The MigrateDB configurationdefaultProperties- Default values of properties to pass to the connection (can be overridden byadditionalProperties)additionalProperties- The properties to pass to the connection.- Throws:
MigrateDbException- when the datasource could not be created.
-
-
Method Detail
-
getDriver
public Driver getDriver()
- Returns:
- the JDBC Driver instance to use.
-
getUrl
public String getUrl()
- Returns:
- the JDBC URL to use for connecting through the Driver.
-
getUser
public String getUser()
- Returns:
- the JDBC user to use for connecting through the Driver.
-
getPassword
public String getPassword()
- Returns:
- the JDBC password to use for connecting through the Driver.
-
getAdditionalProperties
public Map<String,String> getAdditionalProperties()
- Returns:
- The additional properties to pass to a JDBC connection.
-
getConnection
public Connection getConnection() throws SQLException
This implementation delegates togetConnectionFromDriver, using the default user and password of this DataSource.- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException- See Also:
getConnectionFromDriver(String, String)
-
getConnection
public Connection getConnection(String username, String password) throws SQLException
This implementation delegates togetConnectionFromDriver, using the given user and password.- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException- See Also:
getConnectionFromDriver(String, String)
-
getConnectionFromDriver
protected Connection getConnectionFromDriver(String username, String password) throws SQLException
Build properties for the Driver, including the given user and password (if any), and obtain a corresponding Connection.- Parameters:
username- the name of the userpassword- the password to use- Returns:
- the obtained Connection
- Throws:
SQLException- in case of failure- See Also:
Driver.connect(String, java.util.Properties)
-
isAutoCommit
public boolean isAutoCommit()
- Returns:
- Whether connection should have auto commit activated or not. Default:
true
-
setAutoCommit
public void setAutoCommit(boolean autoCommit)
- Parameters:
autoCommit- Whether connection should have auto commit activated or not. Default:true
-
shutdownDatabase
public void shutdownDatabase()
-
getLoginTimeout
public int getLoginTimeout()
- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource
-
setLoginTimeout
public void setLoginTimeout(int timeout)
- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource
-
getLogWriter
public PrintWriter getLogWriter()
- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource
-
setLogWriter
public void setLogWriter(PrintWriter pw)
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface)
- Specified by:
isWrapperForin interfaceWrapper
-
getParentLogger
public Logger getParentLogger()
- Specified by:
getParentLoggerin interfaceCommonDataSource
-
-