org.dellroad.stuff.schema
Class AbstractUpdatingDataSource

java.lang.Object
  extended by org.dellroad.stuff.schema.AbstractUpdatingDataSource
All Implemented Interfaces:
Wrapper, CommonDataSource, DataSource
Direct Known Subclasses:
SchemaUpdatingDataSource, UpdatingDataSource

public abstract class AbstractUpdatingDataSource
extends Object
implements DataSource

A DataSource that wraps an inner DataSource and automatically performs some update operation on the inner DataSource on first access.

The dataSource property is required.


Constructor Summary
AbstractUpdatingDataSource()
           
 
Method Summary
 Connection getConnection()
           
 Connection getConnection(String username, String password)
           
protected  DataSource getInnerDataSource()
          Get the underlying DataSource.
 int getLoginTimeout()
           
 PrintWriter getLogWriter()
           
protected  boolean isUpdated()
          Determine if the underlying DataSource has been updated.
 boolean isWrapperFor(Class<?> cl)
           
 void setDataSource(DataSource dataSource)
          Configure the underlying DataSource.
 void setLoginTimeout(int timeout)
           
 void setLogWriter(PrintWriter pw)
           
<T> T
unwrap(Class<T> cl)
           
protected abstract  void updateDataSource(DataSource dataSource)
          Update the inner DataSource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractUpdatingDataSource

public AbstractUpdatingDataSource()
Method Detail

setDataSource

public void setDataSource(DataSource dataSource)
Configure the underlying DataSource. Required property.


updateDataSource

protected abstract void updateDataSource(DataSource dataSource)
                                  throws SQLException
Update the inner DataSource.

This method will be invoked at most once.

Throws:
SQLException

getInnerDataSource

protected DataSource getInnerDataSource()
Get the underlying DataSource.


isUpdated

protected boolean isUpdated()
Determine if the underlying DataSource has been updated.

If the update is currently happening in another thread, the current thread will block until the update operation finishes.


getConnection

public Connection getConnection()
                         throws SQLException
Specified by:
getConnection in interface DataSource
Throws:
SQLException

getConnection

public Connection getConnection(String username,
                                String password)
                         throws SQLException
Specified by:
getConnection in interface DataSource
Throws:
SQLException

getLogWriter

public PrintWriter getLogWriter()
                         throws SQLException
Specified by:
getLogWriter in interface CommonDataSource
Throws:
SQLException

setLogWriter

public void setLogWriter(PrintWriter pw)
                  throws SQLException
Specified by:
setLogWriter in interface CommonDataSource
Throws:
SQLException

setLoginTimeout

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

getLoginTimeout

public int getLoginTimeout()
                    throws SQLException
Specified by:
getLoginTimeout in interface CommonDataSource
Throws:
SQLException

unwrap

public <T> T unwrap(Class<T> cl)
         throws SQLException
Specified by:
unwrap in interface Wrapper
Throws:
SQLException

isWrapperFor

public boolean isWrapperFor(Class<?> cl)
                     throws SQLException
Specified by:
isWrapperFor in interface Wrapper
Throws:
SQLException