|
Log4j 1.3alpha-1 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.log4j.db.ConnectionSourceSkeleton | +--org.apache.log4j.db.DriverManagerConnectionSource
The DriverManagerConnectionSource is an implementation of ConnectionSource
that obtains the Connection in the traditional JDBC manner based on the
connection URL.
Note that this class will establish a new Connection for each call to
getConnection()
. It is recommended that you either use a JDBC
driver that natively supported Connection pooling or that you create
your own implementation of ConnectionSource
that taps into whatever
pooling mechanism you are already using. (If you have access to a JNDI
implementation that supports DataSource
s, e.g. within
a J2EE application server, see JNDIConnectionSource
). See
below for a configuration example that uses the
commons-dbcp
package from Apache.
Sample configuration:
<connectionSource class="org.apache.log4j.jdbc.DriverManagerConnectionSource"> <param name="driver" value="com.mysql.jdbc.Driver" /> <param name="url" value="jdbc:mysql://localhost:3306/mydb" /> <param name="username" value="myUser" /> <param name="password" value="myPassword" /> </connectionSource>
If you do not have another connection pooling mechanism
built into your application, you can use the
commons-dbcp
package from Apache:
<connectionSource class="org.apache.log4j.jdbc.DriverManagerConnectionSource"> <param name="driver" value="org.apache.commons.dbcp.PoolingDriver" /> <param name="url" value="jdbc:apache:commons:dbcp:/myPoolingDriver" /> </connectionSource>Then the configuration information for the commons-dbcp package goes into the file myPoolingDriver.jocl and is placed in the classpath. See the commons-dbcp documentation for details.
Field Summary | |
protected java.lang.String |
url
|
Fields inherited from class org.apache.log4j.db.ConnectionSourceSkeleton |
dialectCode, errorHandler, password, supportsBatchUpdates, supportsGetGeneratedKeys, user |
Fields inherited from interface org.apache.log4j.db.ConnectionSource |
HSQL_DIALECT, MSSQL_DIALECT, MYSQL_DIALECT, ORACLE_DIALECT, POSTGRES_DIALECT, UNKNOWN_DIALECT |
Constructor Summary | |
DriverManagerConnectionSource()
|
Method Summary | |
void |
activateOptions()
Activate the options that were previously set with calls to option setters. |
java.sql.Connection |
getConnection()
Obtain a Connection for use. |
java.lang.String |
getDriverClass()
Returns the name of the driver class. |
java.lang.String |
getUrl()
Returns the url. |
void |
setDriverClass(java.lang.String driverClass)
Sets the driver class. |
void |
setUrl(java.lang.String url)
Sets the url. |
Methods inherited from class org.apache.log4j.db.ConnectionSourceSkeleton |
discoverConnnectionProperties, getErrorHandler, getLogger, getPassword, getSQLDialectCode, getUser, setErrorHandler, setPassword, setUser, supportsBatchUpdates, supportsGetGeneratedKeys |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.String url
Constructor Detail |
public DriverManagerConnectionSource()
Method Detail |
public void activateOptions()
OptionHandler
This allows to defer activiation of the options until all options have been set. This is required for components which have related options that remain ambigous until all are set.
For example, the FileAppender has the File
and Append
options both of
which are ambigous until the other is also set.
public java.sql.Connection getConnection() throws java.sql.SQLException
ConnectionSource
Connection
for use. The client is
responsible for closing the Connection
when it is no
longer required.
java.sql.SQLException
- if a Connection
could not be
obtainedConnectionSource.getConnection()
public java.lang.String getUrl()
public void setUrl(java.lang.String url)
url
- The url to setpublic java.lang.String getDriverClass()
public void setDriverClass(java.lang.String driverClass)
driverClass
- The driver class to set
|
Log4j 1.3alpha-1 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |