SQLFire 1.1

com.vmware.sqlfire.callbacks
Class AsyncEventHelper

java.lang.Object
  extended by com.vmware.sqlfire.callbacks.AsyncEventHelper

public class AsyncEventHelper
extends Object

Some utility methods for AsyncEventListener and WAN. Note that since this is also used by the SQLFire WAN layer, users should not change this class, rather should extend it and then modify for custom changes to DBSynchronizer.


Field Summary
static String CONNECTIVITY_PREFIX
          prefix for SQLStates of connection exceptions
static String INTEGRITY_VIOLATION_PREFIX
          prefix for SQLStates of integrity violations
static String LOGGER_NAME
          the name of the Logger used by SQLFire
static String LSE_COMPILATION_PREFIX
          prefix for SQLStates of syntax and other errors during query prepare
 
Constructor Summary
AsyncEventHelper()
           
 
Method Summary
static String getDeleteString(String tableName, ResultSetMetaData pkMetaData)
          Get a DML string that can be used to delete rows in given table.
static String getInsertString(String tableName, TableMetaData tableMetaData, boolean hasAutoIncrementColumns)
          Get a DML string that can be used to insert rows in given table.
 void getStackTrace(Throwable t, StringBuilder sb)
          Append the backtrace of given exception to provided StringBuilder.
static String getUpdateString(String tableName, ResultSetMetaData pkMetaData, ResultSetMetaData updateMetaData)
          Get a DML string that can be used to update rows in given table.
 void log(Logger logger, Level level, Throwable t, String message)
          Log the given message and exception to the provided logger.
 boolean logFineEnabled()
          Returns true if fine-level logging is enabled in this SQLFire instance.
 void logFormat(Logger logger, Level level, Throwable t, String format, Object... params)
          Log the given formatted message and exception to the provided logger.
static AsyncEventHelper newInstance()
           
 RuntimeException newRuntimeException(String message, Throwable t)
          Return a new SQLFire runtime exception to wrap an underlying exception with optional message detail.
 boolean removeEventFromFailureMap(Event event)
          After a successful event execution remove from failure map if present (i.e.
 void setColumnInPrepStatement(int javaSqlType, PreparedStatement ps, ResultSet row, int rowPosition, int paramIndex, DBSynchronizer sync)
          Set column value at given index in a prepared statement.
 boolean setParamsInBulkPreparedStatement(Event event, Event.Type evType, PreparedStatement ps, PreparedStatement prevPS, DBSynchronizer sync)
          Set the parameters to the prepared statement for a Event.Type.BULK_DML or Event.Type.BULK_INSERT operation.
 boolean skipFailureLogging(Event event)
          Check if logging for the same event repeatedly has to be skipped.
 boolean traceDBSynchronizer()
          Returns true if "TraceDBSynchronizer" debug flag is enabled in this SQLFire instance (via sqlfire.debug.true=TraceDBSynchronizer).
 boolean traceExecute()
          Returns true if minimal execution tracing is enabled in this SQLFire instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER_NAME

public static final String LOGGER_NAME
the name of the Logger used by SQLFire

See Also:
Constant Field Values

INTEGRITY_VIOLATION_PREFIX

public static final String INTEGRITY_VIOLATION_PREFIX
prefix for SQLStates of integrity violations

See Also:
Constant Field Values

CONNECTIVITY_PREFIX

public static final String CONNECTIVITY_PREFIX
prefix for SQLStates of connection exceptions

See Also:
Constant Field Values

LSE_COMPILATION_PREFIX

public static final String LSE_COMPILATION_PREFIX
prefix for SQLStates of syntax and other errors during query prepare

See Also:
Constant Field Values
Constructor Detail

AsyncEventHelper

public AsyncEventHelper()
Method Detail

newInstance

public static AsyncEventHelper newInstance()

getStackTrace

public final void getStackTrace(Throwable t,
                                StringBuilder sb)
Append the backtrace of given exception to provided StringBuilder.

Parameters:
t - the exception whose backtrace is required
sb - the StringBuilder to which the stack trace is to be appended

logFineEnabled

public final boolean logFineEnabled()
Returns true if fine-level logging is enabled in this SQLFire instance.


traceExecute

public final boolean traceExecute()
Returns true if minimal execution tracing is enabled in this SQLFire instance.


traceDBSynchronizer

public final boolean traceDBSynchronizer()
Returns true if "TraceDBSynchronizer" debug flag is enabled in this SQLFire instance (via sqlfire.debug.true=TraceDBSynchronizer).


log

public final void log(Logger logger,
                      Level level,
                      Throwable t,
                      String message)
Log the given message and exception to the provided logger.

Parameters:
logger - the Logger to log the message to
level - the Level to use for logging the message
t - the exception whose backtrace is to be logged; can be null in which case it is ignored
message - the message to be logged

logFormat

public final void logFormat(Logger logger,
                            Level level,
                            Throwable t,
                            String format,
                            Object... params)
Log the given formatted message and exception to the provided logger. The format expected is the same as supported by String.format(String, Object...).

Parameters:
logger - the Logger to log the message to
level - the Level to use for logging the message
t - the exception whose backtrace is to be logged; can be null in which case it is ignored
format - the message format
params - the parameters to the message format
See Also:
String.format(String, Object...), Formatter.format(String, Object...)

getInsertString

public static final String getInsertString(String tableName,
                                           TableMetaData tableMetaData,
                                           boolean hasAutoIncrementColumns)
                                    throws SQLException
Get a DML string that can be used to insert rows in given table. Any auto-increment columns are skipped from the insert statement assuming that they have to be re-generated by the backend database.

Parameters:
tableName - name of the table
tableMetaData - meta-data of the columns of the table
hasAutoIncrementColumns - should be true if table has any auto-increment columns
Throws:
SQLException - in case of an error in getting column information from table meta-data

getDeleteString

public static final String getDeleteString(String tableName,
                                           ResultSetMetaData pkMetaData)
                                    throws SQLException
Get a DML string that can be used to delete rows in given table. Caller needs to pass the primary-key column information as a ResultSetMetaData obtained from Event.getPrimaryKeysAsResultSet().

Parameters:
tableName - name of the table
pkMetaData - meta-data of the primary key columns of the table
Throws:
SQLException - in case of an error in getting column information from primary key meta-data

getUpdateString

public static final String getUpdateString(String tableName,
                                           ResultSetMetaData pkMetaData,
                                           ResultSetMetaData updateMetaData)
                                    throws SQLException
Get a DML string that can be used to update rows in given table. Caller needs to pass the primary-key column information as a ResultSetMetaData obtained from Event.getPrimaryKeysAsResultSet(), and the meta-data of updated columns as a ResultSetMetaData obtained from Event.getNewRowsAsResultSet().

Parameters:
tableName - name of the table
pkMetaData - meta-data of the primary key columns of the table
updateMetaData - meta-data of the updated columns of the table
Throws:
SQLException - in case of an error in getting column information from primary key meta-data, or from meta-data of updated columns

setParamsInBulkPreparedStatement

public final boolean setParamsInBulkPreparedStatement(Event event,
                                                      Event.Type evType,
                                                      PreparedStatement ps,
                                                      PreparedStatement prevPS,
                                                      DBSynchronizer sync)
                                               throws SQLException
Set the parameters to the prepared statement for a Event.Type.BULK_DML or Event.Type.BULK_INSERT operation. The implementation creates a batch for Event.Type.BULK_INSERT and also tries to add as a batch for Event.Type.BULK_DML in case the previous prepared statement is same as this one.

Parameters:
event - the Event object
evType - the Event.Type of the event
ps - the prepared statement to be used for prepare
prevPS - the prepared statement used for the previous event; in case it is same as the current one the new update for a Event.Type.BULK_DML operation will be added as a batch
sync - the DBSynchronizer object, if any; it is used to store whether the current driver is JDBC4 compliant to enable performing BLOB/CLOB operations PreparedStatement.setBinaryStream(int, java.io.InputStream, int), PreparedStatement.setCharacterStream(int, java.io.Reader, int)
Returns:
true if the event was Event.Type.BULK_INSERT and false otherwise
Throws:
SQLException - in case of an exception in getting meta-data or setting parameters

setColumnInPrepStatement

public final void setColumnInPrepStatement(int javaSqlType,
                                           PreparedStatement ps,
                                           ResultSet row,
                                           int rowPosition,
                                           int paramIndex,
                                           DBSynchronizer sync)
                                    throws SQLException
Set column value at given index in a prepared statement. The implementation tries using the matching underlying type to minimize any data type conversions, and avoid creating wrapper Java objects (e.g. Integer for primitive int).

Parameters:
javaSqlType - the SQL type of the column as specified by JDBC Types class
ps - the prepared statement where the column value has to be set
row - the source row as a ResultSet from where the value has to be extracted
rowPosition - the 1-based position of the column in the provided row
paramIndex - the 1-based position of the column in the target prepared statement (provided ps argument)
sync - the DBSynchronizer object, if any; it is used to store whether the current driver is JDBC4 compliant to enable performing BLOB/CLOB operations PreparedStatement.setBinaryStream(int, java.io.InputStream, int), PreparedStatement.setCharacterStream(int, java.io.Reader, int)
Throws:
SQLException - in case of an exception in setting parameters

skipFailureLogging

public final boolean skipFailureLogging(Event event)
Check if logging for the same event repeatedly has to be skipped. This keeps a map of failed event against the last logged time and doubles the time interval to wait before next logging on every subsequent call for the same event.


removeEventFromFailureMap

public final boolean removeEventFromFailureMap(Event event)
After a successful event execution remove from failure map if present (i.e. if the event had failed on a previous try).


newRuntimeException

public RuntimeException newRuntimeException(String message,
                                            Throwable t)
Return a new SQLFire runtime exception to wrap an underlying exception with optional message detail. When an external exception is received in a callback, using this method to wrap it is recommended for SQLFire engine to deal with it cleanly.

Parameters:
message - the detail message of the exception
t - the underlying exception to be wrapped

SQLFire 1.1

Copyright © 2010-2013 VMware, Inc. All rights reserved.