Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java @ 997:4c82609824c8
For doc purposes add section with db config in config.xml
flys-artifacts/trunk@2433 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 01 Aug 2011 08:11:12 +0000 |
parents | f61fe8b561d2 |
children | b0218f21c664 |
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; |
990
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
5 |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
6 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
|
7 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
|
8 import java.sql.Types; |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
9 |
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
|
10 import de.intevation.artifacts.GlobalContext; |
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
|
11 |
983
4ea5f5a2284e
Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
982
diff
changeset
|
12 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
|
13 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
|
14 |
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 import de.intevation.artifactdatabase.LifetimeListener; |
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
|
16 |
990
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
17 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
|
18 |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
19 import de.intevation.artifactdatabase.state.Output; |
992
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
20 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
|
21 |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
22 import de.intevation.artifacts.Artifact; |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
23 import de.intevation.artifacts.ArtifactDatabase; |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
24 import de.intevation.artifacts.ArtifactDatabaseException; |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
25 |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
26 import de.intevation.flys.artifacts.FLYSArtifact; |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
27 |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
28 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
|
29 |
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
|
30 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
|
31 |
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
|
32 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
|
33 |
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
|
34 public class 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
|
35 implements LifetimeListener |
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 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
|
38 |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
39 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
|
40 "global.artifact.database"; |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
41 |
987
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 "collection.item.id.nextval"; |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 private String SQL_INSERT_OUT = "insert.out"; |
992
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
60 private String SQL_FACET_ID_NEXTVAL = "facet.id.nextval"; |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
61 private String SQL_INSERT_FACET = "insert.facet"; |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
62 |
983
4ea5f5a2284e
Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
982
diff
changeset
|
63 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
|
64 |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
65 public class InitialScan |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
66 implements ArtifactDatabase.ArtifactLoadedCallback |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
67 { |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
68 protected LRUCache<String, Integer> users; |
986
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
69 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
|
70 protected LRUCache<String, Integer> artifacts; |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
71 |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
72 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
|
73 |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
74 public InitialScan() { |
986
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
75 users = new LRUCache<String, Integer>(); |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
76 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
|
77 artifacts = new LRUCache<String, Integer>(); |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
78 } |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
79 |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
80 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
|
81 this(); |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
82 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
|
83 } |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
84 |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
85 @Override |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
86 public void artifactLoaded( |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
87 String userId, |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
88 String collectionId, |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
89 String artifactId, |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
90 Artifact artifact |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
91 ) { |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
92 if (!(artifact instanceof FLYSArtifact)) { |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
93 log.warn("ignoring none FLYS artifacts"); |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
94 return; |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
95 } |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
96 |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
97 FLYSArtifact flysArtifact = (FLYSArtifact)artifact; |
986
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
98 |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
99 Integer uId = getUserId(userId); |
987
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
100 // TODO: We need the name of the collection |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
101 Integer cId = getCollectionId(collectionId, uId, "XXX"); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
102 |
988
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
103 storeArtifact(artifactId, cId, flysArtifact); |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
104 } |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
105 |
987
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
106 protected Integer getId( |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
107 LRUCache<String, Integer> cache, |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
108 final String idString, |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
109 final String selectById |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
110 ) { |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
111 Integer id = cache.get(idString); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
112 if (id != null) { |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
113 return id; |
986
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
114 } |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
115 |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
116 final Integer [] res = new Integer[1]; |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
117 |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
118 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
119 @Override |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
120 public boolean doIt() throws SQLException { |
987
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
121 prepareStatement(selectById); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
122 stmnt.setString(1, idString); |
986
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
123 result = stmnt.executeQuery(); |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
124 if (!result.next()) { |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
125 return false; |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
126 } |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
127 res[0] = result.getInt(1); |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
128 return true; |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
129 } |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
130 }; |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
131 |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
132 if (exec.runRead()) { |
987
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
133 cache.put(idString, res[0]); |
986
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
134 return res[0]; |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
135 } |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
136 |
987
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
137 return null; |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
138 } |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
139 |
988
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
140 protected void storeArtifact( |
989
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
141 final String artifactId, |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
142 Integer collectionId, |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
143 final FLYSArtifact artifact |
988
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
144 ) { |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
145 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
|
146 |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
147 if (aId != null) { |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
148 // 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
|
149 storeCollectionItem(collectionId, aId); |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
150 return; |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
151 } |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
152 // 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
|
153 |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
154 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
|
155 |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
156 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
|
157 @Override |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
158 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
|
159 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
|
160 result = stmnt.executeQuery(); |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
161 if (!result.next()) { |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
162 return false; |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
163 } |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
164 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
|
165 reset(); |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
166 prepareStatement(SQL_INSERT_ARTIFACT); |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
167 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
|
168 stmnt.setString(2, artifactId); |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
169 stmnt.setString(3, artifact.getCurrentStateId()); |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
170 stmnt.execute(); |
990
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
171 conn.commit(); |
989
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
172 return true; |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
173 } |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
174 }; |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
175 |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
176 if (!exec.runWrite()) { |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
177 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
|
178 return; |
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 |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
181 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
|
182 |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
183 storeCollectionItem(collectionId, aId); |
f3be883325ce
Add artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
184 |
990
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
185 storeData(aId, artifact); |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
186 |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
187 storeOuts(aId, artifact); |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
188 } |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
189 |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
190 protected void storeOuts( |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
191 final int artifactId, |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
192 final FLYSArtifact artifact |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
193 ) { |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
194 final List<Output> outs = artifact.getCurrentOutputs(context); |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
195 |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
196 if (outs.isEmpty()) { |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
197 return; |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
198 } |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
199 |
992
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
200 final int [] outIds = new int[outs.size()]; |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
201 |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
202 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
203 @Override |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
204 public boolean doIt() throws SQLException { |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
205 prepareStatement(SQL_OUT_ID_NEXTVALUE); |
992
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
206 for (int i = 0; i < outIds.length; ++i) { |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
207 result = stmnt.executeQuery(); |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
208 if (!result.next()) { |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
209 log.error("generation of out ids failed"); |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
210 return false; |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
211 } |
992
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
212 outIds[i] = result.getInt(1); |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
213 result.close(); result = null; |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
214 } |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
215 reset(); |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
216 prepareStatement(SQL_INSERT_OUT); |
992
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
217 for (int i = 0; i < outIds.length; ++i) { |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
218 Output out = outs.get(i); |
992
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
219 stmnt.setInt(1, outIds[i]); |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
220 stmnt.setInt(2, artifactId); |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
221 stmnt.setString(3, out.getName()); |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
222 setString(stmnt, 4, out.getDescription()); |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
223 setString(stmnt, 5, out.getType()); |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
224 stmnt.execute(); |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
225 } |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
226 conn.commit(); |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
227 return true; |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
228 } |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
229 }; |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
230 |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
231 if (!exec.runWrite()) { |
992
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
232 log.error("storing artifact outs failed"); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
233 return; |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
234 } |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
235 |
992
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
236 final int FACETS = numFacets(outs); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
237 |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
238 if (FACETS == 0) { |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
239 return; |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
240 } |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
241 |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
242 exec = sqlExecutor.new Instance() { |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
243 @Override |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
244 public boolean doIt() throws SQLException { |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
245 int [] facetIds = new int[FACETS]; |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
246 prepareStatement(SQL_FACET_ID_NEXTVAL); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
247 for (int i = 0; i < facetIds.length; ++i) { |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
248 result = stmnt.executeQuery(); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
249 if (!result.next()) { |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
250 log.error("generation of facet ids failed"); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
251 return false; |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
252 } |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
253 facetIds[i] = result.getInt(1); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
254 result.close(); result = null; |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
255 } |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
256 reset(); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
257 prepareStatement(SQL_INSERT_FACET); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
258 int index = 0; |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
259 for (int i = 0, N = outs.size(); i < N; ++i) { |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
260 Output out = outs.get(i); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
261 int outId = outIds[i]; |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
262 for (Facet facet: out.getFacets()) { |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
263 stmnt.setInt(1, facetIds[index]); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
264 stmnt.setInt(2, outId); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
265 stmnt.setString(3, facet.getName()); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
266 stmnt.setInt(4, facet.getIndex()); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
267 stmnt.setString(5, "XXX"); // TODO: handle states |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
268 setString(stmnt, 6, facet.getDescription()); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
269 stmnt.execute(); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
270 ++index; |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
271 } |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
272 } |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
273 conn.commit(); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
274 return true; |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
275 } |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
276 }; |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
277 |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
278 if (!exec.runWrite()) { |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
279 log.error("storing facets failed"); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
280 } |
988
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
281 } |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
282 |
990
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
283 protected void storeData( |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
284 final int artifactId, |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
285 FLYSArtifact artifact |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
286 ) { |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
287 final Collection<StateData> data = artifact.getAllData(); |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
288 |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
289 if (data.isEmpty()) { |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
290 return; |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
291 } |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
292 |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
293 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
294 @Override |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
295 public boolean doIt() throws SQLException { |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
296 int [] ids = new int[data.size()]; |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
297 prepareStatement(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
|
298 |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
299 for (int i = 0; i < ids.length; ++i) { |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
300 result = stmnt.executeQuery(); |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
301 if (!result.next()) { |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
302 log.error("generating id for artifact data failed"); |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
303 return false; |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
304 } |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
305 ids[i] = result.getInt(1); |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
306 result.close(); result = null; |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
307 } |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
308 reset(); |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
309 prepareStatement(SQL_INSERT_ARTIFACT_DATA); |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
310 |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
311 int i = 0; |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
312 for (StateData sd: data) { |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
313 int id = ids[i++]; |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
314 stmnt.setInt(1, id); |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
315 stmnt.setInt(2, artifactId); |
995
e0df86bc6d31
Added kludge for the null type information of artifact data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
993
diff
changeset
|
316 // XXX: Where come the nulls from? |
e0df86bc6d31
Added kludge for the null type information of artifact data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
993
diff
changeset
|
317 String type = sd.getType(); |
e0df86bc6d31
Added kludge for the null type information of artifact data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
993
diff
changeset
|
318 if (type == null) type = "String"; |
e0df86bc6d31
Added kludge for the null type information of artifact data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
993
diff
changeset
|
319 stmnt.setString(3, type); |
990
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
320 stmnt.setString(4, sd.getName()); |
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
|
321 setString(stmnt, 5, sd.getValue()); |
990
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
322 stmnt.execute(); |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
323 } |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
324 |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
325 conn.commit(); |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
326 return true; |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
327 } |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
328 }; |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
329 |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
330 if (!exec.runWrite()) { |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
331 log.error("storing artifact data failed"); |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
332 } |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
333 } |
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
334 |
988
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
335 protected void storeCollectionItem( |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
336 final Integer collectionId, |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
337 final Integer artifactId |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
338 ) { |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
339 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
|
340 @Override |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
341 public boolean doIt() throws SQLException { |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
342 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
|
343 result = stmnt.executeQuery(); |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
344 if (!result.next()) { |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
345 return false; |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
346 } |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
347 int ciId = result.getInt(1); |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
348 reset(); |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
349 prepareStatement(SQL_INSERT_COLLECTION_ITEM); |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
350 stmnt.setInt(1, ciId); |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
351 stmnt.setInt(2, collectionId); |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
352 stmnt.setInt(3, artifactId); |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
353 stmnt.execute(); |
990
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
354 conn.commit(); |
988
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
355 return true; |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
356 } |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
357 }; |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
358 |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
359 if (!exec.runWrite()) { |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
360 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
|
361 } |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
362 } |
987
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
363 |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
364 protected Integer getCollectionId( |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
365 final String collectionId, |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
366 final Integer ownerId, |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
367 final String collectionName |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
368 ) { |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
369 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
|
370 |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
371 if (c != null) { |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
372 return c; |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
373 } |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
374 |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
375 final Integer [] res = new Integer[1]; |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
376 |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
377 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
378 @Override |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
379 public boolean doIt() throws SQLException { |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
380 prepareStatement(SQL_COLLECTION_ID_NEXTVAL); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
381 result = stmnt.executeQuery(); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
382 if (!result.next()) { |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
383 return false; |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
384 } |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
385 res[0] = result.getInt(1); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
386 reset(); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
387 prepareStatement(SQL_INSERT_COLLECTION); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
388 stmnt.setInt (1, res[0]); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
389 stmnt.setString(2, collectionId); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
390 stmnt.setInt (3, ownerId); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
391 stmnt.setString(4, collectionName); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
392 stmnt.execute(); |
990
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
393 conn.commit(); |
987
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
394 return true; |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
395 } |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
396 }; |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
397 |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
398 if (exec.runWrite()) { |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
399 collections.put(collectionId, res[0]); |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
400 return res[0]; |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
401 } |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
402 |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
403 return null; |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
404 } |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
405 |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
406 protected Integer getUserId(final String userId) { |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
407 |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
408 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
|
409 |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
410 if (u != null) { |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
411 return u; |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
412 } |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
413 |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
414 final Integer [] res = new Integer[1]; |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
415 |
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
416 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
|
417 @Override |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
418 public boolean doIt() throws SQLException { |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
419 prepareStatement(SQL_USER_ID_NEXTVAL); |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
420 result = stmnt.executeQuery(); |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
421 if (!result.next()) { |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
422 return false; |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
423 } |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
424 res[0] = result.getInt(1); |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
425 reset(); |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
426 prepareStatement(SQL_INSERT_USER); |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
427 stmnt.setInt (1, res[0]); |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
428 stmnt.setString(2, userId); |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
429 stmnt.execute(); |
990
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
430 conn.commit(); |
986
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
431 return true; |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
432 } |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
433 }; |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
434 |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
435 if (exec.runWrite()) { |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
436 users.put(userId, res[0]); |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
437 return res[0]; |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
438 } |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
439 |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
440 return null; |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
441 } |
70545233f8ee
Datacage: Add users at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
984
diff
changeset
|
442 |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
443 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
|
444 log.debug("scan"); |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
445 try { |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
446 adb.loadAllArtifacts(this); |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
447 } |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
448 catch (ArtifactDatabaseException ade) { |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
449 log.error(ade); |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
450 return false; |
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 return true; |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
453 } |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
454 } // class InitialScan |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
455 |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
456 |
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
|
457 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
|
458 } |
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
|
459 |
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
|
460 @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
|
461 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
|
462 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
|
463 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
|
464 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
|
465 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
|
466 } |
4ea5f5a2284e
Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
982
diff
changeset
|
467 |
4ea5f5a2284e
Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
982
diff
changeset
|
468 protected void setupSQL(SQL sql) { |
987
82ef338fee91
Datacage: Add collections at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
986
diff
changeset
|
469 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
|
470 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
|
471 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
|
472 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
|
473 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
|
474 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
|
475 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
|
476 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
|
477 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
|
478 SQL_COLLECTION_ITEM_ID_NEXTVAL = |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
479 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
|
480 SQL_INSERT_COLLECTION_ITEM = |
dbe39e1fb5e7
Datacage: Add collection items at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
987
diff
changeset
|
481 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
|
482 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
|
483 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
|
484 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
|
485 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
|
486 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
|
487 SQL_INSERT_OUT = sql.get(SQL_INSERT_OUT); |
992
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
488 SQL_FACET_ID_NEXTVAL = sql.get(SQL_FACET_ID_NEXTVAL); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
489 SQL_INSERT_FACET = sql.get(SQL_INSERT_FACET); |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
490 } |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
491 |
992
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
492 protected static final int numFacets(List<Output> outs) { |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
493 int sum = 0; |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
494 for (Output out: outs) { |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
495 sum += out.getFacets().size(); |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
496 } |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
497 return sum; |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
498 } |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
499 |
5b467bc27eda
Datacage: Store
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
991
diff
changeset
|
500 protected static final void setString( |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
501 PreparedStatement stmnt, |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
502 int index, |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
503 Object value |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
504 ) |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
505 throws SQLException |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
506 { |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
507 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
|
508 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
|
509 } |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
510 else { |
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
511 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
|
512 } |
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
|
513 } |
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
|
514 |
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
|
515 @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
|
516 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
|
517 log.debug("systemUp entered"); |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
518 initialScan(context); |
993
aabcca7aeb6c
Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
992
diff
changeset
|
519 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
|
520 } |
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
|
521 |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
522 protected void initialScan(GlobalContext context) { |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
523 log.debug("initialScan"); |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
524 |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
525 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
|
526 |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
527 if (!(adbObject instanceof ArtifactDatabase)) { |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
528 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
|
529 return; |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
530 } |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
531 |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
532 ArtifactDatabase adb = (ArtifactDatabase)adbObject; |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
533 |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
534 if (!cleanDatabase()) { |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
535 log.error("cleaning database failed"); |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
536 return; |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
537 } |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
538 |
991
c675b4a87201
Store outs of artifacts into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
990
diff
changeset
|
539 InitialScan is = new InitialScan(context); |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
540 |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
541 if (!is.scan(adb)) { |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
542 log.error("initial scan failed"); |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
543 return; |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
544 } |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
545 |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
546 } |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
547 |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
548 protected boolean cleanDatabase() { |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
549 |
993
aabcca7aeb6c
Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
992
diff
changeset
|
550 log.debug("cleanDatabase"); |
aabcca7aeb6c
Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
992
diff
changeset
|
551 |
aabcca7aeb6c
Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
992
diff
changeset
|
552 boolean success = sqlExecutor.new Instance() { |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
553 @Override |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
554 public boolean doIt() throws SQLException { |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
555 prepareStatement(SQL_DELETE_ALL_USERS); |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
556 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
|
557 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
|
558 stmnt.execute(); |
990
e573c4715d81
Add artifacts data into datacage db at initial scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
989
diff
changeset
|
559 conn.commit(); |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
560 return true; |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
561 } |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
562 }.runWrite(); |
993
aabcca7aeb6c
Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
992
diff
changeset
|
563 |
aabcca7aeb6c
Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
992
diff
changeset
|
564 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
|
565 |
aabcca7aeb6c
Fixed datacage db scheme. add some debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
992
diff
changeset
|
566 return success; |
984
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
567 } |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
568 |
2b05c4a0c6fd
Datacage: clear database before initial scan
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
983
diff
changeset
|
569 |
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
|
570 @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
|
571 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
|
572 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
|
573 } |
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
|
574 } |
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
|
575 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |