annotate artifact-database/src/main/java/org/dive4elements/artifactdatabase/h2/CollectionAccessUpdateTrigger.java @ 570:584591f8203c 3.2.x

Upgrade to Log4j 2
author Tom Gottfried <tom@intevation.de>
date Mon, 28 Feb 2022 17:41:14 +0100
parents 415df0fc4fa1
children
rev   line source
475
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
1 package org.dive4elements.artifactdatabase.h2;
229
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import org.h2.api.Trigger;
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import java.sql.Connection;
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.sql.SQLException;
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 import java.sql.PreparedStatement;
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8
475
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
9 import org.dive4elements.artifactdatabase.DBConfig;
305
f33401ea2a6c Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 233
diff changeset
10
475
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
11 import org.dive4elements.artifactdatabase.db.SQL;
229
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
570
584591f8203c Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 475
diff changeset
13 import org.apache.logging.log4j.Logger;
584591f8203c Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 475
diff changeset
14 import org.apache.logging.log4j.LogManager;
229
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 public class CollectionAccessUpdateTrigger
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 implements Trigger
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 {
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 private static Logger logger =
570
584591f8203c Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 475
diff changeset
20 LogManager.getLogger(CollectionAccessUpdateTrigger.class);
229
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
305
f33401ea2a6c Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 233
diff changeset
22 public String COLLECTIONS_TOUCH_TRIGGER_FUNCTION;
229
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 public void init(
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 Connection conn,
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 String schemaName,
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 String triggerName,
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 String tableName,
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 boolean before,
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 int type
233
16cd059945e5 Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 229
diff changeset
31 )
229
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 throws SQLException {
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 logger.debug("CollectionAccessUpdateTrigger.init");
305
f33401ea2a6c Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 233
diff changeset
34 setupSQL(DBConfig.getInstance().getSQL());
f33401ea2a6c Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 233
diff changeset
35 }
f33401ea2a6c Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 233
diff changeset
36
f33401ea2a6c Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 233
diff changeset
37 protected void setupSQL(SQL sql) {
f33401ea2a6c Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 233
diff changeset
38 COLLECTIONS_TOUCH_TRIGGER_FUNCTION =
f33401ea2a6c Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 233
diff changeset
39 sql.get("collections.touch.trigger.function");
229
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 }
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 public void fire(
233
16cd059945e5 Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 229
diff changeset
43 Connection conn,
229
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 Object [] oldRow,
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 Object [] newRow
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 )
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 throws SQLException {
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 logger.debug("CollectionAccessUpdateTrigger.fire");
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 PreparedStatement stmnt = conn.prepareStatement(
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 COLLECTIONS_TOUCH_TRIGGER_FUNCTION);
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 stmnt.setObject(1, newRow[0]);
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 stmnt.execute();
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 stmnt.close();
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 }
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 public void close() throws SQLException {
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 logger.debug("CollectionAccessUpdateTrigger.close");
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 }
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 public void remove() throws SQLException {
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 logger.debug("CollectionAccessUpdateTrigger.remove");
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 }
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 }
328ef982d768 When an artifact is touched the collections which contain the artifact are touched, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org