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 XLocalDeleteTrigger implements Trigger {
09: private static final String CONNECTION_NAME = "default";
10: protected NamedConnectionManager connMgr;
11:
12: public XLocalDeleteTrigger() {
13: connMgr = (NamedConnectionManager) NamedConnectionManager
14: .getInstance();
15: }
16:
17: public void fire(int type, String trigName, String tableName,
18: Object[] oldRow, Object[] newRow) {
19: ConnectionObject connObj = null;
20: try {
21: connObj = connMgr.getConnection(CONNECTION_NAME);
22:
23: if (oldRow.length < 3)
24: return;
25: Object pseudoId = oldRow[oldRow.length - 2];
26:
27: String sql = ("INSERT INTO xSysLocalDeletions (tableName,pseudoId,deleteDate) VALUES('"
28: + tableName + "', " + pseudoId.toString() + ", CURRENT_TIMESTAMP)");
29:
30: Statement stmt = connObj.createStatement();
31: stmt.executeUpdate(sql);
32: } catch (Exception ex) {
33: ex.printStackTrace();
34: throw new RuntimeException(
35: "Error while inserting data into xSysLocalDeletions");
36: } finally {
37: if (connObj != null)
38: connObj.closeStatement();
39: }
40: }
41:
42: }
|