01: package com.xoetrope.service.replication.hsqldb;
02:
03: import com.xoetrope.carousel.build.BuildProperties;
04: import net.xoetrope.debug.DebugLogger;
05:
06: /**
07: * A service proxy to support replication of data to a client side database.
08: * This object must be setup as an application object if used in a servlet
09: * context. If a call for more data is made and the context of a previous
10: * request cannot be found then an exception will be thrown.
11: *
12: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
13: * the GNU Public License (GPL), please see license.txt for more details. If
14: * you make commercial use of this software you must purchase a commercial
15: * license from Xoetrope.</p>
16: * <p> $Revision: 1.14 $</p>
17: */
18: public class XHsqlReplicationService extends
19: com.xoetrope.service.XReplicationService {
20: /**
21: * Creates a new instance of XHsqlReplicationSerivce
22: */
23: public XHsqlReplicationService() {
24: super ();
25: }
26:
27: /**
28: * Creates the timestamps tables
29: */
30: protected void setupTimestampTables() {
31: doUpdate("CREATE TABLE XSYSSERVERTIMESTAMPS (tableName VARCHAR(64), lastUpdate TIMESTAMP, lastDelete TIMESTAMP)");
32: doUpdate("CREATE TABLE XSYSDELETIONS (tableName VARCHAR(64), pseudoId INT, deleteDate TIMESTAMP)");
33: doUpdate("CREATE TABLE XSYSNEXTIDS( TABLENAME VARCHAR(64), FIELDNAME VARCHAR(64), NEXTID INT, MODE INT )");
34: }
35:
36: /**
37: * Add the required PseudoId column and Timestamp column to the named table.
38: * @param tableName the table to tag.
39: */
40: protected void tagTable(String tableName) {
41: try {
42: doUpdate("ALTER TABLE "
43: + tableName
44: + " ADD COLUMN PseudoId INT GENERATED BY DEFAULT AS IDENTITY");
45: doUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
46: + tableName + "_ts TIMESTAMP");
47: doUpdate("UPDATE " + tableName + " SET " + tableName
48: + "_ts=CURRENT_TIMESTAMP");
49:
50: // Triggers
51: doUpdate("CREATE TRIGGER "
52: + tableName
53: + "_updTrigger AFTER UPDATE ON "
54: + tableName
55: + " FOR EACH ROW CALL \"com.xoetrope.service.replication.hsqldb.XRemoteUpdateTrigger\"");
56:
57: doUpdate("CREATE TRIGGER "
58: + tableName
59: + "_insTrigger AFTER INSERT ON "
60: + tableName
61: + " FOR EACH ROW CALL \"com.xoetrope.service.replication.hsqldb.XRemoteInsertTrigger\"");
62:
63: doUpdate("CREATE TRIGGER "
64: + tableName
65: + "_delTrigger AFTER DELETE ON "
66: + tableName
67: + " FOR EACH ROW CALL \"com.xoetrope.service.replication.hsqldb.XRemoteDelTrigger\"");
68:
69: doUpdate("CREATE TRIGGER "
70: + tableName
71: + "_deleteTrigger AFTER DELETE ON "
72: + tableName
73: + " FOR EACH ROW CALL \"com.xoetrope.service.replication.hsqldb.XRemoteDeleteTrigger\"");
74:
75: } catch (Exception ex) {
76: if (BuildProperties.DEBUG)
77: DebugLogger.logError("Error tagging table: "
78: + tableName);
79: }
80: }
81:
82: }
|