Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.jcorporate.expresso.core.db
Class SimpleDataSource  view SimpleDataSource download SimpleDataSource.java

java.lang.Object
  extended bycom.jcorporate.expresso.core.db.SimpleDataSource
All Implemented Interfaces:
javax.sql.DataSource

public class SimpleDataSource
extends java.lang.Object
implements javax.sql.DataSource

DataConnectionPool is an implementation of the javax.sql.DataSource. Normally you would get an instance of the DataConnectionPool using DBConnectionPool.getDataSource(String)

The reason for this class is that some libraries that can access a database often take a DataSource as their way of connecting to the database. Unfortunately, Expresso's DBConnectionPool's API is incompatible with the javax.sql.DataSource API. So this class wraps the DBConnectionPool with the DataSource interface so that libraries that require DataSource and Connection interfaces can operate within Expresso's database connection management capabilities.

Typical Usage:

javax.sql.DataSource dataSource = DBConnectionPool.getDataSource("default");
java.sql.Connection connection = dataSource.getConnection();
...
connection.close();


Field Summary
private static org.apache.log4j.Logger log
          The log4j Logger
private  java.io.PrintWriter logWriter
           
private  DBConnectionPool poolInstance
          The pool instance
 
Constructor Summary
SimpleDataSource(DBConnectionPool newPoolInstance)
          Wrapping constructor.
 
Method Summary
 java.sql.Connection getConnection()
          Retreive a java.sql.Connection for this data source.
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          [Unused]
protected  DBConnectionPool getConnectionPool()
          Helper method to retrieve the instance of the connectionPool we're attached to
 int getLoginTimeout()
          Retrieve the login timeout [unimplemented]
 java.io.PrintWriter getLogWriter()
          Retrieve the current logWriter.
 void setLoginTimeout(int seconds)
          Set the login timeout.
 void setLogWriter(java.io.PrintWriter out)
          Sets the log writer and thus turns on logging
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logWriter

private java.io.PrintWriter logWriter

log

private static final org.apache.log4j.Logger log
The log4j Logger


poolInstance

private DBConnectionPool poolInstance
The pool instance

Constructor Detail

SimpleDataSource

public SimpleDataSource(DBConnectionPool newPoolInstance)
Wrapping constructor. Takes a DBConnectionPool instance and wraps it for the DataSource implementation

Method Detail

getConnectionPool

protected DBConnectionPool getConnectionPool()
Helper method to retrieve the instance of the connectionPool we're attached to


getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Retreive a java.sql.Connection for this data source. It does not attempt to retrieve pooled connections.

Specified by:
getConnection in interface javax.sql.DataSource

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
[Unused]

Normally would retrieve a connection with the given username and password. However, that is not possible with the Expresso's DBConnectionPool which manages the default username and password as given in the configuration file. So this implementation logs a warning about this method and falls back to getConnection()

Specified by:
getConnection in interface javax.sql.DataSource

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
Retrieve the current logWriter. Default is null

Specified by:
getLogWriter in interface javax.sql.DataSource

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException
Sets the log writer and thus turns on logging

Specified by:
setLogWriter in interface javax.sql.DataSource

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws java.sql.SQLException
Set the login timeout. [unimplemented]

Specified by:
setLoginTimeout in interface javax.sql.DataSource

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Retrieve the login timeout [unimplemented]

Specified by:
getLoginTimeout in interface javax.sql.DataSource