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