annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java @ 5796:53cff50918b1

Fix other buildings. Previously there was one level to many so that for each building a new folder was created
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 23 Apr 2013 18:47:57 +0200
parents cbe2febe30cc
children
rev   line source
982
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.datacage;
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
3 import java.util.Collection;
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
4 import java.util.List;
1024
ba88157c6aa3 Make it compilable again (BackendListener interface changed).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1010
diff changeset
5 import java.util.Date;
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
6
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
7 import java.sql.SQLException;
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
8 import java.sql.PreparedStatement;
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
9 import java.sql.Types;
1025
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
10 import java.sql.Timestamp;
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
11
982
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import de.intevation.artifacts.GlobalContext;
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
13 import de.intevation.artifacts.ArtifactCollection;
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
14 import de.intevation.artifacts.User;
982
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
983
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 982
diff changeset
16 import de.intevation.artifactdatabase.db.SQL;
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 982
diff changeset
17 import de.intevation.artifactdatabase.db.SQLExecutor;
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 982
diff changeset
18
982
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 import de.intevation.artifactdatabase.LifetimeListener;
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
20 import de.intevation.artifactdatabase.Backend;
982
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
22 import de.intevation.artifactdatabase.data.StateData;
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
23
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
24 import de.intevation.artifactdatabase.state.Output;
992
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
25 import de.intevation.artifactdatabase.state.Facet;
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
26
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
27 import de.intevation.artifacts.Artifact;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
28 import de.intevation.artifacts.ArtifactDatabase;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
29 import de.intevation.artifacts.ArtifactDatabaseException;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
30
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
31 import de.intevation.flys.artifacts.FLYSArtifact;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
32
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
33 import de.intevation.artifacts.common.utils.LRUCache;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
34
982
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 import org.apache.log4j.Logger;
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 import org.w3c.dom.Document;
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 public class Datacage
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
40 implements LifetimeListener
982
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 {
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 private static Logger log = Logger.getLogger(Datacage.class);
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
44 public static final String DATACAGE_KEY =
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
45 "global.datacage.instance";
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
46
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
47 public static final String ARTEFACT_DATABASE_KEY =
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
48 "global.artifact.database";
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
49
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
50 private String SQL_DELETE_ALL_USERS = "delete.all.users";
996
f61fe8b561d2 Datacage: delete artifacts at initial scan, too. Fixed problem with writing content of state data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 995
diff changeset
51 private String SQL_DELETE_ALL_ARTIFACTS = "delete.all.artifacts";
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
52 private String SQL_USER_ID_NEXTVAL = "user.id.nextval";
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
53 private String SQL_USER_BY_GID = "user.by.gid";
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
54 private String SQL_INSERT_USER = "insert.user";
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
55 private String SQL_COLLECTION_BY_GID = "collection.by.gid";
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
56 private String SQL_COLLECTION_ID_NEXTVAL = "collection.id.nextval";
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
57 private String SQL_INSERT_COLLECTION = "insert.collection";
988
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
58 private String SQL_ARTIFACT_BY_GID = "artifact.by.gid";
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
59 private String SQL_COLLECTION_ITEM_ID_NEXTVAL =
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
60 "collection.item.id.nextval";
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
61 private String SQL_INSERT_COLLECTION_ITEM = "insert.collection.item";
989
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
62 private String SQL_ARTIFACT_ID_NEXTVAL = "artifact.id.nextval";
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
63 private String SQL_INSERT_ARTIFACT = "insert.artifact";
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
64 private String SQL_ARTIFACT_DATA_ID_NEXTVAL = "artifact.data.id.nextval";
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
65 private String SQL_INSERT_ARTIFACT_DATA = "insert.artifact.data";
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
66 private String SQL_OUT_ID_NEXTVALUE = "out.id.nextval";
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
67 private String SQL_INSERT_OUT = "insert.out";
992
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
68 private String SQL_FACET_ID_NEXTVAL = "facet.id.nextval";
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
69 private String SQL_INSERT_FACET = "insert.facet";
1003
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
70 private String SQL_UPDATE_COLLECTION_NAME = "update.collection.name";
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
71 private String SQL_DELETE_ARTIFACT_FROM_COLLECTION =
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
72 "delete.artifact.from.collection";
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
73 private String SQL_DELETE_COLLECTION_BY_GID =
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
74 "delete.collection.by.gid";
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
75 private String SQL_DELETE_USER_BY_GID = "delete.user.by.gid";
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
76 private String SQL_DELETE_ARTIFACT_DATA_BY_ARTIFACT_ID =
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
77 "delete.artifact.data.by.artifact.id";
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
78 private String SQL_DELETE_OUTS_BY_ARTIFACT_ID =
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
79 "delete.outs.by.artifact.id";
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
80 private String SQL_DELETE_FACETS_BY_ARTIFACT_ID =
1008
6268009e177d Datacage: fixed wrong SQL references
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1007
diff changeset
81 "delete.facets.by.artifact.id";
1006
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
82 private String SQL_DELETE_ARTIFACT_BY_GID =
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
83 "delete.artifact.by.gid";
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
84
983
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 982
diff changeset
85 protected SQLExecutor sqlExecutor;
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 982
diff changeset
86
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1624
diff changeset
87 public class InitialScan
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
88 implements ArtifactDatabase.ArtifactLoadedCallback
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
89 {
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
90 protected LRUCache<String, Integer> users;
986
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
91 protected LRUCache<String, Integer> collections;
988
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
92 protected LRUCache<String, Integer> artifacts;
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
93
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
94 protected GlobalContext context;
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
95
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
96 public InitialScan() {
986
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
97 users = new LRUCache<String, Integer>();
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
98 collections = new LRUCache<String, Integer>();
988
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
99 artifacts = new LRUCache<String, Integer>();
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
100 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
101
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
102 public InitialScan(GlobalContext context) {
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
103 this();
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
104 this.context = context;
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
105 }
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
106
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
107 @Override
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
108 public void artifactLoaded(
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
109 String userId,
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
110 String collectionId,
1009
fc5fca0c33b3 Datacage: Set the name of the collections at initial scan, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1008
diff changeset
111 String collectionName,
1024
ba88157c6aa3 Make it compilable again (BackendListener interface changed).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1010
diff changeset
112 Date collectionCreated,
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
113 String artifactId,
1024
ba88157c6aa3 Make it compilable again (BackendListener interface changed).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1010
diff changeset
114 Date artifactCreated,
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
115 Artifact artifact
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
116 ) {
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
117 if (!(artifact instanceof FLYSArtifact)) {
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
118 log.warn("ignoring none FLYS artifacts");
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
119 return;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
120 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
121
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
122 FLYSArtifact flysArtifact = (FLYSArtifact)artifact;
986
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
123
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
124 Integer uId = getUserId(userId);
1025
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
125 Integer cId = getCollectionId(
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
126 collectionId, uId, collectionName, collectionCreated);
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
127
1025
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
128 storeArtifact(artifactId, cId, flysArtifact, artifactCreated);
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
129 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
130
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
131 protected Integer getId(
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
132 LRUCache<String, Integer> cache,
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
133 final String idString,
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
134 final String selectById
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
135 ) {
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
136 Integer id = cache.get(idString);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
137 if (id != null) {
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
138 return id;
986
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
139 }
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
140
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
141 final Integer [] res = new Integer[1];
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
142
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
143 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
144 @Override
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
145 public boolean doIt() throws SQLException {
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
146 prepareStatement(selectById);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
147 stmnt.setString(1, idString);
986
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
148 result = stmnt.executeQuery();
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
149 if (!result.next()) {
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
150 return false;
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
151 }
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
152 res[0] = result.getInt(1);
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
153 return true;
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
154 }
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
155 };
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
156
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
157 if (exec.runRead()) {
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
158 cache.put(idString, res[0]);
986
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
159 return res[0];
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
160 }
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
161
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
162 return null;
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
163 }
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
164
988
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
165 protected void storeArtifact(
989
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
166 final String artifactId,
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
167 Integer collectionId,
1025
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
168 final FLYSArtifact artifact,
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
169 final Date artifactCreated
988
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
170 ) {
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
171 Integer aId = getId(artifacts, artifactId, SQL_ARTIFACT_BY_GID);
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
172
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
173 if (aId != null) {
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
174 // We've already stored it. Just create the collection item.
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
175 storeCollectionItem(collectionId, aId);
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
176 return;
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
177 }
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
178 // We need to write it to database
989
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
179
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
180 final Integer [] res = new Integer[1];
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
181
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
182 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
183 @Override
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
184 public boolean doIt() throws SQLException {
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
185 prepareStatement(SQL_ARTIFACT_ID_NEXTVAL);
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
186 result = stmnt.executeQuery();
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
187 if (!result.next()) {
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
188 return false;
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
189 }
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
190 res[0] = result.getInt(1);
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
191 reset();
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
192 prepareStatement(SQL_INSERT_ARTIFACT);
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
193 stmnt.setInt (1, res[0]);
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
194 stmnt.setString(2, artifactId);
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
195 stmnt.setString(3, artifact.getCurrentStateId());
1025
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
196 Timestamp timestamp = new Timestamp(artifactCreated != null
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
197 ? artifactCreated.getTime()
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
198 : System.currentTimeMillis());
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
199 stmnt.setTimestamp(4, timestamp);
989
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
200 stmnt.execute();
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
201 conn.commit();
989
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
202 return true;
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
203 }
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
204 };
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
205
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
206 if (!exec.runWrite()) {
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
207 log.error("storing of artifact failed.");
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
208 return;
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
209 }
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
210
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
211 artifacts.put(artifactId, aId = res[0]);
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
212
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
213 storeCollectionItem(collectionId, aId);
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
214
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
215 storeData(aId, artifact);
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
216
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
217 storeOuts(aId, artifact, context);
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
218 }
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
219
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
220
988
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
221 protected void storeCollectionItem(
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
222 final Integer collectionId,
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
223 final Integer artifactId
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
224 ) {
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
225 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
226 @Override
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
227 public boolean doIt() throws SQLException {
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
228 prepareStatement(SQL_COLLECTION_ITEM_ID_NEXTVAL);
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
229 result = stmnt.executeQuery();
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
230 if (!result.next()) {
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
231 return false;
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
232 }
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
233 int ciId = result.getInt(1);
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
234 reset();
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
235 prepareStatement(SQL_INSERT_COLLECTION_ITEM);
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
236 stmnt.setInt(1, ciId);
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
237 stmnt.setInt(2, collectionId);
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
238 stmnt.setInt(3, artifactId);
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
239 stmnt.execute();
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
240 conn.commit();
988
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
241 return true;
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
242 }
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
243 };
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
244
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
245 if (!exec.runWrite()) {
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
246 log.error("storing of collection item failed.");
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
247 }
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
248 }
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
249
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
250 protected Integer getCollectionId(
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
251 final String collectionId,
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
252 final Integer ownerId,
1025
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
253 final String collectionName,
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
254 final Date collectionCreated
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
255 ) {
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
256 Integer c = getId(collections, collectionId, SQL_COLLECTION_BY_GID);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
257
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
258 if (c != null) {
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
259 return c;
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
260 }
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
261
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
262 final Integer [] res = new Integer[1];
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
263
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
264 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
265 @Override
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
266 public boolean doIt() throws SQLException {
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
267 prepareStatement(SQL_COLLECTION_ID_NEXTVAL);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
268 result = stmnt.executeQuery();
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
269 if (!result.next()) {
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
270 return false;
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
271 }
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
272 res[0] = result.getInt(1);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
273 reset();
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
274 prepareStatement(SQL_INSERT_COLLECTION);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
275 stmnt.setInt (1, res[0]);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
276 stmnt.setString(2, collectionId);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
277 stmnt.setInt (3, ownerId);
1009
fc5fca0c33b3 Datacage: Set the name of the collections at initial scan, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1008
diff changeset
278 setString(stmnt, 4, collectionName);
1025
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
279 Timestamp timestamp = new Timestamp(collectionCreated != null
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
280 ? collectionCreated.getTime()
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
281 : System.currentTimeMillis());
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
282 stmnt.setTimestamp(5, timestamp);
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
283 stmnt.execute();
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
284 conn.commit();
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
285 return true;
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
286 }
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
287 };
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
288
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
289 if (exec.runWrite()) {
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
290 collections.put(collectionId, res[0]);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
291 return res[0];
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
292 }
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
293
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
294 return null;
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
295 }
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
296
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
297 protected Integer getUserId(final String userId) {
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
298
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
299 Integer u = getId(users, userId, SQL_USER_BY_GID);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
300
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
301 if (u != null) {
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
302 return u;
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
303 }
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
304
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
305 final Integer [] res = new Integer[1];
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
306
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
307 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
986
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
308 @Override
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
309 public boolean doIt() throws SQLException {
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
310 prepareStatement(SQL_USER_ID_NEXTVAL);
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
311 result = stmnt.executeQuery();
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
312 if (!result.next()) {
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
313 return false;
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
314 }
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
315 res[0] = result.getInt(1);
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
316 reset();
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
317 prepareStatement(SQL_INSERT_USER);
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
318 stmnt.setInt (1, res[0]);
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
319 stmnt.setString(2, userId);
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
320 stmnt.execute();
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
321 conn.commit();
986
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
322 return true;
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
323 }
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
324 };
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
325
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
326 if (exec.runWrite()) {
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
327 users.put(userId, res[0]);
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
328 return res[0];
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
329 }
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
330
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
331 return null;
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
332 }
70545233f8ee Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 984
diff changeset
333
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
334 public boolean scan(ArtifactDatabase adb) {
993
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
335 log.debug("scan");
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
336 try {
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
337 adb.loadAllArtifacts(this);
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
338 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
339 catch (ArtifactDatabaseException ade) {
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
340 log.error(ade);
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
341 return false;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
342 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
343 return true;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
344 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
345 } // class InitialScan
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
346
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
347
982
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
348 public Datacage() {
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
349 }
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
350
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
351 @Override
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
352 public void setup(Document document) {
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
353 log.debug("setup");
983
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 982
diff changeset
354 DBConfig config = DBConfig.getInstance();
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 982
diff changeset
355 setupSQL(config.getSQL());
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 982
diff changeset
356 sqlExecutor = new SQLExecutor(config.getDBConnection());
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 982
diff changeset
357 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 982
diff changeset
358
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 982
diff changeset
359 protected void setupSQL(SQL sql) {
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
360 SQL_DELETE_ALL_USERS = sql.get(SQL_DELETE_ALL_USERS);
996
f61fe8b561d2 Datacage: delete artifacts at initial scan, too. Fixed problem with writing content of state data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 995
diff changeset
361 SQL_DELETE_ALL_ARTIFACTS = sql.get(SQL_DELETE_ALL_ARTIFACTS);
987
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
362 SQL_USER_ID_NEXTVAL = sql.get(SQL_USER_ID_NEXTVAL);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
363 SQL_USER_BY_GID = sql.get(SQL_USER_BY_GID);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
364 SQL_INSERT_USER = sql.get(SQL_INSERT_USER);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
365 SQL_COLLECTION_BY_GID = sql.get(SQL_COLLECTION_BY_GID);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
366 SQL_COLLECTION_ID_NEXTVAL = sql.get(SQL_COLLECTION_ID_NEXTVAL);
82ef338fee91 Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 986
diff changeset
367 SQL_INSERT_COLLECTION = sql.get(SQL_INSERT_COLLECTION);
988
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
368 SQL_ARTIFACT_BY_GID = sql.get(SQL_ARTIFACT_BY_GID);
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
369 SQL_COLLECTION_ITEM_ID_NEXTVAL =
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
370 sql.get(SQL_COLLECTION_ITEM_ID_NEXTVAL);
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
371 SQL_INSERT_COLLECTION_ITEM =
dbe39e1fb5e7 Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 987
diff changeset
372 sql.get(SQL_INSERT_COLLECTION_ITEM);
989
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
373 SQL_ARTIFACT_ID_NEXTVAL = sql.get(SQL_ARTIFACT_ID_NEXTVAL);
f3be883325ce Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
374 SQL_INSERT_ARTIFACT = sql.get(SQL_INSERT_ARTIFACT);
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
375 SQL_ARTIFACT_DATA_ID_NEXTVAL = sql.get(SQL_ARTIFACT_DATA_ID_NEXTVAL);
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
376 SQL_INSERT_ARTIFACT_DATA = sql.get(SQL_INSERT_ARTIFACT_DATA);
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
377 SQL_OUT_ID_NEXTVALUE = sql.get(SQL_OUT_ID_NEXTVALUE);
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
378 SQL_INSERT_OUT = sql.get(SQL_INSERT_OUT);
992
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
379 SQL_FACET_ID_NEXTVAL = sql.get(SQL_FACET_ID_NEXTVAL);
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
380 SQL_INSERT_FACET = sql.get(SQL_INSERT_FACET);
1003
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
381 SQL_UPDATE_COLLECTION_NAME = sql.get(SQL_UPDATE_COLLECTION_NAME);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
382 SQL_DELETE_ARTIFACT_FROM_COLLECTION =
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
383 sql.get(SQL_DELETE_ARTIFACT_FROM_COLLECTION);
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
384 SQL_DELETE_COLLECTION_BY_GID = sql.get(SQL_DELETE_COLLECTION_BY_GID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
385 SQL_DELETE_USER_BY_GID = sql.get(SQL_DELETE_USER_BY_GID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
386 SQL_DELETE_ARTIFACT_DATA_BY_ARTIFACT_ID =
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
387 sql.get(SQL_DELETE_ARTIFACT_DATA_BY_ARTIFACT_ID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
388 SQL_DELETE_OUTS_BY_ARTIFACT_ID =
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
389 sql.get(SQL_DELETE_OUTS_BY_ARTIFACT_ID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
390 SQL_DELETE_FACETS_BY_ARTIFACT_ID =
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
391 sql.get(SQL_DELETE_FACETS_BY_ARTIFACT_ID);
1010
d419c9904825 Datacage: Forgot to fetch dialect dependent SQL statement for deleting artifacts by uuid.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1009
diff changeset
392 SQL_DELETE_ARTIFACT_BY_GID =
d419c9904825 Datacage: Forgot to fetch dialect dependent SQL statement for deleting artifacts by uuid.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1009
diff changeset
393 sql.get(SQL_DELETE_ARTIFACT_BY_GID);
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
394 }
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
395
992
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
396 protected static final int numFacets(List<Output> outs) {
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
397 int sum = 0;
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
398 for (Output out: outs) {
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
399 sum += out.getFacets().size();
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
400 }
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
401 return sum;
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
402 }
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
403
5b467bc27eda Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
404 protected static final void setString(
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1624
diff changeset
405 PreparedStatement stmnt,
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
406 int index,
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
407 Object value
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1624
diff changeset
408 )
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
409 throws SQLException
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
410 {
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
411 if (value == null) {
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
412 stmnt.setNull(index, Types.VARCHAR);
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
413 }
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
414 else {
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
415 stmnt.setString(index, value.toString());
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
416 }
982
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
417 }
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
418
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
419 @Override
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
420 public void systemUp(GlobalContext context) {
993
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
421 log.debug("systemUp entered");
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
422 initialScan(context);
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
423 context.put(DATACAGE_KEY, this);
993
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
424 log.debug("systemUp leaved");
982
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
425 }
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
426
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
427 protected void initialScan(GlobalContext context) {
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
428 log.debug("initialScan");
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
429
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
430 Object adbObject = context.get(ARTEFACT_DATABASE_KEY);
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
431
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
432 if (!(adbObject instanceof ArtifactDatabase)) {
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
433 log.error("missing artefact database. Cannot scan");
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
434 return;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
435 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
436
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
437 ArtifactDatabase adb = (ArtifactDatabase)adbObject;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
438
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
439 if (!cleanDatabase()) {
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
440 log.error("cleaning database failed");
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
441 return;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
442 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
443
991
c675b4a87201 Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 990
diff changeset
444 InitialScan is = new InitialScan(context);
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
445
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
446 if (!is.scan(adb)) {
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
447 log.error("initial scan failed");
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
448 return;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
449 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
450
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
451 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
452
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
453 protected boolean cleanDatabase() {
993
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
454 log.debug("cleanDatabase");
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
455
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
456 boolean success = sqlExecutor.new Instance() {
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
457 @Override
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
458 public boolean doIt() throws SQLException {
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
459 prepareStatement(SQL_DELETE_ALL_USERS);
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
460 stmnt.execute();
996
f61fe8b561d2 Datacage: delete artifacts at initial scan, too. Fixed problem with writing content of state data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 995
diff changeset
461 prepareStatement(SQL_DELETE_ALL_ARTIFACTS);
f61fe8b561d2 Datacage: delete artifacts at initial scan, too. Fixed problem with writing content of state data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 995
diff changeset
462 stmnt.execute();
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
463 conn.commit();
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
464 return true;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
465 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
466 }.runWrite();
993
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
467
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
468 log.debug("after runWrite(): " + success);
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
469
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
470 return success;
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
471 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
472
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
473
982
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
474 @Override
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
475 public void systemDown(GlobalContext context) {
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
476 log.debug("systemDown");
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
477 }
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
478
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
479 public void setup(GlobalContext globalContext) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
480 log.debug("setup");
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
481 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
482
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
483 public void createdArtifact(
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1624
diff changeset
484 Artifact artifact,
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
485 Backend backend,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
486 GlobalContext context
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
487 ) {
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
488 log.debug("createdArtifact");
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
489
1624
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
490 if (artifact == null) {
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
491 log.warn("artifact to create is null");
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
492 return;
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
493 }
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
494
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
495 if (!(artifact instanceof FLYSArtifact)) {
1624
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
496 log.warn("need FLYSArtifact here (have " + artifact.getClass() + ")");
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
497 return;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
498 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
499
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
500 final FLYSArtifact flys = (FLYSArtifact)artifact;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
501
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
502 final int [] res = new int[1];
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
503
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
504 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
505 @Override
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
506 public boolean doIt() throws SQLException {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
507 prepareStatement(SQL_ARTIFACT_ID_NEXTVAL);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
508 result = stmnt.executeQuery();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
509 if (!result.next()) {
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
510 log.error("id generation for artifact failed");
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
511 return false;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
512 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
513 res[0] = result.getInt(1);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
514 reset();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
515 prepareStatement(SQL_INSERT_ARTIFACT);
1025
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
516 stmnt.setInt (1, res[0]);
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
517 stmnt.setString (2, flys.identifier());
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
518 stmnt.setString (3, flys.getCurrentStateId());
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
519 stmnt.setTimestamp(4,
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
520 new Timestamp(System.currentTimeMillis()));
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
521 stmnt.execute();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
522 conn.commit();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
523 return true;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
524 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
525 };
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
526
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
527 if (!exec.runWrite()) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
528 log.error("storing of artifact failed.");
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
529 return;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
530 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
531
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
532 storeData(res[0], flys);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
533 storeOuts(res[0], flys, context);
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
534 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
535
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
536 public void storedArtifact(
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
537 Artifact artifact,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
538 Backend backend,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
539 GlobalContext context
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
540 ) {
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
541 log.debug("storedArtifact");
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
542 if (!(artifact instanceof FLYSArtifact)) {
1624
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
543 log.warn("need FLYSArtifact here but have a " + artifact.getClass());
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
544 return;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
545 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
546
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
547 final FLYSArtifact flys = (FLYSArtifact)artifact;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
548
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
549 final Integer [] res = new Integer[1];
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
550
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
551 // check first if artifact already exists
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
552 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
553 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
554 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
555 prepareStatement(SQL_ARTIFACT_BY_GID);
1007
ed918497873b Datacage: Fixed two NPEs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1006
diff changeset
556 stmnt.setString(1, flys.identifier());
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
557 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
558 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
559 // new artifact
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
560 return true;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
561 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
562 res[0] = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
563 return true;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
564 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
565 };
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
566
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
567 if (!exec.runRead()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
568 log.error("querying artifact failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
569 return;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
570 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
571
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
572 if (res[0] == null) { // new artifact
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
573 createdArtifact(artifact, backend, context);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
574 return;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
575 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
576
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
577 // artifact already exists -> delete old data
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
578 exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
579 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
580 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
581 prepareStatement(SQL_DELETE_ARTIFACT_DATA_BY_ARTIFACT_ID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
582 stmnt.setInt(1, res[0]);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
583 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
584 prepareStatement(SQL_DELETE_FACETS_BY_ARTIFACT_ID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
585 stmnt.setInt(1, res[0]);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
586 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
587 prepareStatement(SQL_DELETE_OUTS_BY_ARTIFACT_ID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
588 stmnt.setInt(1, res[0]);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
589 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
590 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
591 return true;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
592 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
593 };
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
594
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
595 if (!exec.runWrite()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
596 log.error("deleting old artifact data failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
597 return;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
598 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
599
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
600 // write new data
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
601 storeData(res[0], flys);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
602 storeOuts(res[0], flys, context);
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
603 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
604
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
605 public void createdUser(
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
606 final User user,
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
607 Backend backend,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
608 GlobalContext context
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
609 ) {
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
610 log.debug("createdUser");
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
611 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
612 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
613 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
614 prepareStatement(SQL_USER_ID_NEXTVAL);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
615 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
616 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
617 log.error("id generation for user failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
618 return false;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
619 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
620 int uId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
621 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
622 prepareStatement(SQL_INSERT_USER);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
623 stmnt.setInt(1, uId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
624 stmnt.setString(2, user.identifier());
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
625 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
626 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
627 return true;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
628 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
629 };
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
630
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
631 if (!exec.runWrite()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
632 log.error("create user failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
633 }
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
634 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
635
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
636 public void deletedUser(
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
637 final String identifier,
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
638 Backend backend,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
639 GlobalContext context
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
640 ) {
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
641 log.debug("deletedUser");
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
642 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
643 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
644 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
645 prepareStatement(SQL_DELETE_USER_BY_GID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
646 stmnt.setString(1, identifier);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
647 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
648 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
649 return true;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
650 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
651 };
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
652
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
653 if (!exec.runWrite()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
654 log.error("delete user failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
655 }
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
656 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
657
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
658 public void createdCollection(
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
659 final ArtifactCollection collection,
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
660 Backend backend,
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
661 GlobalContext context
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
662 ) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
663 log.debug("createdCollection");
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
664 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
665 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
666 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
667 String userId = collection.getUser().identifier();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
668 prepareStatement(SQL_USER_BY_GID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
669 stmnt.setString(1, userId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
670 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
671 int uId;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
672 if (result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
673 uId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
674 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
675 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
676 else {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
677 // need to create user first
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
678 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
679 prepareStatement(SQL_USER_ID_NEXTVAL);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
680 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
681 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
682 log.error("id generation for user failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
683 return false;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
684 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
685 uId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
686 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
687 prepareStatement(SQL_INSERT_USER);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
688 stmnt.setInt(1, uId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
689 stmnt.setString(2, userId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
690 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
691 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
692 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
693 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
694
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
695 prepareStatement(SQL_COLLECTION_ID_NEXTVAL);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
696 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
697 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
698 log.error("id generation for collection failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
699 return false;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
700 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
701 int cId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
702 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
703
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
704 String identifier = collection.identifier();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
705 String name = collection.getName();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
706
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
707 prepareStatement(SQL_INSERT_COLLECTION);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
708 stmnt.setInt(1, cId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
709 stmnt.setString(2, identifier);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
710 stmnt.setInt(3, uId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
711 setString(stmnt, 4, name);
1025
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
712 stmnt.setTimestamp(5,
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
713 new Timestamp(System.currentTimeMillis()));
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
714 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
715
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
716 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
717 return true;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
718 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
719 };
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
720
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
721 if (!exec.runWrite()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
722 log.error("create collection failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
723 }
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
724 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
725
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
726 public void deletedCollection(
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
727 final String identifier,
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
728 Backend backend,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
729 GlobalContext context
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
730 ) {
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
731 log.debug("deletedCollection");
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
732 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
733 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
734 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
735 prepareStatement(SQL_DELETE_COLLECTION_BY_GID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
736 stmnt.setString(1, identifier);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
737 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
738 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
739 return true;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
740 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
741 };
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
742
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
743 if (!exec.runWrite()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
744 log.error("delete collection failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
745 }
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
746 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
747
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
748 public void changedCollectionAttribute(
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
749 String identifier,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
750 Document document,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
751 Backend backend,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
752 GlobalContext context
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
753 ) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
754 log.debug("changedCollectionAttribute");
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
755 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
756
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
757 public void changedCollectionItemAttribute(
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
758 String collectionId,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
759 String artifactId,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
760 Document document,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
761 Backend backend,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
762 GlobalContext context
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
763 ) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
764 log.debug("changedCollectionItemAttribute");
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
765 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
766
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
767 public void addedArtifactToCollection(
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
768 final String artifactId,
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
769 final String collectionId,
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
770 Backend backend,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
771 GlobalContext context
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
772 ) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
773 log.debug("addedArtifactToCollection");
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
774 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
775 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
776 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
777 prepareStatement(SQL_ARTIFACT_BY_GID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
778 stmnt.setString(1, artifactId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
779 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
780 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
781 return false;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
782 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
783 int aId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
784 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
785
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
786 prepareStatement(SQL_COLLECTION_BY_GID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
787 stmnt.setString(1, collectionId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
788 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
789 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
790 return false;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
791 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
792 int cId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
793 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
794
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
795 prepareStatement(SQL_COLLECTION_ITEM_ID_NEXTVAL);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
796 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
797 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
798 return false;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
799 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
800 int ciId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
801 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
802
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
803 prepareStatement(SQL_INSERT_COLLECTION_ITEM);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
804 stmnt.setInt(1, ciId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
805 stmnt.setInt(2, cId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
806 stmnt.setInt(3, aId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
807 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
808
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
809 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
810 return true;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
811 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
812 };
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
813 if (!exec.runWrite()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
814 log.error("added artifact to collection failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
815 }
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
816 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
817
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
818 public void removedArtifactFromCollection(
1003
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
819 final String artifactId,
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
820 final String collectionId,
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
821 Backend backend,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
822 GlobalContext context
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
823 ) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
824 log.debug("removedArtifactFromCollection");
1003
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
825 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
826 @Override
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
827 public boolean doIt() throws SQLException {
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
828 prepareStatement(SQL_ARTIFACT_BY_GID);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
829 stmnt.setString(1, artifactId);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
830 result = stmnt.executeQuery();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
831 if (!result.next()) {
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
832 return false;
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
833 }
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
834 int aId = result.getInt(1);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
835 reset();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
836 prepareStatement(SQL_COLLECTION_BY_GID);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
837 stmnt.setString(1, collectionId);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
838 result = stmnt.executeQuery();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
839 if (!result.next()) {
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
840 return false;
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
841 }
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
842 int cId = result.getInt(1);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
843 reset();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
844 prepareStatement(SQL_DELETE_ARTIFACT_FROM_COLLECTION);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
845 stmnt.setInt(1, cId);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
846 stmnt.setInt(2, aId);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
847 stmnt.execute();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
848 conn.commit();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
849 return true;
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
850 }
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
851 };
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
852 if (!exec.runWrite()) {
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
853 log.error("removing artifact from collection failed");
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
854 }
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
855 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
856
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
857 public void setCollectionName(
1003
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
858 final String collectionId,
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
859 final String name,
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
860 GlobalContext context
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
861 ) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
862 log.debug("setCollectionName");
1003
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
863 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
864 @Override
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
865 public boolean doIt() throws SQLException {
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
866 prepareStatement(SQL_UPDATE_COLLECTION_NAME);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
867 stmnt.setString(1, name);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
868 stmnt.setString(2, collectionId);
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
869 stmnt.execute();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
870 conn.commit();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
871 return true;
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
872 }
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
873 };
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
874 if (!exec.runWrite()) {
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
875 log.error("changing name failed");
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
876 }
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
877 }
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
878
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
879 protected void storeData(
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
880 final int artifactId,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
881 FLYSArtifact artifact
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
882 ) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
883 final Collection<StateData> data = artifact.getAllData();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
884
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
885 if (data.isEmpty()) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
886 return;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
887 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
888
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
889 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
890 @Override
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
891 public boolean doIt() throws SQLException {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
892 int [] ids = new int[data.size()];
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
893 prepareStatement(SQL_ARTIFACT_DATA_ID_NEXTVAL);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
894
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
895 for (int i = 0; i < ids.length; ++i) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
896 result = stmnt.executeQuery();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
897 if (!result.next()) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
898 log.error("generating id for artifact data failed");
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
899 return false;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
900 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
901 ids[i] = result.getInt(1);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
902 result.close(); result = null;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
903 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
904 reset();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
905 prepareStatement(SQL_INSERT_ARTIFACT_DATA);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
906
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
907 int i = 0;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
908 for (StateData sd: data) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
909 int id = ids[i++];
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
910 stmnt.setInt(1, id);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
911 stmnt.setInt(2, artifactId);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
912 // XXX: Where come the nulls from?
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
913 String type = sd.getType();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
914 if (type == null) type = "String";
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
915 stmnt.setString(3, type);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
916 stmnt.setString(4, sd.getName());
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
917 setString(stmnt, 5, sd.getValue());
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
918 stmnt.execute();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
919 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
920
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
921 conn.commit();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
922 return true;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
923 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
924 };
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
925
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
926 if (!exec.runWrite()) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
927 log.error("storing artifact data failed");
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
928 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
929 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
930
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
931 protected void storeOuts(
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
932 final int artifactId,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
933 final FLYSArtifact artifact,
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
934 GlobalContext context
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
935 ) {
1050
eccf966fb677 State engine: Removed CallContext from state validation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1025
diff changeset
936 final List<Output> outs = artifact.getOutputs(context);
1002
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
937
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
938 if (outs.isEmpty()) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
939 return;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
940 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
941
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
942 final int [] outIds = new int[outs.size()];
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
943
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
944 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
945 @Override
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
946 public boolean doIt() throws SQLException {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
947 prepareStatement(SQL_OUT_ID_NEXTVALUE);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
948 for (int i = 0; i < outIds.length; ++i) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
949 result = stmnt.executeQuery();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
950 if (!result.next()) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
951 log.error("generation of out ids failed");
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
952 return false;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
953 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
954 outIds[i] = result.getInt(1);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
955 result.close(); result = null;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
956 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
957 reset();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
958 prepareStatement(SQL_INSERT_OUT);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
959 for (int i = 0; i < outIds.length; ++i) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
960 Output out = outs.get(i);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
961 stmnt.setInt(1, outIds[i]);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
962 stmnt.setInt(2, artifactId);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
963 stmnt.setString(3, out.getName());
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
964 setString(stmnt, 4, out.getDescription());
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
965 setString(stmnt, 5, out.getType());
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
966 stmnt.execute();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
967 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
968 conn.commit();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
969 return true;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
970 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
971 };
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
972
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
973 if (!exec.runWrite()) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
974 log.error("storing artifact outs failed");
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
975 return;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
976 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
977
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
978 final int FACETS = numFacets(outs);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
979
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
980 if (FACETS == 0) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
981 return;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
982 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
983
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
984 exec = sqlExecutor.new Instance() {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
985 @Override
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
986 public boolean doIt() throws SQLException {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
987 int [] facetIds = new int[FACETS];
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
988 prepareStatement(SQL_FACET_ID_NEXTVAL);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
989 for (int i = 0; i < facetIds.length; ++i) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
990 result = stmnt.executeQuery();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
991 if (!result.next()) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
992 log.error("generation of facet ids failed");
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
993 return false;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
994 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
995 facetIds[i] = result.getInt(1);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
996 result.close(); result = null;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
997 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
998 reset();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
999 prepareStatement(SQL_INSERT_FACET);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1000 int index = 0;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1001 for (int i = 0, N = outs.size(); i < N; ++i) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1002 Output out = outs.get(i);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1003 int outId = outIds[i];
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1004 for (Facet facet: out.getFacets()) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1005 stmnt.setInt(1, facetIds[index]);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1006 stmnt.setInt(2, outId);
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1007 stmnt.setString(3, facet.getName());
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1008 stmnt.setInt(4, facet.getIndex());
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1009 stmnt.setString(5, "XXX"); // TODO: handle states
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1010 setString(stmnt, 6, facet.getDescription());
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1011 stmnt.execute();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1012 ++index;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1013 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1014 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1015 conn.commit();
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1016 return true;
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1017 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1018 };
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1019
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1020 if (!exec.runWrite()) {
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1021 log.error("storing facets failed");
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1022 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1023 }
1006
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1024
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1025 public void killedCollections(
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1026 final List<String> identifiers,
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1027 GlobalContext context
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1028 ) {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1029 log.debug("killedCollections");
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1030
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1031 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1032 @Override
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1033 public boolean doIt() throws SQLException {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1034 prepareStatement(SQL_DELETE_COLLECTION_BY_GID);
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1035 for (String identifier: identifiers) {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1036 stmnt.setString(1, identifier);
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1037 stmnt.execute();
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1038 }
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1039 conn.commit();
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1040 return true;
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1041 }
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1042 };
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1043
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1044 if (!exec.runWrite()) {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1045 log.error("killing collections failed");
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1046 }
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1047 }
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1048
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1049 public void killedArtifacts(
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1050 final List<String> identifiers,
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1051 GlobalContext context
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1052 ) {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1053 log.debug("killedArtifacts");
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1054
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1055 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1056 @Override
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1057 public boolean doIt() throws SQLException {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1058 prepareStatement(SQL_DELETE_ARTIFACT_BY_GID);
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1059 for (String identifier: identifiers) {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1060 stmnt.setString(1, identifier);
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1061 stmnt.execute();
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1062 }
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1063 conn.commit();
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1064 return true;
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1065 }
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1066 };
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1067
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1068 if (!exec.runWrite()) {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1069 log.error("killing artifacts failed");
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1070 }
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1071 }
982
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1072 }
66b3f2f064de Added the datacage as lifetime listener to the artifact database to create the initial index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1073 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org