SafeJDBC v2.00

com.safejdbc.javax.sql
Class SafeDataSourceJndiBean

java.lang.Object
  extended by com.safejdbc.javax.sql.SafeDataSourceJndiBean
All Implemented Interfaces:
Wrapper, CommonDataSource, DataSource

public class SafeDataSourceJndiBean
extends Object
implements DataSource

Implementation of DataSource that allows the wrapping of native "clear" DataSource that references an application database - Works as a Bean (Caucho Resin, ...).

This class is a Bean factory to be used with some J2EE environments which enable to load a Bean with setFoo() and getFoo() methods where foo is a property.

This is an example of resin.conf extract for Caucho resin 2.1.xx. It loads a SafeDataSource that enable to use getConnection() to get a Cipher Connection.

It's equivalent to the Tomcat 5.0 example described in SafeDataSourceFactory.

See Also:
SafeDataSourceFactory

Constructor Summary
SafeDataSourceJndiBean()
          This class should *not* be instanced (this constructor is mandatory for EJB behavior).
 
Method Summary
 Connection getConnection()
          Returns a Cipher Connection to the database.
 Connection getConnection(String username, String password)
          Returns a Cipher Connection to the database.
 int getLoginTimeout()
          Returns the login timeout (in seconds) for connecting to the database.
 PrintWriter getLogWriter()
          Returns the log writer being used by this data source.
 boolean isWrapperFor(Class<?> iface)
          Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does.
 void setBase_jndi_context(String base_jndi_context)
          Setter for base_jndi_context
 void setDs_safejdbc_catalog_lookup_name(String safejdbc_catalog_lookup_name)
          Setter for ds_safejdbc_catalog_lookup_name
 void setDs_wrapped_lookup_name(String wrapped_lookup_name)
          Setter for ds_wrapped_lookup_name
 void setLoginTimeout(int loginTimeout)
          Sets the login timeout (in seconds) for connecting to the database.
 void setLogWriter(PrintWriter logWriter)
          Sets the log writer being used by this data source.
<T> T
unwrap(Class<T> iface)
          Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SafeDataSourceJndiBean

public SafeDataSourceJndiBean()
This class should *not* be instanced (this constructor is mandatory for EJB behavior).

Method Detail

setBase_jndi_context

public void setBase_jndi_context(String base_jndi_context)
Setter for base_jndi_context

Parameters:
base_jndi_context - The base_jndi_context to set.

setDs_safejdbc_catalog_lookup_name

public void setDs_safejdbc_catalog_lookup_name(String safejdbc_catalog_lookup_name)
Setter for ds_safejdbc_catalog_lookup_name

Parameters:
ds_safejdbc_catalog_lookup_name - The ds_safejdbc_catalog_lookup_name to set.

setDs_wrapped_lookup_name

public void setDs_wrapped_lookup_name(String wrapped_lookup_name)
Setter for ds_wrapped_lookup_name

Parameters:
ds_wrapped_lookup_name - The ds_wrapped_lookup_name to set.

getConnection

public Connection getConnection()
                         throws SQLException
Returns a Cipher Connection to the database.

Specified by:
getConnection in interface DataSource
Throws:
SQLException - if a database access error occurs

getConnection

public Connection getConnection(String username,
                                String password)
                         throws SQLException
Returns a Cipher Connection to the database.

Specified by:
getConnection in interface DataSource
Parameters:
username - Database user on whose behalf the Connection is being made
password - The database user's password
Throws:
SQLException - if a database access error occurs

getLoginTimeout

public int getLoginTimeout()
                    throws SQLException
Returns the login timeout (in seconds) for connecting to the database.

Specified by:
getLoginTimeout in interface CommonDataSource
Throws:
SQLException - if a database access error occurs

getLogWriter

public PrintWriter getLogWriter()
                         throws SQLException
Returns the log writer being used by this data source.

Specified by:
getLogWriter in interface CommonDataSource
Throws:
SQLException - if a database access error occurs

setLoginTimeout

public void setLoginTimeout(int loginTimeout)
                     throws SQLException
Sets the login timeout (in seconds) for connecting to the database.

Specified by:
setLoginTimeout in interface CommonDataSource
Parameters:
loginTimeout - The new login timeout, or zero for no timeout
Throws:
SQLException - if a database access error occurs

setLogWriter

public void setLogWriter(PrintWriter logWriter)
                  throws SQLException
Sets the log writer being used by this data source.

Specified by:
setLogWriter in interface CommonDataSource
Parameters:
logWriter - The new log writer
Throws:
SQLException - if a database access error occurs

unwrap

public <T> T unwrap(Class<T> iface)
         throws SQLException
Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy. If the receiver implements the interface then the result is the receiver or a proxy for the receiver. If the receiver is a wrapper and the wrapped object implements the interface then the result is the wrapped object or a proxy for the wrapped object. Otherwise return the the result of calling unwrap recursively on the wrapped object or a proxy for that result. If the receiver is not a wrapper and does not implement the interface, then an SQLException is thrown.

Specified by:
unwrap in interface Wrapper
Parameters:
iface - A Class defining an interface that the result must implement.
Returns:
an object that implements the interface. May be a proxy for the actual implementing object.
Throws:
SQLException - If no object found that implements the interface
Since:
1.6

isWrapperFor

public boolean isWrapperFor(Class<?> iface)
                     throws SQLException
Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. Returns false otherwise. If this implements the interface then return true, else if this is a wrapper then return the result of recursively calling isWrapperFor on the wrapped object. If this does not implement the interface and is not a wrapper, return false. This method should be implemented as a low-cost operation compared to unwrap so that callers can use this method to avoid expensive unwrap calls that may fail. If this method returns true then calling unwrap with the same argument should succeed.

Specified by:
isWrapperFor in interface Wrapper
Parameters:
iface - a Class defining an interface.
Returns:
true if this implements the interface or directly or indirectly wraps an object that does.
Throws:
SQLException - if an error occurs while determining whether this is a wrapper for an object with the given interface.
Since:
1.6

SafeJDBC v2.00

Copyright © SafeLogic 2011