org.mentawai.db
Class JNDIConnectionHandler

java.lang.Object
  extended by org.mentawai.db.JNDIConnectionHandler
All Implemented Interfaces:
ConnectionHandler

public class JNDIConnectionHandler
extends java.lang.Object
implements ConnectionHandler

A connection handler that looks for a DataSource in a JNDI context. Use this class if you want to create a connection handler backed up by a DataSource which is bound to a JNDI context.

Author:
Sergio Oliveira

Method Summary
 void destroy()
          Destroy the connection pool, closing and cleaning all connections.
 java.sql.Connection getConnection()
          Returns a Connection to the database.
static ConnectionHandler getInstance(java.lang.String poolname)
          Gets a ConnectionHandler with a DataSource bound to the JNDI context with the given name.
 void release(java.sql.Connection conn)
          Release this connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Description copied from interface: ConnectionHandler
Returns a Connection to the database. Notice that it can never return null. If no connection can be acquired, then a SQLException is thrown.

Specified by:
getConnection in interface ConnectionHandler
Returns:
A connection to the database.
Throws:
java.sql.SQLException - if there were problems trying to acquire the connection.

release

public void release(java.sql.Connection conn)
Description copied from interface: ConnectionHandler
Release this connection. If this connection handler is using a database pool, the connection is returned to the pool. If this connection handler is not using a database pool, the connection is closed. If the connection passed as an argument is null, nothing is done.

Specified by:
release in interface ConnectionHandler
Parameters:
conn - The connection to release.

getInstance

public static ConnectionHandler getInstance(java.lang.String poolname)
Gets a ConnectionHandler with a DataSource bound to the JNDI context with the given name.

Parameters:
poolname - The name with which the DataSource is bound to the JNDI context.
Returns:
A ConnectionHandler from cache or a new one if this is the first call with this name.

destroy

public void destroy()
Description copied from interface: ConnectionHandler
Destroy the connection pool, closing and cleaning all connections. This is important for restarting the web context.

Specified by:
destroy in interface ConnectionHandler


Copyright © 2005 Mentawai Team. All Rights Reserved.