01: package com.xoetrope.service.replication.hsqldb;
02:
03: import java.sql.Statement;
04: import net.xoetrope.optional.data.sql.ConnectionObject;
05: import net.xoetrope.optional.data.sql.NamedConnectionManager;
06: import org.hsqldb.Trigger;
07:
08: public class XRemoteDelTrigger implements Trigger {
09: // TODO: should the connection name be obtained from some
10: // configuration file???
11: private static final String CONNECTION_NAME = "default";
12: protected NamedConnectionManager connMgr;
13:
14: public XRemoteDelTrigger() {
15: connMgr = (NamedConnectionManager) NamedConnectionManager
16: .getInstance();
17: }
18:
19: public void fire(int type, String trigName, String tableName,
20: Object[] oldRow, Object[] newRow) {
21: ConnectionObject connObj = null;
22: try {
23: connObj = connMgr.getConnection(CONNECTION_NAME);
24:
25: String sql = "UPDATE XSYSSERVERTIMESTAMPS SET lastDelete=CURRENT_TIMESTAMP, "
26: + "lastUpdate=CURRENT_TIMESTAMP WHERE tableName='"
27: + tableName + "'";
28:
29: Statement stmt = connObj.createStatement();
30: stmt.executeUpdate(sql);
31: } catch (Exception ex) {
32: ex.printStackTrace();
33: throw new RuntimeException(
34: "Error while updating XSYSSERVERTIMESTAMPS table.");
35: } finally {
36: if (connObj != null)
37: connObj.closeStatement();
38: }
39: }
40:
41: }
|