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 is SqlToDatabaseLogger.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 from Configuration 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 use setLoggingEnabled(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 at BcdSqlLogger class enabling programmatic switching of jdbc logging. Additionally this logger currently also logs HTTP layer information, if available, provided by RequestLifeCycleFilter, therefore the dependency on that class.
  • Constructor Details

    • SqlToDatabaseLogger

      protected SqlToDatabaseLogger()
  • Method Details

    • 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 from Configuration 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 to getInstance().setEnabled()
      Parameters:
      isEnabled -
    • getInstance

      public static SqlToDatabaseLogger getInstance()
    • getSqlTemplate

      protected 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 Object[][] convertData(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(Collection<SqlToDatabaseLogger.LogRecord> records)
      Description copied from class: AWorkerQueue
      implement the method to process the objects polled from queue (FIFO)
      Specified by:
      processObjects in class AWorkerQueue<T>
      Parameters:
      records - to process
    • executeStatement

      protected int[] executeStatement(Object[][] params) throws SQLException
      executes statement with raw parameters and returns number of updated rows
      Parameters:
      params -
      Returns:
      The number of rows updated per statement
      Throws:
      SQLException
    • getDataSource

      protected DataSource getDataSource()
      Returns:
      a datasource as referenced by the binding-set or the default datasource
      Throws:
      RuntimeException - in case datasource name discovery via Bindings takes place whilst Bindings has not initialized yet.