Class DataSourceConnectionSource
- java.lang.Object
-
- org.apache.logging.log4j.core.AbstractLifeCycle
-
- org.apache.logging.log4j.core.appender.db.jdbc.AbstractConnectionSource
-
- org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource
-
- All Implemented Interfaces:
ConnectionSource,LifeCycle,LifeCycle2
@Plugin(name="DataSource", category="Core", elementType="connectionSource", printObject=true) public final class DataSourceConnectionSource extends AbstractConnectionSource
AJdbcAppenderconnection source that uses aDataSourceto connect to the database.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
-
Field Summary
Fields Modifier and Type Field Description private javax.sql.DataSourcedataSourceprivate java.lang.Stringdescriptionprivate static LoggerLOGGER-
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT
-
-
Constructor Summary
Constructors Modifier Constructor Description privateDataSourceConnectionSource(java.lang.String dataSourceName, javax.sql.DataSource dataSource)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DataSourceConnectionSourcecreateConnectionSource(java.lang.String jndiName)Factory method for creating a connection source within the plugin manager.java.sql.ConnectiongetConnection()This should return a new connection every time it is called.java.lang.StringtoString()All implementations must overrideObject.toString()to provide information about the connection configuration (obscuring passwords with one-way hashes).-
Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, start, stop, stop, stop
-
-
-
-
Field Detail
-
LOGGER
private static final Logger LOGGER
-
dataSource
private final javax.sql.DataSource dataSource
-
description
private final java.lang.String description
-
-
Method Detail
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLExceptionDescription copied from interface:ConnectionSourceThis should return a new connection every time it is called.- Returns:
- the SQL connection object.
- Throws:
java.sql.SQLException- if a database error occurs.
-
toString
public java.lang.String toString()
Description copied from interface:ConnectionSourceAll implementations must overrideObject.toString()to provide information about the connection configuration (obscuring passwords with one-way hashes).- Specified by:
toStringin interfaceConnectionSource- Overrides:
toStringin classjava.lang.Object- Returns:
- the string representation of this connection source.
-
createConnectionSource
@PluginFactory public static DataSourceConnectionSource createConnectionSource(@PluginAttribute("jndiName") java.lang.String jndiName)
Factory method for creating a connection source within the plugin manager.- Parameters:
jndiName- The full JNDI path where the data source is bound. Must start with java:/comp/env or environment-equivalent.- Returns:
- the created connection source.
-
-