public class DBSynchronizer extends java.lang.Object implements AsyncEventListener
| Modifier and Type | Class and Description |
|---|---|
protected static class |
DBSynchronizer.SqlExceptionHandler
Enumeration that defines the action to be performed in case an exception is
received during processing by
processEvents(List) |
| Modifier and Type | Field and Description |
|---|---|
protected java.util.HashMap<java.lang.String,java.sql.PreparedStatement> |
bulkOpStmntMap
the cached
PreparedStatements for other non-primary key based DML
operations |
protected java.sql.Connection |
conn
the current JDBC connection being used by this instance
|
protected static java.lang.String |
DBDRIVER |
protected java.lang.String |
dbUrl
the JDBC connection URL for the external database
|
protected static java.lang.String |
DBURL |
protected static int |
DEFAULT_ERROR_TRIES
default number of retries after an error is 3 when
errorFile is
defined |
protected java.util.HashMap<java.lang.String,java.sql.PreparedStatement> |
deleteStmntMap
the cached
PreparedStatements for primary key based deletes |
protected java.sql.Driver |
driver
the
Driver implementation instance loaded using the
driverClass |
protected java.lang.String |
driverClass
fully qualified name of the implementation class of the JDBC
Driver
interface |
protected java.lang.String |
errorFile
file to write errors
|
protected static java.lang.String |
ERRORFILE |
protected static java.lang.String |
ERRORTRIES |
protected java.util.concurrent.ConcurrentSkipListMap<com.pivotal.gemfirexd.callbacks.DBSynchronizer.ErrorEvent,java.lang.Object[]> |
errorTriesMap
keeps track of the retries that have been done for an event
|
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__1 |
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__10 |
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__11 |
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__12 |
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__13 |
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__2 |
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__3 |
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__4 |
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__5 |
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__6 |
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__7 |
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__8 |
protected static java.lang.String |
Gfxd_DB_SYNCHRONIZER__9 |
protected AsyncEventHelper |
helper |
protected java.util.HashMap<java.lang.String,java.sql.PreparedStatement> |
insertStmntMap
the cached
PreparedStatements for inserts |
protected static byte |
JDBC4DRIVER_FALSE
if it is known that the driver is not JDBC4 compliant for BLOB/CLOB related
API
|
protected static byte |
JDBC4DRIVER_TRUE
if it is known that the driver is JDBC4 compliant for BLOB/CLOB related API
|
protected static byte |
JDBC4DRIVER_UNKNOWN
if it is unknown whether the driver is JDBC4 compliant for BLOB/CLOB
related API
|
protected int |
keySize
the key size of the algorithm being used for encrypted the password
|
protected static java.lang.String |
KEYSIZE |
protected java.util.logging.Logger |
logger |
protected java.util.HashMap<java.lang.String,TableMetaData> |
metadataMap
the map of table name to its current metadata object
|
protected int |
numErrorTries
number of retries after an error before dumping to
errorFile |
protected java.lang.String |
passwd
password for the user to use for establishing JDBC connection
|
protected static java.lang.String |
PASSWORD |
protected java.util.HashMap<java.lang.String,java.sql.ResultSetMetaData> |
pkMetadataMap
the map of table name to its current primary key metadata object
|
protected static java.lang.String |
SECRET |
protected boolean |
shutDown
true if this instance has been closed or not initialized
|
protected static java.lang.String |
SKIP_IDENTITY_COLUMNS |
protected boolean |
skipIdentityColumns
if true then skip identity columns in sync else also set the values of
identity columns as in GemFireXD
|
protected boolean |
traceDBSynchronizer
true if "TraceDBSynchronizer" debug flag is enabled in this GemFireXD
instance (via gemfirexd.debug.true=TraceDBSynchronizer).
|
protected boolean |
traceDBSynchronizerHA
true if "TraceDBSynchronizer" debug flag is enabled in this GemFireXD
instance (via gemfirexd.debug.true=TraceDBSynchronizer).
|
protected java.lang.String |
transformation
the transformation (e.g.
|
protected static java.lang.String |
TRANSFORMATION |
protected java.util.HashMap<java.lang.String,java.sql.PreparedStatement> |
updtStmntMap
the cached
PreparedStatements for primary key based updates |
protected static java.lang.String |
USER |
protected java.lang.String |
userName
user name to use for establishing JDBC connection
|
| Constructor and Description |
|---|
DBSynchronizer() |
| Modifier and Type | Method and Description |
|---|---|
void |
basicClose()
Basic actions to be performed to close the
DBSynchronizer instance
though the instance will itself not be marked as having shut down. |
protected DBSynchronizer.SqlExceptionHandler |
checkExceptionString(java.lang.String message,
DBSynchronizer.SqlExceptionHandler defaultHandler) |
protected DBSynchronizer.SqlExceptionHandler |
checkExceptionType(java.sql.SQLException sqle) |
void |
close()
Close this
DBSynchronizer instance. |
protected void |
closeStatements(java.util.Map<java.lang.String,java.sql.PreparedStatement> psMap) |
protected java.sql.PreparedStatement |
getExecutableDeletePrepStmntPKBased(Event pkEvent,
java.sql.PreparedStatement prevPS)
Get or create a
PreparedStatement for a primary key based delete
operation. |
protected java.sql.PreparedStatement |
getExecutableInsertPrepStmntPKBased(Event pkEvent,
java.sql.PreparedStatement prevPS)
Get or create a
PreparedStatement for an insert operation. |
protected java.sql.PreparedStatement |
getExecutablePrepStmntBulkOp(Event event,
java.sql.PreparedStatement prevPS)
Get or create a
PreparedStatement for a
Event.Type.isBulkOperation() type of operation. |
protected java.sql.PreparedStatement |
getExecutableUpdatePrepStmntPKBased(Event pkEvent,
java.sql.PreparedStatement prevPS)
Get or create a
PreparedStatement for a primary key based update
operation. |
protected DBSynchronizer.SqlExceptionHandler |
handleSQLException(java.sql.SQLException sqle)
Returns an
DBSynchronizer.SqlExceptionHandler for the given SQLException. |
protected DBSynchronizer.SqlExceptionHandler |
handleSQLException(java.sql.SQLException sqle,
java.lang.String format,
java.sql.Statement stmt,
Event event,
java.lang.String eventString,
java.util.logging.Logger logger,
boolean logWarning)
Log exception including stack traces for fine logging with
traceDBSynchronizer, and returns an DBSynchronizer.SqlExceptionHandler
for the given SQLException. |
void |
init(java.lang.String initParamStr)
Initialize this
DBSynchronizer instance, creating a new JDBC
connection to the backend database as per the provided parameter.The recommended format of the parameter string is: file=<path> The file is a properties file specifying the driver, JDBC URL, user and password. Driver=<driver-class> URL=<JDBC URL> User=<user name> Secret=<encrypted password> Transformation=<transformation for the encryption cipher> KeySize=<size of the private key to use for encryption> -- OR -- Password=<password> The password provided in the "Secret" property should be an encrypted one generated using the "gfxd encrypt-password external" command, else the "Password" property can be used to specify the password in plain-text. |
protected void |
initConnection() |
protected void |
inlineInit(java.lang.String initParamStr) |
protected void |
instantiateConnection() |
protected boolean |
isArgPresent(java.lang.String s,
java.lang.String prefix,
java.lang.StringBuilder extracted) |
protected byte |
isJDBC4Driver()
Return
JDBC4DRIVER_TRUE if this driver is known to be JDBC4
compliant for LOB support, JDBC4DRIVER_FALSE if it is known to not
be JDBC4 compliant and JDBC4DRIVER_UNKNOWN if the status is
unknown. |
protected static java.lang.String |
maskPassword(java.lang.String dbUrl)
mask the known password patterns from URL for exception/log messages
|
boolean |
processEvents(java.util.List<Event> events)
Process the list of
Events. |
protected void |
setJDBC4Driver(byte status)
Set the JDBC4 status of this driver as per
isJDBC4Driver(). |
protected void |
setKeysInPrepStatement(java.sql.ResultSet pkValues,
java.sql.ResultSetMetaData pkMetaData,
java.sql.PreparedStatement ps,
int startIndex)
Set the key column values in
PreparedStatement for a primary key
based update or delete operation. |
protected boolean |
skipIdentityColumns()
Returns true if this DBSynchronizer has been configured to skip IDENTITY
column values when syncing to backend database (the default behaviour) and
false if IDENTITY column values from GemFireXD should also be synced
|
void |
start()
This is invoked just prior to starting the async invocation thread for processing the events.
|
protected java.lang.String |
trimIgnoreCase(java.lang.String s,
java.lang.String prefix) |
protected java.lang.String dbUrl
protected java.lang.String userName
protected java.lang.String passwd
protected java.lang.String errorFile
protected int numErrorTries
errorFileprotected static final int DEFAULT_ERROR_TRIES
errorFile is
definedprotected java.lang.String transformation
protected int keySize
protected java.lang.String driverClass
Driver
interfaceprotected java.sql.Driver driver
Driver implementation instance loaded using the
driverClassprotected java.sql.Connection conn
protected static final byte JDBC4DRIVER_UNKNOWN
protected static final byte JDBC4DRIVER_FALSE
protected static final byte JDBC4DRIVER_TRUE
protected volatile boolean shutDown
protected final AsyncEventHelper helper
protected final java.util.logging.Logger logger
protected boolean traceDBSynchronizer
protected boolean traceDBSynchronizerHA
protected final java.util.HashMap<java.lang.String,java.sql.PreparedStatement> insertStmntMap
PreparedStatements for insertsprotected final java.util.HashMap<java.lang.String,java.sql.PreparedStatement> updtStmntMap
PreparedStatements for primary key based updatesprotected final java.util.HashMap<java.lang.String,java.sql.PreparedStatement> deleteStmntMap
PreparedStatements for primary key based deletesprotected final java.util.HashMap<java.lang.String,TableMetaData> metadataMap
protected final java.util.HashMap<java.lang.String,java.sql.ResultSetMetaData> pkMetadataMap
protected final java.util.HashMap<java.lang.String,java.sql.PreparedStatement> bulkOpStmntMap
PreparedStatements for other non-primary key based DML
operationsprotected boolean skipIdentityColumns
protected static final java.lang.String DBDRIVER
protected static final java.lang.String DBURL
protected static final java.lang.String USER
protected static final java.lang.String PASSWORD
protected static final java.lang.String SECRET
protected static final java.lang.String TRANSFORMATION
protected static final java.lang.String KEYSIZE
protected static final java.lang.String ERRORFILE
protected static final java.lang.String ERRORTRIES
protected static final java.lang.String SKIP_IDENTITY_COLUMNS
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__1
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__2
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__3
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__4
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__5
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__6
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__7
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__8
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__9
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__10
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__11
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__12
protected static final java.lang.String Gfxd_DB_SYNCHRONIZER__13
protected final java.util.concurrent.ConcurrentSkipListMap<com.pivotal.gemfirexd.callbacks.DBSynchronizer.ErrorEvent,java.lang.Object[]> errorTriesMap
public void close()
DBSynchronizer instance.
To prevent a possible concurrency issue between closing thread & the
processor thread, access to this method is synchronized on 'this'close in interface AsyncEventListenerpublic final void basicClose()
DBSynchronizer instance
though the instance will itself not be marked as having shut down.
To prevent a possible concurrency issue between closing thread & the
processor thread, access to this method is synchronized on 'this'protected final byte isJDBC4Driver()
JDBC4DRIVER_TRUE if this driver is known to be JDBC4
compliant for LOB support, JDBC4DRIVER_FALSE if it is known to not
be JDBC4 compliant and JDBC4DRIVER_UNKNOWN if the status is
unknown.protected final void setJDBC4Driver(byte status)
isJDBC4Driver().protected void closeStatements(java.util.Map<java.lang.String,java.sql.PreparedStatement> psMap)
public void init(java.lang.String initParamStr)
DBSynchronizer instance, creating a new JDBC
connection to the backend database as per the provided parameter.init in interface AsyncEventListenerinitParamStr - String containing initialisation parameters for the
AsyncEventListenerprotected void inlineInit(java.lang.String initParamStr)
protected boolean isArgPresent(java.lang.String s,
java.lang.String prefix,
java.lang.StringBuilder extracted)
protected java.lang.String trimIgnoreCase(java.lang.String s,
java.lang.String prefix)
protected void initConnection()
protected void instantiateConnection()
protected static final java.lang.String maskPassword(java.lang.String dbUrl)
public boolean processEvents(java.util.List<Event> events)
AsyncEventListenerEvents. This method will be invoked
asynchronously when events are queued for processing. For
AsyncEventListener, the Event.getOldRow() will always return null
indicating that old value is not available. Event.getNewRow() will
return the column values for a row created. For update operations it will
only return meaningful values for modified columns and null for unmodified
columns. The positions of columns modified can be obtained from
Event.getModifiedColumns()processEvents in interface AsyncEventListenerevents - The list of Events to processprotected java.sql.PreparedStatement getExecutablePrepStmntBulkOp(Event event, java.sql.PreparedStatement prevPS) throws java.sql.SQLException
PreparedStatement for a
Event.Type.isBulkOperation() type of operation.java.sql.SQLExceptionprotected java.sql.PreparedStatement getExecutableInsertPrepStmntPKBased(Event pkEvent, java.sql.PreparedStatement prevPS) throws java.sql.SQLException
PreparedStatement for an insert operation.java.sql.SQLExceptionprotected java.sql.PreparedStatement getExecutableDeletePrepStmntPKBased(Event pkEvent, java.sql.PreparedStatement prevPS) throws java.sql.SQLException
PreparedStatement for a primary key based delete
operation.java.sql.SQLExceptionprotected java.sql.PreparedStatement getExecutableUpdatePrepStmntPKBased(Event pkEvent, java.sql.PreparedStatement prevPS) throws java.sql.SQLException
PreparedStatement for a primary key based update
operation.java.sql.SQLExceptionprotected void setKeysInPrepStatement(java.sql.ResultSet pkValues,
java.sql.ResultSetMetaData pkMetaData,
java.sql.PreparedStatement ps,
int startIndex)
throws java.sql.SQLException
PreparedStatement for a primary key
based update or delete operation.java.sql.SQLExceptionprotected DBSynchronizer.SqlExceptionHandler handleSQLException(java.sql.SQLException sqle)
DBSynchronizer.SqlExceptionHandler for the given SQLException.protected DBSynchronizer.SqlExceptionHandler checkExceptionType(java.sql.SQLException sqle)
protected DBSynchronizer.SqlExceptionHandler checkExceptionString(java.lang.String message, DBSynchronizer.SqlExceptionHandler defaultHandler)
protected DBSynchronizer.SqlExceptionHandler handleSQLException(java.sql.SQLException sqle, java.lang.String format, java.sql.Statement stmt, Event event, java.lang.String eventString, java.util.logging.Logger logger, boolean logWarning) throws java.sql.SQLException
traceDBSynchronizer, and returns an DBSynchronizer.SqlExceptionHandler
for the given SQLException.java.sql.SQLExceptionpublic void start()
AsyncEventListenerstart in interface AsyncEventListenerprotected final boolean skipIdentityColumns()
Copyright © 2010-2015 Pivotal Software, Inc. All rights reserved.