org.mortbay.jetty.plus
Class AbstractDataSourceService

java.lang.Object
  extended by org.mortbay.jetty.plus.AbstractService
      extended by org.mortbay.jetty.plus.AbstractDataSourceService
All Implemented Interfaces:
Service, LifeCycle
Direct Known Subclasses:
DefaultDataSourceService

public abstract class AbstractDataSourceService
extends AbstractService

AbstractDataSourceService Base class for DataSource Service implementations. This class provides support for plugging DataSources and DataSource Connection pooling implementations into JettyPlus. A DefaultDataSourceService subclass provides a Connection pooling implementation courtesy of XAPool project http://xapool.experlog.com. If you wish to incorporate a different connection pooling implementation, then subclass this class an implement the addDataSource(name, connectionpoolingdatasource) method.


Nested Class Summary
static interface AbstractDataSourceService.DataSourceMap
           
static class AbstractDataSourceService.DataSourceObjectFactory
          DataSourceObjectFactory ObjectFactory for references to DataSources bound in JNDI.
 
Field Summary
protected  java.util.Map dsMap
          Map of jndiNames to DataSource objects.
 
Fields inherited from class org.mortbay.jetty.plus.AbstractService
_jndi, _name, _started
 
Constructor Summary
AbstractDataSourceService()
          Constructor.
 
Method Summary
 javax.sql.DataSource addConnectionPoolDataSource(java.lang.String jndiName, javax.sql.ConnectionPoolDataSource cpds)
          Add a JDBC2/3 compliant source of poolable connections.
 void addDataSource(java.lang.String jndiName, javax.sql.DataSource ds)
          Add a DataSource implementation to JettyPlus.
abstract  javax.sql.DataSource createPooledDataSource(java.lang.String jndiName, javax.sql.ConnectionPoolDataSource cpds)
          Implement this method to create your pool implementation.
 javax.sql.DataSource getDataSource(java.lang.String jndiName)
          Get a DataSource implementation from the list of registered DataSources.
protected  javax.naming.Reference getDataSourceReference(java.lang.String jndiName, javax.sql.DataSource ds)
          Create a Reference for a DataSource.
 void start()
          Start the Service.
 
Methods inherited from class org.mortbay.jetty.plus.AbstractService
getJNDI, getName, isStarted, setJNDI, setName, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dsMap

protected java.util.Map dsMap
Map of jndiNames to DataSource objects.

Constructor Detail

AbstractDataSourceService

public AbstractDataSourceService()
Constructor.

Method Detail

addConnectionPoolDataSource

public javax.sql.DataSource addConnectionPoolDataSource(java.lang.String jndiName,
                                                        javax.sql.ConnectionPoolDataSource cpds)
                                                 throws java.lang.Exception
Add a JDBC2/3 compliant source of poolable connections. The pool implementation is pluggable in JettyPlus. To use a particular pool implementation (eg XAPool, DBCP etc), subclass this class and implement the method createPooledDataSource() to instantiate the pool. A DefaultDataSourceService is provided that uses XAPool to plug in a Pool implementation. The DataSource returned by this method must be capable of interacting with the pool implemenation, as the DataSource will be bound into JNDI and will be accessed by webapps doing a lookup on java:comp/env/

Parameters:
jndiName -
cpds -
Returns:
Throws:
java.lang.Exception

createPooledDataSource

public abstract javax.sql.DataSource createPooledDataSource(java.lang.String jndiName,
                                                            javax.sql.ConnectionPoolDataSource cpds)
                                                     throws java.lang.Exception
Implement this method to create your pool implementation. The method must return a javax.sql.DataSource that will be bound into JNDI for client lookups on java:comp/env

Parameters:
jndiName -
cpds -
Returns:
Throws:
java.lang.Exception

addDataSource

public void addDataSource(java.lang.String jndiName,
                          javax.sql.DataSource ds)
                   throws java.lang.Exception
Add a DataSource implementation to JettyPlus. Note that the particular javax.sql.DataSource implementation may implement many other features, such as internal connection pooling. If this is the case, and you want to take advantage

Parameters:
jndiName - then name the client uses to lookup the DataSource relative to java:comp/env
ds - the javax.sql.DataSource implementation
Throws:
java.lang.Exception

getDataSource

public javax.sql.DataSource getDataSource(java.lang.String jndiName)
Get a DataSource implementation from the list of registered DataSources.

Parameters:
jndiName - the name of the DataSource from addDataSource()
Returns:
the DataSource object

start

public void start()
           throws java.lang.Exception
Start the Service. Called by org.mortbay.jetty.plus.Server.start(). This will bind all of the registered DataSources into the global java: namespace in JNDI.

Specified by:
start in interface Service
Specified by:
start in interface LifeCycle
Overrides:
start in class AbstractService
Throws:
java.lang.Exception - An arbitrary exception may be thrown.

getDataSourceReference

protected javax.naming.Reference getDataSourceReference(java.lang.String jndiName,
                                                        javax.sql.DataSource ds)
Create a Reference for a DataSource. The Reference will be bound into JNDI. Lookups on the Reference will return the instance of the DataSource as stored in the dsMap.

Parameters:
jndiName -
ds -
Returns:


Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.