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 XRemoteDeleteTrigger 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 XRemoteDeleteTrigger() {
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:
24: connObj = connMgr.getConnection(CONNECTION_NAME);
25:
26: if (oldRow.length < 3)
27: return;
28: Object pseudoId = oldRow[oldRow.length - 2];
29:
30: String sql = "INSERT INTO XSYSDELETIONS VALUES( '"
31: + tableName + "', " + String.valueOf(pseudoId)
32: + ", CURRENT_TIMESTAMP )";
33:
34: Statement stmt = connObj.createStatement();
35: stmt.executeUpdate(sql);
36: } catch (Exception ex) {
37: ex.printStackTrace();
38: throw new RuntimeException(
39: "Error while inserting data into XSYSDELETIONS table");
40: } finally {
41: if (connObj != null)
42: connObj.closeStatement();
43: }
44: }
45:
46: }
|