org.apache.log.output.db

Class DefaultJDBCTarget

public class DefaultJDBCTarget extends AbstractJDBCTarget

The basic DB target for configurable output formats.

Author: Avalon Development Team Peter Donald

Field Summary
ColumnInfo[]m_columns
PreparedStatementm_statement
Stringm_table
Constructor Summary
DefaultJDBCTarget(DataSource dataSource, String table, ColumnInfo[] columns)
Creation of a new JDBC logging target.
Method Summary
protected voidcloseConnection()
Close connection to underlying database.
protected ColumnInfogetColumn(int index)
Return the column info for an supplied index.
StringgetContextMap(ContextMap map, String aux)
StringgetStackTrace(Throwable throwable)
protected StringgetStatementSQL()
Return the SQL insert statement.
protected StringgetTable()
Return the underlying table
protected booleanisStale()
Test if the target is stale.
protected voidopenConnection()
Open connection to underlying database.
protected voidoutput(LogEvent event)
Output a log event to DB.
protected voidspecifyColumn(PreparedStatement statement, int index, LogEvent event)
Adds a single object into statement.

Field Detail

m_columns

private final ColumnInfo[] m_columns

m_statement

private PreparedStatement m_statement

m_table

private final String m_table

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

closeConnection

protected void closeConnection()
Close connection to underlying database.

getColumn

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

Parameters: index the index

Returns: the column info

getContextMap

private String getContextMap(ContextMap map, String aux)

getStackTrace

private String getStackTrace(Throwable throwable)

getStatementSQL

protected String getStatementSQL()
Return the SQL insert statement.

Returns: the statement

getTable

protected final String getTable()
Return the underlying table

Returns: the table name

isStale

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

Returns: TRUE if the target is stale else FALSE

openConnection

protected void openConnection()
Open connection to underlying database.

output

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

Parameters: event the log event.

specifyColumn

protected void specifyColumn(PreparedStatement statement, int index, LogEvent event)
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