org.mentawai.db
Class C3P0ConnectionHandler

java.lang.Object
  extended by org.mentawai.db.AbstractConnectionHandler
      extended by org.mentawai.db.C3P0ConnectionHandler
All Implemented Interfaces:
org.mentacontainer.Factory, org.mentacontainer.Interceptor<Connection>, ConnectionHandler

public class C3P0ConnectionHandler
extends AbstractConnectionHandler

A connection handler that uses the C3P0 connection pool. (http://sourceforge.net/projects/c3p0) To use this class you must have the C3P0 jar in your /WEB-INF/lib directory. You may access the underlying C3P0's ComboPooledDataSource to configure the pool, before you start calling getConnection().

Author:
Sergio Oliveira

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.mentawai.db.ConnectionHandler
ConnectionHandler.Exec
 
Field Summary
static boolean DEBUG
           
 
Constructor Summary
C3P0ConnectionHandler(String driver, String url, String user, String pass)
           
C3P0ConnectionHandler(String driver, String url, String user, String pass, String testQuery)
          Constructs a C3P0ConnectionHandler with C3P0's ComboPooledDataSource.
 
Method Summary
 void destroy()
          Destroy the connection pool, closing and cleaning all connections.
 Object getBean()
           
 com.mchange.v2.c3p0.ComboPooledDataSource getComboPooledDataSource()
          Gets the underlying C3P0's ComboPooledDataSource.
 Connection getConnection()
          Returns a Connection to the database.
 String getStatus()
          Print the status of this connection pool if any.
 void release(Connection conn)
          Release this connection.
 
Methods inherited from class org.mentawai.db.AbstractConnectionHandler
exec, getInstance, getType, onCleared, onCreated
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static boolean DEBUG
Constructor Detail

C3P0ConnectionHandler

public C3P0ConnectionHandler(String driver,
                             String url,
                             String user,
                             String pass,
                             String testQuery)
Constructs a C3P0ConnectionHandler with C3P0's ComboPooledDataSource.

Parameters:
driver - The JDBC driver class name to use.
url - The JDBC url to connect to the database.
user - The database username to use.
pass - The database password to use.
testQuery - The test sql statement used to test the db connection.
Throws:
IllegalStateException - If the C3P0 jar is not in the /WEB-INF/lib directory or if the JDBC driver cannot be loaded.

C3P0ConnectionHandler

public C3P0ConnectionHandler(String driver,
                             String url,
                             String user,
                             String pass)
Method Detail

getStatus

public String getStatus()
Description copied from interface: ConnectionHandler
Print the status of this connection pool if any.

Returns:
The status

getComboPooledDataSource

public com.mchange.v2.c3p0.ComboPooledDataSource getComboPooledDataSource()
Gets the underlying C3P0's ComboPooledDataSource.

Returns:
The ComboPooledDataSource

getConnection

public Connection getConnection()
                         throws 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.

Returns:
A connection to the database.
Throws:
SQLException - if there were problems trying to acquire the connection.

release

public void release(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.

Parameters:
conn - The connection to release.

getBean

public Object getBean()
               throws InstantiationException
Throws:
InstantiationException

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.



Copyright © 2013. All Rights Reserved.