org.huihoo.jfox.datasource
Class PoolDataSource

java.lang.Object
  extended byorg.huihoo.jfox.system.ComponentSupport
      extended byorg.huihoo.jfox.datasource.PoolDataSource
All Implemented Interfaces:
Component, javax.sql.DataSource, Loggable, javax.naming.spi.ObjectFactory, Persistentable, javax.naming.Referenceable, java.io.Serializable

public class PoolDataSource
extends ComponentSupport
implements javax.sql.DataSource, javax.naming.Referenceable, javax.naming.spi.ObjectFactory

See Also:
Serialized Form

Field Summary
protected  SimpleConnectionPool pool
           
 
Fields inherited from class org.huihoo.jfox.system.ComponentSupport
logger, name, proxyInstance, sequence, state
 
Constructor Summary
PoolDataSource()
          Default constructor used by JNDI to get a new Instance without any parameters.
PoolDataSource(java.lang.String dbDriver, java.lang.String dbURL, java.lang.String user, java.lang.String password)
          Constructor specify database connection parameters to generate a valid and usable datasource.
 
Method Summary
protected  void doDestroy()
          do actually destory action
protected  void doInit()
          do actually create action
 java.sql.Connection getConnection()
          Get usable connection from datasource
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          Get connection by specific user name and password, the connection is not pooled by Connection Pool
 java.lang.String getDbDriver()
           
 java.lang.String getDbURL()
           
 int getLoginTimeout()
          Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
 java.io.PrintWriter getLogWriter()
          Get logger writer
 java.lang.Object getObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable environment)
          Method that inherited from ObjectFactory.
 java.lang.String getPassword()
           
 javax.naming.Reference getReference()
          Method that inherited from Referenceable.
 java.lang.String getUser()
           
 void setDbDriver(java.lang.String dbDriver)
           
 void setDbURL(java.lang.String dbURL)
           
 void setLoginTimeout(int seconds)
          Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
 void setLogWriter(java.io.PrintWriter out)
          Sets the log writer for this DataSource object to the given java.io.PrintWriter object.
 void setPassword(java.lang.String password)
           
 void setUser(java.lang.String user)
           
 
Methods inherited from class org.huihoo.jfox.system.ComponentSupport
destroy, getLogger, getName, getState, init, parseName, setLogger, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pool

protected SimpleConnectionPool pool
Constructor Detail

PoolDataSource

public PoolDataSource()
Default constructor used by JNDI to get a new Instance without any parameters.


PoolDataSource

public PoolDataSource(java.lang.String dbDriver,
                      java.lang.String dbURL,
                      java.lang.String user,
                      java.lang.String password)
               throws java.lang.Exception
Constructor specify database connection parameters to generate a valid and usable datasource.

Parameters:
dbDriver - database class name according your dabase
dbURL - database url used to access database
user - valid database user
password - // corresponding database password
Throws:
java.lang.Exception - any exception who cares?
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Get usable connection from datasource

Specified by:
getConnection in interface javax.sql.DataSource
Returns:
Connection the valid database connection can used by user
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Get connection by specific user name and password, the connection is not pooled by Connection Pool

Specified by:
getConnection in interface javax.sql.DataSource
Parameters:
username -
password -
Returns:
Throws:
java.sql.SQLException

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
Get logger writer

Specified by:
getLogWriter in interface javax.sql.DataSource
Returns:
Throws:
java.sql.SQLException
See Also:
DataSource.setLogWriter(java.io.PrintWriter)

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException
Description copied from interface: javax.sql.DataSource

Sets the log writer for this DataSource object to the given java.io.PrintWriter object.

The log writer is a character output stream to which all logging and tracing messages for this data source will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source- specific log writer are not printed to the log writer associated with the java.sql.Drivermanager class. When a DataSource object is created the log writer is initially null; in other words, the default is for logging to be disabled.

Specified by:
setLogWriter in interface javax.sql.DataSource
Parameters:
out -
Throws:
java.sql.SQLException
See Also:
DataSource.getLogWriter()

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws java.sql.SQLException
Description copied from interface: javax.sql.DataSource

Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise, it specifies that there is no timeout. When a DataSource object is created, the login timeout is initially zero.

Specified by:
setLoginTimeout in interface javax.sql.DataSource
Parameters:
seconds -
Throws:
java.sql.SQLException
See Also:
DataSource.getLoginTimeout()

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Description copied from interface: javax.sql.DataSource
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise, it means that there is no timeout. When a DataSource object is created, the login timeout is initially zero.

Specified by:
getLoginTimeout in interface javax.sql.DataSource
Returns:
Throws:
java.sql.SQLException
See Also:
DataSource.setLoginTimeout(int)

getReference

public javax.naming.Reference getReference()
                                    throws javax.naming.NamingException
Method that inherited from Referenceable.

Specified by:
getReference in interface javax.naming.Referenceable
Returns:
Throws:
javax.naming.NamingException

getObjectInstance

public java.lang.Object getObjectInstance(java.lang.Object obj,
                                          javax.naming.Name name,
                                          javax.naming.Context nameCtx,
                                          java.util.Hashtable environment)
                                   throws java.lang.Exception
Method that inherited from ObjectFactory.

Specified by:
getObjectInstance in interface javax.naming.spi.ObjectFactory
Parameters:
obj -
name -
nameCtx -
environment -
Returns:
Throws:
java.lang.Exception
See Also:
NamingManager.getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable), NamingManager.getURLContext(java.lang.String, java.util.Hashtable)

getDbDriver

public java.lang.String getDbDriver()

setDbDriver

public void setDbDriver(java.lang.String dbDriver)

getDbURL

public java.lang.String getDbURL()

setDbURL

public void setDbURL(java.lang.String dbURL)

getUser

public java.lang.String getUser()

setUser

public void setUser(java.lang.String user)

getPassword

public java.lang.String getPassword()

setPassword

public void setPassword(java.lang.String password)

doInit

protected void doInit()
               throws java.lang.Exception
Description copied from class: ComponentSupport
do actually create action

Specified by:
doInit in class ComponentSupport
Throws:
java.lang.Exception

doDestroy

protected void doDestroy()
                  throws java.lang.Exception
Description copied from class: ComponentSupport
do actually destory action

Specified by:
doDestroy in class ComponentSupport
Throws:
java.lang.Exception