Package de.businesscode.bcdui.logging
Class SqlToDatabaseLogger
- java.lang.Object
-
- de.businesscode.bcdui.toolbox.AWorkerQueue<T>
-
- de.businesscode.bcdui.logging.SqlToDatabaseLogger
-
public final class SqlToDatabaseLogger extends AWorkerQueue<T>
a singleton logger for SQL statements, the binding set used for it is bcd_log_sql, record logged isSqlToDatabaseLogger.LogRecord
this class is not intended to be customized or extended in projects. The existence of the binding-set enables this logger automatically. This logger used by BcdConnectionWrapper, so only wrapped JDBC connections log into database, any connection obtained fromConfiguration
class provides such a wrapped connection. If you want to disable logging temporarily, i.e. in case you're in another logger you may want to usesetLoggingEnabled(boolean)
method. Then, the SQLs generated by your code might be propagated to Log4J logging, but they will not be published to the database. You may also want to take a look atBcdSqlLogger
class enabling programmatic switching of jdbc logging. Additionally this logger currently also logs HTTP layer information, if available, provided byRequestLifeCycleFilter
, therefore the dependency on that class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SqlToDatabaseLogger.LogRecord
record being logged into db
-
Field Summary
-
Fields inherited from class de.businesscode.bcdui.toolbox.AWorkerQueue
DEFAULT_MAX_QUEUE_SIZE, log
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SqlToDatabaseLogger()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object[][]
convertData(java.util.Collection<SqlToDatabaseLogger.LogRecord> records)
processes given collection of type to dimensional object array to be consumed by batch SQLprotected int[]
executeStatement(java.lang.Object[][] params)
executes statement with raw parameters and returns number of updated rowsprotected javax.sql.DataSource
getDataSource()
static SqlToDatabaseLogger
getInstance()
protected java.lang.String
getSqlTemplate()
boolean
isEnabled()
as SQL logger we are depended on Bindings, which in turn use classes using us, so we dont participate in Binding bootstrap processprotected void
processObjects(java.util.Collection<T> records)
implement the method to process the objects polled from queue (FIFO)void
setEnabled(boolean isEnabled)
enables/disables JDBC logging for this thread, this method has to be called prior creating a JDBC statement (or connection, datasource), if you dont obtain DataSource or Connection object fromConfiguration
class, you dont need to use this method, as those Connections are not logged anyway.static void
setLoggingEnabled(boolean isEnabled)
a shortcut togetInstance().setEnabled()
-
Methods inherited from class de.businesscode.bcdui.toolbox.AWorkerQueue
enqueue, onIdle, process, process, shutdownQueues
-
-
-
-
Method Detail
-
isEnabled
public boolean isEnabled()
as SQL logger we are depended on Bindings, which in turn use classes using us, so we dont participate in Binding bootstrap process- Returns:
-
setEnabled
public void setEnabled(boolean isEnabled)
enables/disables JDBC logging for this thread, this method has to be called prior creating a JDBC statement (or connection, datasource), if you dont obtain DataSource or Connection object fromConfiguration
class, you dont need to use this method, as those Connections are not logged anyway. sample usage:try{ SqlToDatabaseLogger.setLoggingEnabled(false); ;; // obtain and work with JDBC statement here }finally{ SqlToDatabaseLogger.setLoggingEnabled(true); }
- Parameters:
isEnabled
-
-
setLoggingEnabled
public static void setLoggingEnabled(boolean isEnabled)
a shortcut togetInstance().setEnabled()
- Parameters:
isEnabled
-
-
getInstance
public static SqlToDatabaseLogger getInstance()
-
getSqlTemplate
protected java.lang.String getSqlTemplate()
- Returns:
- SQL template for inserts (prepared statement compatible to process batch updates) this sql template is not intended to change and is cached so this function is called only once
-
convertData
protected java.lang.Object[][] convertData(java.util.Collection<SqlToDatabaseLogger.LogRecord> records)
processes given collection of type to dimensional object array to be consumed by batch SQL- Parameters:
records
-- Returns:
-
processObjects
protected void processObjects(java.util.Collection<T> records)
Description copied from class:AWorkerQueue
implement the method to process the objects polled from queue (FIFO)- Specified by:
processObjects
in classAWorkerQueue<T>
- Parameters:
records
- to process
-
executeStatement
protected int[] executeStatement(java.lang.Object[][] params) throws java.sql.SQLException
executes statement with raw parameters and returns number of updated rows- Parameters:
params
-- Returns:
- The number of rows updated per statement
- Throws:
java.sql.SQLException
-
getDataSource
protected javax.sql.DataSource getDataSource()
- Returns:
- a datasource as referenced by the binding-set or the default datasource
- Throws:
java.lang.RuntimeException
- in case datasource name discovery via Bindings takes place whilst Bindings has not initialized yet.
-
-