Class FactoryMethodConnectionSource
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.FactoryMethodConnectionSource
- All Implemented Interfaces:
ConnectionSource,LifeCycle,LifeCycle2
@Plugin(name="ConnectionFactory",
category="Core",
elementType="connectionSource",
printObject=true)
public final class FactoryMethodConnectionSource
extends AbstractConnectionSource
A
JdbcAppender connection source that uses a public static factory method to obtain a Connection or
DataSource.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DataSourceprivate final Stringprivate static final LoggerFields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateFactoryMethodConnectionSource(DataSource dataSource, String className, String methodName, String returnType) -
Method Summary
Modifier and TypeMethodDescriptioncreateConnectionSource(String className, String methodName) Factory method for creating a connection source within the plugin manager.This should return a new connection every time it is called.toString()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 Details
-
LOGGER
-
dataSource
-
description
-
-
Constructor Details
-
FactoryMethodConnectionSource
private FactoryMethodConnectionSource(DataSource dataSource, String className, String methodName, String returnType)
-
-
Method Details
-
getConnection
Description copied from interface:ConnectionSourceThis should return a new connection every time it is called.- Returns:
- the SQL connection object.
- Throws:
SQLException- if a database error occurs.
-
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 classObject- Returns:
- the string representation of this connection source.
-
createConnectionSource
@PluginFactory public static FactoryMethodConnectionSource createConnectionSource(@PluginAttribute("class") String className, @PluginAttribute("method") String methodName) Factory method for creating a connection source within the plugin manager.- Parameters:
className- The name of a public class that contains a static method capable of returning either aDataSourceor aConnection.methodName- The name of the public static method on the aforementioned class that returns the data source or connection. If this method returns aConnection, it should return a new connection every call.- Returns:
- the created connection source.
-