Class JdbcDatabaseManager
- java.lang.Object
-
- org.apache.logging.log4j.core.appender.AbstractManager
-
- org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager
-
- org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager
-
- All Implemented Interfaces:
Flushable
,AutoCloseable
public final class JdbcDatabaseManager extends AbstractDatabaseManager
AnAbstractDatabaseManager
implementation for relational databases accessed via JDBC.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager
AbstractDatabaseManager.AbstractFactoryData
-
-
Field Summary
-
Fields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected boolean
commitAndClose()
Commits any active transaction (if applicable) and disconnects from the database (returns the connection to the connection pool).protected void
connectAndStart()
Connects to the database and starts a transaction (if applicable).static JdbcDatabaseManager
getJDBCDatabaseManager(String name, int bufferSize, ConnectionSource connectionSource, String tableName, ColumnConfig[] columnConfigs)
static JdbcDatabaseManager
getManager(String name, int bufferSize, ConnectionSource connectionSource, String tableName, ColumnConfig[] columnConfigs, ColumnMapping[] columnMappings)
static JdbcDatabaseManager
getManager(String name, int bufferSize, Layout<? extends Serializable> layout, ConnectionSource connectionSource, String tableName, ColumnConfig[] columnConfigs, ColumnMapping[] columnMappings)
Creates a JDBC manager for use within theJdbcAppender
, or returns a suitable one if it already exists.protected boolean
shutdownInternal()
Implementations should implement this method to perform any proprietary disconnection / shutdown operations.protected void
startupInternal()
Implementations should implement this method to perform any proprietary startup operations.protected void
writeInternal(LogEvent event)
Deprecated.protected void
writeInternal(LogEvent event, Serializable serializable)
Performs the actual writing of the event in an implementation-specific way.-
Methods inherited from class org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager
flush, getManager, isRunning, releaseSub, shutdown, startup, toString, write, write
-
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
close, getContentFormat, getCount, getLoggerContext, getManager, getName, hasManager, log, logDebug, logError, logWarn, narrow, release, stop, updateData
-
-
-
-
Method Detail
-
startupInternal
protected void startupInternal() throws Exception
Description copied from class:AbstractDatabaseManager
Implementations should implement this method to perform any proprietary startup operations. This method will never be called twice on the same instance. It is safe to throw any exceptions from this method. This method does not necessarily connect to the database, as it is generally unreliable to connect once and use the same connection for hours.- Specified by:
startupInternal
in classAbstractDatabaseManager
- Throws:
Exception
-
shutdownInternal
protected boolean shutdownInternal()
Description copied from class:AbstractDatabaseManager
Implementations should implement this method to perform any proprietary disconnection / shutdown operations. This method will never be called twice on the same instance, and it will only be called afterAbstractDatabaseManager.startupInternal()
. It is safe to throw any exceptions from this method. This method does not necessarily disconnect from the database for the same reasons outlined inAbstractDatabaseManager.startupInternal()
.- Specified by:
shutdownInternal
in classAbstractDatabaseManager
- Returns:
- true if all resources were closed normally, false otherwise.
-
connectAndStart
protected void connectAndStart()
Description copied from class:AbstractDatabaseManager
Connects to the database and starts a transaction (if applicable). With buffering enabled, this is called when flushing the buffer begins, before the first call toAbstractDatabaseManager.writeInternal(org.apache.logging.log4j.core.LogEvent)
. With buffering disabled, this is called immediately before every invocation ofAbstractDatabaseManager.writeInternal(org.apache.logging.log4j.core.LogEvent)
.- Specified by:
connectAndStart
in classAbstractDatabaseManager
-
writeInternal
@Deprecated protected void writeInternal(LogEvent event)
Deprecated.Description copied from class:AbstractDatabaseManager
Performs the actual writing of the event in an implementation-specific way. This method is called immediately fromAbstractDatabaseManager.write(LogEvent, Serializable)
if buffering is off, or fromAbstractDatabaseManager.flush()
if the buffer has reached its limit.- Specified by:
writeInternal
in classAbstractDatabaseManager
- Parameters:
event
- The event to write to the database.
-
writeInternal
protected void writeInternal(LogEvent event, Serializable serializable)
Description copied from class:AbstractDatabaseManager
Performs the actual writing of the event in an implementation-specific way. This method is called immediately fromAbstractDatabaseManager.write(LogEvent, Serializable)
if buffering is off, or fromAbstractDatabaseManager.flush()
if the buffer has reached its limit.- Specified by:
writeInternal
in classAbstractDatabaseManager
- Parameters:
event
- The event to write to the database.
-
commitAndClose
protected boolean commitAndClose()
Description copied from class:AbstractDatabaseManager
Commits any active transaction (if applicable) and disconnects from the database (returns the connection to the connection pool). With buffering enabled, this is called when flushing the buffer completes, after the last call toAbstractDatabaseManager.writeInternal(org.apache.logging.log4j.core.LogEvent)
. With buffering disabled, this is called immediately after every invocation ofAbstractDatabaseManager.writeInternal(org.apache.logging.log4j.core.LogEvent)
.- Specified by:
commitAndClose
in classAbstractDatabaseManager
- Returns:
- true if all resources were closed normally, false otherwise.
-
getJDBCDatabaseManager
@Deprecated public static JdbcDatabaseManager getJDBCDatabaseManager(String name, int bufferSize, ConnectionSource connectionSource, String tableName, ColumnConfig[] columnConfigs)
Deprecated.Creates a JDBC manager for use within theJdbcAppender
, or returns a suitable one if it already exists.- Parameters:
name
- The name of the manager, which should include connection details and hashed passwords where possible.bufferSize
- The size of the log event buffer.connectionSource
- The source for connections to the database.tableName
- The name of the database table to insert log events into.columnConfigs
- Configuration information about the log table columns.- Returns:
- a new or existing JDBC manager as applicable.
-
getManager
@Deprecated public static JdbcDatabaseManager getManager(String name, int bufferSize, ConnectionSource connectionSource, String tableName, ColumnConfig[] columnConfigs, ColumnMapping[] columnMappings)
Deprecated.Creates a JDBC manager for use within theJdbcAppender
, or returns a suitable one if it already exists.- Parameters:
name
- The name of the manager, which should include connection details and hashed passwords where possible.bufferSize
- The size of the log event buffer.connectionSource
- The source for connections to the database.tableName
- The name of the database table to insert log events into.columnConfigs
- Configuration information about the log table columns.columnMappings
- column mapping configuration (including type conversion).- Returns:
- a new or existing JDBC manager as applicable.
-
getManager
public static JdbcDatabaseManager getManager(String name, int bufferSize, Layout<? extends Serializable> layout, ConnectionSource connectionSource, String tableName, ColumnConfig[] columnConfigs, ColumnMapping[] columnMappings)
Creates a JDBC manager for use within theJdbcAppender
, or returns a suitable one if it already exists.- Parameters:
name
- The name of the manager, which should include connection details and hashed passwords where possible.bufferSize
- The size of the log event buffer.layout
- The Appender-level layoutconnectionSource
- The source for connections to the database.tableName
- The name of the database table to insert log events into.columnConfigs
- Configuration information about the log table columns.columnMappings
- column mapping configuration (including type conversion).- Returns:
- a new or existing JDBC manager as applicable.
-
-