com.safejdbc.javax.sql
Class SafeDataSourceFactory
java.lang.Object
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:
base_jndi_context:
Base JNDI Context name for DataSources name
lookup.
(Defaults to "java:/comp/env/")
ds_wrapped_lookup_name:
Application DataSource lookup name in JNDI syntax naming.
ds_safejdbc_catalog_lookup_name:
SafeJdbc Catalog DataSource lookup name in JNDI syntax naming.
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:
- Rename the
"jdbc/application" Resource in server.xml to a any name whatsoever
("jdbc/application_wrapped" for example).
- 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".
- Add a new DataSource Resource named
"jdbc/application" in server.xmlthat will
wrap the two previous Resources using three parameters:
- Parameter
factory
Value com.safejdbc.javax.sql.SafeDataSourceFactory
- Parameter
ds_wrapped_lookup_name
Value jdbc/application_wrapped
- Parameter
ds_safejdbc_catalog_lookup_name
Value jdbc/safejdbc_catalog
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). |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SafeDataSourceFactory
public SafeDataSourceFactory()
- This class should *not* be instanced (this constructor is mandatory for EJB behavior).
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 objectname - The name of this object relating to nameCtxnameCtx - The context relative to which the name
parameter is specified, or null if name
relates to the default initial contextenvironment - The environment, which may be null, that is used in
to create this object
- Throws:
Exception - if an exception occurs creating the instance
Copyright © SafeLogic 2011