org.apache.myfaces.extensions.cdi.jpa.impl.datasource
Class ConfigurableDataSource

java.lang.Object
  extended by org.apache.myfaces.extensions.cdi.jpa.impl.datasource.ConfigurableDataSource
All Implemented Interfaces:
Wrapper, CommonDataSource, DataSource

public class ConfigurableDataSource
extends Object
implements DataSource

This class can be used instead of a real DataSource. It is a simple wrapper to hide any database configuration details and make it configurable via CDI.

See DataSourceConfig on how to configure it!

The configuration itself will be provided via CDI mechanics. To distinguish different databases, users can specify a connectionId. If no connectionId is set, the String default will be used


Constructor Summary
ConfigurableDataSource()
           
 
Method Summary
 Connection getConnection()
           
 Connection getConnection(String userName, String password)
           
 int getLoginTimeout()
           
 PrintWriter getLogWriter()
           
 Logger getParentLogger()
          NEW JDK1.7 signature.
protected  void initDataSource()
          Initialize the DataSource either from JNDI or via JDBC Driver.
 boolean isWrapperFor(Class<?> iface)
           
 void setConnectionId(String connectionId)
           
 void setLoginTimeout(int loginTimeout)
           
 void setLogWriter(PrintWriter printWriter)
           
protected  void setProperty(Object instance, String key, String value)
           
<T> T
unwrap(Class<T> iface)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigurableDataSource

public ConfigurableDataSource()
Method Detail

setConnectionId

public void setConnectionId(String connectionId)

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 printWriter)
                  throws SQLException
Specified by:
setLogWriter in interface CommonDataSource
Throws:
SQLException

setLoginTimeout

public void setLoginTimeout(int loginTimeout)
                     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> iface)
         throws SQLException
Specified by:
unwrap in interface Wrapper
Throws:
SQLException

isWrapperFor

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

getParentLogger

public Logger getParentLogger()
                       throws SQLFeatureNotSupportedException
NEW JDK1.7 signature. This makes sure that CODI can also get compiled using java-7. This method is not actively used though.

Throws:
SQLFeatureNotSupportedException

initDataSource

protected void initDataSource()
                       throws SQLException
Initialize the DataSource either from JNDI or via JDBC Driver. This method does not actually create a connection yet.

Throws:
SQLException

setProperty

protected void setProperty(Object instance,
                           String key,
                           String value)
                    throws InvocationTargetException,
                           IllegalAccessException
Throws:
InvocationTargetException
IllegalAccessException


Copyright © 2010-2011 The Apache Software Foundation. All Rights Reserved.