org.apache.log.output.db
Class DefaultJDBCTarget

java.lang.Object
  extended by org.apache.log.output.AbstractTarget
      extended by org.apache.log.output.db.AbstractJDBCTarget
          extended by org.apache.log.output.db.DefaultJDBCTarget
All Implemented Interfaces:
ErrorAware, LogTarget, Closeable
Direct Known Subclasses:
NormalizedJDBCTarget

public class DefaultJDBCTarget
extends AbstractJDBCTarget

The basic DB target for configurable output formats.

Author:
Avalon Development Team, Peter Donald

Field Summary
private  ColumnInfo[] m_columns
           
private  PreparedStatement m_statement
           
private  String m_table
           
 
Constructor Summary
DefaultJDBCTarget(DataSource dataSource, String table, ColumnInfo[] columns)
          Creation of a new JDBC logging target.
 
Method Summary
protected  void closeConnection()
          Close connection to underlying database.
protected  ColumnInfo getColumn(int index)
          Return the column info for an supplied index.
private  String getContextMap(ContextMap map, String aux)
           
private  String getStackTrace(Throwable throwable)
           
protected  String getStatementSQL()
          Return the SQL insert statement.
protected  String getTable()
          Return the underlying table
protected  boolean isStale()
          Test if the target is stale.
protected  void openConnection()
          Open connection to underlying database.
protected  void output(LogEvent event)
          Output a log event to DB.
protected  void specifyColumn(PreparedStatement statement, int index, LogEvent event)
          Adds a single object into statement.
 
Methods inherited from class org.apache.log.output.db.AbstractJDBCTarget
checkConnection, close, doProcessEvent, getConnection, open
 
Methods inherited from class org.apache.log.output.AbstractTarget
getErrorHandler, isOpen, processEvent, setErrorHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_table

private final String m_table

m_columns

private final ColumnInfo[] m_columns

m_statement

private PreparedStatement m_statement
Constructor Detail

DefaultJDBCTarget

public DefaultJDBCTarget(DataSource dataSource,
                         String table,
                         ColumnInfo[] columns)
Creation of a new JDBC logging target.

Parameters:
dataSource - the JDBC datasource
table - the table
columns - a ColumnInfo array
Method Detail

output

protected void output(LogEvent event)
Output a log event to DB. This must be implemented by subclasses.

Specified by:
output in class AbstractJDBCTarget
Parameters:
event - the log event.

openConnection

protected void openConnection()
Open connection to underlying database.

Overrides:
openConnection in class AbstractJDBCTarget

getStatementSQL

protected String getStatementSQL()
Return the SQL insert statement.

Returns:
the statement

isStale

protected boolean isStale()
Test if the target is stale.

Overrides:
isStale in class AbstractJDBCTarget
Returns:
TRUE if the target is stale else FALSE

closeConnection

protected void closeConnection()
Close connection to underlying database.

Overrides:
closeConnection in class AbstractJDBCTarget

specifyColumn

protected void specifyColumn(PreparedStatement statement,
                             int index,
                             LogEvent event)
                      throws SQLException,
                             IllegalStateException
Adds a single object into statement.

Parameters:
statement - the prepard statement
index - the index
event - the log event
Throws:
SQLException - if an SQL related error occurs
IllegalStateException - if the supplied index is out of bounds

getTable

protected final String getTable()
Return the underlying table

Returns:
the table name

getColumn

protected final ColumnInfo getColumn(int index)
Return the column info for an supplied index.

Parameters:
index - the index
Returns:
the column info

getStackTrace

private String getStackTrace(Throwable throwable)

getContextMap

private String getContextMap(ContextMap map,
                             String aux)


Copyright © 2003-2004 The Apache Software Foundation. All Rights Reserved.