LogDBHelperpublic class LogDBHelper extends Object The LogDBHelper class takes care of writing the transaction logs
into database. |
Fields Summary |
---|
String | resName | DataSource | ds | Method | getNonTxConnectionMethod | static final String | insertStatement | static final String | deleteStatement | static final String | selectStatement | static Logger | _logger | static LogDBHelper | _instance |
Constructors Summary |
---|
LogDBHelper()
if (Configuration.getPropertyValue(Configuration.DB_LOG_RESOURCE) != null) {
resName = Configuration.getPropertyValue(Configuration.DB_LOG_RESOURCE);
}
try {
InitialContext ctx = new InitialContext();
ds = (DataSource)ctx.lookup(resName);
Class cls = ds.getClass();
getNonTxConnectionMethod = cls.getMethod("getNonTxConnection", null);
} catch (Throwable t) {
_logger.log(Level.SEVERE,"jts.unconfigured_db_log_resource",resName);
_logger.log(Level.SEVERE,t.getLocalizedMessage(),t);
}
|
Methods Summary |
---|
boolean | addRecord(long localTID, byte[] data)
if (ds != null) {
Connection conn = null;
PreparedStatement prepStmt1 = null;
try {
conn = ds.getConnection();
prepStmt1 = conn.prepareStatement(insertStatement);
prepStmt1.setLong(1,localTID);
prepStmt1.setString(2,Configuration.getServerName());
prepStmt1.setBytes(3,data);
prepStmt1 .executeUpdate();
return true;
} catch (Throwable ex) {
_logger.log(Level.SEVERE,"jts.exception_in_db_log_resource",ex);
return false;
} finally {
try {
if (prepStmt1 != null)
prepStmt1.close();
if (conn != null)
conn.close();
} catch (Exception ex1) {
_logger.log(Level.SEVERE,"jts.exception_in_db_log_resource",ex1);
}
}
}
return false;
| boolean | deleteRecord(long localTID)
if (ds != null) {
Connection conn = null;
PreparedStatement prepStmt1 = null;
try {
// To avoid compile time dependency to get NonTxConnection
conn = (Connection)(getNonTxConnectionMethod.invoke(ds, null));
prepStmt1 = conn.prepareStatement(deleteStatement);
prepStmt1.setLong(1,localTID);
prepStmt1.setString(2,Configuration.getServerName());
prepStmt1 .executeUpdate();
return true;
} catch (Exception ex) {
_logger.log(Level.SEVERE,"jts.exception_in_db_log_resource",ex);
return false;
} finally {
try {
if (prepStmt1 != null)
prepStmt1.close();
if (conn != null)
conn.close();
} catch (Exception ex1) {
_logger.log(Level.SEVERE,"jts.exception_in_db_log_resource",ex1);
}
}
}
return false;
| java.util.Map | getGlobalTIDMap()
Map gtidMap = new HashMap();
if (ds != null) {
Connection conn = null;
PreparedStatement prepStmt1 = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
prepStmt1 = conn.prepareStatement(selectStatement);
prepStmt1.setString(1,Configuration.getServerName());
rs = prepStmt1.executeQuery();
while (rs.next()) {
Long localTID = new Long(rs.getLong(1));
byte[] gtridbytes = rs.getBytes(3);
gtidMap.put(GlobalTID.fromTIDBytes(rs.getBytes(3)), localTID);
}
} catch (Exception ex) {
_logger.log(Level.SEVERE,"jts.exception_in_db_log_resource",ex);
} finally {
try {
if (rs != null)
rs.close();
if (prepStmt1 != null)
prepStmt1.close();
if (conn != null)
conn.close();
} catch (Exception ex1) {
_logger.log(Level.SEVERE,"jts.exception_in_db_log_resource",ex1);
}
}
}
return gtidMap;
| static com.sun.jts.CosTransactions.LogDBHelper | getInstance()
return _instance;
|
|