SafeJDBC v2.00

com.safejdbc.javax.sql
Class SafeDataSourceFactory

java.lang.Object
  extended by com.safejdbc.javax.sql.SafeDataSourceFactory
All Implemented Interfaces:
ObjectFactory

public class SafeDataSourceFactory
extends Object
implements ObjectFactory

JNDI object factory that creates an instance of the SafeDataSource class.

This class must not be called directly by a user program.

This class will be called/created automatically by any EJB compatible modern application server or web server
( JBoss, JOnAS, Orion, Sun Application Server, Tomcat, WebLogic, WebSphere, etc.).

The RefAddr values of the specified Reference must match the names and data types of the SafeDataSource bean properties.

Please configure your application server to load this factory and configure the values of the RefAddr parameters:



Example in Tomcat 5.0:

We will create a DataSource Resource named "jdbc/application" in the server.xml file. The "jdbc/application" Resource allows a Connection pool to be created for the sample sj_clients database. The DataSource Resource is defined in this file.

The following code allows Connections to be obtained from the DataSource:

InitialContext initCtx = new InitialContext();

// Get a DataSource for connection to the application database
DataSource dsApplication = (DataSource)initCtx.lookup("java:/comp/env/jdbc/application");

// Get the Connection from the DataSource
Connection connnection = dsApplication.getConnection();

Now, we want the program without there being any change to the source code, to get Cipher Connections from the pool, rather than"normal" Connections.

Three simple steps are required:
  1. Rename the "jdbc/application" Resource in server.xml to a any name whatsoever ("jdbc/application_wrapped" for example).


  2. Add a new DataSource Resource in server.xml to access the SafeJDBC Catalog Database.
    This is an example with a Resource named "jdbc/safejdbc_catalog".


  3. Add a new DataSource Resource named "jdbc/application" in server.xmlthat will wrap the two previous Resources using three parameters: This is an example
We are all set.
Now re-run the previous code and the program will get Cipher Connections from the pool.


Constructor Summary
SafeDataSourceFactory()
          This class should *not* be instanced (this constructor is mandatory for EJB behavior).
 
Method Summary
 Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment)
          Creates and returns a new SafeDataSource instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SafeDataSourceFactory

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

Method Detail

getObjectInstance

public Object getObjectInstance(Object obj,
                                Name name,
                                Context nameCtx,
                                Hashtable environment)
                         throws Exception
Creates and returns a new SafeDataSource instance. If no instance can be created, return null instead.

Specified by:
getObjectInstance in interface ObjectFactory
Parameters:
obj - The object,which may be null, that contains location or reference information to be used to create an object
name - The name of this object relating to nameCtx
nameCtx - The context relative to which the name parameter is specified, or null if name relates to the default initial context
environment - The environment, which may be null, that is used in to create this object
Throws:
Exception - if an exception occurs creating the instance

SafeJDBC v2.00

Copyright © SafeLogic 2011