public class DBSynchronizer extends 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 HashMap<String,PreparedStatement> |
bulkOpStmntMap
the cached
PreparedStatements for other non-primary key based DML
operations |
protected Connection |
conn
the current JDBC connection being used by this instance
|
protected static String |
DBDRIVER |
protected String |
dbUrl
the JDBC connection URL for the external database
|
protected static String |
DBURL |
protected static int |
DEFAULT_ERROR_TRIES
default number of retries after an error is 3 when
errorFile is
defined |
protected HashMap<String,PreparedStatement> |
deleteStmntMap
the cached
PreparedStatements for primary key based deletes |
protected Driver |
driver
the
Driver implementation instance loaded using the
driverClass |
protected String |
driverClass
fully qualified name of the implementation class of the JDBC
Driver
interface |
protected String |
errorFile
file to write errors
|
protected static String |
ERRORFILE |
protected static String |
ERRORTRIES |
protected ConcurrentSkipListMap<com.pivotal.gemfirexd.callbacks.DBSynchronizer.ErrorEvent,Object[]> |
errorTriesMap
keeps track of the retries that have been done for an event
|
protected static String |
Gfxd_DB_SYNCHRONIZER__1 |
protected static String |
Gfxd_DB_SYNCHRONIZER__10 |
protected static String |
Gfxd_DB_SYNCHRONIZER__11 |
protected static String |
Gfxd_DB_SYNCHRONIZER__12 |
protected static String |
Gfxd_DB_SYNCHRONIZER__13 |
protected static String |
Gfxd_DB_SYNCHRONIZER__2 |
protected static String |
Gfxd_DB_SYNCHRONIZER__3 |
protected static String |
Gfxd_DB_SYNCHRONIZER__4 |
protected static String |
Gfxd_DB_SYNCHRONIZER__5 |
protected static String |
Gfxd_DB_SYNCHRONIZER__6 |
protected static String |
Gfxd_DB_SYNCHRONIZER__7 |
protected static String |
Gfxd_DB_SYNCHRONIZER__8 |
protected static String |
Gfxd_DB_SYNCHRONIZER__9 |
protected AsyncEventHelper |
helper |
protected HashMap<String,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 String |
KEYSIZE |
protected Logger |
logger |
protected HashMap<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 String |
passwd
password for the user to use for establishing JDBC connection
|
protected static String |
PASSWORD |
protected HashMap<String,ResultSetMetaData> |
pkMetadataMap
the map of table name to its current primary key metadata object
|
protected static String |
SECRET |
protected boolean |
shutDown
true if this instance has been closed or not initialized
|
protected static 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 String |
transformation
the transformation (e.g.
|
protected static String |
TRANSFORMATION |
protected HashMap<String,PreparedStatement> |
updtStmntMap
the cached
PreparedStatements for primary key based updates |
protected static String |
USER |
protected 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(String message,
DBSynchronizer.SqlExceptionHandler defaultHandler) |
protected DBSynchronizer.SqlExceptionHandler |
checkExceptionType(SQLException sqle) |
void |
close()
Close this
DBSynchronizer instance. |
protected void |
closeStatements(Map<String,PreparedStatement> psMap) |
protected PreparedStatement |
getExecutableDeletePrepStmntPKBased(Event pkEvent,
PreparedStatement prevPS)
Get or create a
PreparedStatement for a primary key based delete
operation. |
protected PreparedStatement |
getExecutableInsertPrepStmntPKBased(Event pkEvent,
PreparedStatement prevPS)
Get or create a
PreparedStatement for an insert operation. |
protected PreparedStatement |
getExecutablePrepStmntBulkOp(Event event,
PreparedStatement prevPS)
Get or create a
PreparedStatement for a
Event.Type.isBulkOperation() type of operation. |
protected PreparedStatement |
getExecutableUpdatePrepStmntPKBased(Event pkEvent,
PreparedStatement prevPS)
Get or create a
PreparedStatement for a primary key based update
operation. |
protected DBSynchronizer.SqlExceptionHandler |
handleSQLException(SQLException sqle)
Returns an
DBSynchronizer.SqlExceptionHandler for the given SQLException. |
protected DBSynchronizer.SqlExceptionHandler |
handleSQLException(SQLException sqle,
String format,
Statement stmt,
Event event,
String eventString,
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(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(String initParamStr) |
protected void |
instantiateConnection() |
protected boolean |
isArgPresent(String s,
String prefix,
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 String |
maskPassword(String dbUrl)
mask the known password patterns from URL for exception/log messages
|
boolean |
processEvents(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(ResultSet pkValues,
ResultSetMetaData pkMetaData,
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 String |
trimIgnoreCase(String s,
String prefix) |
protected String dbUrl
protected String userName
protected String passwd
protected String errorFile
protected int numErrorTries
errorFileprotected static final int DEFAULT_ERROR_TRIES
errorFile is
definedprotected String transformation
protected int keySize
protected String driverClass
Driver
interfaceprotected Driver driver
Driver implementation instance loaded using the
driverClassprotected 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 Logger logger
protected boolean traceDBSynchronizer
protected boolean traceDBSynchronizerHA
protected final HashMap<String,PreparedStatement> insertStmntMap
PreparedStatements for insertsprotected final HashMap<String,PreparedStatement> updtStmntMap
PreparedStatements for primary key based updatesprotected final HashMap<String,PreparedStatement> deleteStmntMap
PreparedStatements for primary key based deletesprotected final HashMap<String,TableMetaData> metadataMap
protected final HashMap<String,ResultSetMetaData> pkMetadataMap
protected final HashMap<String,PreparedStatement> bulkOpStmntMap
PreparedStatements for other non-primary key based DML
operationsprotected boolean skipIdentityColumns
protected static final String DBDRIVER
protected static final String DBURL
protected static final String USER
protected static final String PASSWORD
protected static final String SECRET
protected static final String TRANSFORMATION
protected static final String KEYSIZE
protected static final String ERRORFILE
protected static final String ERRORTRIES
protected static final String SKIP_IDENTITY_COLUMNS
protected static final String Gfxd_DB_SYNCHRONIZER__1
protected static final String Gfxd_DB_SYNCHRONIZER__2
protected static final String Gfxd_DB_SYNCHRONIZER__3
protected static final String Gfxd_DB_SYNCHRONIZER__4
protected static final String Gfxd_DB_SYNCHRONIZER__5
protected static final String Gfxd_DB_SYNCHRONIZER__6
protected static final String Gfxd_DB_SYNCHRONIZER__7
protected static final String Gfxd_DB_SYNCHRONIZER__8
protected static final String Gfxd_DB_SYNCHRONIZER__9
protected static final String Gfxd_DB_SYNCHRONIZER__10
protected static final String Gfxd_DB_SYNCHRONIZER__11
protected static final String Gfxd_DB_SYNCHRONIZER__12
protected static final String Gfxd_DB_SYNCHRONIZER__13
protected final ConcurrentSkipListMap<com.pivotal.gemfirexd.callbacks.DBSynchronizer.ErrorEvent,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(Map<String,PreparedStatement> psMap)
public void init(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(String initParamStr)
protected boolean isArgPresent(String s, String prefix, StringBuilder extracted)
protected void initConnection()
protected void instantiateConnection()
protected static final String maskPassword(String dbUrl)
public boolean processEvents(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 PreparedStatement getExecutablePrepStmntBulkOp(Event event, PreparedStatement prevPS) throws SQLException
PreparedStatement for a
Event.Type.isBulkOperation() type of operation.SQLExceptionprotected PreparedStatement getExecutableInsertPrepStmntPKBased(Event pkEvent, PreparedStatement prevPS) throws SQLException
PreparedStatement for an insert operation.SQLExceptionprotected PreparedStatement getExecutableDeletePrepStmntPKBased(Event pkEvent, PreparedStatement prevPS) throws SQLException
PreparedStatement for a primary key based delete
operation.SQLExceptionprotected PreparedStatement getExecutableUpdatePrepStmntPKBased(Event pkEvent, PreparedStatement prevPS) throws SQLException
PreparedStatement for a primary key based update
operation.SQLExceptionprotected void setKeysInPrepStatement(ResultSet pkValues, ResultSetMetaData pkMetaData, PreparedStatement ps, int startIndex) throws SQLException
PreparedStatement for a primary key
based update or delete operation.SQLExceptionprotected DBSynchronizer.SqlExceptionHandler handleSQLException(SQLException sqle)
DBSynchronizer.SqlExceptionHandler for the given SQLException.protected DBSynchronizer.SqlExceptionHandler checkExceptionType(SQLException sqle)
protected DBSynchronizer.SqlExceptionHandler checkExceptionString(String message, DBSynchronizer.SqlExceptionHandler defaultHandler)
protected DBSynchronizer.SqlExceptionHandler handleSQLException(SQLException sqle, String format, Statement stmt, Event event, String eventString, Logger logger, boolean logWarning) throws SQLException
traceDBSynchronizer, and returns an DBSynchronizer.SqlExceptionHandler
for the given SQLException.SQLExceptionpublic void start()
AsyncEventListenerstart in interface AsyncEventListenerprotected final boolean skipIdentityColumns()
Copyright © 2010-2015 Pivotal Software, Inc. All rights reserved.