Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 296:a8e009ebe13c
Added a addFacets(List<Facet) method to Outputs to be able to add more than only a single facet to an output.
artifacts/trunk@2358 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 19 Jul 2011 06:59:19 +0000 |
parents | 942a54670a72 |
children | b0a949d3fe09 |
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; |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
13 import de.intevation.artifacts.ArtifactFactory; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
14 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
|
15 import de.intevation.artifacts.CollectionItem; |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
16 import de.intevation.artifacts.User; |
157
6e6965873a48
Simplified creation of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
156
diff
changeset
|
17 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
|
18 |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
19 import de.intevation.artifacts.common.utils.XMLUtils; |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
20 |
93
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
21 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
|
22 import java.sql.Timestamp; |
93
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
23 import java.sql.Types; |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
24 |
148
101a52d3ad08
Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
147
diff
changeset
|
25 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
|
26 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
|
27 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
|
28 |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
15
diff
changeset
|
29 import org.apache.log4j.Logger; |
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
15
diff
changeset
|
30 |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
31 import org.w3c.dom.Document; |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
32 |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 /** |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
34 * 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
|
35 * in a SQL database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
36 * |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
37 * @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
|
38 */ |
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 public class Backend |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
40 implements DatabaseCleaner.ArtifactReviver |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 { |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
15
diff
changeset
|
42 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
|
43 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
44 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
45 * 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
|
46 */ |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
47 public static final String SQL_NEXT_ID = |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
48 SQL.get("artifacts.id.nextval"); |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
49 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
50 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
51 * The SQL statement to insert an artifact into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
52 */ |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
53 public static final String SQL_INSERT = |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
54 SQL.get("artifacts.insert"); |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
55 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
56 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
57 * The SQL statement to update some columns of an existing |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
58 * artifact in the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
59 */ |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
60 public static final String SQL_UPDATE = |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
61 SQL.get("artifacts.update"); |
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 touch the access time of an |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
65 * artifact inside the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
66 */ |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
67 public static final String SQL_TOUCH = |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
68 SQL.get("artifacts.touch"); |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
69 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
70 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
71 * The SQL statement to load an artifact by a given |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
72 * identifier from the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
73 */ |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
74 public static final String SQL_LOAD_BY_GID = |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
75 SQL.get("artifacts.select.gid"); |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
76 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
77 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
78 * 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
|
79 * identified by the identifier. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
80 */ |
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
|
81 public static final String SQL_GET_ID = |
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
|
82 SQL.get("artifacts.get.id"); |
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
|
83 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
84 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
85 * The SQL statement to replace the content of an |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
86 * existing artifact inside the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
87 */ |
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
|
88 public static final String SQL_REPLACE = |
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
|
89 SQL.get("artifacts.replace"); |
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
|
90 |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
91 // USER SQL |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
92 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
93 public static final String SQL_USERS_NEXT_ID = |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
94 SQL.get("users.id.nextval"); |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
95 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
96 public static final String SQL_USERS_INSERT = |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
97 SQL.get("users.insert"); |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
98 |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
99 public static final String SQL_USERS_SELECT_ID_BY_GID = |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
100 SQL.get("users.select.id.by.gid"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
101 |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
102 public static final String SQL_USERS_SELECT_GID = |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
103 SQL.get("users.select.gid"); |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
104 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
105 public static final String SQL_USERS_DELETE_ID = |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
106 SQL.get("users.delete.id"); |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
107 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
108 public static final String SQL_USERS_DELETE_COLLECTIONS = |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
109 SQL.get("users.delete.collections"); |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
110 |
148
101a52d3ad08
Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
147
diff
changeset
|
111 public static final String SQL_USERS_SELECT_ALL = |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
112 SQL.get("users.select.all"); |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
113 |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
114 public static final String SQL_USERS_COLLECTIONS = |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
115 SQL.get("users.collections"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
116 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
117 public static final String SQL_USERS_COLLECTION_IDS = |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
118 SQL.get("users.collection.ids"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
119 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
120 public static final String SQL_USERS_DELETE_ALL_COLLECTIONS = |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
121 SQL.get("users.delete.all.collections"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
122 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
123 public static final String SQL_ARTIFACTS_IN_ONLY_COLLECTION_ONLY = |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
124 SQL.get("artifacts.in.one.collection.only"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
125 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
126 public static final String SQL_OUTDATE_ARTIFACTS_COLLECTION = |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
127 SQL.get("outdate.artifacts.collection"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
128 |
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
|
129 public static final String 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
|
130 SQL.get("collections.update.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
|
131 |
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
|
132 public static final String 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
|
133 SQL.get("collections.update.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
|
134 |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
135 public static final String SQL_OUTDATE_ARTIFACTS_USER = |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
136 SQL.get("outdate.artifacts.user"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
137 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
138 public static final String SQL_DELETE_USER_COLLECTION_ITEMS = |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
139 SQL.get("delete.user.collection.items"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
140 |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
141 public static final String SQL_COLLECTIONS_NEXT_ID = |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
142 SQL.get("collections.id.nextval"); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
143 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
144 public static final String SQL_COLLECTIONS_INSERT = |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
145 SQL.get("collections.insert"); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
146 |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
147 public static final String SQL_COLLECTIONS_SELECT_USER = |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
148 SQL.get("collections.select.user"); |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
149 |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
150 public static final String SQL_COLLECTIONS_SELECT_ALL = |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
151 SQL.get("collections.select.all"); |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
152 |
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
|
153 public static final String 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
|
154 SQL.get("collections.select.by.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
|
155 |
170
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
156 public static final String SQL_COLLECTIONS_CREATION_TIME = |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
157 SQL.get("collection.creation.time"); |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
158 |
175
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
159 public static final String SQL_COLLECTIONS_ID_BY_GID = |
187
a85d889a1b0d
Fixed some backend specific stuff (sql statements, schema).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
186
diff
changeset
|
160 SQL.get("collections.id.by.gid"); |
175
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
161 |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
162 public static final String SQL_DELETE_COLLECTION_ITEMS = |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
163 SQL.get("delete.collection.items"); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
164 |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
165 public static final String SQL_DELETE_COLLECTION = |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
166 SQL.get("delete.collection"); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
167 |
176
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
168 public static final String SQL_COLLECTION_CHECK_ARTIFACT = |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
169 SQL.get("collection.check.artifact"); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
170 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
171 public static final String SQL_COLLECTION_ITEMS_ID_NEXTVAL = |
187
a85d889a1b0d
Fixed some backend specific stuff (sql statements, schema).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
186
diff
changeset
|
172 SQL.get("collection.items.id.nextval"); |
176
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
173 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
174 public static final String SQL_COLLECTION_ITEMS_INSERT = |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
175 SQL.get("collection.items.insert"); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
176 |
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
|
177 public static final String 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
|
178 SQL.get("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
|
179 |
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
|
180 public static final String 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
|
181 SQL.get("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
|
182 |
178
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
183 public static final String 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
|
184 SQL.get("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
|
185 |
179
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
186 public static final String 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
|
187 SQL.get("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
|
188 |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
189 public static final String SQL_COLLECTIONS_TOUCH_BY_GID = |
180
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
190 SQL.get("collections.touch.by.gid"); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
191 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
192 public static final String 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
|
193 SQL.get("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
|
194 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
195 public static final String 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
|
196 SQL.get("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
|
197 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
198 public static final String 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
|
199 SQL.get("collection.item.delete"); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
200 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
201 public static final String 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
|
202 SQL.get("collections.touch.by.id"); |
179
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
203 |
184
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
204 public static final String 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
|
205 SQL.get("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
|
206 |
128
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
207 /** The singleton.*/ |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
208 protected static Backend instance; |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
209 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
210 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
211 * The database cleaner. Reference is stored here because |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
212 * 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
|
213 * artifact. This artifact should be removed as soon as |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
214 * possible. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
215 */ |
30
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
216 protected DatabaseCleaner cleaner; |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
217 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
218 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
219 * 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
|
220 * we need the artifact factory which references the artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
221 * serializer which is able to do the reviving job. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
222 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
223 protected FactoryLookup factoryLookup; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
224 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
225 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
226 * Little helper interface to decouple the ArtifactDatabase |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
227 * from the Backend. A ArtifactDatabase should depend on a |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
228 * Backend but a Backend not from an ArtifactDatabase. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
229 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
230 public interface FactoryLookup { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
231 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
232 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
233 * Returns an ArtifactFactory which is bound to a given name. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
234 * @param factoryName The name of the artifact factory. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
235 * @return The ArtifactFactory bound to the factory name or |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
236 * null if not matching factory is found. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
237 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
238 ArtifactFactory getArtifactFactory(String factoryName); |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
239 |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
240 } // interface FactoryLookup |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
241 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
242 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
243 * Inner class that brigdes between the persisten form of the |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
244 * artifact and the living one inside the artifact database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
245 * After the describe(), feed(), advance() and out() operations |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
246 * 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
|
247 * back into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
248 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
249 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
|
250 { |
230
fbd57d2eeaef
Changed semantics of locked artifact ids.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
217
diff
changeset
|
251 private int id; |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
252 private Artifact artifact; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
253 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
|
254 private Long ttl; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
255 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
256 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
257 * Cronstructor to create a persistent artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
258 * @param artifact The living artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
259 * @param serializer The serializer to store the artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
260 * after the operations. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
261 * @param ttl The time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
262 * @param id The database id of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
263 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
264 public PersistentArtifact( |
47
4ae4dc99127d
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
46
diff
changeset
|
265 Artifact artifact, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
266 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
|
267 Long ttl, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
268 int id |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
269 ) { |
230
fbd57d2eeaef
Changed semantics of locked artifact ids.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
217
diff
changeset
|
270 this.id = id; |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
271 this.artifact = artifact; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
272 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
|
273 this.ttl = ttl; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
274 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
275 |
230
fbd57d2eeaef
Changed semantics of locked artifact ids.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
217
diff
changeset
|
276 public int getId() { |
fbd57d2eeaef
Changed semantics of locked artifact ids.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
217
diff
changeset
|
277 return id; |
fbd57d2eeaef
Changed semantics of locked artifact ids.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
217
diff
changeset
|
278 } |
fbd57d2eeaef
Changed semantics of locked artifact ids.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
217
diff
changeset
|
279 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
280 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
281 * Returns the wrapped living artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
282 * @return the living artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
283 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
284 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
|
285 return artifact; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
286 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
287 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
288 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
289 * Returns the serialized which is able to write a |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
290 * modified artifact back into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
291 * @return The serializer. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
292 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
293 public ArtifactSerializer getSerializer() { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
294 return serializer; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
295 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
296 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
297 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
298 * The time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
299 * @return The time to live. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
300 */ |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
301 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
|
302 return ttl; |
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
303 } |
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
304 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
305 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
306 * Stores the living artifact back into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
307 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
308 public void store() { |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
309 if (logger.isDebugEnabled()) { |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
310 logger.debug("storing artifact id = " + getId()); |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
311 } |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
312 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
|
313 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
314 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
315 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
316 * Only touches the access time of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
317 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
318 public void touch() { |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
319 if (logger.isDebugEnabled()) { |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
320 logger.debug("touching artifact id = " + getId()); |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
321 } |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
322 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
|
323 } |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
324 } // class ArtifactWithId |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
325 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
326 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
327 * Default constructor |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
328 */ |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
329 public Backend() { |
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
330 } |
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
331 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
332 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
333 * 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
|
334 * @param cleaner The clean which periodically removes outdated |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
335 * artifacts from the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
336 */ |
30
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
337 public Backend(DatabaseCleaner cleaner) { |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
338 this.cleaner = cleaner; |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
339 } |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
340 |
128
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
341 |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
342 /** |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
343 * Returns the singleton of this Backend. |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
344 * |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
345 * @return the backend. |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
346 */ |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
347 public static synchronized Backend getInstance() { |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
348 if (instance == null) { |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
349 instance = new Backend(); |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
350 } |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
351 |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
352 return instance; |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
353 } |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
354 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
355 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
356 * Sets the factory lookup mechanism to decouple ArtifactDatabase |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
357 * and Backend. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
358 * @param factoryLookup |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
359 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
360 public void setFactoryLookup(FactoryLookup factoryLookup) { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
361 this.factoryLookup = factoryLookup; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
362 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
363 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
364 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
365 * Sets the database cleaner explicitly. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
366 * @param cleaner The database cleaner |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
367 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
368 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
|
369 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
|
370 } |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
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 * Returns a new unique identifier to external identify |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
374 * the artifact across the system. This implementation |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
375 * uses random UUIDs v4 to achieve this target. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
376 * @return the new identifier |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
377 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
378 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
|
379 // 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
|
380 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
|
381 } |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
382 |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
383 public boolean isValidIdentifier(String identifier) { |
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
384 return StringUtils.checkUUID(identifier); |
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
385 } |
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
386 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
387 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
388 * Stores a new artifact into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
389 * @param artifact The artifact to be stored |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
390 * @param factory The factory which build the artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
391 * @param ttl The initial time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
392 * @return A persistent wrapper around the living |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
393 * artifact to be able to write modification later. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
394 * @throws Exception Thrown if something went wrong with the |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
395 * storage process. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
396 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
397 public PersistentArtifact storeInitially( |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
398 Artifact artifact, |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
399 ArtifactFactory factory, |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
400 Long ttl |
47
4ae4dc99127d
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
46
diff
changeset
|
401 ) |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
402 throws Exception |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
403 { |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
404 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
|
405 artifact, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
406 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
|
407 ttl, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
408 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
|
409 } |
47
4ae4dc99127d
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
46
diff
changeset
|
410 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
411 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
412 * 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
|
413 * If it exists there it is only updated. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
414 * @param artifact The artifact to store/update. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
415 * @param factory The factory which created the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
416 * @param ttl The initial time to live of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
417 * @return A persistent version of the artifact to be able |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
418 * to store a modification later. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
419 * @throws Exception Thrown if something went wrong during |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
420 * storing/updating. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
421 */ |
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
|
422 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
|
423 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
|
424 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
|
425 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
|
426 ) |
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
|
427 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
|
428 { |
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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 } |
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
|
435 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
436 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
437 * Implementors of this interface are able to process the raw |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
438 * artifact data from the database for loading. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
439 */ |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
440 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
|
441 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
442 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
443 * Creates a custom object from the raw artifact database data. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
444 * @param factory The factory that created this artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
445 * @param ttl The current time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
446 * @param bytes The raw artifact bytes from the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
447 * @param id The database id of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
448 * @return The custom object created by the implementation. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
449 */ |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
450 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
|
451 |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
452 } // 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
|
453 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
454 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
455 * Fetches an artifact from the database identified by the |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
456 * given identifier. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
457 * @param identifer The identifier of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
458 * @return A persistent wrapper around the found artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
459 * 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
|
460 * if no artifact is found for this identifier. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
461 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
462 public PersistentArtifact getArtifact(String identifer) { |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
463 |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
464 return (PersistentArtifact)loadArtifact( |
86
b2e0cb83631c
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
84
diff
changeset
|
465 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
|
466 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
|
467 |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 ) { |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
474 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
|
475 |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
476 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
|
477 |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
478 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
|
479 ? null |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
480 : 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
|
481 } |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
482 }); |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
483 } |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
484 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
485 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
486 * More general loading mechanism for artifacts. The concrete |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
487 * load processing is delegated to the given loader. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
488 * @param identifer The identifier of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
489 * @param loader The loader which processes the raw database data. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
490 * @return The object created by the loader. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
491 */ |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
492 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
|
493 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
|
494 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
|
495 ) { |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
496 if (!isValidIdentifier(identifer)) { |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
497 return null; |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
498 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
499 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
500 final Object [] loaded = new Object[1]; |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
501 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
502 SQLExecutor exec = new SQLExecutor() { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
503 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
|
504 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
|
505 stmnt.setString(1, identifer); |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
506 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
507 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
|
508 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
509 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
|
510 return false; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
511 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
512 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
513 int id = result.getInt(1); |
242
b35d32e507b6
Fix for flys/issue9
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
514 long ttlX = result.getLong(2); |
b35d32e507b6
Fix for flys/issue9
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
515 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
|
516 |
242
b35d32e507b6
Fix for flys/issue9
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
517 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
|
518 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
519 if (factoryLookup == null) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
520 logger.error("factory lookup == null"); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
521 return false; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
522 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
523 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
524 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
|
525 .getArtifactFactory(factoryName); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
526 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
527 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
|
528 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
|
529 return false; |
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 |
242
b35d32e507b6
Fix for flys/issue9
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
532 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
|
533 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
534 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
|
535 return true; |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
536 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
537 }; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
538 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
539 return exec.runRead() ? loaded[0] : null; |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
540 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
541 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
542 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
543 * Called if the load mechanism found an outdated artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
544 * It wakes up the database cleaner. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
545 * @param id The id of the outdated artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
546 */ |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
547 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
|
548 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
|
549 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
|
550 } |
30
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
551 if (cleaner != null) { |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
552 cleaner.wakeup(); |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
553 } |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
554 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
555 |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
556 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
|
557 if (factoryLookup == null) { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
558 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
|
559 return null; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
560 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
561 ArtifactFactory factory = factoryLookup |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
562 .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
|
563 |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
564 if (factory == null) { |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
565 logger.error( |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
566 "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
|
567 return null; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
568 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
569 |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
570 ArtifactSerializer serializer = factory.getSerializer(); |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
571 |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
572 return serializer.fromBytes(bytes); |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
573 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
574 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
575 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
576 * Internal method to store/replace an artifact inside the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
577 * 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
|
578 * created else only the content data is updated. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
579 * @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
|
580 * @param factory The factory that created the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
581 * @param ttl The initial time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
582 * @return The database id of the stored/updated artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
583 */ |
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
|
584 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
|
585 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
|
586 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
|
587 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
|
588 ) { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
589 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
|
590 |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
591 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
|
592 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
|
593 } |
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
|
594 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
595 final int [] id = new int[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
|
596 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
597 SQLExecutor exec = new SQLExecutor() { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
598 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
|
599 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
600 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
|
601 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
|
602 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
|
603 |
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
|
604 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
|
605 ? 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
|
606 : 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
|
607 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
608 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
|
609 |
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 if (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
|
611 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
|
612 |
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
|
613 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
|
614 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
|
615 } |
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
|
616 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
|
617 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
|
618 } |
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 |
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 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
|
621 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
|
622 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
|
623 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
|
624 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
|
625 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
|
626 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
627 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
|
628 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
|
629 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
|
630 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
631 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
|
632 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
|
633 return false; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
634 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
635 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
636 reset(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
637 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
638 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
|
639 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
640 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
|
641 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
|
642 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
|
643 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
|
644 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
|
645 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
646 else { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
647 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
|
648 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
649 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
650 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
|
651 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
652 stmnt.setBytes( |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
653 5, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
654 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
|
655 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
656 stmnt.execute(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
657 conn.commit(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
658 return true; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
659 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
660 }; |
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
|
661 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
662 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
|
663 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
|
664 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
665 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
666 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
|
667 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
668 |
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 * 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
|
671 * @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
|
672 * @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
|
673 * @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
|
674 * @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
|
675 */ |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
676 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
|
677 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
|
678 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
|
679 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
|
680 ) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
681 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
|
682 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
683 SQLExecutor exec = new SQLExecutor() { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
684 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
|
685 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
|
686 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
|
687 |
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
|
688 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
|
689 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
|
690 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
|
691 } |
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
|
692 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
693 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
|
694 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
695 reset(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
696 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
|
697 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
698 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
|
699 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
|
700 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
|
701 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
|
702 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
|
703 } |
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
|
704 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
|
705 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
|
706 } |
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
|
707 |
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
|
708 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
|
709 |
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
|
710 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
|
711 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
|
712 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
|
713 |
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
|
714 stmnt.execute(); |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
715 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
716 conn.commit(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
717 return true; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
718 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
719 }; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
720 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
721 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
|
722 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
|
723 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
724 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
725 return id[0]; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
726 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
727 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
728 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
729 * Touches the access timestamp of a given artifact to prevent |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
730 * 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
|
731 * @param artifact The persistent wrapper around the living artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
732 */ |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
733 public void touch(final PersistentArtifact artifact) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
734 new SQLExecutor() { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
735 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
|
736 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
|
737 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
|
738 stmnt.execute(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
739 conn.commit(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
740 return true; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
741 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
742 }.runWrite(); |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
743 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
744 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
745 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
746 * Writes modification of an artifact back to the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
747 * @param artifact The persistent wrapper around a living |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
748 * artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
749 */ |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
750 public void store(final PersistentArtifact artifact) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
751 new SQLExecutor() { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
752 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
|
753 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
|
754 stmnt.setInt(2, artifact.getId()); |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
755 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
756 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
|
757 .getSerializer() |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
758 .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
|
759 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
760 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
|
761 stmnt.execute(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
762 conn.commit(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
763 return true; |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
764 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
765 }.runWrite(); |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
766 } |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
767 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
768 public User createUser( |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
769 final String name, |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
770 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
|
771 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
|
772 final Object context |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
773 ) { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
774 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
|
775 |
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
|
776 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
|
777 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
778 SQLExecutor exec = new SQLExecutor() { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
779 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
|
780 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
781 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
|
782 result = stmnt.executeQuery(); |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
783 |
146
967dc552455d
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
145
diff
changeset
|
784 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
|
785 return false; |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
786 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
787 |
145
c0d025df722d
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
144
diff
changeset
|
788 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
|
789 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
790 reset(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
791 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
792 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
|
793 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
794 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
|
795 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
796 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
|
797 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
|
798 stmnt.setString(3, name); |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
799 |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
800 if (roleData == null) { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
801 stmnt.setNull(4, Types.BIGINT); |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
802 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
803 else { |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
804 stmnt.setBytes(4, roleData); |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
805 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
806 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
807 stmnt.execute(); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
808 conn.commit(); |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
809 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
810 user[0] = factory.createUser( |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
811 identifier, name, role, context); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
812 return true; |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
813 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
814 }; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
815 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
816 return exec.runWrite() ? user[0] : null; |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
817 } |
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 public boolean deleteUser(final String identifier) { |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
820 |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
821 if (!isValidIdentifier(identifier)) { |
154
1a72f08ce8d7
Propagate delete user errors correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
822 return false; |
147
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
823 } |
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
824 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
825 SQLExecutor exec = new SQLExecutor() { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
826 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
|
827 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
|
828 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
829 stmnt.setString(1, identifier); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
830 result = stmnt.executeQuery(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
831 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
832 if (!result.next()) { // No such user |
154
1a72f08ce8d7
Propagate delete user errors correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
833 return false; |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
834 } |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
835 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
836 int id = result.getInt(1); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
837 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
838 reset(); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
839 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
840 // 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
|
841 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
842 prepareStatement(SQL_OUTDATE_ARTIFACTS_USER); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
843 stmnt.setInt(1, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
844 stmnt.setInt(2, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
845 stmnt.execute(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
846 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
847 reset(); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
848 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
849 // delete the collection items of the user |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
850 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
851 prepareStatement(SQL_DELETE_USER_COLLECTION_ITEMS); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
852 stmnt.setInt(1, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
853 stmnt.execute(); |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
854 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
855 reset(); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
856 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
857 // delete the collections of the user |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
858 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
859 prepareStatement(SQL_USERS_DELETE_COLLECTIONS); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
860 stmnt.setInt(1, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
861 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
|
862 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
863 reset(); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
864 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
865 // delete the user |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
866 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
867 prepareStatement(SQL_USERS_DELETE_ID); |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
868 stmnt.setInt(1, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
869 stmnt.execute(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
870 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
871 conn.commit(); |
154
1a72f08ce8d7
Propagate delete user errors correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
872 return true; |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
873 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
874 }; |
154
1a72f08ce8d7
Propagate delete user errors correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
875 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
876 return exec.runWrite(); |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
877 } |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
878 |
157
6e6965873a48
Simplified creation of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
156
diff
changeset
|
879 public User getUser( |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
880 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
|
881 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
|
882 final Object context |
157
6e6965873a48
Simplified creation of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
156
diff
changeset
|
883 ) { |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
884 if (!isValidIdentifier(identifier)) { |
147
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
885 logger.debug("Invalid UUID: '" + identifier + "'"); |
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
886 return null; |
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
887 } |
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
888 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
889 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
|
890 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
891 SQLExecutor exec = new SQLExecutor() { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
892 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
|
893 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
|
894 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
|
895 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
|
896 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
|
897 return false; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
898 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
899 // omit id |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
900 String name = 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
|
901 byte [] roleData = result.getBytes(3); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
902 |
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
|
903 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
|
904 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
905 user[0] = factory.createUser( |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
906 identifier, name, role, context); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
907 return true; |
147
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
908 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
909 }; |
147
9a64e0c1c737
Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
910 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
911 return exec.runRead() ? user[0] : null; |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
912 } |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
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 public User [] getUsers( |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
915 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
|
916 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
|
917 ) { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
918 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
|
919 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
920 SQLExecutor exec = new SQLExecutor() { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
921 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
|
922 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
|
923 result = stmnt.executeQuery(); |
148
101a52d3ad08
Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
147
diff
changeset
|
924 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
925 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
|
926 // omit id |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
927 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
|
928 String name = result.getString(3); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
929 byte [] roleData = result.getBytes(4); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
930 |
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
|
931 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
|
932 User user = factory.createUser( |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
933 identifier, name, role, context); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
934 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
|
935 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
936 return true; |
148
101a52d3ad08
Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
147
diff
changeset
|
937 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
938 }; |
148
101a52d3ad08
Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
147
diff
changeset
|
939 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
940 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
|
941 ? 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
|
942 : null; |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
943 } |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
944 |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
945 public ArtifactCollection createCollection( |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
946 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
|
947 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
|
948 final ArtifactCollectionFactory factory, |
199
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
949 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
|
950 final Object context |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
951 ) { |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
952 if (name == null) { |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
953 logger.debug("Name is null"); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
954 return null; |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
955 } |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
956 |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
957 if (!isValidIdentifier(ownerIdentifier)) { |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
958 logger.debug("Invalid owner id: '" + ownerIdentifier + "'"); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
959 return null; |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
960 } |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
961 |
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
|
962 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
|
963 |
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
|
964 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
|
965 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
966 SQLExecutor exec = new SQLExecutor() { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
967 public boolean doIt() throws SQLException { |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
968 // 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
|
969 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
|
970 stmnt.setString(1, ownerIdentifier); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
971 result = stmnt.executeQuery(); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
972 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
973 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
|
974 return false; |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
975 } |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
976 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
977 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
|
978 reset(); |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
979 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
980 // 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
|
981 prepareStatement(SQL_COLLECTIONS_NEXT_ID); |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
982 result = stmnt.executeQuery(); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
983 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
984 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
|
985 return false; |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
986 } |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
987 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
988 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
|
989 reset(); |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
990 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
991 String identifier = newIdentifier(); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
992 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
993 prepareStatement(SQL_COLLECTIONS_INSERT); |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
994 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
995 stmnt.setInt(1, id); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
996 stmnt.setString(2, identifier); |
161
e4a1562dfc21
Bugfixed the collection creation in the Backend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
159
diff
changeset
|
997 stmnt.setString(3, name); |
e4a1562dfc21
Bugfixed the collection creation in the Backend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
159
diff
changeset
|
998 stmnt.setInt(4, ownerId); |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
999 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1000 // 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
|
1001 Long ttl = factory.timeToLiveUntouched(null, context); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1002 |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1003 if (ttl == null) { |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1004 stmnt.setNull(5, Types.BIGINT); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1005 } |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1006 else { |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1007 stmnt.setLong(5, ttl); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1008 } |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1009 |
199
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1010 if (data == null) { |
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1011 stmnt.setNull(6, Types.BINARY); |
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1012 } |
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1013 else { |
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1014 stmnt.setBytes(6, data); |
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1015 } |
face2302387c
Insert collection attribute into database, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
194
diff
changeset
|
1016 |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1017 stmnt.execute(); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1018 conn.commit(); |
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1019 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1020 reset(); |
170
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1021 |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1022 // 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
|
1023 // 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
|
1024 // of the database. |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1025 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1026 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
|
1027 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
|
1028 |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1029 result = stmnt.executeQuery(); |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1030 |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1031 Date creationTime = null; |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1032 |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1033 if (result.next()) { |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1034 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
|
1035 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
|
1036 } |
ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
167
diff
changeset
|
1037 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1038 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
|
1039 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
|
1040 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1041 return true; |
159
db0d20440b92
Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
158
diff
changeset
|
1042 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1043 }; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1044 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1045 return exec.runWrite() ? collection[0]: null; |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1046 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1047 |
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
|
1048 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
|
1049 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
|
1050 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
|
1051 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
|
1052 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
|
1053 ) { |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1054 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
|
1055 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
|
1056 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
|
1057 } |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1058 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1059 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
|
1060 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1061 SQLExecutor exec = new SQLExecutor() { |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1062 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
|
1063 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1064 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
|
1065 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
|
1066 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1067 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
|
1068 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
|
1069 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
|
1070 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
|
1071 } |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1072 |
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
|
1073 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
|
1074 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
|
1075 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
|
1076 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
|
1077 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
|
1078 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
|
1079 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
|
1080 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
|
1081 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
|
1082 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1083 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
|
1084 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
|
1085 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
|
1086 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
|
1087 creationTime, |
281
942a54670a72
Made the TTL of a Collection retrievable via getter method.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
275
diff
changeset
|
1088 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
|
1089 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
|
1090 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
|
1091 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1092 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
|
1093 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
|
1094 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
|
1095 } |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1096 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1097 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
|
1098 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1099 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
|
1100 } |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1101 }; |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1102 |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1103 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
|
1104 } |
87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
206
diff
changeset
|
1105 |
164
268c2972d4a7
Implemented the interface method listCollections() in the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
161
diff
changeset
|
1106 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
|
1107 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
|
1108 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
|
1109 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
|
1110 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
|
1111 final Object context |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1112 ) { |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
1113 if (ownerIdentifier != null |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
1114 && !isValidIdentifier(ownerIdentifier)) { |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1115 logger.debug("Invalid owner id: '" + ownerIdentifier + "'"); |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1116 return null; |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1117 } |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1118 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1119 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
|
1120 new ArrayList<ArtifactCollection>(); |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1121 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1122 SQLExecutor exec = new SQLExecutor() { |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1123 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1124 public boolean doIt() throws SQLException { |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1125 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1126 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
|
1127 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
|
1128 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
|
1129 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1130 else { |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1131 prepareStatement(SQL_COLLECTIONS_SELECT_ALL); |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1132 } |
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1133 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1134 result = stmnt.executeQuery(); |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1135 |
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
|
1136 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
|
1137 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
|
1138 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1139 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
|
1140 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
|
1141 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
|
1142 Date creationTime = |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1143 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
|
1144 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
|
1145 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
|
1146 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1147 ArtifactCollection collection = |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1148 collectionFactory.createCollection( |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1149 collectionIdentifier, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1150 collectionName, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1151 creationTime, |
281
942a54670a72
Made the TTL of a Collection retrievable via getter method.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
275
diff
changeset
|
1152 ttl, |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1153 data, |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1154 context); |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1155 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1156 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
|
1157 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
|
1158 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
|
1159 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
|
1160 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
|
1161 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
|
1162 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
|
1163 } |
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
|
1164 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
|
1165 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1166 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1167 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
|
1168 } |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1169 return true; |
167
c9c27aca2f70
Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
164
diff
changeset
|
1170 } |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1171 }; |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1172 |
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1173 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
|
1174 ? 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
|
1175 : null; |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1176 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1177 |
174
25d472a67a9f
Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
170
diff
changeset
|
1178 |
175
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1179 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
|
1180 if (!isValidIdentifier(collectionId)) { |
175
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1181 logger.debug("Invalid collection id: '" + collectionId + "'"); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1182 return false; |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1183 } |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1184 SQLExecutor exec = new SQLExecutor() { |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1185 public boolean doIt() throws SQLException { |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1186 // fetch collection id |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1187 prepareStatement(SQL_COLLECTIONS_ID_BY_GID); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1188 stmnt.setString(1, collectionId); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1189 result = stmnt.executeQuery(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1190 if (!result.next()) { |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1191 logger.debug("No such collection: " + collectionId); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1192 return false; |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1193 } |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1194 int id = result.getInt(1); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1195 reset(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1196 |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1197 // outdate artifacts that are only in this collection |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1198 prepareStatement(SQL_OUTDATE_ARTIFACTS_COLLECTION); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1199 stmnt.setInt(1, id); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1200 stmnt.setInt(2, id); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1201 stmnt.execute(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1202 reset(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1203 |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1204 // delete the collection items |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1205 prepareStatement(SQL_DELETE_COLLECTION_ITEMS); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1206 stmnt.setInt(1, id); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1207 stmnt.execute(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1208 reset(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1209 |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1210 // delete the collection |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1211 prepareStatement(SQL_DELETE_COLLECTION); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1212 stmnt.setInt(1, id); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1213 stmnt.execute(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1214 conn.commit(); |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1215 return true; |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1216 } |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1217 }; |
16e6e661e6bf
Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
174
diff
changeset
|
1218 return exec.runWrite(); |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1219 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1220 |
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
|
1221 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
|
1222 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
|
1223 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
|
1224 } |
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
|
1225 |
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
|
1226 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
|
1227 |
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
|
1228 SQLExecutor exec = new SQLExecutor() { |
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
|
1229 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
|
1230 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
|
1231 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
|
1232 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
|
1233 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
|
1234 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
|
1235 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
|
1236 } |
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
|
1237 |
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
|
1238 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
|
1239 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
|
1240 } |
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
|
1241 }; |
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
|
1242 |
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
|
1243 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
|
1244 ? 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
|
1245 : 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
|
1246 } |
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
|
1247 |
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
|
1248 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
|
1249 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
|
1250 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
|
1251 ) { |
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
|
1252 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
|
1253 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
|
1254 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
|
1255 } |
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
|
1256 |
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
|
1257 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
|
1258 |
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
|
1259 return new SQLExecutor() { |
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
|
1260 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
|
1261 |
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
|
1262 // 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
|
1263 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
|
1264 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
|
1265 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
|
1266 } |
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
|
1267 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
|
1268 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
|
1269 } |
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
|
1270 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
|
1271 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
|
1272 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
|
1273 |
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
|
1274 // 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
|
1275 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
|
1276 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
|
1277 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
|
1278 |
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
|
1279 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
|
1280 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
|
1281 } |
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
|
1282 }.runWrite(); |
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
|
1283 } |
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
|
1284 |
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
|
1285 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
|
1286 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
|
1287 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
|
1288 ) { |
178
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1289 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
|
1290 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
|
1291 return null; |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1292 } |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1293 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
|
1294 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
|
1295 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
|
1296 } |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1297 |
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
|
1298 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
|
1299 |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1300 SQLExecutor exec = new SQLExecutor() { |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1301 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
|
1302 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
|
1303 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
|
1304 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
|
1305 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
|
1306 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
|
1307 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
|
1308 return false; |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1309 } |
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
|
1310 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
|
1311 return true; |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1312 } |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1313 }; |
535e4ea2ef9b
Added code to get the attribute of a collection item
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
177
diff
changeset
|
1314 |
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
|
1315 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
|
1316 ? 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
|
1317 : null; |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1318 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1319 |
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
|
1320 public boolean setCollectionItemAttribute( |
233
16cd059945e5
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
230
diff
changeset
|
1321 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
|
1322 final String artifactId, |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1323 Document attribute |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1324 ) { |
179
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1325 if (!isValidIdentifier(collectionId)) { |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1326 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
|
1327 return false; |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1328 } |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1329 if (!isValidIdentifier(artifactId)) { |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1330 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
|
1331 return false; |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1332 } |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1333 |
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
|
1334 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
|
1335 |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1336 return new SQLExecutor() { |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1337 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
|
1338 |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1339 // 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
|
1340 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
|
1341 if (data == null) { |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1342 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
|
1343 } |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1344 else { |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1345 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
|
1346 } |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1347 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
|
1348 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
|
1349 stmnt.execute(); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1350 reset(); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1351 |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1352 // touch the collection |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1353 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
|
1354 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
|
1355 stmnt.execute(); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1356 |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1357 conn.commit(); |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1358 return true; |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1359 } |
644fd11ddd9f
Added code to set attribute of a collection item.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
178
diff
changeset
|
1360 }.runWrite(); |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1361 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1362 |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1363 public boolean addCollectionArtifact( |
176
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1364 final String collectionId, |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1365 final String artifactId, |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1366 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
|
1367 ) { |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
1368 if (!isValidIdentifier(collectionId)) { |
176
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1369 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
|
1370 return false; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1371 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1372 |
177
77cd37a93fca
Backend: isIdentifierValid more symmetric to new newIndentifier
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
176
diff
changeset
|
1373 if (!isValidIdentifier(artifactId)) { |
176
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1374 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
|
1375 return false; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1376 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1377 |
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
|
1378 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
|
1379 |
176
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1380 SQLExecutor exec = new SQLExecutor() { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1381 public boolean doIt() throws SQLException { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1382 // fetch artifact id |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1383 prepareStatement(SQL_GET_ID); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1384 stmnt.setString(1, artifactId); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1385 result = stmnt.executeQuery(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1386 if (!result.next()) { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1387 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
|
1388 return false; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1389 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1390 int aid = result.getInt(1); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1391 reset(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1392 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1393 // fetch collection id |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1394 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
|
1395 stmnt.setString(1, collectionId); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1396 result = stmnt.executeQuery(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1397 if (!result.next()) { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1398 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
|
1399 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1400 int cid = result.getInt(1); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1401 reset(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1402 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1403 // 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
|
1404 prepareStatement(SQL_COLLECTION_CHECK_ARTIFACT); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1405 stmnt.setInt(1, aid); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1406 stmnt.setInt(2, cid); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1407 result = stmnt.executeQuery(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1408 if (result.next()) { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1409 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
|
1410 return false; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1411 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1412 reset(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1413 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1414 // 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
|
1415 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
|
1416 result = stmnt.executeQuery(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1417 if (!result.next()) { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1418 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
|
1419 return false; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1420 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1421 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
|
1422 reset(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1423 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1424 // insert new collection item |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1425 prepareStatement(SQL_COLLECTION_ITEMS_INSERT); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1426 stmnt.setInt(1, ci_id); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1427 stmnt.setInt(2, cid); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1428 stmnt.setInt(3, aid); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1429 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1430 if (data == null) { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1431 stmnt.setNull(4, Types.BINARY); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1432 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1433 else { |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1434 stmnt.setBytes(4, data); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1435 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1436 stmnt.execute(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1437 conn.commit(); |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1438 |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1439 return true; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1440 } |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1441 }; |
a0eff2227588
Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
175
diff
changeset
|
1442 return exec.runWrite(); |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1443 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1444 |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1445 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
|
1446 final String collectionId, |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1447 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
|
1448 ) { |
180
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1449 if (!isValidIdentifier(collectionId)) { |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1450 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
|
1451 return false; |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1452 } |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1453 return new SQLExecutor() { |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1454 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
|
1455 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1456 // 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
|
1457 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
|
1458 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
|
1459 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
|
1460 result = stmnt.executeQuery(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1461 if (!result.next()) { |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1462 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
|
1463 return false; |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1464 } |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1465 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
|
1466 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
|
1467 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
|
1468 reset(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1469 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1470 // 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
|
1471 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
|
1472 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
|
1473 stmnt.setInt(2, cid); |
194
fde2f193e846
Small typo fix
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
193
diff
changeset
|
1474 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
|
1475 stmnt.execute(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1476 reset(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1477 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1478 // delete collection item |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1479 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
|
1480 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
|
1481 stmnt.execute(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1482 reset(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1483 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1484 // touch collection |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1485 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
|
1486 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
|
1487 stmnt.execute(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1488 |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1489 conn.commit(); |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1490 return true; |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1491 } |
38fbbeffe8fe
Added code to remove an artifact from a collection
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
179
diff
changeset
|
1492 }.runWrite(); |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1493 } |
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1494 |
184
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1495 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
|
1496 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
|
1497 ) { |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1498 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
|
1499 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
|
1500 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
|
1501 } |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1502 |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1503 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
|
1504 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
|
1505 |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1506 SQLExecutor exec = new SQLExecutor() { |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1507 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
|
1508 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
|
1509 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
|
1510 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
|
1511 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
|
1512 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
|
1513 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
|
1514 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
|
1515 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
|
1516 } |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1517 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
|
1518 } |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1519 }; |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1520 |
a22b7e367b25
Added Backend code to list the collection items in a collection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
182
diff
changeset
|
1521 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
|
1522 ? 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
|
1523 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
|
1524 : null; |
156
a76de72ad6d1
Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
1525 } |
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
|
1526 |
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
|
1527 |
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
|
1528 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
|
1529 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
|
1530 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
|
1531 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
|
1532 } |
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
|
1533 |
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
|
1534 return new SQLExecutor() { |
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
|
1535 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
|
1536 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
|
1537 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
|
1538 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
|
1539 } |
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
|
1540 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
|
1541 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
|
1542 } |
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
|
1543 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
|
1544 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
|
1545 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
|
1546 |
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
|
1547 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
|
1548 } |
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
|
1549 }.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
|
1550 } |
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
|
1551 |
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
|
1552 |
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
|
1553 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
|
1554 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
|
1555 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
|
1556 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
|
1557 } |
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
|
1558 |
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
|
1559 return new SQLExecutor() { |
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
|
1560 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
|
1561 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
|
1562 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
|
1563 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
|
1564 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
|
1565 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
|
1566 |
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
|
1567 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
|
1568 } |
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
|
1569 }.runWrite(); |
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
|
1570 } |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1571 } |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
1572 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |