Package org.apache.log.output.db
Class DefaultJDBCTarget
- java.lang.Object
-
- org.apache.log.output.AbstractTarget
-
- org.apache.log.output.db.AbstractJDBCTarget
-
- 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.
-
-
Field Summary
Fields Modifier and Type Field Description private ColumnInfo[]
m_columns
private java.sql.PreparedStatement
m_statement
private java.lang.String
m_table
-
Constructor Summary
Constructors Constructor Description DefaultJDBCTarget(javax.sql.DataSource dataSource, java.lang.String table, ColumnInfo[] columns)
Creation of a new JDBC logging target.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeConnection()
Close connection to underlying database.protected ColumnInfo
getColumn(int index)
Return the column info for an supplied index.private java.lang.String
getContextMap(ContextMap map, java.lang.String aux)
private java.lang.String
getStackTrace(java.lang.Throwable throwable)
protected java.lang.String
getStatementSQL()
Return the SQL insert statement.protected java.lang.String
getTable()
Return the underlying tableprotected 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(java.sql.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
-
-
-
-
Field Detail
-
m_table
private final java.lang.String m_table
-
m_columns
private final ColumnInfo[] m_columns
-
m_statement
private java.sql.PreparedStatement m_statement
-
-
Constructor Detail
-
DefaultJDBCTarget
public DefaultJDBCTarget(javax.sql.DataSource dataSource, java.lang.String table, ColumnInfo[] columns)
Creation of a new JDBC logging target.- Parameters:
dataSource
- the JDBC datasourcetable
- the tablecolumns
- 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 classAbstractJDBCTarget
- Parameters:
event
- the log event.
-
openConnection
protected void openConnection()
Open connection to underlying database.- Overrides:
openConnection
in classAbstractJDBCTarget
-
getStatementSQL
protected java.lang.String getStatementSQL()
Return the SQL insert statement.- Returns:
- the statement
-
isStale
protected boolean isStale()
Test if the target is stale.- Overrides:
isStale
in classAbstractJDBCTarget
- Returns:
- TRUE if the target is stale else FALSE
-
closeConnection
protected void closeConnection()
Close connection to underlying database.- Overrides:
closeConnection
in classAbstractJDBCTarget
-
specifyColumn
protected void specifyColumn(java.sql.PreparedStatement statement, int index, LogEvent event) throws java.sql.SQLException, java.lang.IllegalStateException
Adds a single object into statement.- Parameters:
statement
- the prepard statementindex
- the indexevent
- the log event- Throws:
java.sql.SQLException
- if an SQL related error occursjava.lang.IllegalStateException
- if the supplied index is out of bounds
-
getTable
protected final java.lang.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 java.lang.String getStackTrace(java.lang.Throwable throwable)
-
getContextMap
private java.lang.String getContextMap(ContextMap map, java.lang.String aux)
-
-