com.googlecode.flyway.core.util.jdbc
Class DriverDataSource

java.lang.Object
  extended by com.googlecode.flyway.core.util.jdbc.DriverDataSource
All Implemented Interfaces:
java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource

public class DriverDataSource
extends java.lang.Object
implements javax.sql.DataSource

YAGNI: The simplest DataSource implementation that works for Flyway.


Constructor Summary
DriverDataSource()
          Creates a new DriverDataSource.
DriverDataSource(java.sql.Driver driver, java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String... initSqls)
          Creates a new DriverDataSource.
DriverDataSource(java.lang.String driverClass, java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String... initSqls)
          Creates a new DriverDataSource.
 
Method Summary
 java.sql.Connection getConnection()
          This implementation delegates to getConnectionFromDriver, using the default user and password of this DataSource.
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          This implementation delegates to getConnectionFromDriver, using the given user and password.
protected  java.sql.Connection getConnectionFromDriver(java.lang.String username, java.lang.String password)
          Build properties for the Driver, including the given user and password (if any), and obtain a corresponding Connection.
 java.sql.Driver getDriver()
           
 java.lang.String[] getInitSqls()
           
 int getLoginTimeout()
           
 java.io.PrintWriter getLogWriter()
           
 java.lang.String getPassword()
           
 java.lang.String getUrl()
           
 java.lang.String getUser()
           
 boolean isWrapperFor(java.lang.Class<?> iface)
           
 void setLoginTimeout(int timeout)
           
 void setLogWriter(java.io.PrintWriter pw)
           
<T> T
unwrap(java.lang.Class<T> iface)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DriverDataSource

public DriverDataSource()
Creates a new DriverDataSource.


DriverDataSource

public DriverDataSource(java.sql.Driver driver,
                        java.lang.String url,
                        java.lang.String user,
                        java.lang.String password,
                        java.lang.String... initSqls)
                 throws FlywayException
Creates a new DriverDataSource.

Parameters:
driver - The JDBC Driver instance to use.
url - The JDBC URL to use for connecting through the Driver.
user - The JDBC user to use for connecting through the Driver.
password - The JDBC password to use for connecting through the Driver.
initSqls - The (optional) sql statements to execute to initialize a connection immediately after obtaining it.
Throws:
FlywayException - when the datasource could not be created.

DriverDataSource

public DriverDataSource(java.lang.String driverClass,
                        java.lang.String url,
                        java.lang.String user,
                        java.lang.String password,
                        java.lang.String... initSqls)
                 throws FlywayException
Creates a new DriverDataSource.

Parameters:
driverClass - The name of the JDBC Driver class to use.
url - The JDBC URL to use for connecting through the Driver.
user - The JDBC user to use for connecting through the Driver.
password - The JDBC password to use for connecting through the Driver.
initSqls - The (optional) sql statements to execute to initialize a connection immediately after obtaining it.
Throws:
FlywayException - when the datasource could not be created.
Method Detail

getDriver

public java.sql.Driver getDriver()
Returns:
the JDBC Driver instance to use.

getUrl

public java.lang.String getUrl()
Returns:
the JDBC URL to use for connecting through the Driver.

getUser

public java.lang.String getUser()
Returns:
the JDBC user to use for connecting through the Driver.

getPassword

public java.lang.String getPassword()
Returns:
the JDBC password to use for connecting through the Driver.

getInitSqls

public java.lang.String[] getInitSqls()
Returns:
The (optional) sql statements to execute to initialize a connection immediately after obtaining it.

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
This implementation delegates to getConnectionFromDriver, using the default user and password of this DataSource.

Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException
See Also:
getConnectionFromDriver(String, String)

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
This implementation delegates to getConnectionFromDriver, using the given user and password.

Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException
See Also:
getConnectionFromDriver(String, String)

getConnectionFromDriver

protected java.sql.Connection getConnectionFromDriver(java.lang.String username,
                                                      java.lang.String password)
                                               throws java.sql.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 user
password - the password to use
Returns:
the obtained Connection
Throws:
java.sql.SQLException - in case of failure
See Also:
Driver.connect(String, java.util.Properties)

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Specified by:
getLoginTimeout in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

setLoginTimeout

public void setLoginTimeout(int timeout)
                     throws java.sql.SQLException
Specified by:
setLoginTimeout in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

getLogWriter

public java.io.PrintWriter getLogWriter()
Specified by:
getLogWriter in interface javax.sql.CommonDataSource

setLogWriter

public void setLogWriter(java.io.PrintWriter pw)
                  throws java.sql.SQLException
Specified by:
setLogWriter in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

unwrap

public <T> T unwrap(java.lang.Class<T> iface)
         throws java.sql.SQLException
Specified by:
unwrap in interface java.sql.Wrapper
Throws:
java.sql.SQLException

isWrapperFor

public boolean isWrapperFor(java.lang.Class<?> iface)
                     throws java.sql.SQLException
Specified by:
isWrapperFor in interface java.sql.Wrapper
Throws:
java.sql.SQLException


Copyright © 2012. All Rights Reserved.