Class JdbcDatabaseManager

    • Method Detail

      • appendColumnName

        private static void appendColumnName​(int i,
                                             java.lang.String columnName,
                                             java.lang.StringBuilder sb)
      • appendColumnNames

        private static void appendColumnNames​(java.lang.String sqlVerb,
                                              JdbcDatabaseManager.FactoryData data,
                                              java.lang.StringBuilder sb)
        Appends column names to the given buffer in the format "A,B,C".
      • getJDBCDatabaseManager

        @Deprecated
        public static JdbcDatabaseManager getJDBCDatabaseManager​(java.lang.String name,
                                                                 int bufferSize,
                                                                 ConnectionSource connectionSource,
                                                                 java.lang.String tableName,
                                                                 ColumnConfig[] columnConfigs)
        Creates a JDBC manager for use within the JdbcAppender, or returns a suitable one if it already exists.
        Parameters:
        name - The name of the manager, which should include connection details and hashed passwords where possible.
        bufferSize - The size of the log event buffer.
        connectionSource - The source for connections to the database.
        tableName - The name of the database table to insert log events into.
        columnConfigs - Configuration information about the log table columns.
        Returns:
        a new or existing JDBC manager as applicable.
      • getManager

        @Deprecated
        public static JdbcDatabaseManager getManager​(java.lang.String name,
                                                     int bufferSize,
                                                     Layout<? extends java.io.Serializable> layout,
                                                     ConnectionSource connectionSource,
                                                     java.lang.String tableName,
                                                     ColumnConfig[] columnConfigs,
                                                     ColumnMapping[] columnMappings)
        Deprecated.
        Creates a JDBC manager for use within the JdbcAppender, or returns a suitable one if it already exists.
        Parameters:
        name - The name of the manager, which should include connection details and hashed passwords where possible.
        bufferSize - The size of the log event buffer.
        layout - The Appender-level layout
        connectionSource - The source for connections to the database.
        tableName - The name of the database table to insert log events into.
        columnConfigs - Configuration information about the log table columns.
        columnMappings - column mapping configuration (including type conversion).
        Returns:
        a new or existing JDBC manager as applicable.
      • getManager

        @Deprecated
        public static JdbcDatabaseManager getManager​(java.lang.String name,
                                                     int bufferSize,
                                                     Layout<? extends java.io.Serializable> layout,
                                                     ConnectionSource connectionSource,
                                                     java.lang.String tableName,
                                                     ColumnConfig[] columnConfigs,
                                                     ColumnMapping[] columnMappings,
                                                     boolean immediateFail,
                                                     long reconnectIntervalMillis)
        Creates a JDBC manager for use within the JdbcAppender, or returns a suitable one if it already exists.
        Parameters:
        name - The name of the manager, which should include connection details and hashed passwords where possible.
        bufferSize - The size of the log event buffer.
        layout -
        connectionSource - The source for connections to the database.
        tableName - The name of the database table to insert log events into.
        columnConfigs - Configuration information about the log table columns.
        columnMappings - column mapping configuration (including type conversion).
        reconnectIntervalMillis -
        immediateFail -
        Returns:
        a new or existing JDBC manager as applicable.
      • getManager

        public static JdbcDatabaseManager getManager​(java.lang.String name,
                                                     int bufferSize,
                                                     Layout<? extends java.io.Serializable> layout,
                                                     ConnectionSource connectionSource,
                                                     java.lang.String tableName,
                                                     ColumnConfig[] columnConfigs,
                                                     ColumnMapping[] columnMappings,
                                                     boolean immediateFail,
                                                     long reconnectIntervalMillis,
                                                     boolean truncateStrings)
        Creates a JDBC manager for use within the JdbcAppender, or returns a suitable one if it already exists.
        Parameters:
        name - The name of the manager, which should include connection details and hashed passwords where possible.
        bufferSize - The size of the log event buffer.
        layout - The Appender-level layout
        connectionSource - The source for connections to the database.
        tableName - The name of the database table to insert log events into.
        columnConfigs - Configuration information about the log table columns.
        columnMappings - column mapping configuration (including type conversion).
        immediateFail - Whether or not to fail immediately with a AppenderLoggingException when connecting to JDBC fails.
        reconnectIntervalMillis - How often to reconnect to the database when a SQL exception is detected.
        truncateStrings - Whether or not to truncate strings to match column metadata.
        Returns:
        a new or existing JDBC manager as applicable.
      • checkConnection

        private void checkConnection()
      • closeResources

        protected void closeResources​(boolean logExceptions)
      • commitAndCloseAll

        private boolean commitAndCloseAll()
      • connectAndPrepare

        private void connectAndPrepare()
                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • createSqlSelect

        private java.lang.String createSqlSelect()
      • fieldsToString

        private java.lang.String fieldsToString()
      • getSqlStatement

        public java.lang.String getSqlStatement()
      • getTableName

        public java.lang.String getTableName()
      • initColumnMetaData

        private void initColumnMetaData()
                                 throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • isClosed

        private boolean isClosed​(java.sql.Statement statement)
                          throws java.sql.SQLException
        Checks if a statement is closed. A null statement is considered closed.
        Parameters:
        statement - The statement to check.
        Returns:
        true if a statement is closed, false if null.
        Throws:
        java.sql.SQLException - if a database access error occurs
      • isClosed

        private boolean isClosed​(java.sql.Connection connection)
                          throws java.sql.SQLException
        Checks if a connection is closed. A null connection is considered closed.
        Parameters:
        connection - The connection to check.
        Returns:
        true if a connection is closed, false if null.
        Throws:
        java.sql.SQLException - if a database access error occurs
      • reconnectOn

        private void reconnectOn​(java.lang.Exception exception)
      • setFields

        private void setFields​(MapMessage<?,​?> mapMessage)
                        throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setStatementObject

        private void setStatementObject​(int j,
                                        java.lang.String nameKey,
                                        java.lang.Object value)
                                 throws java.sql.SQLException
        Sets the given Object in the prepared statement. The value is truncated if needed.
        Throws:
        java.sql.SQLException
      • startupInternal

        protected void startupInternal()
                                throws java.lang.Exception
        Description copied from class: AbstractDatabaseManager
        Implementations should implement this method to perform any proprietary startup operations. This method will never be called twice on the same instance. It is safe to throw any exceptions from this method. This method does not necessarily connect to the database, as it is generally unreliable to connect once and use the same connection for hours.
        Specified by:
        startupInternal in class AbstractDatabaseManager
        Throws:
        java.lang.Exception
      • truncate

        private java.lang.Object truncate​(java.lang.String nameKey,
                                          java.lang.Object value)
        Truncates the value if needed.