Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 415:d4a846ee35b8
Implement ArtifactDatabase findUser method
artifacts/trunk@5262 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 24 Aug 2012 14:08:31 +0000 |
parents | f5ecca16f601 |
children | da33275fb765 |
rev | line source |
---|---|
100
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
1 /* |
182
7eebe707a034
Added helper to be return in Backend.listCollectionArtifacts()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
180
diff
changeset
|
2 * Copyright (c) 2010, 2011 by Intevation GmbH |
100
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
3 * |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
7 */ |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 package de.intevation.artifactdatabase; |
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
158
d718a4d55662
Implemented the createCollection() method in the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
157
diff
changeset
|
10 import de.intevation.artifacts.Artifact; |
157
6e6965873a48
Simplified creation of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
156
diff
changeset
|
11 import de.intevation.artifacts.ArtifactCollection; |
158
d718a4d55662
Implemented the createCollection() method in the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
157
diff
changeset
|
12 import de.intevation.artifacts.ArtifactCollectionFactory; |
303
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
13 import de.intevation.artifacts.ArtifactDatabase.ArtifactLoadedCallback; |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
14 import de.intevation.artifacts.ArtifactFactory; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
15 import de.intevation.artifacts.ArtifactSerializer; |
186
15c7638511dc
Added an interface for CollectionItems and renamed the CollectionItem class from the artifact-database package to DefaultCollectionItem - because this is the default implementation of the interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
184
diff
changeset
|
16 import de.intevation.artifacts.CollectionItem; |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
17 import de.intevation.artifacts.User; |
157
6e6965873a48
Simplified creation of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
156
diff
changeset
|
18 import de.intevation.artifacts.UserFactory; |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
301
b0a949d3fe09
Moved StringUtils to common package. Added some Override annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
281
diff
changeset
|
20 import de.intevation.artifacts.common.utils.StringUtils; |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
21 import de.intevation.artifacts.common.utils.XMLUtils; |
308
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
22 import de.intevation.artifacts.common.utils.LRUCache; |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
23 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
24 import de.intevation.artifactdatabase.db.SQLExecutor; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
25 import de.intevation.artifactdatabase.db.SQL; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
26 |
93
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
27 import java.sql.SQLException; |
170
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
28 import java.sql.Timestamp; |
93
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
29 import java.sql.Types; |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
30 |
310
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
31 import java.util.List; |
148
101a52d3ad08
Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
147
diff
changeset
|
32 import java.util.ArrayList; |
170
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
33 import java.util.Date; |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
34 import java.util.HashMap; |
148
101a52d3ad08
Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
147
diff
changeset
|
35 |
310
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
36 import java.util.concurrent.CopyOnWriteArrayList; |
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
37 |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
15
diff
changeset
|
38 import org.apache.log4j.Logger; |
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
15
diff
changeset
|
39 |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
40 import org.w3c.dom.Document; |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
41 |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 /** |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
43 * The backend implements the low level layer used to store artifacts |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
44 * in a SQL database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
45 * |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
46 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 */ |
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 public class Backend |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
49 implements DatabaseCleaner.ArtifactReviver |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 { |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
15
diff
changeset
|
51 private static Logger logger = Logger.getLogger(Backend.class); |
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
15
diff
changeset
|
52 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
53 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
54 * The SQL statement to create new artifact id inside the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
55 */ |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
56 public String SQL_NEXT_ID; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
57 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
58 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
59 * The SQL statement to insert an artifact into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
60 */ |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
61 public String SQL_INSERT; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
62 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
63 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
64 * The SQL statement to update some columns of an existing |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
65 * artifact in the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
66 */ |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
67 public String SQL_UPDATE; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
68 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
69 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
70 * The SQL statement to touch the access time of an |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
71 * artifact inside the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
72 */ |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
73 public String SQL_TOUCH; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
74 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
75 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
76 * The SQL statement to load an artifact by a given |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
77 * identifier from the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
78 */ |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
79 public String SQL_LOAD_BY_GID; |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
80 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
81 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
82 * The SQL statement to get the database id of an artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
83 * identified by the identifier. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
84 */ |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
85 public String SQL_GET_ID; |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
86 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
87 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
88 * The SQL statement to replace the content of an |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
89 * existing artifact inside the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
90 */ |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
91 public String SQL_REPLACE; |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
92 |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
93 // USER SQL |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
94 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
95 public String SQL_USERS_NEXT_ID; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
96 public String SQL_USERS_INSERT; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
97 public String SQL_USERS_SELECT_ID_BY_GID; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
98 public String SQL_USERS_SELECT_GID; |
413
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
99 public String SQL_USERS_SELECT_ACCOUNT; |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
100 public String SQL_USERS_DELETE_ID; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
101 public String SQL_USERS_DELETE_COLLECTIONS; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
102 public String SQL_USERS_SELECT_ALL; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
103 public String SQL_USERS_COLLECTIONS; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
104 public String SQL_USERS_COLLECTION_IDS; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
105 public String SQL_USERS_DELETE_ALL_COLLECTIONS; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
106 public String SQL_ARTIFACTS_IN_ONLY_COLLECTION_ONLY; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
107 public String SQL_OUTDATE_ARTIFACTS_COLLECTION; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
108 public String SQL_UPDATE_COLLECTION_TTL; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
109 public String SQL_UPDATE_COLLECTION_NAME; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
110 public String SQL_OUTDATE_ARTIFACTS_USER; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
111 public String SQL_DELETE_USER_COLLECTION_ITEMS; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
112 public String SQL_COLLECTIONS_NEXT_ID; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
113 public String SQL_COLLECTIONS_INSERT; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
114 public String SQL_COLLECTIONS_SELECT_USER; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
115 public String SQL_COLLECTIONS_SELECT_ALL; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
116 public String SQL_COLLECTIONS_SELECT_GID; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
117 public String SQL_COLLECTIONS_CREATION_TIME; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
118 public String SQL_COLLECTIONS_ID_BY_GID; |
343
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
119 public String SQL_COLLECTIONS_OLDEST_ARTIFACT; |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
120 public String SQL_DELETE_COLLECTION_ITEMS; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
121 public String SQL_DELETE_COLLECTION; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
122 public String SQL_COLLECTION_CHECK_ARTIFACT; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
123 public String SQL_COLLECTION_ITEMS_ID_NEXTVAL; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
124 public String SQL_COLLECTION_ITEMS_INSERT; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
125 public String SQL_COLLECTION_GET_ATTRIBUTE; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
126 public String SQL_COLLECTION_SET_ATTRIBUTE; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
127 public String SQL_COLLECTION_ITEM_GET_ATTRIBUTE; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
128 public String SQL_COLLECTION_ITEM_SET_ATTRIBUTE; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
129 public String SQL_COLLECTIONS_TOUCH_BY_GID; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
130 public String SQL_COLLECTION_ITEM_ID_CID_AID; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
131 public String SQL_COLLECTION_ITEM_OUTDATE_ARTIFACT; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
132 public String SQL_COLLECTION_ITEM_DELETE; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
133 public String SQL_COLLECTIONS_TOUCH_BY_ID; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
134 public String SQL_COLLECTION_ITEMS_LIST_GID; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
135 public String SQL_ALL_ARTIFACTS; |
303
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
136 |
128
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
137 /** The singleton.*/ |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
138 protected static Backend instance; |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
139 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
140 protected SQLExecutor sqlExecutor; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
141 |
310
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
142 protected List<BackendListener> listeners; |
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
143 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
144 protected DBConfig config; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
145 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
146 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
147 * The database cleaner. Reference is stored here because |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
148 * the cleaner is woken up if the backend finds an outdated |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
149 * artifact. This artifact should be removed as soon as |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
150 * possible. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
151 */ |
30
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
152 protected DatabaseCleaner cleaner; |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
153 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
154 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
155 * To revive an artifact from the bytes coming from the database |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
156 * we need the artifact factory which references the artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
157 * serializer which is able to do the reviving job. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
158 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
159 protected FactoryLookup factoryLookup; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
160 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
161 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
162 * Little helper interface to decouple the ArtifactDatabase |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
163 * from the Backend. A ArtifactDatabase should depend on a |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
164 * Backend but a Backend not from an ArtifactDatabase. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
165 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
166 public interface FactoryLookup { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
167 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
168 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
169 * Returns an ArtifactFactory which is bound to a given name. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
170 * @param factoryName The name of the artifact factory. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
171 * @return The ArtifactFactory bound to the factory name or |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
172 * null if not matching factory is found. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
173 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
174 ArtifactFactory getArtifactFactory(String factoryName); |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
175 |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
176 } // interface FactoryLookup |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
177 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
178 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
179 * Inner class that brigdes between the persisten form of the |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
180 * artifact and the living one inside the artifact database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
181 * After the describe(), feed(), advance() and out() operations |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
182 * of the artifact it must be possible to write to modified artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
183 * back into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
184 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
185 public final class PersistentArtifact |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
186 { |
230
fbd57d2eeaef
Changed semantics of locked artifact ids.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
217
diff
changeset
|
187 private int id; |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
188 private Artifact artifact; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
189 private ArtifactSerializer serializer; |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
190 private Long ttl; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
191 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
192 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
193 * Cronstructor to create a persistent artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
194 * @param artifact The living artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
195 * @param serializer The serializer to store the artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
196 * after the operations. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
197 * @param ttl The time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
198 * @param id The database id of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
199 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
200 public PersistentArtifact( |
47
4ae4dc99127d
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
46
diff
changeset
|
201 Artifact artifact, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
202 ArtifactSerializer serializer, |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
203 Long ttl, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
204 int id |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
205 ) { |
230
fbd57d2eeaef
Changed semantics of locked artifact ids.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
217
diff
changeset
|
206 this.id = id; |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
207 this.artifact = artifact; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
208 this.serializer = serializer; |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
209 this.ttl = ttl; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
210 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
211 |
230
fbd57d2eeaef
Changed semantics of locked artifact ids.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
217
diff
changeset
|
212 public int getId() { |
fbd57d2eeaef
Changed semantics of locked artifact ids.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
217
diff
changeset
|
213 return id; |
fbd57d2eeaef
Changed semantics of locked artifact ids.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
217
diff
changeset
|
214 } |
fbd57d2eeaef
Changed semantics of locked artifact ids.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
217
diff
changeset
|
215 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
216 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
217 * Returns the wrapped living artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
218 * @return the living artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
219 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
220 public Artifact getArtifact() { |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
221 return artifact; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
222 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
223 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
224 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
225 * Returns the serialized which is able to write a |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
226 * modified artifact back into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
227 * @return The serializer. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
228 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
229 public ArtifactSerializer getSerializer() { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
230 return serializer; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
231 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
232 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
233 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
234 * The time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
235 * @return The time to live. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
236 */ |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
237 public Long getTTL() { |
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
238 return ttl; |
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
239 } |
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
240 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
241 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
242 * Stores the living artifact back into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
243 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
244 public void store() { |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
245 if (logger.isDebugEnabled()) { |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
246 logger.debug("storing artifact id = " + getId()); |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
247 } |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
248 Backend.this.store(this); |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
249 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
250 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
251 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
252 * Only touches the access time of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
253 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
254 public void touch() { |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
255 if (logger.isDebugEnabled()) { |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
256 logger.debug("touching artifact id = " + getId()); |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
257 } |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
258 Backend.this.touch(this); |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
259 } |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
260 } // class ArtifactWithId |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
261 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
262 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
263 * Default constructor |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
264 */ |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 public Backend() { |
310
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
266 listeners = new CopyOnWriteArrayList<BackendListener>(); |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 } |
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
269 public Backend(DBConfig config) { |
312
fa056f9c8a0c
Fixed NPE with list of backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
311
diff
changeset
|
270 this(); |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
271 this.config = config; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
272 sqlExecutor = new SQLExecutor(config.getDBConnection()); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
273 setupSQL(config.getSQL()); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
274 } |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
275 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
276 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
277 * Constructor to create a backend with a link to the database cleaner. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
278 * @param cleaner The clean which periodically removes outdated |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
279 * artifacts from the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
280 */ |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
281 public Backend(DBConfig config, DatabaseCleaner cleaner) { |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
282 this(config); |
30
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
283 this.cleaner = cleaner; |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
284 } |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
285 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
286 public DBConfig getConfig() { |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
287 return config; |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
288 } |
128
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
289 |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
290 /** |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
291 * Returns the singleton of this Backend. |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
292 * |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
293 * @return the backend. |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
294 */ |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
295 public static synchronized Backend getInstance() { |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
296 if (instance == null) { |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
297 instance = new Backend(DBConfig.getInstance()); |
128
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
298 } |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
299 |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
300 return instance; |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
301 } |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
302 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
303 protected void setupSQL(SQL sql) { |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
304 SQL_NEXT_ID = sql.get("artifacts.id.nextval"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
305 SQL_INSERT = sql.get("artifacts.insert"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
306 SQL_UPDATE = sql.get("artifacts.update"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
307 SQL_TOUCH = sql.get("artifacts.touch"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
308 SQL_LOAD_BY_GID = sql.get("artifacts.select.gid"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
309 SQL_GET_ID = sql.get("artifacts.get.id"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
310 SQL_REPLACE = sql.get("artifacts.replace"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
311 SQL_USERS_NEXT_ID = sql.get("users.id.nextval"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
312 SQL_USERS_INSERT = sql.get("users.insert"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
313 SQL_USERS_SELECT_ID_BY_GID = sql.get("users.select.id.by.gid"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
314 SQL_USERS_SELECT_GID = sql.get("users.select.gid"); |
413
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
315 SQL_USERS_SELECT_ACCOUNT = sql.get("users.select.account"); |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
316 SQL_USERS_DELETE_ID = sql.get("users.delete.id"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
317 SQL_USERS_DELETE_COLLECTIONS = sql.get("users.delete.collections"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
318 SQL_USERS_SELECT_ALL = sql.get("users.select.all"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
319 SQL_USERS_COLLECTIONS = sql.get("users.collections"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
320 SQL_USERS_COLLECTION_IDS = sql.get("users.collection.ids"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
321 SQL_USERS_DELETE_ALL_COLLECTIONS = |
307
d96bcb40dbf9
Make artifact server bootable again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
305
diff
changeset
|
322 sql.get("users.delete.collections"); |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
323 SQL_ARTIFACTS_IN_ONLY_COLLECTION_ONLY = |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
324 sql.get("artifacts.in.one.collection.only"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
325 SQL_OUTDATE_ARTIFACTS_COLLECTION = |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
326 sql.get("outdate.artifacts.collection"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
327 SQL_UPDATE_COLLECTION_TTL = sql.get("collections.update.ttl"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
328 SQL_UPDATE_COLLECTION_NAME = sql.get("collections.update.name"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
329 SQL_OUTDATE_ARTIFACTS_USER = sql.get("outdate.artifacts.user"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
330 SQL_DELETE_USER_COLLECTION_ITEMS = |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
331 sql.get("delete.user.collection.items"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
332 SQL_COLLECTIONS_NEXT_ID = sql.get("collections.id.nextval"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
333 SQL_COLLECTIONS_INSERT = sql.get("collections.insert"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
334 SQL_COLLECTIONS_SELECT_USER = sql.get("collections.select.user"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
335 SQL_COLLECTIONS_SELECT_ALL = sql.get("collections.select.all"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
336 SQL_COLLECTIONS_SELECT_GID = sql.get("collections.select.by.gid"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
337 SQL_COLLECTIONS_CREATION_TIME = sql.get("collection.creation.time"); |
343
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
338 SQL_COLLECTIONS_OLDEST_ARTIFACT = sql.get("collections.artifacts.oldest"); |
344
be883e843539
Fix accidental corruption of key for sql statement.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
343
diff
changeset
|
339 SQL_COLLECTIONS_ID_BY_GID = sql.get("collections.id.by.gid"); |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
340 SQL_DELETE_COLLECTION_ITEMS = sql.get("delete.collection.items"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
341 SQL_DELETE_COLLECTION = sql.get("delete.collection"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
342 SQL_COLLECTION_CHECK_ARTIFACT = sql.get("collection.check.artifact"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
343 SQL_COLLECTION_ITEMS_ID_NEXTVAL = |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
344 sql.get("collection.items.id.nextval"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
345 SQL_COLLECTION_ITEMS_INSERT = sql.get("collection.items.insert"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
346 SQL_COLLECTION_GET_ATTRIBUTE = sql.get("collection.get.attribute"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
347 SQL_COLLECTION_SET_ATTRIBUTE = sql.get("collection.set.attribute"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
348 SQL_COLLECTION_ITEM_GET_ATTRIBUTE = |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
349 sql.get("collection.item.get.attribute"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
350 SQL_COLLECTION_ITEM_SET_ATTRIBUTE = |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
351 sql.get("collection.item.set.attribute"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
352 SQL_COLLECTIONS_TOUCH_BY_GID = sql.get("collections.touch.by.gid"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
353 SQL_COLLECTION_ITEM_ID_CID_AID = sql.get("collection.item.id.cid.aid"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
354 SQL_COLLECTION_ITEM_OUTDATE_ARTIFACT = |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
355 sql.get("collection.item.outdate.artifact"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
356 SQL_COLLECTION_ITEM_DELETE = sql.get("collection.item.delete"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
357 SQL_COLLECTIONS_TOUCH_BY_ID = sql.get("collections.touch.by.id"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
358 SQL_COLLECTION_ITEMS_LIST_GID = sql.get("collection.items.list.gid"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
359 SQL_ALL_ARTIFACTS = sql.get("all.artifacts"); |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
360 } |
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
361 |
310
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
362 public void addListener(BackendListener listener) { |
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
363 listeners.add(listener); |
313
ddc35c950e97
Backend: Handle forgotten store/create event source.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
312
diff
changeset
|
364 logger.debug("# listeners: " + listeners.size()); |
310
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
365 } |
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
366 |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
367 public void addAllListeners(List<BackendListener> others) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
368 listeners.addAll(others); |
313
ddc35c950e97
Backend: Handle forgotten store/create event source.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
312
diff
changeset
|
369 logger.debug("# listeners: " + listeners.size()); |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
370 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
371 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
372 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
373 * Sets the factory lookup mechanism to decouple ArtifactDatabase |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
374 * and Backend. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
375 * @param factoryLookup |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
376 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
377 public void setFactoryLookup(FactoryLookup factoryLookup) { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
378 this.factoryLookup = factoryLookup; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
379 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
380 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
381 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
382 * Sets the database cleaner explicitly. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
383 * @param cleaner The database cleaner |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
384 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
385 public void setCleaner(DatabaseCleaner cleaner) { |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
386 this.cleaner = cleaner; |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
387 } |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
388 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
389 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
390 * Returns a new unique identifier to external identify |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
391 * the artifact across the system. This implementation |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
392 * uses random UUIDs v4 to achieve this target. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
393 * @return the new identifier |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
394 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
395 public String newIdentifier() { |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
396 // TODO: check database for collisions. |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
397 return StringUtils.newUUID(); |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
398 } |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
399 |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
400 public boolean isValidIdentifier(String identifier) { |
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
401 return StringUtils.checkUUID(identifier); |
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
402 } |
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
403 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
404 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
405 * Stores a new artifact into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
406 * @param artifact The artifact to be stored |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
407 * @param factory The factory which build the artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
408 * @param ttl The initial time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
409 * @return A persistent wrapper around the living |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
410 * artifact to be able to write modification later. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
411 * @throws Exception Thrown if something went wrong with the |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
412 * storage process. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
413 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
414 public PersistentArtifact storeInitially( |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
415 Artifact artifact, |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
416 ArtifactFactory factory, |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
417 Long ttl |
47
4ae4dc99127d
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
46
diff
changeset
|
418 ) |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
419 throws Exception |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
420 { |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
421 return new PersistentArtifact( |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
422 artifact, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
423 factory.getSerializer(), |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
424 ttl, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
425 insertDatabase(artifact, factory, ttl)); |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
426 } |
47
4ae4dc99127d
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
46
diff
changeset
|
427 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
428 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
429 * Stores an artifact into database if it does not exist there. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
430 * If it exists there it is only updated. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
431 * @param artifact The artifact to store/update. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
432 * @param factory The factory which created the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
433 * @param ttl The initial time to live of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
434 * @return A persistent version of the artifact to be able |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
435 * to store a modification later. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
436 * @throws Exception Thrown if something went wrong during |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
437 * storing/updating. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
438 */ |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
439 public PersistentArtifact storeOrReplace( |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
440 Artifact artifact, |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
441 ArtifactFactory factory, |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
442 Long ttl |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
443 ) |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
444 throws Exception |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
445 { |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
446 return new PersistentArtifact( |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
447 artifact, |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
448 factory.getSerializer(), |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
449 ttl, |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
450 storeOrReplaceDatabase(artifact, factory, ttl)); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
451 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
452 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
453 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
454 * Implementors of this interface are able to process the raw |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
455 * artifact data from the database for loading. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
456 */ |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
457 public interface ArtifactLoader { |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
458 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
459 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
460 * Creates a custom object from the raw artifact database data. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
461 * @param factory The factory that created this artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
462 * @param ttl The current time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
463 * @param bytes The raw artifact bytes from the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
464 * @param id The database id of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
465 * @return The custom object created by the implementation. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
466 */ |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
467 Object load(ArtifactFactory factory, Long ttl, byte [] bytes, int id); |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
468 |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
469 } // interface ArtifactLoader |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
470 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
471 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
472 * Fetches an artifact from the database identified by the |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
473 * given identifier. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
474 * @param identifer The identifier of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
475 * @return A persistent wrapper around the found artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
476 * to be able to write back a modifaction later or null |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
477 * if no artifact is found for this identifier. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
478 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
479 public PersistentArtifact getArtifact(String identifer) { |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
480 |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
481 return (PersistentArtifact)loadArtifact( |
86
b2e0cb83631c
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
84
diff
changeset
|
482 identifer, |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
483 new ArtifactLoader() { |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
484 |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
485 public Object load( |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
486 ArtifactFactory factory, |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
487 Long ttl, |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
488 byte [] bytes, |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
489 int id |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
490 ) { |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
491 ArtifactSerializer serializer = factory.getSerializer(); |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
492 |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
493 Artifact artifact = serializer.fromBytes(bytes); |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
494 |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
495 return artifact == null |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
496 ? null |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
497 : new PersistentArtifact(artifact, serializer, ttl, id); |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
498 } |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
499 }); |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
500 } |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
501 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
502 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
503 * More general loading mechanism for artifacts. The concrete |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
504 * load processing is delegated to the given loader. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
505 * @param identifer The identifier of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
506 * @param loader The loader which processes the raw database data. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
507 * @return The object created by the loader. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
508 */ |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
509 public Object loadArtifact( |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
510 final String identifer, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
511 final ArtifactLoader loader |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
512 ) { |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
513 if (!isValidIdentifier(identifer)) { |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
514 return null; |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
515 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
516 |
303
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
517 if (factoryLookup == null) { |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
518 logger.error("factory lookup == null"); |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
519 return false; |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
520 } |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
521 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
522 final Object [] loaded = new Object[1]; |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
523 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
524 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
525 public boolean doIt() throws SQLException { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
526 prepareStatement(SQL_LOAD_BY_GID); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
527 stmnt.setString(1, identifer); |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
528 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
529 result = stmnt.executeQuery(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
530 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
531 if (!result.next()) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
532 return false; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
533 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
534 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
535 int id = result.getInt(1); |
242
b35d32e507b6
Fix for flys/issue9
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
536 long ttlX = result.getLong(2); |
b35d32e507b6
Fix for flys/issue9
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
537 Long ttl = result.wasNull() ? null : ttlX; |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
538 |
242
b35d32e507b6
Fix for flys/issue9
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
539 String factoryName = result.getString(3); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
540 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
541 ArtifactFactory factory = factoryLookup |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
542 .getArtifactFactory(factoryName); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
543 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
544 if (factory == null) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
545 logger.error("factory '" + factoryName + "' not found"); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
546 return false; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
547 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
548 |
242
b35d32e507b6
Fix for flys/issue9
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
549 byte [] bytes = result.getBytes(4); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
550 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
551 loaded[0] = loader.load(factory, ttl, bytes, id); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
552 return true; |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
553 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
554 }; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
555 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
556 return exec.runRead() ? loaded[0] : null; |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
557 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
558 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
559 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
560 * Called if the load mechanism found an outdated artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
561 * It wakes up the database cleaner. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
562 * @param id The id of the outdated artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
563 */ |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
564 protected void artifactOutdated(int id) { |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
565 if (logger.isDebugEnabled()) { |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
566 logger.info("artifactOutdated: id = " + id); |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
567 } |
30
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
568 if (cleaner != null) { |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
569 cleaner.wakeup(); |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
570 } |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
571 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
572 |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
573 public Artifact reviveArtifact(String factoryName, byte [] bytes) { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
574 if (factoryLookup == null) { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
575 logger.error("reviveArtifact: factory lookup == null"); |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
576 return null; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
577 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
578 ArtifactFactory factory = factoryLookup |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
579 .getArtifactFactory(factoryName); |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
580 |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
581 if (factory == null) { |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
582 logger.error( |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
583 "reviveArtifact: no factory '" + factoryName + "' found"); |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
584 return null; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
585 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
586 |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
587 ArtifactSerializer serializer = factory.getSerializer(); |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
588 |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
589 return serializer.fromBytes(bytes); |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
590 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
591 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
592 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
593 * Internal method to store/replace an artifact inside the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
594 * If an artifact with the given identifier does not exists it is |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
595 * created else only the content data is updated. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
596 * @param artifact The artifact to be store/update inside the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
597 * @param factory The factory that created the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
598 * @param ttl The initial time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
599 * @return The database id of the stored/updated artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
600 */ |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
601 protected int storeOrReplaceDatabase( |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
602 final Artifact artifact, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
603 final ArtifactFactory factory, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
604 final Long ttl |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
605 ) { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
606 final String uuid = artifact.identifier(); |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
607 |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
608 if (!isValidIdentifier(uuid)) { |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
609 throw new RuntimeException("No valid UUID"); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
610 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
611 |
313
ddc35c950e97
Backend: Handle forgotten store/create event source.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
312
diff
changeset
|
612 final int [] id = new int[1]; |
ddc35c950e97
Backend: Handle forgotten store/create event source.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
312
diff
changeset
|
613 final boolean [] stored = new boolean[1]; |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
614 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
615 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
616 public boolean doIt() throws SQLException { |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
617 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
618 prepareStatement(SQL_GET_ID); |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
619 stmnt.setString(1, uuid); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
620 result = stmnt.executeQuery(); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
621 |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
622 Integer ID = result.next() |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
623 ? Integer.valueOf(result.getInt(1)) |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
624 : null; |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
625 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
626 reset(); |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
627 |
313
ddc35c950e97
Backend: Handle forgotten store/create event source.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
312
diff
changeset
|
628 if (stored[0] = ID != null) { // already in database |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
629 prepareStatement(SQL_REPLACE); |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
630 |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
631 if (ttl == null) { |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
632 stmnt.setNull(1, Types.BIGINT); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
633 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
634 else { |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
635 stmnt.setLong(1, ttl.longValue()); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
636 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
637 |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
638 stmnt.setString(2, factory.getName()); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
639 stmnt.setBytes( |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
640 3, |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
641 factory.getSerializer().toBytes(artifact)); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
642 id[0] = ID.intValue(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
643 stmnt.setInt(4, id[0]); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
644 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
645 else { // new artifact |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
646 prepareStatement(SQL_NEXT_ID); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
647 result = stmnt.executeQuery(); |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
648 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
649 if (!result.next()) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
650 logger.error("No id generated"); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
651 return false; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
652 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
653 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
654 reset(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
655 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
656 prepareStatement(SQL_INSERT); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
657 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
658 id[0] = result.getInt(1); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
659 stmnt.setInt(1, id[0]); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
660 stmnt.setString(2, uuid); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
661 if (ttl == null) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
662 stmnt.setNull(3, Types.BIGINT); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
663 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
664 else { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
665 stmnt.setLong(3, ttl.longValue()); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
666 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
667 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
668 stmnt.setString(4, factory.getName()); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
669 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
670 stmnt.setBytes( |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
671 5, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
672 factory.getSerializer().toBytes(artifact)); |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
673 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
674 stmnt.execute(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
675 conn.commit(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
676 return true; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
677 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
678 }; |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
679 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
680 if (!exec.runWrite()) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
681 throw new RuntimeException("failed insert artifact into database"); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
682 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
683 |
313
ddc35c950e97
Backend: Handle forgotten store/create event source.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
312
diff
changeset
|
684 if (stored[0]) { |
ddc35c950e97
Backend: Handle forgotten store/create event source.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
312
diff
changeset
|
685 fireStoredArtifact(artifact); |
ddc35c950e97
Backend: Handle forgotten store/create event source.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
312
diff
changeset
|
686 } |
ddc35c950e97
Backend: Handle forgotten store/create event source.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
312
diff
changeset
|
687 else { |
ddc35c950e97
Backend: Handle forgotten store/create event source.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
312
diff
changeset
|
688 fireCreatedArtifact(artifact); |
ddc35c950e97
Backend: Handle forgotten store/create event source.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
312
diff
changeset
|
689 } |
ddc35c950e97
Backend: Handle forgotten store/create event source.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
312
diff
changeset
|
690 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
691 return id[0]; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
692 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
693 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
694 /** |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
695 * Internal method to store an artifact inside the database. |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
696 * @param artifact The artifact to be stored. |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
697 * @param factory The factory which created the artifact. |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
698 * @param ttl The initial time to live of the artifact. |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
699 * @return The database id of the stored artifact. |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
700 */ |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
701 protected int insertDatabase( |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
702 final Artifact artifact, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
703 final ArtifactFactory factory, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
704 final Long ttl |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
705 ) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
706 final int [] id = new int[1]; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
707 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
708 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
709 public boolean doIt() throws SQLException { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
710 prepareStatement(SQL_NEXT_ID); |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
711 result = stmnt.executeQuery(); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
712 |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
713 if (!result.next()) { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
714 logger.error("No id generated"); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
715 return false; |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
716 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
717 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
718 id[0] = result.getInt(1); |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
719 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
720 reset(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
721 prepareStatement(SQL_INSERT); |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
722 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
723 String uuid = artifact.identifier(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
724 stmnt.setInt(1, id[0]); |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
725 stmnt.setString(2, uuid); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
726 if (ttl == null) { |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
727 stmnt.setNull(3, Types.BIGINT); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
728 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
729 else { |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
730 stmnt.setLong(3, ttl.longValue()); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
731 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
732 |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
733 stmnt.setString(4, factory.getName()); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
734 |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
735 stmnt.setBytes( |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
736 5, |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
737 factory.getSerializer().toBytes(artifact)); |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
738 |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
739 stmnt.execute(); |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
740 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
741 conn.commit(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
742 return true; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
743 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
744 }; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
745 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
746 if (!exec.runWrite()) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
747 throw new RuntimeException("failed insert artifact into database"); |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
748 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
749 |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
750 fireCreatedArtifact(artifact); |
310
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
751 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
752 return id[0]; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
753 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
754 |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
755 protected void fireCreatedArtifact(Artifact artifact) { |
310
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
756 for (BackendListener listener: listeners) { |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
757 listener.createdArtifact(artifact, this); |
310
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
758 } |
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
759 } |
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
760 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
761 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
762 * Touches the access timestamp of a given artifact to prevent |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
763 * that it will be removed from the database by the database cleaner. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
764 * @param artifact The persistent wrapper around the living artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
765 */ |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
766 public void touch(final PersistentArtifact artifact) { |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
767 sqlExecutor.new Instance() { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
768 public boolean doIt() throws SQLException { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
769 prepareStatement(SQL_TOUCH); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
770 stmnt.setInt(1, artifact.getId()); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
771 stmnt.execute(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
772 conn.commit(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
773 return true; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
774 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
775 }.runWrite(); |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
776 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
777 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
778 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
779 * Writes modification of an artifact back to the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
780 * @param artifact The persistent wrapper around a living |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
781 * artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
782 */ |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
783 public void store(final PersistentArtifact artifact) { |
310
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
784 boolean success = sqlExecutor.new Instance() { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
785 public boolean doIt() throws SQLException { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
786 prepareStatement(SQL_UPDATE); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
787 stmnt.setInt(2, artifact.getId()); |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
788 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
789 byte [] bytes = artifact |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
790 .getSerializer() |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
791 .toBytes(artifact.getArtifact()); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
792 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
793 stmnt.setBytes(1, bytes); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
794 stmnt.execute(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
795 conn.commit(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
796 return true; |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
797 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
798 }.runWrite(); |
310
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
799 |
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
800 if (success) { |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
801 fireStoredArtifact(artifact.getArtifact()); |
310
63122b9dee1d
Added interface to listen events in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
309
diff
changeset
|
802 } |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
803 } |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
804 |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
805 protected void fireStoredArtifact(Artifact artifact) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
806 for (BackendListener listener: listeners) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
807 listener.storedArtifact(artifact, this); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
808 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
809 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
810 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
811 |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
812 public User createUser( |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
813 final String name, |
410
f456d9d55541
Read the account information from the database
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
393
diff
changeset
|
814 final String account, |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
815 final Document role, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
816 final UserFactory factory, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
817 final Object context |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
818 ) { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
819 final User [] user = new User[1]; |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
820 |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
821 final byte [] roleData = XMLUtils.toByteArray(role, true); |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
822 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
823 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
824 public boolean doIt() throws SQLException { |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
825 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
826 prepareStatement(SQL_USERS_NEXT_ID); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
827 result = stmnt.executeQuery(); |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
828 |
146
967dc552455d
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
145
diff
changeset
|
829 if (!result.next()) { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
830 return false; |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
831 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
832 |
145
c0d025df722d
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
144
diff
changeset
|
833 int id = result.getInt(1); |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
834 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
835 reset(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
836 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
837 String identifier = newIdentifier(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
838 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
839 prepareStatement(SQL_USERS_INSERT); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
840 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
841 stmnt.setInt(1, id); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
842 stmnt.setString(2, identifier); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
843 stmnt.setString(3, name); |
410
f456d9d55541
Read the account information from the database
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
393
diff
changeset
|
844 stmnt.setString(4, account); |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
845 |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
846 if (roleData == null) { |
410
f456d9d55541
Read the account information from the database
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
393
diff
changeset
|
847 stmnt.setNull(5, Types.BIGINT); |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
848 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
849 else { |
410
f456d9d55541
Read the account information from the database
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
393
diff
changeset
|
850 stmnt.setBytes(5, roleData); |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
851 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
852 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
853 stmnt.execute(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
854 conn.commit(); |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
855 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
856 user[0] = factory.createUser( |
410
f456d9d55541
Read the account information from the database
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
393
diff
changeset
|
857 identifier, name, account, role, context); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
858 return true; |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
859 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
860 }; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
861 |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
862 boolean success = exec.runWrite(); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
863 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
864 if (success) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
865 fireCreatedUser(user[0]); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
866 return user[0]; |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
867 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
868 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
869 return null; |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
870 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
871 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
872 protected void fireCreatedUser(User user) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
873 for (BackendListener listener: listeners) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
874 listener.createdUser(user, this); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
875 } |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
876 } |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
877 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
878 public boolean deleteUser(final String identifier) { |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
879 |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
880 if (!isValidIdentifier(identifier)) { |
154
1a72f08ce8d7
Propagate delete user errors correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
881 return false; |
147
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
882 } |
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
883 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
884 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
885 public boolean doIt() throws SQLException { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
886 prepareStatement(SQL_USERS_SELECT_ID_BY_GID); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
887 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
888 stmnt.setString(1, identifier); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
889 result = stmnt.executeQuery(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
890 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
891 if (!result.next()) { // No such user |
154
1a72f08ce8d7
Propagate delete user errors correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
892 return false; |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
893 } |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
894 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
895 int id = result.getInt(1); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
896 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
897 reset(); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
898 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
899 // outdate the artifacts exclusively used by the user |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
900 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
901 prepareStatement(SQL_OUTDATE_ARTIFACTS_USER); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
902 stmnt.setInt(1, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
903 stmnt.setInt(2, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
904 stmnt.execute(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
905 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
906 reset(); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
907 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
908 // delete the collection items of the user |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
909 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
910 prepareStatement(SQL_DELETE_USER_COLLECTION_ITEMS); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
911 stmnt.setInt(1, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
912 stmnt.execute(); |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
913 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
914 reset(); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
915 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
916 // delete the collections of the user |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
917 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
918 prepareStatement(SQL_USERS_DELETE_COLLECTIONS); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
919 stmnt.setInt(1, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
920 stmnt.execute(); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
921 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
922 reset(); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
923 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
924 // delete the user |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
925 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
926 prepareStatement(SQL_USERS_DELETE_ID); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
927 stmnt.setInt(1, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
928 stmnt.execute(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
929 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
930 conn.commit(); |
154
1a72f08ce8d7
Propagate delete user errors correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
931 return true; |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
932 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
933 }; |
154
1a72f08ce8d7
Propagate delete user errors correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
934 |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
935 boolean success = exec.runWrite(); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
936 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
937 if (success) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
938 fireDeletedUser(identifier); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
939 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
940 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
941 return success; |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
942 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
943 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
944 protected void fireDeletedUser(String identifier) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
945 for (BackendListener listener: listeners) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
946 listener.deletedUser(identifier, this); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
947 } |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
948 } |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
949 |
157
6e6965873a48
Simplified creation of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
156
diff
changeset
|
950 public User getUser( |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
951 final String identifier, |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
952 final UserFactory factory, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
953 final Object context |
157
6e6965873a48
Simplified creation of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
156
diff
changeset
|
954 ) { |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
955 if (!isValidIdentifier(identifier)) { |
147
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
956 logger.debug("Invalid UUID: '" + identifier + "'"); |
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
957 return null; |
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
958 } |
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
959 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
960 final User [] user = new User[1]; |
147
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
961 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
962 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
963 public boolean doIt() throws SQLException { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
964 prepareStatement(SQL_USERS_SELECT_GID); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
965 stmnt.setString(1, identifier); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
966 result = stmnt.executeQuery(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
967 if (!result.next()) { // no such user |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
968 return false; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
969 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
970 // omit id |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
971 String name = result.getString(2); |
410
f456d9d55541
Read the account information from the database
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
393
diff
changeset
|
972 String account = result.getString(3); |
f456d9d55541
Read the account information from the database
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
393
diff
changeset
|
973 byte [] roleData = result.getBytes(4); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
974 |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
975 Document role = XMLUtils.fromByteArray(roleData, true); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
976 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
977 user[0] = factory.createUser( |
410
f456d9d55541
Read the account information from the database
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
393
diff
changeset
|
978 identifier, name, account, role, context); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
979 return true; |
147
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
980 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
981 }; |
147
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
982 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
983 return exec.runRead() ? user[0] : null; |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
984 } |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
985 |
413
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
986 /** |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
987 * Find/Get user by account |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
988 */ |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
989 public User findUser( |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
990 final String account, |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
991 final UserFactory factory, |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
992 final Object context |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
993 ) { |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
994 |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
995 final User [] user = new User[1]; |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
996 logger.debug("Tying to find user by account " + account); |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
997 |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
998 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
999 public boolean doIt() throws SQLException { |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1000 prepareStatement(SQL_USERS_SELECT_ACCOUNT); |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1001 stmnt.setString(1, account); |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1002 result = stmnt.executeQuery(); |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1003 if (!result.next()) { // no such user |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1004 logger.debug("No user found."); |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1005 return false; |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1006 } |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1007 String identifier = result.getString(1); |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1008 String name = result.getString(2); |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1009 String account = result.getString(3); |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1010 byte [] roleData = result.getBytes(4); |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1011 |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1012 Document role = XMLUtils.fromByteArray(roleData, true); |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1013 |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1014 user[0] = factory.createUser( |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1015 identifier, name, account, role, context); |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1016 return true; |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1017 } |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1018 }; |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1019 |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1020 return exec.runRead() ? user[0] : null; |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1021 } |
f5ecca16f601
Implement method to find/get a user by its account name
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
410
diff
changeset
|
1022 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1023 public User [] getUsers( |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
1024 final UserFactory factory, |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1025 final Object context |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1026 ) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1027 final ArrayList<User> users = new ArrayList<User>(); |
148
101a52d3ad08
Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
147
diff
changeset
|
1028 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
1029 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1030 public boolean doIt() throws SQLException { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1031 prepareStatement(SQL_USERS_SELECT_ALL); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1032 result = stmnt.executeQuery(); |
148
101a52d3ad08
Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
147
diff
changeset
|
1033 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1034 while (result.next()) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1035 // omit id |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1036 String identifier = result.getString(2); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1037 String name = result.getString(3); |
410
f456d9d55541
Read the account information from the database
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
393
diff
changeset
|
1038 String account = result.getString(4); |
f456d9d55541
Read the account information from the database
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
393
diff
changeset
|
1039 byte [] roleData = result.getBytes(5); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1040 |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1041 Document role = XMLUtils.fromByteArray(roleData, true); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1042 User user = factory.createUser( |
410
f456d9d55541
Read the account information from the database
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
393
diff
changeset
|
1043 identifier, name, account, role, context); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1044 users.add(user); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1045 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1046 return true; |
148
101a52d3ad08
Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
147
diff
changeset
|
1047 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1048 }; |
148
101a52d3ad08
Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
147
diff
changeset
|
1049 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1050 return exec.runRead() |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1051 ? users.toArray(new User[users.size()]) |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1052 : null; |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
1053 } |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1054 |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1055 public ArtifactCollection createCollection( |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
1056 final String ownerIdentifier, |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1057 final String name, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1058 final ArtifactCollectionFactory factory, |
199
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1059 final Document attribute, |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1060 final Object context |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1061 ) { |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1062 if (name == null) { |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1063 logger.debug("Name is null"); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1064 return null; |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1065 } |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1066 |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
1067 if (!isValidIdentifier(ownerIdentifier)) { |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1068 logger.debug("Invalid owner id: '" + ownerIdentifier + "'"); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1069 return null; |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1070 } |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1071 |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1072 final ArtifactCollection [] collection = new ArtifactCollection[1]; |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1073 |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1074 final byte [] data = XMLUtils.toByteArray(attribute, true); |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1075 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
1076 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1077 public boolean doIt() throws SQLException { |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1078 // fetch owner id |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1079 prepareStatement(SQL_USERS_SELECT_ID_BY_GID); |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1080 stmnt.setString(1, ownerIdentifier); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1081 result = stmnt.executeQuery(); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1082 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1083 if (!result.next()) { // no such user |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1084 return false; |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1085 } |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1086 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1087 int ownerId = result.getInt(1); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1088 reset(); |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1089 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1090 // fetch new collection seq number. |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1091 prepareStatement(SQL_COLLECTIONS_NEXT_ID); |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1092 result = stmnt.executeQuery(); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1093 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1094 if (!result.next()) { // no identifier generated |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1095 return false; |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1096 } |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1097 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1098 int id = result.getInt(1); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1099 reset(); |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1100 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1101 String identifier = newIdentifier(); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1102 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1103 prepareStatement(SQL_COLLECTIONS_INSERT); |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1104 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1105 stmnt.setInt(1, id); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1106 stmnt.setString(2, identifier); |
161
e4a1562dfc21
Bugfixed the collection creation in the Backend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
159
diff
changeset
|
1107 stmnt.setString(3, name); |
e4a1562dfc21
Bugfixed the collection creation in the Backend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
159
diff
changeset
|
1108 stmnt.setInt(4, ownerId); |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1109 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1110 // XXX: A bit odd: we don't have a collection, yet. |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1111 Long ttl = factory.timeToLiveUntouched(null, context); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1112 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1113 if (ttl == null) { |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1114 stmnt.setNull(5, Types.BIGINT); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1115 } |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1116 else { |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1117 stmnt.setLong(5, ttl); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1118 } |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1119 |
199
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1120 if (data == null) { |
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1121 stmnt.setNull(6, Types.BINARY); |
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1122 } |
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1123 else { |
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1124 stmnt.setBytes(6, data); |
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1125 } |
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1126 |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1127 stmnt.execute(); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1128 conn.commit(); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1129 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1130 reset(); |
170
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1131 |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1132 // fetch creation time from database |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1133 // done this way to use the time system |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1134 // of the database. |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1135 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1136 prepareStatement(SQL_COLLECTIONS_CREATION_TIME); |
170
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1137 stmnt.setInt(1, id); |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1138 |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1139 result = stmnt.executeQuery(); |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1140 |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1141 Date creationTime = null; |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1142 |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1143 if (result.next()) { |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1144 Timestamp timestamp = result.getTimestamp(1); |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1145 creationTime = new Date(timestamp.getTime()); |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1146 } |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1147 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1148 collection[0] = factory.createCollection( |
281
942a54670a72
Made the TTL of a Collection retrievable via getter method.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
275
diff
changeset
|
1149 identifier, name, creationTime, ttl, attribute, context); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1150 |
316
0ca9b1073ccf
Added dummy user to fresh created collections to have it available in the backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
314
diff
changeset
|
1151 if (collection[0] != null) { |
0ca9b1073ccf
Added dummy user to fresh created collections to have it available in the backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
314
diff
changeset
|
1152 // XXX: Little hack to make the listeners happy |
0ca9b1073ccf
Added dummy user to fresh created collections to have it available in the backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
314
diff
changeset
|
1153 collection[0].setUser(new DefaultUser(ownerIdentifier)); |
0ca9b1073ccf
Added dummy user to fresh created collections to have it available in the backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
314
diff
changeset
|
1154 } |
0ca9b1073ccf
Added dummy user to fresh created collections to have it available in the backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
314
diff
changeset
|
1155 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1156 return true; |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1157 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1158 }; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1159 |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1160 boolean success = exec.runWrite(); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1161 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1162 if (success) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1163 fireCreatedCollection(collection[0]); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1164 return collection[0]; |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1165 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1166 return null; |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1167 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1168 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1169 protected void fireCreatedCollection(ArtifactCollection collection) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1170 for (BackendListener listener: listeners) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1171 listener.createdCollection(collection, this); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1172 } |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1173 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1174 |
217
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1175 public ArtifactCollection getCollection( |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1176 final String collectionId, |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1177 final ArtifactCollectionFactory collectionFactory, |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1178 final UserFactory userFactory, |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1179 final Object context |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1180 ) { |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1181 if (!isValidIdentifier(collectionId)) { |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1182 logger.debug("collection id is not valid: " + collectionId); |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1183 return null; |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1184 } |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1185 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1186 final ArtifactCollection[] ac = new ArtifactCollection[1]; |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1187 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
1188 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
217
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1189 public boolean doIt() throws SQLException { |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1190 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1191 prepareStatement(SQL_COLLECTIONS_SELECT_GID); |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1192 stmnt.setString(1, collectionId); |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1193 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1194 result = stmnt.executeQuery(); |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1195 if (!result.next()) { |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1196 logger.debug("No such collection"); |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1197 return false; |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1198 } |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1199 |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1200 String collectionName = result.getString(2); |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1201 String ownerId = result.getString(3); |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1202 Date creationTime = |
217
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1203 new Date(result.getTimestamp(4).getTime()); |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1204 Date lastAccess = |
217
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1205 new Date(result.getTimestamp(5).getTime()); |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1206 Document attr = |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1207 XMLUtils.fromByteArray(result.getBytes(6), true); |
281
942a54670a72
Made the TTL of a Collection retrievable via getter method.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
275
diff
changeset
|
1208 long ttl = result.getLong(7); |
217
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1209 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1210 ArtifactCollection collection = |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1211 collectionFactory.createCollection( |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1212 collectionId, |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1213 collectionName, |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1214 creationTime, |
281
942a54670a72
Made the TTL of a Collection retrievable via getter method.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
275
diff
changeset
|
1215 ttl, |
217
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1216 attr, |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1217 context); |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1218 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1219 if (ownerId != null) { |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1220 collection.setUser(new LazyBackendUser( |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1221 ownerId, userFactory, Backend.this, context)); |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1222 } |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1223 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1224 ac[0] = collection; |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1225 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1226 return true; |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1227 } |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1228 }; |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1229 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1230 return exec.runRead() ? ac[0] : null; |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1231 } |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1232 |
164
268c2972d4a7
Implemented the interface method listCollections() in the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
161
diff
changeset
|
1233 public ArtifactCollection [] listCollections( |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1234 final String ownerIdentifier, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1235 final Document data, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1236 final ArtifactCollectionFactory collectionFactory, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1237 final UserFactory userFactory, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1238 final Object context |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1239 ) { |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
1240 if (ownerIdentifier != null |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
1241 && !isValidIdentifier(ownerIdentifier)) { |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1242 logger.debug("Invalid owner id: '" + ownerIdentifier + "'"); |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1243 return null; |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1244 } |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1245 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1246 final ArrayList<ArtifactCollection> collections = |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1247 new ArrayList<ArtifactCollection>(); |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1248 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
1249 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1250 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1251 public boolean doIt() throws SQLException { |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1252 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1253 if (ownerIdentifier != null) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1254 prepareStatement(SQL_COLLECTIONS_SELECT_USER); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1255 stmnt.setString(1, ownerIdentifier); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1256 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1257 else { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1258 prepareStatement(SQL_COLLECTIONS_SELECT_ALL); |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1259 } |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1260 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1261 result = stmnt.executeQuery(); |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1262 |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1263 HashMap<String, LazyBackendUser> users = |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1264 new HashMap<String, LazyBackendUser>(); |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1265 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1266 while (result.next()) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1267 String collectionIdentifier = result.getString(1); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1268 String collectionName = result.getString(2); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1269 Date creationTime = |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1270 new Date(result.getTimestamp(3).getTime()); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1271 String userIdentifier = result.getString(4); |
281
942a54670a72
Made the TTL of a Collection retrievable via getter method.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
275
diff
changeset
|
1272 long ttl = result.getLong(5); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1273 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1274 ArtifactCollection collection = |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1275 collectionFactory.createCollection( |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1276 collectionIdentifier, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1277 collectionName, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1278 creationTime, |
281
942a54670a72
Made the TTL of a Collection retrievable via getter method.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
275
diff
changeset
|
1279 ttl, |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1280 data, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1281 context); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1282 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1283 if (userIdentifier != null) { |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1284 LazyBackendUser user = users.get(userIdentifier); |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1285 if (user == null) { |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1286 user = new LazyBackendUser( |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1287 userIdentifier, userFactory, |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1288 Backend.this, context); |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1289 users.put(userIdentifier, user); |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1290 } |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1291 collection.setUser(user); |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1292 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1293 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1294 collections.add(collection); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1295 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1296 return true; |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1297 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1298 }; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1299 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1300 return exec.runRead() |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1301 ? collections.toArray(new ArtifactCollection[collections.size()]) |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1302 : null; |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1303 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1304 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1305 |
343
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1306 public String getMasterArtifact(final String collectionId) { |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1307 if (!isValidIdentifier(collectionId)) { |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1308 logger.debug("Invalid collection id: '" + collectionId + "'"); |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1309 return null; |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1310 } |
345
7514fe89efef
Backend.getMasterArtifact: Limit result to one row.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
344
diff
changeset
|
1311 final String [] uuid = new String[1]; |
7514fe89efef
Backend.getMasterArtifact: Limit result to one row.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
344
diff
changeset
|
1312 |
343
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1313 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1314 public boolean doIt() throws SQLException { |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1315 // Fetch masters (oldest artifact) id. |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1316 prepareStatement(SQL_COLLECTIONS_OLDEST_ARTIFACT); |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1317 stmnt.setString(1, collectionId); |
345
7514fe89efef
Backend.getMasterArtifact: Limit result to one row.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
344
diff
changeset
|
1318 stmnt.setMaxRows(1); // |
343
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1319 result = stmnt.executeQuery(); |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1320 if (!result.next()) { |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1321 logger.debug("No such collection: " + collectionId); |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1322 return false; |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1323 } |
345
7514fe89efef
Backend.getMasterArtifact: Limit result to one row.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
344
diff
changeset
|
1324 uuid[0] = result.getString(1); |
7514fe89efef
Backend.getMasterArtifact: Limit result to one row.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
344
diff
changeset
|
1325 if (logger.isDebugEnabled()) { |
7514fe89efef
Backend.getMasterArtifact: Limit result to one row.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
344
diff
changeset
|
1326 logger.debug("getMasterArtifact result.getString " + |
7514fe89efef
Backend.getMasterArtifact: Limit result to one row.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
344
diff
changeset
|
1327 uuid[0]); |
7514fe89efef
Backend.getMasterArtifact: Limit result to one row.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
344
diff
changeset
|
1328 } |
343
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1329 return true; |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1330 } |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1331 }; |
345
7514fe89efef
Backend.getMasterArtifact: Limit result to one row.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
344
diff
changeset
|
1332 return exec.runRead() ? uuid[0] : null; |
343
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1333 } |
542caebea773
Add functionality to get 'oldest' artifact of a collection.'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
320
diff
changeset
|
1334 |
175
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1335 public boolean deleteCollection(final String collectionId) { |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
1336 if (!isValidIdentifier(collectionId)) { |
175
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1337 logger.debug("Invalid collection id: '" + collectionId + "'"); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1338 return false; |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1339 } |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
1340 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
175
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1341 public boolean doIt() throws SQLException { |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1342 // fetch collection id |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1343 prepareStatement(SQL_COLLECTIONS_ID_BY_GID); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1344 stmnt.setString(1, collectionId); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1345 result = stmnt.executeQuery(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1346 if (!result.next()) { |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1347 logger.debug("No such collection: " + collectionId); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1348 return false; |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1349 } |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1350 int id = result.getInt(1); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1351 reset(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1352 |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1353 // outdate artifacts that are only in this collection |
393
b7831cefbb62
Added some more debug output during the process of removing Artifacts and Collections by the DatabaseCleaner.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
345
diff
changeset
|
1354 logger.info("Outdate Artifacts that belong to collection: " + id); |
b7831cefbb62
Added some more debug output during the process of removing Artifacts and Collections by the DatabaseCleaner.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
345
diff
changeset
|
1355 |
175
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1356 prepareStatement(SQL_OUTDATE_ARTIFACTS_COLLECTION); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1357 stmnt.setInt(1, id); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1358 stmnt.setInt(2, id); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1359 stmnt.execute(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1360 reset(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1361 |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1362 // delete the collection items |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1363 prepareStatement(SQL_DELETE_COLLECTION_ITEMS); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1364 stmnt.setInt(1, id); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1365 stmnt.execute(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1366 reset(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1367 |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1368 // delete the collection |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1369 prepareStatement(SQL_DELETE_COLLECTION); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1370 stmnt.setInt(1, id); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1371 stmnt.execute(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1372 conn.commit(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1373 return true; |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1374 } |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1375 }; |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1376 boolean success = exec.runWrite(); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1377 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1378 if (success) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1379 fireDeletedCollection(collectionId); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1380 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1381 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1382 return success; |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1383 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1384 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1385 protected void fireDeletedCollection(String identifier) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1386 for (BackendListener listener: listeners) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1387 listener.deletedCollection(identifier, this); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1388 } |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1389 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1390 |
253
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1391 public Document getCollectionAttribute(final String collectionId) { |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1392 if (!isValidIdentifier(collectionId)) { |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1393 logger.debug("collection id is not valid: " + collectionId); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1394 } |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1395 |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1396 final byte[][] data = new byte[1][1]; |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1397 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
1398 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
253
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1399 public boolean doIt() throws SQLException { |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1400 prepareStatement(SQL_COLLECTION_GET_ATTRIBUTE); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1401 stmnt.setString(1, collectionId); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1402 result = stmnt.executeQuery(); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1403 if (!result.next()) { |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1404 logger.debug("No such collection."); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1405 return false; |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1406 } |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1407 |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1408 data[0] = result.getBytes(1); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1409 return true; |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1410 } |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1411 }; |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1412 |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1413 return exec.runRead() |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1414 ? XMLUtils.fromByteArray(data[0], true) |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1415 : null; |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1416 } |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1417 |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1418 public boolean setCollectionAttribute( |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1419 final String collectionId, |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1420 Document attribute |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1421 ) { |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1422 if (!isValidIdentifier(collectionId)) { |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1423 logger.debug("collection id is not valid: " + collectionId); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1424 return false; |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1425 } |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1426 |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1427 final byte [] data = XMLUtils.toByteArray(attribute, true); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1428 |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1429 boolean success = sqlExecutor.new Instance() { |
253
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1430 public boolean doIt() throws SQLException { |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1431 |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1432 // set the column in collection items |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1433 prepareStatement(SQL_COLLECTION_SET_ATTRIBUTE); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1434 if (data == null) { |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1435 stmnt.setNull(1, Types.BINARY); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1436 } |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1437 else { |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1438 stmnt.setBytes(1, data); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1439 } |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1440 stmnt.setString(2, collectionId); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1441 stmnt.execute(); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1442 reset(); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1443 |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1444 // touch the collection |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1445 prepareStatement(SQL_COLLECTIONS_TOUCH_BY_GID); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1446 stmnt.setString(1, collectionId); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1447 stmnt.execute(); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1448 |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1449 conn.commit(); |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1450 return true; |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1451 } |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1452 }.runWrite(); |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1453 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1454 if (success) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1455 fireChangedCollectionAttribute(collectionId, attribute); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1456 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1457 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1458 return success; |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1459 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1460 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1461 protected void fireChangedCollectionAttribute( |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1462 String collectionId, |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1463 Document document |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1464 ) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1465 for (BackendListener listener: listeners) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1466 listener.changedCollectionAttribute(collectionId, document, this); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1467 } |
253
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1468 } |
a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
252
diff
changeset
|
1469 |
252
6de74b0b878e
Changed the method names to get and set the attributes of collection items.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
242
diff
changeset
|
1470 public Document getCollectionItemAttribute( |
178
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1471 final String collectionId, |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1472 final String artifactId |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1473 ) { |
178
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1474 if (!isValidIdentifier(collectionId)) { |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1475 logger.debug("collection id is not valid: " + collectionId); |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1476 return null; |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1477 } |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1478 if (!isValidIdentifier(artifactId)) { |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1479 logger.debug("artifact id is not valid: " + artifactId); |
179
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1480 return null; |
178
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1481 } |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1482 |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1483 final byte [][] data = new byte[1][1]; |
178
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1484 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
1485 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
178
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1486 public boolean doIt() throws SQLException { |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1487 prepareStatement(SQL_COLLECTION_ITEM_GET_ATTRIBUTE); |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1488 stmnt.setString(1, collectionId); |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1489 stmnt.setString(2, artifactId); |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1490 result = stmnt.executeQuery(); |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1491 if (!result.next()) { |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1492 logger.debug("No such collection item"); |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1493 return false; |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1494 } |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1495 data[0] = result.getBytes(1); |
178
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1496 return true; |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1497 } |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1498 }; |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1499 |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1500 return exec.runRead() |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1501 ? XMLUtils.fromByteArray(data[0], true) |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1502 : null; |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1503 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1504 |
252
6de74b0b878e
Changed the method names to get and set the attributes of collection items.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
242
diff
changeset
|
1505 public boolean setCollectionItemAttribute( |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
1506 final String collectionId, |
179
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1507 final String artifactId, |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1508 Document attribute |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1509 ) { |
179
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1510 if (!isValidIdentifier(collectionId)) { |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1511 logger.debug("collection id is not valid: " + collectionId); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1512 return false; |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1513 } |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1514 if (!isValidIdentifier(artifactId)) { |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1515 logger.debug("artifact id is not valid: " + artifactId); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1516 return false; |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1517 } |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1518 |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1519 final byte [] data = XMLUtils.toByteArray(attribute, true); |
179
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1520 |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1521 boolean success = sqlExecutor.new Instance() { |
179
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1522 public boolean doIt() throws SQLException { |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1523 |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1524 // set the column in collection items |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1525 prepareStatement(SQL_COLLECTION_ITEM_SET_ATTRIBUTE); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1526 if (data == null) { |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1527 stmnt.setNull(1, Types.BINARY); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1528 } |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1529 else { |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1530 stmnt.setBytes(1, data); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1531 } |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1532 stmnt.setString(2, collectionId); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1533 stmnt.setString(3, artifactId); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1534 stmnt.execute(); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1535 reset(); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1536 |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1537 // touch the collection |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1538 prepareStatement(SQL_COLLECTIONS_TOUCH_BY_GID); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1539 stmnt.setString(1, collectionId); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1540 stmnt.execute(); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1541 |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1542 conn.commit(); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1543 return true; |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1544 } |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1545 }.runWrite(); |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1546 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1547 if (success) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1548 fireChangedCollectionItemAttribute( |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1549 collectionId, artifactId, attribute); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1550 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1551 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1552 return success; |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1553 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1554 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1555 protected void fireChangedCollectionItemAttribute( |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1556 String collectionId, |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1557 String artifactId, |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1558 Document document |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1559 ) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1560 for (BackendListener listener: listeners) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1561 listener.changedCollectionItemAttribute( |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1562 collectionId, artifactId, document, this); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1563 } |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1564 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1565 |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1566 public boolean addCollectionArtifact( |
176
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1567 final String collectionId, |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1568 final String artifactId, |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1569 final Document attribute |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1570 ) { |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
1571 if (!isValidIdentifier(collectionId)) { |
176
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1572 logger.debug("Invalid collection id: '" + collectionId + "'"); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1573 return false; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1574 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1575 |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
1576 if (!isValidIdentifier(artifactId)) { |
176
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1577 logger.debug("Invalid artifact id: '" + artifactId + "'"); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1578 return false; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1579 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1580 |
235
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1581 final byte [] data = XMLUtils.toByteArray(attribute, true); |
3e29395ebac6
The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
233
diff
changeset
|
1582 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
1583 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
176
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1584 public boolean doIt() throws SQLException { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1585 // fetch artifact id |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1586 prepareStatement(SQL_GET_ID); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1587 stmnt.setString(1, artifactId); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1588 result = stmnt.executeQuery(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1589 if (!result.next()) { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1590 logger.debug("No such artifact: " + artifactId); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1591 return false; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1592 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1593 int aid = result.getInt(1); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1594 reset(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1595 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1596 // fetch collection id |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1597 prepareStatement(SQL_COLLECTIONS_ID_BY_GID); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1598 stmnt.setString(1, collectionId); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1599 result = stmnt.executeQuery(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1600 if (!result.next()) { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1601 logger.debug("No such collection: " + collectionId); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1602 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1603 int cid = result.getInt(1); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1604 reset(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1605 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1606 // check if artifact is already in collection |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1607 prepareStatement(SQL_COLLECTION_CHECK_ARTIFACT); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1608 stmnt.setInt(1, aid); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1609 stmnt.setInt(2, cid); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1610 result = stmnt.executeQuery(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1611 if (result.next()) { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1612 logger.debug("artifact already in collection"); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1613 return false; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1614 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1615 reset(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1616 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1617 // fetch fresh id for new collection item |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1618 prepareStatement(SQL_COLLECTION_ITEMS_ID_NEXTVAL); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1619 result = stmnt.executeQuery(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1620 if (!result.next()) { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1621 logger.debug("no collection item id generated"); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1622 return false; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1623 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1624 int ci_id = result.getInt(1); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1625 reset(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1626 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1627 // insert new collection item |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1628 prepareStatement(SQL_COLLECTION_ITEMS_INSERT); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1629 stmnt.setInt(1, ci_id); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1630 stmnt.setInt(2, cid); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1631 stmnt.setInt(3, aid); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1632 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1633 if (data == null) { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1634 stmnt.setNull(4, Types.BINARY); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1635 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1636 else { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1637 stmnt.setBytes(4, data); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1638 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1639 stmnt.execute(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1640 conn.commit(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1641 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1642 return true; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1643 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1644 }; |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1645 boolean success = exec.runWrite(); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1646 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1647 if (success) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1648 fireAddedArtifactToCollection(artifactId, collectionId); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1649 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1650 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1651 return success; |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1652 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1653 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1654 protected void fireAddedArtifactToCollection( |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1655 String artifactId, |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1656 String collectionId |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1657 ) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1658 for (BackendListener listener: listeners) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1659 listener.addedArtifactToCollection( |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1660 artifactId, collectionId, this); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1661 } |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1662 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1663 |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1664 public boolean removeCollectionArtifact( |
180
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1665 final String collectionId, |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1666 final String artifactId |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1667 ) { |
180
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1668 if (!isValidIdentifier(collectionId)) { |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1669 logger.debug("Invalid collection id: '" + collectionId + "'"); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1670 return false; |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1671 } |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1672 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1673 boolean success = sqlExecutor.new Instance() { |
180
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1674 public boolean doIt() throws SQLException { |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1675 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1676 // fetch id, collection id and artitfact id |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1677 prepareStatement(SQL_COLLECTION_ITEM_ID_CID_AID); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1678 stmnt.setString(1, collectionId); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1679 stmnt.setString(2, artifactId); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1680 result = stmnt.executeQuery(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1681 if (!result.next()) { |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1682 logger.debug("No such collection item"); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1683 return false; |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1684 } |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1685 int id = result.getInt(1); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1686 int cid = result.getInt(2); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1687 int aid = result.getInt(3); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1688 reset(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1689 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1690 // outdate artifact iff it is only in this collection |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1691 prepareStatement(SQL_COLLECTION_ITEM_OUTDATE_ARTIFACT); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1692 stmnt.setInt(1, aid); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1693 stmnt.setInt(2, cid); |
194
fde2f193e846
Small typo fix
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
193
diff
changeset
|
1694 stmnt.setInt(3, aid); |
180
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1695 stmnt.execute(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1696 reset(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1697 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1698 // delete collection item |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1699 prepareStatement(SQL_COLLECTION_ITEM_DELETE); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1700 stmnt.setInt(1, id); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1701 stmnt.execute(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1702 reset(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1703 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1704 // touch collection |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1705 prepareStatement(SQL_COLLECTIONS_TOUCH_BY_ID); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1706 stmnt.setInt(1, cid); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1707 stmnt.execute(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1708 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1709 conn.commit(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1710 return true; |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1711 } |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1712 }.runWrite(); |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1713 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1714 if (success) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1715 fireRemovedArtifactFromCollection(artifactId, collectionId); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1716 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1717 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1718 return success; |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1719 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1720 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1721 protected void fireRemovedArtifactFromCollection( |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1722 String artifactId, |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1723 String collectionId |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1724 ) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1725 for (BackendListener listener: listeners) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1726 listener.removedArtifactFromCollection( |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1727 artifactId, collectionId, this); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1728 } |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1729 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1730 |
184
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1731 public CollectionItem [] listCollectionArtifacts( |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1732 final String collectionId |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1733 ) { |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1734 if (!isValidIdentifier(collectionId)) { |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1735 logger.debug("Invalid collection id: '" + collectionId + "'"); |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1736 return null; |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1737 } |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1738 |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1739 final ArrayList<CollectionItem> collectionItems = |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1740 new ArrayList<CollectionItem>(); |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1741 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
1742 SQLExecutor.Instance exec = sqlExecutor.new Instance() { |
184
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1743 public boolean doIt() throws SQLException { |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1744 prepareStatement(SQL_COLLECTION_ITEMS_LIST_GID); |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1745 stmnt.setString(1, collectionId); |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1746 result = stmnt.executeQuery(); |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1747 while (result.next()) { |
186
15c7638511dc
Added an interface for CollectionItems and renamed the CollectionItem class from the artifact-database package to DefaultCollectionItem - because this is the default implementation of the interface.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
184
diff
changeset
|
1748 CollectionItem item = new DefaultCollectionItem( |
184
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1749 result.getString(1), |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1750 result.getBytes(2)); |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1751 collectionItems.add(item); |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1752 } |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1753 return true; |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1754 } |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1755 }; |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1756 |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1757 return exec.runRead() |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1758 ? collectionItems.toArray( |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1759 new CollectionItem[collectionItems.size()]) |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1760 : null; |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1761 } |
273
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1762 |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1763 |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1764 public boolean setCollectionTTL(final String uuid, final Long ttl) { |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1765 if (!isValidIdentifier(uuid)) { |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1766 logger.debug("Invalid collection id: '" + uuid + "'"); |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1767 return false; |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1768 } |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1769 |
305
f33401ea2a6c
Artifact database: Refactorized the usage of dialect independent SQL to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
303
diff
changeset
|
1770 return sqlExecutor.new Instance() { |
273
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1771 public boolean doIt() throws SQLException { |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1772 prepareStatement(SQL_UPDATE_COLLECTION_TTL); |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1773 if (ttl == null) { |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1774 stmnt.setNull(1, Types.BIGINT); |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1775 } |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1776 else { |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1777 stmnt.setLong(1, ttl); |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1778 } |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1779 stmnt.setString(2, uuid); |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1780 stmnt.execute(); |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1781 conn.commit(); |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1782 |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1783 return true; |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1784 } |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1785 }.runWrite(); |
22a90706d32d
Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
253
diff
changeset
|
1786 } |
275
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1787 |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1788 |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1789 public boolean setCollectionName(final String uuid, final String name) { |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1790 if (!isValidIdentifier(uuid)) { |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1791 logger.debug("Invalid collection id: '" + uuid + "'"); |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1792 return false; |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1793 } |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1794 |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1795 boolean success = sqlExecutor.new Instance() { |
275
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1796 public boolean doIt() throws SQLException { |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1797 prepareStatement(SQL_UPDATE_COLLECTION_NAME); |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1798 stmnt.setString(1, name); |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1799 stmnt.setString(2, uuid); |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1800 stmnt.execute(); |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1801 conn.commit(); |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1802 |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1803 return true; |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1804 } |
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1805 }.runWrite(); |
311
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1806 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1807 if (success) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1808 fireSetCollectionName(uuid, name); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1809 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1810 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1811 return success; |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1812 } |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1813 |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1814 protected void fireSetCollectionName(String identifier, String name) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1815 for (BackendListener listener: listeners) { |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1816 listener.setCollectionName(identifier, name); |
1d517e051e95
Made backend listeners loadable at boot time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
310
diff
changeset
|
1817 } |
275
e92d5944fe4b
Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
273
diff
changeset
|
1818 } |
303
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1819 |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1820 public boolean loadAllArtifacts(final ArtifactLoadedCallback alc) { |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1821 |
308
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
1822 logger.debug("loadAllArtifacts"); |
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
1823 |
303
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1824 if (factoryLookup == null) { |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1825 logger.error("factory lookup == null"); |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1826 return false; |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1827 } |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1828 |
308
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
1829 boolean success = sqlExecutor.new Instance() { |
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
1830 @Override |
303
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1831 public boolean doIt() throws SQLException { |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1832 // a little cache to avoid too much deserializations. |
308
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
1833 LRUCache<String, Artifact> alreadyLoaded = |
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
1834 new LRUCache<String, Artifact>(200); |
303
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1835 |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1836 prepareStatement(SQL_ALL_ARTIFACTS); |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1837 result = stmnt.executeQuery(); |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1838 while (result.next()) { |
320
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1839 String userId = result.getString("u_gid"); |
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1840 String collectionId = result.getString("c_gid"); |
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1841 String collectionName = result.getString("c_name"); |
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1842 String artifactId = result.getString("a_gid"); |
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1843 String factoryName = result.getString("factory"); |
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1844 Date collectionCreated = |
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1845 new Date(result.getTimestamp("c_creation").getTime()); |
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1846 Date artifactCreated = |
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1847 new Date(result.getTimestamp("a_creation").getTime()); |
303
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1848 |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1849 Artifact artifact = alreadyLoaded.get(artifactId); |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1850 |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1851 if (artifact != null) { |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1852 alc.artifactLoaded( |
317
824051dff018
When loading all artifacts fetch the name of the collections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
1853 userId, |
824051dff018
When loading all artifacts fetch the name of the collections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
1854 collectionId, collectionName, |
320
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1855 collectionCreated, |
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1856 artifactId, artifactCreated, artifact); |
303
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1857 continue; |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1858 } |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1859 |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1860 ArtifactFactory factory = factoryLookup |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1861 .getArtifactFactory(factoryName); |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1862 |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1863 if (factory == null) { |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1864 logger.error("factory '" + factoryName + "' not found"); |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1865 continue; |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1866 } |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1867 |
320
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1868 byte [] bytes = result.getBytes("data"); |
303
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1869 |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1870 artifact = factory.getSerializer().fromBytes(bytes); |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1871 |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1872 if (artifact != null) { |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1873 alc.artifactLoaded( |
317
824051dff018
When loading all artifacts fetch the name of the collections, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
316
diff
changeset
|
1874 userId, |
320
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1875 collectionId, collectionName, collectionCreated, |
b46c5b13ac94
Extract the collection and artifact creation times when doing the initial, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
1876 artifactId, artifactCreated, artifact); |
303
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1877 } |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1878 |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1879 alreadyLoaded.put(artifactId, artifact); |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1880 } |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1881 return true; |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1882 } |
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1883 }.runRead(); |
308
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
1884 |
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
1885 if (logger.isDebugEnabled()) { |
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
1886 logger.debug("loadAllArtifacts success: " + success); |
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
1887 } |
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
1888 |
a077bb098eb4
Fixed broken SQL statement. Added debug output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
1889 return success; |
303
190aa68ae7a8
Added method to artifact database to load all artifacts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
1890 } |
314
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1891 |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1892 @Override |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1893 public void killedArtifacts(List<String> identifiers) { |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1894 logger.debug("killedArtifacts"); |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1895 for (BackendListener listener: listeners) { |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1896 listener.killedArtifacts(identifiers, this); |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1897 } |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1898 } |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1899 |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1900 @Override |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1901 public void killedCollections(List<String> identifiers) { |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1902 logger.debug("killedCollections"); |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1903 for (BackendListener listener: listeners) { |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1904 listener.killedCollections(identifiers, this); |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1905 } |
31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
313
diff
changeset
|
1906 } |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1907 } |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
1908 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |