Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts.util
Class GenericDataSource

    java.lang.Object
      |
      +--org.apache.struts.util.GenericDataSource

All Implemented Interfaces:
  javax.sql.DataSource

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

Generic data source implementation of the `DataSource` interface. WARNING - This implementation does not know how to provide connections with different username/password combinations. Calling this version of the implementation using the getConnection(username,password) signature will throw an exception.

The following properties are supported by the standard `GenericDataSource` implementation:

Property | Description
--- | ---
autoCommit | Set to `true` if you want the connections returned to you by calling `getConnection()` to be configured in "auto-commit after every statement" mode. The default value is `true`, to conform to JDBC standard conventions.
description | A short textual description of this data source. This property is required by the `javax.sql.DataSource` interface, but is not used within this implementation.
driverClass | The fully qualified class name of the JDBC driver to be utilized for the connections created by this data source. Consult the documentation for your JDBC driver to identify the value to be configured for this property.
maxCount | The maximum number of JDBC connections that will be created by this data source. This value must be greater than or equal to the value specified for the `minCount property.`
minCount | The minimum number of JDBC connections to establish when this data source is first opened. This value must be less than or equal to the value specified for the `maxCount` property.
password | The database password used to establish the connections created by this connection pool, in conjunction with the username specified in the `user` property.
pingCommand | A non-query SQL command that, if specified, will be executed before a connection is returned by a call to `getConnection()`. If any SQLException is thrown by the execution of this statement, it is assumed that this connection is stale and it will be discarded. Because this happens on every connection allocation, you should ensure that the statement executes very quickly.
pingQuery | A query SQL command (i.e. a SELECT) that, if specified, will be executed before a connection is returned by a call to `getConnection()`. If any SQLException is thrown by the execution of this query (or by the subsequent processing of the entire returned `ResultSet`), it is assumed that this connection is stale and it will be discarded. Because this happens on every connection allocation, you should ensure that the statement executes very quickly.
readOnly | Set to `true` if you want the connections returned to you by calling `getConnection()` to be configured for read only operations. This can result in more efficient database access, because the database will know it does not need to retain undo logs for rolling back the transaction. The default value is `false`.
url | The connection URL to be passed to our JDBC driver when establishing a new connection. The value specified typically starts with `jdbc:`, and includes a reference to the host (and, optionally, the port number) at which the database server is listening for connections, plus the name of the database to be opened. Consult the documentation for your JDBC driver to identify the value to be configured for this property.
user | The database username used to establish the connections created by this connection pool, in conjunction with the password specified in the `password` property.

In addition, you can add to the set of `Properties` passed to the JDBC driver by calling `addProperty()`.

Version:
  $Revision: 1.1 $ $Date: 2001-09-17 21:13:30 +0100 (Mon, 17 Sep 2001) $
Author:
  Craig R. McClanahan, Ted Husted

Field Summary
`protected int` | `activeCount` The number of connections that have been created by this data source.
`protected boolean` | `autoCommit` The default auto-commit state for newly created connections.
`protected boolean` | `closed` Has this data source been closed?
`protected java.util.LinkedList` | `connections` The list of Connections (wrapped in our associated wrapper class) that have been created but are not currently in use.
`protected int` | `debug` The debugging detail level for this data source.
`protected java.lang.String` | `description` The description of this data source.
`protected java.sql.Driver` | `driver` The JDBC driver that we use as a connection factory.
`protected java.lang.String` | `driverClass` The Java class name of the JDBC driver to use.
`protected int` | `loginTimeout` The login timeout for this data source.
`protected java.io.PrintWriter` | `logWriter` The log writer for this data source.
`protected int` | `maxCount` The maximum number of connections to be created.
`protected int` | `minCount` The minimum number of connections to be created.
`protected java.lang.String` | `password` The database password for use in establishing a connection.
`protected java.lang.String` | `pingCommand` The non-query SQL command used to ping an allocated connection.
`protected java.lang.String` | `pingQuery` The query SQL command used to ping an allocated connection.
`protected java.util.Properties` | `properties` The connection properties for use in establishing connections.
`protected boolean` | `readOnly` The default read-only state for newly created connections.
`private static java.lang.String` | `SQLEXCEPTION_GETCONNECTION`
`protected java.lang.String` | `url` The JDBC URL for the database connection to be opened.
`protected int` | `useCount` The number of connections created by this data source that are currently in use.
`protected java.lang.String` | `user` The database username for use in establishing a connection.

Constructor Summary
`GenericDataSource()`

Method Summary
`void` | `addProperty(java.lang.String name, java.lang.String value)` Add a generic property to the list of connection properties to be used.
`void` | `close()` Close all connections that have been created by this data source.
`protected java.sql.Connection` | `createConnection()` Create, configure, and return a new JDBC Connection that has been wrapped in our corresponding wrapper.
`int` | `getActiveCount()`
`boolean` | `getAutoCommit()`
`java.sql.Connection` | `getConnection()` Attempt to establish a database connection.
`java.sql.Connection` | `getConnection(java.lang.String username, java.lang.String password)` Attempt to establish a database connection.
`int` | `getDebug()`
`java.lang.String` | `getDescription()`
`java.lang.String` | `getDriverClass()`
`int` | `getLoginTimeout()` Return the login timeout for this data source.
`java.io.PrintWriter` | `getLogWriter()` Return the log writer for this data source.
`int` | `getMaxCount()`
`int` | `getMinCount()`
`java.lang.String` | `getPassword()`
`java.lang.String` | `getPingCommand()`
`java.lang.String` | `getPingQuery()`
`boolean` | `getReadOnly()`
`java.lang.String` | `getUrl()`
`int` | `getUseCount()`
`java.lang.String` | `getUser()`
`protected void` | `log(java.lang.String message)` Log the specified message to our log writer, if we have one.
`protected void` | `log(java.lang.String message, java.lang.Throwable throwable)` Log the specified message and exception to our log writer, if we have one.
`void` | `open()` Open the initial connections that are appropriate for this data source.
`protected void` | `ping(java.sql.Connection conn)` Perform any configured `pingCommand` and/or `pingQuery` on the specified connection, returning any SQLException that is encountered along the way.
`(package private) void` | `returnConnection(GenericConnection conn)` Return this connection to the available connection pool.
`void` | `setAutoCommit(boolean autoCommit)`
`void` | `setDebug(int debug)`
`void` | `setDescription(java.lang.String description)`
`void` | `setDriverClass(java.lang.String driverClass)`
`void` | `setLoginTimeout(int loginTimeout)` Set the login timeout for this data source.
`void` | `setLogWriter(java.io.PrintWriter logWriter)` Set the log writer for this data source.
`void` | `setMaxCount(int maxCount)`
`void` | `setMinCount(int minCount)`
`void` | `setPassword(java.lang.String password)`
`void` | `setPingCommand(java.lang.String pingCommand)`
`void` | `setPingQuery(java.lang.String pingQuery)`
`void` | `setReadOnly(boolean readOnly)`
`void` | `setUrl(java.lang.String url)`
`void` | `setUser(java.lang.String user)`
`java.lang.String` | `toString()` Return a string representation of this component.

Methods inherited from class java.lang.Object
`, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait`

Field Detail

### SQLEXCEPTION_GETCONNECTION

    private static final java.lang.String SQLEXCEPTION_GETCONNECTION

### closed

    protected boolean closed

  Has this data source been closed?

### connections

    protected java.util.LinkedList connections

  The list of Connections (wrapped in our associated wrapper class) that have been created but are not currently in use.

### driver

    protected java.sql.Driver driver

  The JDBC driver that we use as a connection factory.

### loginTimeout

    protected int loginTimeout

  The login timeout for this data source.

### logWriter

    protected java.io.PrintWriter logWriter

  The log writer for this data source.

### activeCount

    protected int activeCount

  The number of connections that have been created by this data source.

### autoCommit

    protected boolean autoCommit

  The default auto-commit state for newly created connections.

### debug

    protected int debug

  The debugging detail level for this data source.

### description

    protected java.lang.String description

  The description of this data source.

### driverClass

    protected java.lang.String driverClass

  The Java class name of the JDBC driver to use.

### maxCount

    protected int maxCount

  The maximum number of connections to be created.

### minCount

    protected int minCount

  The minimum number of connections to be created.

### password

    protected java.lang.String password

  The database password for use in establishing a connection.

### pingCommand

    protected java.lang.String pingCommand

  The non-query SQL command used to ping an allocated connection.

### pingQuery

    protected java.lang.String pingQuery

  The query SQL command used to ping an allocated connection.

### properties

    protected java.util.Properties properties

  The connection properties for use in establishing connections.

### readOnly

    protected boolean readOnly

  The default read-only state for newly created connections.

### url

    protected java.lang.String url

  The JDBC URL for the database connection to be opened.

### useCount

    protected int useCount

  The number of connections created by this data source that are currently in use.

### user

    protected java.lang.String user

  The database username for use in establishing a connection.

Constructor Detail

### GenericDataSource

    public GenericDataSource()

Method Detail

### addProperty

    public void addProperty(java.lang.String name,
                            java.lang.String value)

  Add a generic property to the list of connection properties to be used.
  Parameters:
    `name` - Name of the generic property
    `value` - Corresponding generic property value

### getActiveCount

    public int getActiveCount()

### getAutoCommit

    public boolean getAutoCommit()

### setAutoCommit

    public void setAutoCommit(boolean autoCommit)

### getDebug

    public int getDebug()

### setDebug

    public void setDebug(int debug)

### getDescription

    public java.lang.String getDescription()

### setDescription

    public void setDescription(java.lang.String description)

### getDriverClass

    public java.lang.String getDriverClass()

### setDriverClass

    public void setDriverClass(java.lang.String driverClass)

### getMaxCount

    public int getMaxCount()

### setMaxCount

    public void setMaxCount(int maxCount)

### getMinCount

    public int getMinCount()

### setMinCount

    public void setMinCount(int minCount)

### getPassword

    public java.lang.String getPassword()

### setPassword

    public void setPassword(java.lang.String password)

### getPingCommand

    public java.lang.String getPingCommand()

### setPingCommand

    public void setPingCommand(java.lang.String pingCommand)

### getPingQuery

    public java.lang.String getPingQuery()

### setPingQuery

    public void setPingQuery(java.lang.String pingQuery)

### getReadOnly

    public boolean getReadOnly()

### setReadOnly

    public void setReadOnly(boolean readOnly)

### getUrl

    public java.lang.String getUrl()

### setUrl

    public void setUrl(java.lang.String url)

### getUseCount

    public int getUseCount()

### getUser

    public java.lang.String getUser()

### setUser

    public void setUser(java.lang.String user)

### getConnection

    public java.sql.Connection getConnection()
                                      throws java.sql.SQLException

  Attempt to establish a database connection.
  Specified by:
    `getConnection` in interface `javax.sql.DataSource`
  Throws:
    `java.sql.SQLException` - if a database access error occurs

### getConnection

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

  Attempt to establish a database connection. WARNING - The specified username and password are not supported by this implementation.
  Specified by:
    `getConnection` in interface `javax.sql.DataSource`
  Parameters:
    `username` - Database username for this connection
    `password` - Database password for this connection
  Throws:
    `java.sql.SQLException` - if a database access error occurs

### getLoginTimeout

    public int getLoginTimeout()
                        throws java.sql.SQLException

  Return the login timeout for this data source.
  Specified by:
    `getLoginTimeout` in interface `javax.sql.DataSource`
  Throws:
    `java.sql.SQLException` - if a database access error occurs

### getLogWriter

    public java.io.PrintWriter getLogWriter()
                                     throws java.sql.SQLException

  Return the log writer for this data source.
  Specified by:
    `getLogWriter` in interface `javax.sql.DataSource`
  Throws:
    `java.sql.SQLException` - if a database access error occurs

### setLoginTimeout

    public void setLoginTimeout(int loginTimeout)
                         throws java.sql.SQLException

  Set the login timeout for this data source.
  Specified by:
    `setLoginTimeout` in interface `javax.sql.DataSource`
  Parameters:
    `loginTimeout` - The new login timeout
  Throws:
    `java.sql.SQLException` - if a database access error occurs

### setLogWriter

    public void setLogWriter(java.io.PrintWriter logWriter)
                      throws java.sql.SQLException

  Set the log writer for this data source.
  Specified by:
    `setLogWriter` in interface `javax.sql.DataSource`
  Parameters:
    `logWriter` - The new log writer
  Throws:
    `java.sql.SQLException` - if a database access error occurs

### close

    public void close()
               throws java.sql.SQLException

  Close all connections that have been created by this data source.
  Throws:
    `java.sql.SQLException` - if a database access error occurs

### open

    public void open()
              throws java.sql.SQLException

  Open the initial connections that are appropriate for this data source.
  Throws:
    `java.sql.SQLException` - if a database access error occurs

### toString

    public java.lang.String toString()

  Return a string representation of this component.
  Overrides:
    `toString` in class `java.lang.Object`

### createConnection

    protected java.sql.Connection createConnection()
                                            throws java.sql.SQLException

  Create, configure, and return a new JDBC Connection that has been wrapped in our corresponding wrapper.
  Throws:
    `java.sql.SQLException` - if a database access error occurs

### log

    protected void log(java.lang.String message)

  Log the specified message to our log writer, if we have one.
  Parameters:
    `message` - The message to be logged

### log

    protected void log(java.lang.String message,
                       java.lang.Throwable throwable)

  Log the specified message and exception to our log writer, if we have one.
  Parameters:
    `message` - The message to be logged
    `throwable` - The exception to be logged

### ping

    protected void ping(java.sql.Connection conn)
                 throws java.sql.SQLException

  Perform any configured `pingCommand` and/or `pingQuery` on the specified connection, returning any SQLException that is encountered along the way.
  Parameters:
    `conn` - The connection to be pinged

### returnConnection

    void returnConnection(GenericConnection conn)

  Return this connection to the available connection pool.
  Parameters:
    `conn` - The connection being returned

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2001 - Apache Software Foundation