org.apache.logging.log4j.core.appender.db.jpa
Class JpaDatabaseManager

java.lang.Object
  extended by org.apache.logging.log4j.core.appender.AbstractManager
      extended by org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager
          extended by org.apache.logging.log4j.core.appender.db.jpa.JpaDatabaseManager
All Implemented Interfaces:
Flushable

public final class JpaDatabaseManager
extends AbstractDatabaseManager

An AbstractDatabaseManager implementation for relational databases accessed via JPA.


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
protected  void 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 JpaDatabaseManager getJPADatabaseManager(String name, int bufferSize, Class<? extends AbstractLogEventWrapperEntity> entityClass, Constructor<? extends AbstractLogEventWrapperEntity> entityConstructor, String persistenceUnitName)
          Creates a JPA manager for use within the JpaAppender, or returns a suitable one if it already exists.
protected  void 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)
          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
 
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
getContentFormat, getCount, getName, hasManager, release
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

startupInternal

protected void startupInternal()
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 class AbstractDatabaseManager

shutdownInternal

protected void 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 after AbstractDatabaseManager.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 in AbstractDatabaseManager.startupInternal().

Specified by:
shutdownInternal in class AbstractDatabaseManager

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 to AbstractDatabaseManager.writeInternal(org.apache.logging.log4j.core.LogEvent). With buffering disabled, this is called immediately before every invocation of AbstractDatabaseManager.writeInternal(org.apache.logging.log4j.core.LogEvent).

Specified by:
connectAndStart in class AbstractDatabaseManager

writeInternal

protected void writeInternal(LogEvent event)
Description copied from class: AbstractDatabaseManager
Performs the actual writing of the event in an implementation-specific way. This method is called immediately from AbstractDatabaseManager.write(LogEvent) if buffering is off, or from AbstractDatabaseManager.flush() if the buffer has reached its limit.

Specified by:
writeInternal in class AbstractDatabaseManager
Parameters:
event - The event to write to the database.

commitAndClose

protected void 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 to AbstractDatabaseManager.writeInternal(org.apache.logging.log4j.core.LogEvent). With buffering disabled, this is called immediately after every invocation of AbstractDatabaseManager.writeInternal(org.apache.logging.log4j.core.LogEvent).

Specified by:
commitAndClose in class AbstractDatabaseManager

getJPADatabaseManager

public static JpaDatabaseManager getJPADatabaseManager(String name,
                                                       int bufferSize,
                                                       Class<? extends AbstractLogEventWrapperEntity> entityClass,
                                                       Constructor<? extends AbstractLogEventWrapperEntity> entityConstructor,
                                                       String persistenceUnitName)
Creates a JPA manager for use within the JpaAppender, or returns a suitable one if it already exists.

Parameters:
name - The name of the manager, which should include connection details, entity class name, etc.
bufferSize - The size of the log event buffer.
entityClass - The fully-qualified class name of the AbstractLogEventWrapperEntity concrete implementation.
entityConstructor - The one-arg LogEvent constructor for the concrete entity class.
persistenceUnitName - The name of the JPA persistence unit that should be used for persisting log events.
Returns:
a new or existing JPA manager as applicable.


Copyright © 1999-2014 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.