|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.struts.util.GenericDataSource
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()
.
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 |
|
Field Detail |
private static final java.lang.String SQLEXCEPTION_GETCONNECTION
protected boolean closed
protected java.util.LinkedList connections
protected java.sql.Driver driver
protected int loginTimeout
protected java.io.PrintWriter logWriter
protected int activeCount
protected boolean autoCommit
protected int debug
protected java.lang.String description
protected java.lang.String driverClass
protected int maxCount
protected int minCount
protected java.lang.String password
protected java.lang.String pingCommand
protected java.lang.String pingQuery
protected java.util.Properties properties
protected boolean readOnly
protected java.lang.String url
protected int useCount
protected java.lang.String user
Constructor Detail |
public GenericDataSource()
Method Detail |
public void addProperty(java.lang.String name, java.lang.String value)
name
- Name of the generic propertyvalue
- Corresponding generic property valuepublic int getActiveCount()
public boolean getAutoCommit()
public void setAutoCommit(boolean autoCommit)
public int getDebug()
public void setDebug(int debug)
public java.lang.String getDescription()
public void setDescription(java.lang.String description)
public java.lang.String getDriverClass()
public void setDriverClass(java.lang.String driverClass)
public int getMaxCount()
public void setMaxCount(int maxCount)
public int getMinCount()
public void setMinCount(int minCount)
public java.lang.String getPassword()
public void setPassword(java.lang.String password)
public java.lang.String getPingCommand()
public void setPingCommand(java.lang.String pingCommand)
public java.lang.String getPingQuery()
public void setPingQuery(java.lang.String pingQuery)
public boolean getReadOnly()
public void setReadOnly(boolean readOnly)
public java.lang.String getUrl()
public void setUrl(java.lang.String url)
public int getUseCount()
public java.lang.String getUser()
public void setUser(java.lang.String user)
public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
- if a database access error occurspublic java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
username
- Database username for this connectionpassword
- Database password for this connectionjava.sql.SQLException
- if a database access error occurspublic int getLoginTimeout() throws java.sql.SQLException
getLoginTimeout
in interface javax.sql.DataSource
java.sql.SQLException
- if a database access error occurspublic java.io.PrintWriter getLogWriter() throws java.sql.SQLException
getLogWriter
in interface javax.sql.DataSource
java.sql.SQLException
- if a database access error occurspublic void setLoginTimeout(int loginTimeout) throws java.sql.SQLException
setLoginTimeout
in interface javax.sql.DataSource
loginTimeout
- The new login timeoutjava.sql.SQLException
- if a database access error occurspublic void setLogWriter(java.io.PrintWriter logWriter) throws java.sql.SQLException
setLogWriter
in interface javax.sql.DataSource
logWriter
- The new log writerjava.sql.SQLException
- if a database access error occurspublic void close() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurspublic void open() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurspublic java.lang.String toString()
toString
in class java.lang.Object
protected java.sql.Connection createConnection() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occursprotected void log(java.lang.String message)
message
- The message to be loggedprotected void log(java.lang.String message, java.lang.Throwable throwable)
message
- The message to be loggedthrowable
- The exception to be loggedprotected void ping(java.sql.Connection conn) throws java.sql.SQLException
pingCommand
and/or
pingQuery
on the specified connection, returning any
SQLException that is encountered along the way.conn
- The connection to be pingedvoid returnConnection(GenericConnection conn)
conn
- The connection being returned
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |