annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java @ 3133:6f6a8e5fb7a4

Theme updates for sector average wq curves/points flys-artifacts/trunk@4740 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Christian Lins <christian.lins@intevation.de>
date Thu, 21 Jun 2012 12:26:08 +0000
parents 5642a83420f2
children cbe2febe30cc
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() {
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
454
993
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
455 log.debug("cleanDatabase");
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
456
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
457 boolean success = sqlExecutor.new Instance() {
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
458 @Override
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
459 public boolean doIt() throws SQLException {
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
460 prepareStatement(SQL_DELETE_ALL_USERS);
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
461 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
462 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
463 stmnt.execute();
990
e573c4715d81 Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 989
diff changeset
464 conn.commit();
984
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
465 return true;
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
466 }
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
467 }.runWrite();
993
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
468
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
469 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
470
aabcca7aeb6c Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 992
diff changeset
471 return success;
984
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
2b05c4a0c6fd Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
474
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
475 @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
476 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
477 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
478 }
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
479
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
480 public void setup(GlobalContext globalContext) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
481 log.debug("setup");
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
482 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
483
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
484 public void createdArtifact(
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1624
diff changeset
485 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
486 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
487 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
488 ) {
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
489 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
490
1624
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
491 if (artifact == null) {
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
492 log.warn("artifact to create is null");
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
493 return;
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
494 }
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
495
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
496 if (!(artifact instanceof FLYSArtifact)) {
1624
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
497 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
498 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
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
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 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
502
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 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
504
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 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
506 @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
507 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
508 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
509 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
510 if (!result.next()) {
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
511 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
512 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
513 }
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 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
515 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
516 prepareStatement(SQL_INSERT_ARTIFACT);
1025
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
517 stmnt.setInt (1, res[0]);
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
518 stmnt.setString (2, flys.identifier());
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
519 stmnt.setString (3, flys.getCurrentStateId());
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
520 stmnt.setTimestamp(4,
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
521 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
522 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
523 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
524 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
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
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 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
529 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
530 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
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
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 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
534 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
535 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
536
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
537 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
538 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
539 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
540 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
541 ) {
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
542 log.debug("storedArtifact");
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
543 if (!(artifact instanceof FLYSArtifact)) {
1624
238145ef67da Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
544 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
545 return;
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
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
548 final FLYSArtifact flys = (FLYSArtifact)artifact;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
549
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
550 final Integer [] res = new Integer[1];
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
551
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
552 // check first if artifact already exists
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
553 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
554 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
555 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
556 prepareStatement(SQL_ARTIFACT_BY_GID);
1007
ed918497873b Datacage: Fixed two NPEs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1006
diff changeset
557 stmnt.setString(1, flys.identifier());
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
558 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
559 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
560 // new artifact
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
561 return true;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
562 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
563 res[0] = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
564 return true;
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
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
568 if (!exec.runRead()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
569 log.error("querying artifact failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
570 return;
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
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
573 if (res[0] == null) { // new artifact
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
574 createdArtifact(artifact, backend, context);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
575 return;
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
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
578 // artifact already exists -> delete old data
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
579 exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
580 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
581 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
582 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
583 stmnt.setInt(1, res[0]);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
584 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
585 prepareStatement(SQL_DELETE_FACETS_BY_ARTIFACT_ID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
586 stmnt.setInt(1, res[0]);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
587 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
588 prepareStatement(SQL_DELETE_OUTS_BY_ARTIFACT_ID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
589 stmnt.setInt(1, res[0]);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
590 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
591 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
592 return true;
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
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
596 if (!exec.runWrite()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
597 log.error("deleting old artifact data failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
598 return;
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
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
601 // write new data
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
602 storeData(res[0], flys);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
603 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
604 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
605
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
606 public void createdUser(
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
607 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
608 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
609 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
610 ) {
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
611 log.debug("createdUser");
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
612 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
613 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
614 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
615 prepareStatement(SQL_USER_ID_NEXTVAL);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
616 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
617 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
618 log.error("id generation for user failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
619 return false;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
620 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
621 int uId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
622 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
623 prepareStatement(SQL_INSERT_USER);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
624 stmnt.setInt(1, uId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
625 stmnt.setString(2, user.identifier());
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
626 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
627 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
628 return true;
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
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
632 if (!exec.runWrite()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
633 log.error("create user failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
634 }
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
635 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
636
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
637 public void deletedUser(
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
638 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
639 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
640 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
641 ) {
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
642 log.debug("deletedUser");
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
643 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
644 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
645 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
646 prepareStatement(SQL_DELETE_USER_BY_GID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
647 stmnt.setString(1, identifier);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
648 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
649 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
650 return true;
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
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
654 if (!exec.runWrite()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
655 log.error("delete user failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
656 }
999
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
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
659 public void createdCollection(
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
660 final ArtifactCollection collection,
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
661 Backend backend,
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
662 GlobalContext context
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
663 ) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
664 log.debug("createdCollection");
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
665 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
666 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
667 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
668 String userId = collection.getUser().identifier();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
669 prepareStatement(SQL_USER_BY_GID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
670 stmnt.setString(1, userId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
671 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
672 int uId;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
673 if (result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
674 uId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
675 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
676 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
677 else {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
678 // need to create user first
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
679 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
680 prepareStatement(SQL_USER_ID_NEXTVAL);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
681 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
682 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
683 log.error("id generation for user failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
684 return false;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
685 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
686 uId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
687 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
688 prepareStatement(SQL_INSERT_USER);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
689 stmnt.setInt(1, uId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
690 stmnt.setString(2, userId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
691 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
692 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
693 reset();
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
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
696 prepareStatement(SQL_COLLECTION_ID_NEXTVAL);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
697 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
698 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
699 log.error("id generation for collection failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
700 return false;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
701 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
702 int cId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
703 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
704
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
705 String identifier = collection.identifier();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
706 String name = collection.getName();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
707
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
708 prepareStatement(SQL_INSERT_COLLECTION);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
709 stmnt.setInt(1, cId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
710 stmnt.setString(2, identifier);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
711 stmnt.setInt(3, uId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
712 setString(stmnt, 4, name);
1025
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
713 stmnt.setTimestamp(5,
02c327ffbad7 Datacage: Extended schema for artifacts and collections
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1024
diff changeset
714 new Timestamp(System.currentTimeMillis()));
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
715 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
716
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
717 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
718 return true;
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
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
722 if (!exec.runWrite()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
723 log.error("create collection failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
724 }
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
725 }
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
726
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
727 public void deletedCollection(
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
728 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
729 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
730 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
731 ) {
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
732 log.debug("deletedCollection");
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
733 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
734 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
735 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
736 prepareStatement(SQL_DELETE_COLLECTION_BY_GID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
737 stmnt.setString(1, identifier);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
738 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
739 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
740 return true;
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
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
744 if (!exec.runWrite()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
745 log.error("delete collection failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
746 }
999
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
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
749 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
750 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
751 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
752 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
753 GlobalContext context
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
754 ) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
755 log.debug("changedCollectionAttribute");
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
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
758 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
759 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
760 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
761 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
762 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
763 GlobalContext context
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
764 ) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
765 log.debug("changedCollectionItemAttribute");
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
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
768 public void addedArtifactToCollection(
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
769 final String artifactId,
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
770 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
771 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
772 GlobalContext context
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
773 ) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
774 log.debug("addedArtifactToCollection");
1004
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
775 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
776 @Override
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
777 public boolean doIt() throws SQLException {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
778 prepareStatement(SQL_ARTIFACT_BY_GID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
779 stmnt.setString(1, artifactId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
780 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
781 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
782 return false;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
783 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
784 int aId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
785 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
786
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
787 prepareStatement(SQL_COLLECTION_BY_GID);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
788 stmnt.setString(1, collectionId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
789 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
790 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
791 return false;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
792 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
793 int cId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
794 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
795
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
796 prepareStatement(SQL_COLLECTION_ITEM_ID_NEXTVAL);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
797 result = stmnt.executeQuery();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
798 if (!result.next()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
799 return false;
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
800 }
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
801 int ciId = result.getInt(1);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
802 reset();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
803
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
804 prepareStatement(SQL_INSERT_COLLECTION_ITEM);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
805 stmnt.setInt(1, ciId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
806 stmnt.setInt(2, cId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
807 stmnt.setInt(3, aId);
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
808 stmnt.execute();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
809
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
810 conn.commit();
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
811 return true;
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 };
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
814 if (!exec.runWrite()) {
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
815 log.error("added artifact to collection failed");
0e8c03b69627 Datacage: completed backend listener stuff.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1003
diff changeset
816 }
999
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
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
819 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
820 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
821 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
822 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
823 GlobalContext context
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
824 ) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
825 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
826 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
827 @Override
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
828 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
829 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
830 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
831 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
832 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
833 return false;
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
834 }
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
835 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
836 reset();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
837 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
838 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
839 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
840 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
841 return false;
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
842 }
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
843 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
844 reset();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
845 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
846 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
847 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
848 stmnt.execute();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
849 conn.commit();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
850 return true;
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 };
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
853 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
854 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
855 }
999
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
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
858 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
859 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
860 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
861 GlobalContext context
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
862 ) {
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
863 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
864 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
865 @Override
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
866 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
867 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
868 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
869 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
870 stmnt.execute();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
871 conn.commit();
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
872 return true;
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 };
c58da6dd15ed Datacage: Update collection names on change. Remove artifacts from collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1002
diff changeset
875 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
876 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
877 }
999
b0218f21c664 Wire datacage with backend of artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 996
diff changeset
878 }
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
879
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 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
881 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
882 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
883 ) {
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 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
885
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 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
887 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
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
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 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
891 @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
892 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
893 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
894 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
895
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 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
897 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
898 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
899 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
900 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
901 }
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 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
903 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
904 }
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 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
906 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
907
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 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
909 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
910 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
911 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
912 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
913 // 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
914 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
915 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
916 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
917 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
918 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
919 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
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
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 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
923 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
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
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 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
928 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
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
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 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
933 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
934 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
935 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
936 ) {
1050
eccf966fb677 State engine: Removed CallContext from state validation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1025
diff changeset
937 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
938
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 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
940 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
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
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 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
944
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 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
946 @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
947 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
948 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
949 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
950 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
951 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
952 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
953 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
954 }
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 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
956 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
957 }
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 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
959 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
960 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
961 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
962 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
963 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
964 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
965 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
966 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
967 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
968 }
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 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
970 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
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
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 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
975 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
976 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
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
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 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
980
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 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
982 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
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
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 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
986 @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
987 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
988 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
989 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
990 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
991 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
992 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
993 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
994 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
995 }
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 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
997 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
998 }
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 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
1000 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
1001 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
1002 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
1003 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
1004 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
1005 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
1006 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
1007 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
1008 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
1009 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
1010 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
1011 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
1012 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
1013 ++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
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 }
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 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
1017 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
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
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 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
1022 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
1023 }
db86c665ab6e Datacage: Pass global context to datacage if calls come from backend listener.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 999
diff changeset
1024 }
1006
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1025
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1026 public void killedCollections(
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1027 final List<String> identifiers,
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1028 GlobalContext context
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1029 ) {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1030 log.debug("killedCollections");
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1031
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1032 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
1033 @Override
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1034 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
1035 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
1036 for (String identifier: identifiers) {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1037 stmnt.setString(1, identifier);
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1038 stmnt.execute();
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1039 }
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1040 conn.commit();
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1041 return true;
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
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1045 if (!exec.runWrite()) {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1046 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
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
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1050 public void killedArtifacts(
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1051 final List<String> identifiers,
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1052 GlobalContext context
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1053 ) {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1054 log.debug("killedArtifacts");
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1055
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1056 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
1057 @Override
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1058 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
1059 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
1060 for (String identifier: identifiers) {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1061 stmnt.setString(1, identifier);
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1062 stmnt.execute();
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1063 }
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1064 conn.commit();
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1065 return true;
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
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1069 if (!exec.runWrite()) {
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1070 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
1071 }
1917f32701dc Forwarded kill collections and artifacts events to datacage.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1004
diff changeset
1072 }
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
1073 }
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
1074 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org