annotate artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 176:a0eff2227588

Added code to add artifacts to collections. artifacts/trunk@1402 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 04 Mar 2011 17:51:15 +0000
parents 16e6e661e6bf
children 77cd37a93fca
rev   line source
100
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 93
diff changeset
1 /*
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 93
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
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 */
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 93
diff changeset
8
13
0d6badf6af42 Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 package de.intevation.artifactdatabase;
0d6badf6af42 Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
158
d718a4d55662 Implemented the createCollection() method in the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 157
diff changeset
11 import de.intevation.artifacts.Artifact;
157
6e6965873a48 Simplified creation of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 156
diff changeset
12 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
13 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
14 import de.intevation.artifacts.ArtifactFactory;
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
15 import de.intevation.artifacts.ArtifactSerializer;
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;
148
101a52d3ad08 Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 147
diff changeset
27
17
5a6b6a3debc7 Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 15
diff changeset
28 import org.apache.log4j.Logger;
5a6b6a3debc7 Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 15
diff changeset
29
133
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
30 import org.w3c.dom.Document;
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
31
13
0d6badf6af42 Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 /**
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
33 * 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
34 * in a SQL database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
35 *
79
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
36 * @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
37 */
0d6badf6af42 Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 public class Backend
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
39 implements DatabaseCleaner.ArtifactReviver
13
0d6badf6af42 Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 {
17
5a6b6a3debc7 Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 15
diff changeset
41 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
42
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
43 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
44 * 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
45 */
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
46 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
47 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
48
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
49 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
50 * The SQL statement to insert an artifact into the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
51 */
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
52 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
53 SQL.get("artifacts.insert");
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
54
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
55 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
56 * The SQL statement to update some columns of an existing
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
57 * artifact in the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
58 */
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
59 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
60 SQL.get("artifacts.update");
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
61
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
62 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
63 * The SQL statement to touch the access time of an
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
64 * artifact inside the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
65 */
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
66 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
67 SQL.get("artifacts.touch");
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
68
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
69 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
70 * The SQL statement to load an artifact by a given
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
71 * identifier from the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
72 */
15
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
73 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
74 SQL.get("artifacts.select.gid");
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
75
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
76 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
77 * 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
78 * identified by the identifier.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
79 */
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
80 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
81 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
82
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
83 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
84 * The SQL statement to replace the content of an
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
85 * existing artifact inside the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
86 */
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
87 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
88 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
89
133
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
90 // USER SQL
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
91
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
92 public static final String SQL_USERS_NEXT_ID =
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
93 SQL.get("users.id.nextval");
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
94
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
95 public static final String SQL_USERS_INSERT =
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
96 SQL.get("users.insert");
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
97
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
98 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
99 SQL.get("users.select.id.by.gid");
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
100
133
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
101 public static final String SQL_USERS_SELECT_GID =
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
102 SQL.get("users.select.gid");
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
103
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
104 public static final String SQL_USERS_DELETE_ID =
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
105 SQL.get("users.delete.id");
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
106
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
107 public static final String SQL_USERS_DELETE_COLLECTIONS =
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
108 SQL.get("users.delete.collections");
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
109
148
101a52d3ad08 Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 147
diff changeset
110 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
111 SQL.get("users.select.all");
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
112
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
113 public static final String SQL_USERS_COLLECTIONS =
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
114 SQL.get("users.collections");
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
115
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
116 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
117 SQL.get("users.collection.ids");
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
118
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
119 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
120 SQL.get("users.delete.all.collections");
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
121
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
122 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
123 SQL.get("artifacts.in.one.collection.only");
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
124
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
125 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
126 SQL.get("outdate.artifacts.collection");
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
127
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
128 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
129 SQL.get("outdate.artifacts.user");
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
130
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
131 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
132 SQL.get("delete.user.collection.items");
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
133
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
134 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
135 SQL.get("collections.id.nextval");
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
136
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
137 public static final String SQL_COLLECTIONS_INSERT =
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
138 SQL.get("collections.insert");
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
139
167
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
140 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
141 SQL.get("collections.select.user");
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
142
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
143 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
144 SQL.get("collections.select.all");
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
145
170
ac0f8bd97277 Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
146 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
147 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
148
175
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
149 public static final String SQL_COLLECTIONS_ID_BY_GID =
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
150 SQL.get("collection.creation.time");
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
151
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
152 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
153 SQL.get("delete.collection.items");
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
154
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
155 public static final String SQL_DELETE_COLLECTION =
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
156 SQL.get("delete.collection");
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
157
176
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
158 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
159 SQL.get("collection.check.artifact");
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
160
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
161 public static final String SQL_COLLECTION_ITEMS_ID_NEXTVAL =
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
162 SQL.get("collection.check.artifact");
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
163
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
164 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
165 SQL.get("collection.items.insert");
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
166
128
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
167 /** The singleton.*/
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
168 protected static Backend instance;
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
169
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
170 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
171 * The database cleaner. Reference is stored here because
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
172 * 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
173 * artifact. This artifact should be removed as soon as
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
174 * possible.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
175 */
30
88972c6daa4f Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 27
diff changeset
176 protected DatabaseCleaner cleaner;
88972c6daa4f Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 27
diff changeset
177
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
178 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
179 * 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
180 * we need the artifact factory which references the artifact
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
181 * serializer which is able to do the reviving job.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
182 */
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
183 protected FactoryLookup factoryLookup;
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
184
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
185 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
186 * Little helper interface to decouple the ArtifactDatabase
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
187 * from the Backend. A ArtifactDatabase should depend on a
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
188 * Backend but a Backend not from an ArtifactDatabase.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
189 */
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
190 public interface FactoryLookup {
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
191
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
192 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
193 * Returns an ArtifactFactory which is bound to a given name.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
194 * @param factoryName The name of the artifact factory.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
195 * @return The ArtifactFactory bound to the factory name or
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
196 * null if not matching factory is found.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
197 */
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
198 ArtifactFactory getArtifactFactory(String factoryName);
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
199
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
200 } // interface FactoryLookup
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
201
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
202 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
203 * Inner class that brigdes between the persisten form of the
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
204 * artifact and the living one inside the artifact database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
205 * After the describe(), feed(), advance() and out() operations
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
206 * 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
207 * back into the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
208 */
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
209 public final class PersistentArtifact
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
210 extends Id
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
211 {
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
212 private Artifact artifact;
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
213 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
214 private Long ttl;
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
215
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
216 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
217 * Cronstructor to create a persistent artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
218 * @param artifact The living artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
219 * @param serializer The serializer to store the artifact
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
220 * after the operations.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
221 * @param ttl The time to life of the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
222 * @param id The database id of the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
223 */
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
224 public PersistentArtifact(
47
4ae4dc99127d Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 46
diff changeset
225 Artifact artifact,
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
226 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
227 Long ttl,
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
228 int id
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
229 ) {
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
230 super(id);
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
231 this.artifact = artifact;
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
232 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
233 this.ttl = ttl;
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
234 }
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
235
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
236 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
237 * Returns the wrapped living artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
238 * @return the living artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
239 */
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
240 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
241 return artifact;
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
242 }
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
243
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
244 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
245 * Returns the serialized which is able to write a
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
246 * modified artifact back into the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
247 * @return The serializer.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
248 */
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
249 public ArtifactSerializer getSerializer() {
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
250 return serializer;
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
251 }
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
252
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
253 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
254 * The time to life of the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
255 * @return The time to live.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
256 */
84
72e2dd4feb31 Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 80
diff changeset
257 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
258 return ttl;
72e2dd4feb31 Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 80
diff changeset
259 }
72e2dd4feb31 Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 80
diff changeset
260
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
261 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
262 * Stores the living artifact back into the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
263 */
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
264 public void store() {
38
93edc04f3a10 Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 34
diff changeset
265 if (logger.isDebugEnabled()) {
93edc04f3a10 Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 34
diff changeset
266 logger.debug("storing artifact id = " + getId());
93edc04f3a10 Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 34
diff changeset
267 }
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
268 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
269 }
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
270
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
271 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
272 * Only touches the access time of the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
273 */
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
274 public void touch() {
38
93edc04f3a10 Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 34
diff changeset
275 if (logger.isDebugEnabled()) {
93edc04f3a10 Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 34
diff changeset
276 logger.debug("touching artifact id = " + getId());
93edc04f3a10 Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 34
diff changeset
277 }
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
278 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
279 }
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
280 } // class ArtifactWithId
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
281
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
282 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
283 * Default constructor
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
284 */
13
0d6badf6af42 Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
285 public Backend() {
0d6badf6af42 Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
286 }
0d6badf6af42 Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
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 * 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
290 * @param cleaner The clean which periodically removes outdated
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
291 * artifacts from the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
292 */
30
88972c6daa4f Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 27
diff changeset
293 public Backend(DatabaseCleaner cleaner) {
88972c6daa4f Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 27
diff changeset
294 this.cleaner = cleaner;
88972c6daa4f Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 27
diff changeset
295 }
88972c6daa4f Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 27
diff changeset
296
128
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
297
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
298 /**
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
299 * Returns the singleton of this Backend.
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
300 *
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
301 * @return the backend.
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
302 */
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
303 public static synchronized Backend getInstance() {
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
304 if (instance == null) {
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
305 instance = new Backend();
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
306 }
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
307
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
308 return instance;
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
309 }
bfa65a812c7a Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
310
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
311 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
312 * Sets the factory lookup mechanism to decouple ArtifactDatabase
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
313 * and Backend.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
314 * @param factoryLookup
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
315 */
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
316 public void setFactoryLookup(FactoryLookup factoryLookup) {
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
317 this.factoryLookup = factoryLookup;
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
318 }
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
319
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
320 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
321 * Sets the database cleaner explicitly.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
322 * @param cleaner The database cleaner
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
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 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
325 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
326 }
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
327
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
328 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
329 * Returns a new unique identifier to external identify
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
330 * the artifact across the system. This implementation
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
331 * uses random UUIDs v4 to achieve this target.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
332 * @return the new identifier
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
333 */
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
334 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
335 // 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
336 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
337 }
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
338
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
339 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
340 * Stores a new artifact into the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
341 * @param artifact The artifact to be stored
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
342 * @param factory The factory which build the artifact
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
343 * @param ttl The initial time to life of the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
344 * @return A persistent wrapper around the living
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
345 * artifact to be able to write modification later.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
346 * @throws Exception Thrown if something went wrong with the
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
347 * storage process.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
348 */
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
349 public PersistentArtifact storeInitially(
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
350 Artifact artifact,
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
351 ArtifactFactory factory,
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
352 Long ttl
47
4ae4dc99127d Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 46
diff changeset
353 )
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
354 throws Exception
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
355 {
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
356 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
357 artifact,
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
358 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
359 ttl,
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
360 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
361 }
47
4ae4dc99127d Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 46
diff changeset
362
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
363 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
364 * 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
365 * If it exists there it is only updated.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
366 * @param artifact The artifact to store/update.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
367 * @param factory The factory which created the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
368 * @param ttl The initial time to live of the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
369 * @return A persistent version of the artifact to be able
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
370 * to store a modification later.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
371 * @throws Exception Thrown if something went wrong during
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
372 * storing/updating.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
373 */
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
374 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
375 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
376 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
377 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
378 )
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
379 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
380 {
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
381 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
382 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
383 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
384 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
385 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
386 }
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
387
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
388 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
389 * Implementors of this interface are able to process the raw
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
390 * artifact data from the database for loading.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
391 */
79
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
392 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
393
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
394 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
395 * Creates a custom object from the raw artifact database data.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
396 * @param factory The factory that created this artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
397 * @param ttl The current time to life of the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
398 * @param bytes The raw artifact bytes from the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
399 * @param id The database id of the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
400 * @return The custom object created by the implementation.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
401 */
84
72e2dd4feb31 Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 80
diff changeset
402 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
403
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
404 } // 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
405
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
406 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
407 * Fetches an artifact from the database identified by the
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
408 * given identifier.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
409 * @param identifer The identifier of the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
410 * @return A persistent wrapper around the found artifact
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
411 * 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
412 * if no artifact is found for this identifier.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
413 */
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 31
diff changeset
414 public PersistentArtifact getArtifact(String identifer) {
15
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
415
79
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
416 return (PersistentArtifact)loadArtifact(
86
b2e0cb83631c Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 84
diff changeset
417 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
418 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
419
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
420 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
421 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
422 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
423 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
424 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
425 ) {
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
426 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
427
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
428 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
429
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
430 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
431 ? null
84
72e2dd4feb31 Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 80
diff changeset
432 : 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
433 }
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
434 });
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
435 }
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
436
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
437 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
438 * More general loading mechanism for artifacts. The concrete
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
439 * load processing is delegated to the given loader.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
440 * @param identifer The identifier of the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
441 * @param loader The loader which processes the raw database data.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
442 * @return The object created by the loader.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
443 */
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
444 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
445 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
446 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
447 ) {
79
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
448 if (!StringUtils.checkUUID(identifer)) {
15
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
449 return null;
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
450 }
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
451
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
452 final Object [] loaded = new Object[1];
15
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
453
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
454 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
455 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
456 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
457 stmnt.setString(1, identifer);
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
458
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
459 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
460
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
461 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
462 return false;
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
463 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
464
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
465 int id = 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
466 long ttlX = result.getLong(3);
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
467
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
468 Long ttl = result.wasNull() ? null : Long.valueOf(ttlX);
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
469
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
470 if (ttl != null) { // real time to life
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
471 long last_access = result.getTimestamp(2).getTime();
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
472 if (last_access + ttlX < System.currentTimeMillis()) {
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
473 artifactOutdated(id);
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
474 return false;
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
475 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
476 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
477
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
478 String factoryName = result.getString(4);
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
479
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
480 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
481 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
482 return false;
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
483 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
484
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
485 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
486 .getArtifactFactory(factoryName);
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
487
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
488 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
489 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
490 return false;
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
491 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
492
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
493 byte [] bytes = result.getBytes(5);
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
494
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
495 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
496 return true;
15
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
497 }
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
498 };
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
499
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
500 return exec.runRead() ? loaded[0] : null;
15
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
501 }
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
502
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
503 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
504 * Called if the load mechanism found an outdated artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
505 * It wakes up the database cleaner.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
506 * @param id The id of the outdated artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
507 */
15
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
508 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
509 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
510 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
511 }
30
88972c6daa4f Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 27
diff changeset
512 if (cleaner != null) {
88972c6daa4f Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 27
diff changeset
513 cleaner.wakeup();
88972c6daa4f Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 27
diff changeset
514 }
15
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
515 }
9ad6ec2d09c3 Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 14
diff changeset
516
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
517 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
518 if (factoryLookup == null) {
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
519 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
520 return null;
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
521 }
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
522 ArtifactFactory factory = factoryLookup
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
523 .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
524
41
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
525 if (factory == null) {
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
526 logger.error(
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
527 "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
528 return null;
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
529 }
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
530
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
531 ArtifactSerializer serializer = factory.getSerializer();
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
532
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
533 return serializer.fromBytes(bytes);
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
534 }
5e4bc24ea438 Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 38
diff changeset
535
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
536 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
537 * Internal method to store/replace an artifact inside the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
538 * 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
539 * created else only the content data is updated.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
540 * @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
541 * @param factory The factory that created the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
542 * @param ttl The initial time to life of the artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
543 * @return The database id of the stored/updated artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
544 */
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
545 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
546 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
547 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
548 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
549 ) {
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
550 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
551
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
552 if (!StringUtils.checkUUID(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
553 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
554 }
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
555
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
556 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
557
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
558 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
559 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
560
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
561 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
562 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
563 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
564
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
565 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
566 ? 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
567 : 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
568
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
569 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
570
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
571 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
572 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
573
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
574 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
575 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
576 }
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
577 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
578 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
579 }
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
580
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
581 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
582 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
583 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
584 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
585 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
586 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
587 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
588 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
589 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
590 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
591
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
592 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
593 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
594 return false;
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
595 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
596
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
597 reset();
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
598
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
599 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
600
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
601 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
602 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
603 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
604 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
605 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
606 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
607 else {
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
608 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
609 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
610
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
611 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
612
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
613 stmnt.setBytes(
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
614 5,
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
615 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
616 }
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
617 stmnt.execute();
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
618 conn.commit();
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
619 return true;
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
620 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
621 };
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
622
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
623 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
624 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
625 }
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 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
628 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
629
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
630 /**
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
631 * 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
632 * @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
633 * @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
634 * @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
635 * @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
636 */
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
637 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
638 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
639 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
640 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
641 ) {
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
642 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
643
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
644 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
645 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
646 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
647 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
648
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
649 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
650 logger.error("No id generated");
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
651 return false;
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
652 }
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
653
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
654 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
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 reset();
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
657 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
658
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
659 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
660 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
661 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
662 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
663 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
664 }
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
665 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
666 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
667 }
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
668
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
669 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
670
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
671 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
672 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
673 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
674
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
675 stmnt.execute();
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
676
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
677 conn.commit();
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
678 return true;
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
679 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
680 };
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
681
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
682 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
683 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
684 }
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
685
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
686 return id[0];
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
687 }
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
688
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
689 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
690 * Touches the access timestamp of a given artifact to prevent
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
691 * 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
692 * @param artifact The persistent wrapper around the living artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
693 */
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
694 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
695 new SQLExecutor() {
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
696 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
697 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
698 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
699 stmnt.execute();
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
700 conn.commit();
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
701 return true;
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
702 }
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
703 }.runWrite();
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
704 }
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
705
90
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
706 /**
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
707 * Writes modification of an artifact back to the database.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
708 * @param artifact The persistent wrapper around a living
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
709 * artifact.
68285f7bc476 More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
710 */
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
711 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
712 new SQLExecutor() {
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
713 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
714 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
715 stmnt.setInt(2, artifact.getId());
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 24
diff changeset
716
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
717 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
718 .getSerializer()
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
719 .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
720
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
721 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
722 stmnt.execute();
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
723 conn.commit();
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
724 return true;
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 24
diff changeset
725 }
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
726 }.runWrite();
14
0d16d1bb2df0 Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 13
diff changeset
727 }
133
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
728
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
729 public User createUser(
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
730 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
731 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
732 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
733 final Object context
133
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
734 ) {
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
735 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
736
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
737 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
738 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
739
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
740 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
741 result = stmnt.executeQuery();
138
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
742
146
967dc552455d Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 145
diff changeset
743 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
744 return false;
138
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
745 }
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
746
145
c0d025df722d Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 144
diff changeset
747 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
748
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
749 reset();
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
750
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
751 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
752
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_USERS_INSERT);
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
754
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
755 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
756 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
757 stmnt.setString(3, name);
138
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
758
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
759 byte [] roleData = role == null
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
760 ? null
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
761 : XMLUtils.toByteArray(role);
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
762
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
763 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
764 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
765 }
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
766 else {
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
767 stmnt.setBytes(4, roleData);
138
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
768 }
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
769
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
770 stmnt.execute();
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
771 conn.commit();
138
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
772
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
773 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
774 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
775 return true;
138
b90e831d3dfe Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 133
diff changeset
776 }
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
777 };
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
778
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
779 return exec.runWrite() ? user[0] : null;
133
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
780 }
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
781
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
782 public boolean deleteUser(final String identifier) {
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
783
147
9a64e0c1c737 Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
784 if (!StringUtils.checkUUID(identifier)) {
154
1a72f08ce8d7 Propagate delete user errors correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 153
diff changeset
785 return false;
147
9a64e0c1c737 Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
786 }
9a64e0c1c737 Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
787
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
788 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
789 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
790 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
791
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
792 stmnt.setString(1, identifier);
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
793 result = stmnt.executeQuery();
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
794
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
795 if (!result.next()) { // No such user
154
1a72f08ce8d7 Propagate delete user errors correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 153
diff changeset
796 return false;
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
797 }
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
798
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
799 int id = result.getInt(1);
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
800
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
801 reset();
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
802
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
803 // 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
804
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
805 prepareStatement(SQL_OUTDATE_ARTIFACTS_USER);
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
806 stmnt.setInt(1, id);
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
807 stmnt.setInt(2, id);
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
808 stmnt.execute();
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
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 reset();
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
811
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
812 // delete the collection items of the user
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
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 prepareStatement(SQL_DELETE_USER_COLLECTION_ITEMS);
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
815 stmnt.setInt(1, id);
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
816 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
817
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
818 reset();
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
819
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
820 // delete the collections of the user
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
821
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
822 prepareStatement(SQL_USERS_DELETE_COLLECTIONS);
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
823 stmnt.setInt(1, id);
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
824 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
825
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
826 reset();
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
827
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
828 // delete the user
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
829
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
830 prepareStatement(SQL_USERS_DELETE_ID);
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
831 stmnt.setInt(1, id);
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
832 stmnt.execute();
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
833
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
834 conn.commit();
154
1a72f08ce8d7 Propagate delete user errors correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 153
diff changeset
835 return true;
144
5369582d4fbf Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 138
diff changeset
836 }
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
837 };
154
1a72f08ce8d7 Propagate delete user errors correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 153
diff changeset
838
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
839 return exec.runWrite();
133
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
840 }
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
841
157
6e6965873a48 Simplified creation of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 156
diff changeset
842 public User getUser(
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
843 final String identifier,
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
844 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
845 final Object context
157
6e6965873a48 Simplified creation of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 156
diff changeset
846 ) {
147
9a64e0c1c737 Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
847 if (!StringUtils.checkUUID(identifier)) {
9a64e0c1c737 Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
848 logger.debug("Invalid UUID: '" + identifier + "'");
9a64e0c1c737 Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
849 return null;
9a64e0c1c737 Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
850 }
9a64e0c1c737 Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
851
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
852 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
853
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
854 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
855 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
856 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
857 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
858 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
859 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
860 return false;
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
861 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
862 // omit id
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
863 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
864 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
865
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
866 Document role = XMLUtils.fromByteArray(roleData);
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
867
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
868 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
869 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
870 return true;
147
9a64e0c1c737 Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
871 }
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
872 };
147
9a64e0c1c737 Added code to load user from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
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 return exec.runRead() ? user[0] : null;
133
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
875 }
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
876
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
877 public User [] getUsers(
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
878 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
879 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
880 ) {
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
881 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
882
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
883 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
884 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
885 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
886 result = stmnt.executeQuery();
148
101a52d3ad08 Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 147
diff changeset
887
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
888 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
889 // omit id
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
890 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
891 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
892 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
893
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
894 Document role = XMLUtils.fromByteArray(roleData);
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
895 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
896 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
897 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
898 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
899 return true;
148
101a52d3ad08 Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 147
diff changeset
900 }
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
901 };
148
101a52d3ad08 Added code to load all users from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 147
diff changeset
902
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
903 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
904 ? 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
905 : null;
133
2950c6011afa Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 128
diff changeset
906 }
156
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
907
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
908 public ArtifactCollection createCollection(
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
909 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
910 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
911 final ArtifactCollectionFactory factory,
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
912 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
913 final Object context
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
914 ) {
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
915 if (name == null) {
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
916 logger.debug("Name is null");
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
917 return null;
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
918 }
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
919
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
920 if (!StringUtils.checkUUID(ownerIdentifier)) {
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
921 logger.debug("Invalid owner id: '" + ownerIdentifier + "'");
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
922 return null;
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
923 }
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
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 final ArtifactCollection [] collection =
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
926 new ArtifactCollection[1];
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
927
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
928 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
929 public boolean doIt() throws SQLException {
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
930 // 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
931 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
932 stmnt.setString(1, ownerIdentifier);
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
933 result = stmnt.executeQuery();
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
934
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
935 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
936 return false;
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
937 }
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
938
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
939 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
940 reset();
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
941
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
942 // 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
943 prepareStatement(SQL_COLLECTIONS_NEXT_ID);
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
944 result = stmnt.executeQuery();
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
945
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
946 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
947 return false;
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
948 }
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
949
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
950 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
951 reset();
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
952
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
953 String identifier = newIdentifier();
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
954
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
955 prepareStatement(SQL_COLLECTIONS_INSERT);
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
956
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
957 stmnt.setInt(1, id);
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
958 stmnt.setString(2, identifier);
161
e4a1562dfc21 Bugfixed the collection creation in the Backend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 159
diff changeset
959 stmnt.setString(3, name);
e4a1562dfc21 Bugfixed the collection creation in the Backend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 159
diff changeset
960 stmnt.setInt(4, ownerId);
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
961
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
962 // 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
963 Long ttl = factory.timeToLiveUntouched(null, context);
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
964
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
965 if (ttl == null) {
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
966 stmnt.setNull(5, Types.BIGINT);
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
967 }
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
968 else {
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
969 stmnt.setLong(5, ttl);
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
970 }
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
971
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
972 stmnt.execute();
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
973 conn.commit();
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
974
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
975 reset();
170
ac0f8bd97277 Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
976
ac0f8bd97277 Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
977 // 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
978 // 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
979 // of the database.
ac0f8bd97277 Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
980
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
981 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
982 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
983
ac0f8bd97277 Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
984 result = stmnt.executeQuery();
ac0f8bd97277 Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
985
ac0f8bd97277 Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
986 Date creationTime = null;
ac0f8bd97277 Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
987
ac0f8bd97277 Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
988 if (result.next()) {
ac0f8bd97277 Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
989 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
990 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
991 }
ac0f8bd97277 Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
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 collection[0] = factory.createCollection(
170
ac0f8bd97277 Fix parameter propagation of creation time ond collection names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
994 identifier, name, creationTime, data, context);
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
995
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
996 return true;
159
db0d20440b92 Added code to create collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 158
diff changeset
997 }
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
998 };
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
999
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1000 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
1001 }
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1002
164
268c2972d4a7 Implemented the interface method listCollections() in the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 161
diff changeset
1003 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
1004 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
1005 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
1006 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
1007 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
1008 final Object context
167
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1009 ) {
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1010 if (ownerIdentifier != null
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1011 && !StringUtils.checkUUID(ownerIdentifier)) {
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1012 logger.debug("Invalid owner id: '" + ownerIdentifier + "'");
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1013 return null;
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1014 }
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1015
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1016 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
1017 new ArrayList<ArtifactCollection>();
167
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1018
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1019 SQLExecutor exec = new SQLExecutor() {
167
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1020
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1021 public boolean doIt() throws SQLException {
167
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1022
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1023 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
1024 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
1025 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
1026 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1027 else {
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1028 prepareStatement(SQL_COLLECTIONS_SELECT_ALL);
167
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1029 }
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1030
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1031 result = stmnt.executeQuery();
167
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1032
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1033 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
1034 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
1035 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
1036 Date creationTime =
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1037 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
1038 String userIdentifier = result.getString(4);
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1039
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1040 ArtifactCollection collection =
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1041 collectionFactory.createCollection(
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1042 collectionIdentifier,
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1043 collectionName,
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1044 creationTime,
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1045 data,
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1046 context);
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1047
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1048 if (userIdentifier != null) {
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1049 collection.setUser(new LazyBackendUser(
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1050 userIdentifier, userFactory, Backend.this, context));
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1051 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1052
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1053 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
1054 }
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1055 return true;
167
c9c27aca2f70 Added code to list collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 164
diff changeset
1056 }
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1057 };
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1058
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1059 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
1060 ? 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
1061 : null;
156
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1062 }
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1063
174
25d472a67a9f Reduce the code repetition and the complexity of the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 170
diff changeset
1064
175
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1065 public boolean deleteCollection(final String collectionId) {
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1066 if (!StringUtils.checkUUID(collectionId)) {
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1067 logger.debug("Invalid collection id: '" + collectionId + "'");
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1068 return false;
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1069 }
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1070 SQLExecutor exec = new SQLExecutor() {
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1071 public boolean doIt() throws SQLException {
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1072 // fetch collection id
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1073 prepareStatement(SQL_COLLECTIONS_ID_BY_GID);
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1074 stmnt.setString(1, collectionId);
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1075 result = stmnt.executeQuery();
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1076 if (!result.next()) {
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1077 logger.debug("No such collection: " + collectionId);
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1078 return false;
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1079 }
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1080 int id = result.getInt(1);
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1081 reset();
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1082
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1083 // 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
1084 prepareStatement(SQL_OUTDATE_ARTIFACTS_COLLECTION);
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1085 stmnt.setInt(1, id);
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1086 stmnt.setInt(2, id);
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1087 stmnt.execute();
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1088 reset();
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1089
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1090 // delete the collection items
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1091 prepareStatement(SQL_DELETE_COLLECTION_ITEMS);
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1092 stmnt.setInt(1, id);
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1093 stmnt.execute();
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1094 reset();
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1095
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1096 // delete the collection
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1097 prepareStatement(SQL_DELETE_COLLECTION);
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1098 stmnt.setInt(1, id);
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1099 stmnt.execute();
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1100 conn.commit();
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1101 return true;
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1102 }
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1103 };
16e6e661e6bf Added code to delete collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
1104 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
1105 }
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1106
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1107 public Document getCollectionAttribute(
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1108 String collectionId,
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1109 String artifactId
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1110 ) {
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1111 // TODO: Implement me!
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1112 return null;
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1113 }
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1114
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1115 public boolean setCollectionAttribute(
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1116 String collectionId,
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1117 String artifactId,
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1118 Document attribute
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1119 ) {
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1120 // TODO: Implement me!
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1121 return false;
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1122 }
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1123
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1124 public boolean addCollectionArtifact(
176
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1125 final String collectionId,
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1126 final String artifactId,
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1127 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
1128 ) {
176
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1129 if (!StringUtils.checkUUID(collectionId)) {
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1130 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
1131 return false;
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1132 }
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1133
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1134 if (!StringUtils.checkUUID(artifactId)) {
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1135 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
1136 return false;
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1137 }
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1138
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1139 SQLExecutor exec = new SQLExecutor() {
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1140 public boolean doIt() throws SQLException {
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1141 // fetch artifact id
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1142 prepareStatement(SQL_GET_ID);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1143 stmnt.setString(1, artifactId);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1144 result = stmnt.executeQuery();
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1145 if (!result.next()) {
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1146 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
1147 return false;
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1148 }
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1149 int aid = result.getInt(1);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1150 reset();
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1151
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1152 // fetch collection id
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1153 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
1154 stmnt.setString(1, collectionId);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1155 result = stmnt.executeQuery();
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1156 if (!result.next()) {
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1157 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
1158 }
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1159 int cid = result.getInt(1);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1160 reset();
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1161
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1162 // 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
1163 prepareStatement(SQL_COLLECTION_CHECK_ARTIFACT);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1164 stmnt.setInt(1, aid);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1165 stmnt.setInt(2, cid);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1166 result = stmnt.executeQuery();
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1167 if (result.next()) {
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1168 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
1169 return false;
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1170 }
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1171 reset();
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1172
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1173 // 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
1174 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
1175 result = stmnt.executeQuery();
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1176 if (!result.next()) {
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1177 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
1178 return false;
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1179 }
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1180 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
1181 reset();
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1182
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1183 // insert new collection item
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1184 prepareStatement(SQL_COLLECTION_ITEMS_INSERT);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1185 stmnt.setInt(1, ci_id);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1186 stmnt.setInt(2, cid);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1187 stmnt.setInt(3, aid);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1188
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1189 byte [] data = attribute != null
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1190 ? XMLUtils.toByteArray(attribute)
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1191 : null;
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1192
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1193 if (data == null) {
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1194 stmnt.setNull(4, Types.BINARY);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1195 }
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1196 else {
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1197 stmnt.setBytes(4, data);
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1198 }
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1199 stmnt.execute();
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1200 conn.commit();
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1201
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1202 return true;
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1203 }
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1204 };
a0eff2227588 Added code to add artifacts to collections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 175
diff changeset
1205 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
1206 }
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1207
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1208 public boolean removeCollectionArtifact(
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1209 String collectionId,
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1210 String artifactId
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1211 ) {
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1212 // TODO: Implement me!
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1213 return false;
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1214 }
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1215
157
6e6965873a48 Simplified creation of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 156
diff changeset
1216 public ArtifactCollection [] listCollectionArtifacts(String collectionId) {
156
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1217 // TODO: Implement me!
a76de72ad6d1 Added stubs for the collection handling in db backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
1218 return null;
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
13
0d6badf6af42 Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1221 }
79
f69e5b87f05f Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 47
diff changeset
1222 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org