Class 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 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 SQL
      protected int[] executeStatement​(java.lang.Object[][] params)
      executes statement with raw parameters and returns number of updated rows
      protected 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 process
      protected 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 from Configuration class, you dont need to use this method, as those Connections are not logged anyway.
      static void setLoggingEnabled​(boolean isEnabled)
      a shortcut to getInstance().setEnabled()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SqlToDatabaseLogger

        protected SqlToDatabaseLogger()
    • 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 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 -
      • 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 class AWorkerQueue<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.