Package org.apache.log4j.db
Class JNDIConnectionSource
- java.lang.Object
-
- org.apache.log4j.spi.ComponentBase
-
- org.apache.log4j.db.ConnectionSourceSkeleton
-
- org.apache.log4j.db.JNDIConnectionSource
-
- All Implemented Interfaces:
ConnectionSource,Component,org.apache.log4j.spi.OptionHandler
public class JNDIConnectionSource extends ConnectionSourceSkeleton
TheJNDIConnectionSourceis an implementation ofConnectionSourcethat obtains aDataSourcefrom a JNDI provider and uses it to obtain aConnection. It is primarily designed to be used inside of J2EE application servers or application server clients, assuming the application server supports remote access ofDataSources. In this way one can take advantage of connection pooling and whatever other goodies the application server provides.Sample configuration:
<connectionSource class="org.apache.log4j.jdbc.JNDIConnectionSource"> <param name="jndiLocation" value="jdbc/MySQLDS" /> </connectionSource>Sample configuration (with username and password):
<connectionSource class="org.apache.log4j.jdbc.JNDIConnectionSource"> <param name="jndiLocation" value="jdbc/MySQLDS" /> <param name="username" value="myUser" /> <param name="password" value="myPassword" /> </connectionSource>Note that this class will obtain an
InitialContextusing the no-argument constructor. This will usually work when executing within a J2EE environment. When outside the J2EE environment, make sure that you provide a jndi.properties file as described by your JNDI provider's documentation.- Author:
- Ray DeCampo
-
-
Field Summary
-
Fields inherited from class org.apache.log4j.spi.ComponentBase
repository
-
Fields inherited from interface org.apache.log4j.db.ConnectionSource
HSQL_DIALECT, MSSQL_DIALECT, MYSQL_DIALECT, ORACLE_DIALECT, POSTGRES_DIALECT, UNKNOWN_DIALECT
-
-
Constructor Summary
Constructors Constructor Description JNDIConnectionSource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateOptions()ConnectiongetConnection()Obtain aConnectionfor use.StringgetJndiLocation()Returns the jndiLocation.voidsetJndiLocation(String jndiLocation)Sets the jndiLocation.-
Methods inherited from class org.apache.log4j.db.ConnectionSourceSkeleton
discoverConnnectionProperties, getOverriddenSupportsGetGeneratedKeys, getPassword, getSQLDialectCode, getUser, setOverriddenSupportsGetGeneratedKeys, setPassword, setUser, supportsBatchUpdates, supportsGetGeneratedKeys
-
Methods inherited from class org.apache.log4j.spi.ComponentBase
getLogger, getLoggerRepository, getNonFloodingLogger, resetErrorCount, setLoggerRepository
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.log4j.spi.Component
setLoggerRepository
-
-
-
-
Method Detail
-
activateOptions
public void activateOptions()
- See Also:
OptionHandler.activateOptions()
-
getConnection
public Connection getConnection() throws SQLException
Description copied from interface:ConnectionSourceObtain aConnectionfor use. The client is responsible for closing theConnectionwhen it is no longer required.- Throws:
SQLException- if aConnectioncould not be obtained- See Also:
ConnectionSource.getConnection()
-
getJndiLocation
public String getJndiLocation()
Returns the jndiLocation.- Returns:
- String
-
setJndiLocation
public void setJndiLocation(String jndiLocation)
Sets the jndiLocation.- Parameters:
jndiLocation- The jndiLocation to set
-
-