Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 146:967dc552455d
Enable backend to delete users
artifacts/trunk@1371 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 02 Mar 2011 17:47:54 +0000 |
parents | c0d025df722d |
children | 9a64e0c1c737 |
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 |
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.artifacts.Artifact; |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
12 import de.intevation.artifacts.ArtifactFactory; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
13 import de.intevation.artifacts.ArtifactSerializer; |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
14 import de.intevation.artifacts.User; |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
16 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
|
17 |
93
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
18 import java.sql.Connection; |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
19 import java.sql.PreparedStatement; |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
20 import java.sql.ResultSet; |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
21 import java.sql.SQLException; |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
22 import java.sql.Types; |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
23 |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
24 import javax.sql.DataSource; |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
90
diff
changeset
|
25 |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
15
diff
changeset
|
26 import org.apache.log4j.Logger; |
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
15
diff
changeset
|
27 |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
28 import org.w3c.dom.Document; |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
29 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
30 |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 /** |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
32 * 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
|
33 * in a SQL database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
34 * |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
35 * @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
|
36 */ |
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 public class Backend |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
38 implements DatabaseCleaner.ArtifactReviver |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 { |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
15
diff
changeset
|
40 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
|
41 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
42 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
43 * 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
|
44 */ |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
45 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
|
46 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
|
47 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
48 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
49 * The SQL statement to insert an artifact into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
50 */ |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
51 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
|
52 SQL.get("artifacts.insert"); |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
53 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
54 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
55 * The SQL statement to update some columns of an existing |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
56 * artifact in the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
57 */ |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
58 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
|
59 SQL.get("artifacts.update"); |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
60 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
61 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
62 * The SQL statement to touch the access time of an |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
63 * artifact inside the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
64 */ |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
65 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
|
66 SQL.get("artifacts.touch"); |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
67 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
68 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
69 * The SQL statement to load an artifact by a given |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
70 * identifier from the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
71 */ |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
72 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
|
73 SQL.get("artifacts.select.gid"); |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
74 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
75 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
76 * The SQL statement to get the database id of an artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
77 * identified by the identifier. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
78 */ |
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
|
79 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
|
80 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
|
81 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
82 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
83 * The SQL statement to replace the content of an |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
84 * existing artifact inside the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
85 */ |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
86 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
|
87 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
|
88 |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
89 // USER SQL |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
90 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
91 public static final String SQL_USERS_NEXT_ID = |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
92 SQL.get("users.id.nextval"); |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
93 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
94 public static final String SQL_USERS_INSERT = |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
95 SQL.get("users.insert"); |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
96 |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
97 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
|
98 SQL.get("users.select.id.by.gid"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
99 |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
100 public static final String SQL_USERS_SELECT_GID = |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
101 SQL.get("users.select.gid"); |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
102 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
103 public static final String SQL_USERS_DELETE_ID = |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
104 SQL.get("users.delete.id"); |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
105 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
106 public static final String SQL_USERS_DELETE_COLLECTIONS = |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
107 SQL.get("users.delete.collections"); |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
108 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
109 public static final String SQL_USER_SELECT_ALL = |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
110 SQL.get("users.select.all"); |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
111 |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
112 public static final String SQL_USERS_COLLECTIONS = |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
113 SQL.get("users.collections"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
114 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
115 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
|
116 SQL.get("users.collection.ids"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
117 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
118 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
|
119 SQL.get("users.delete.all.collections"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
120 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
121 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
|
122 SQL.get("artifacts.in.one.collection.only"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
123 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
124 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
|
125 SQL.get("outdate.artifacts.collection"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
126 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
127 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
|
128 SQL.get("outdate.artifacts.user"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
129 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
130 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
|
131 SQL.get("delete.user.collection.items"); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
132 |
128
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
133 /** The singleton.*/ |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
134 protected static Backend instance; |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
135 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
136 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
137 * The database cleaner. Reference is stored here because |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
138 * 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
|
139 * artifact. This artifact should be removed as soon as |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
140 * possible. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
141 */ |
30
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
142 protected DatabaseCleaner cleaner; |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
143 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
144 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
145 * 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
|
146 * we need the artifact factory which references the artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
147 * serializer which is able to do the reviving job. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
148 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
149 protected FactoryLookup factoryLookup; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
150 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
151 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
152 * Little helper interface to decouple the ArtifactDatabase |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
153 * from the Backend. A ArtifactDatabase should depend on a |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
154 * Backend but a Backend not from an ArtifactDatabase. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
155 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
156 public interface FactoryLookup { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
157 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
158 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
159 * Returns an ArtifactFactory which is bound to a given name. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
160 * @param factoryName The name of the artifact factory. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
161 * @return The ArtifactFactory bound to the factory name or |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
162 * null if not matching factory is found. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
163 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
164 ArtifactFactory getArtifactFactory(String factoryName); |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
165 |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
166 } // interface FactoryLookup |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
167 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
168 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
169 * Inner class that brigdes between the persisten form of the |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
170 * artifact and the living one inside the artifact database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
171 * After the describe(), feed(), advance() and out() operations |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
172 * 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
|
173 * back into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
174 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
175 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
|
176 extends Id |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
177 { |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
178 private Artifact artifact; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
179 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
|
180 private Long ttl; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
181 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
182 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
183 * Cronstructor to create a persistent artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
184 * @param artifact The living artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
185 * @param serializer The serializer to store the artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
186 * after the operations. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
187 * @param ttl The time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
188 * @param id The database id of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
189 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
190 public PersistentArtifact( |
47
4ae4dc99127d
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
46
diff
changeset
|
191 Artifact artifact, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
192 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
|
193 Long ttl, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
194 int id |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
195 ) { |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
196 super(id); |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
197 this.artifact = artifact; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
198 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
|
199 this.ttl = ttl; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
200 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
201 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
202 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
203 * Returns the wrapped living artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
204 * @return the living artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
205 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
206 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
|
207 return artifact; |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
208 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
209 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
210 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
211 * Returns the serialized which is able to write a |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
212 * modified artifact back into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
213 * @return The serializer. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
214 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
215 public ArtifactSerializer getSerializer() { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
216 return serializer; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
217 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
218 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
219 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
220 * The time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
221 * @return The time to live. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
222 */ |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
223 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
|
224 return ttl; |
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
225 } |
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
226 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
227 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
228 * Stores the living artifact back into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
229 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
230 public void store() { |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
231 if (logger.isDebugEnabled()) { |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
232 logger.debug("storing artifact id = " + getId()); |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
233 } |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
234 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
|
235 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
236 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
237 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
238 * Only touches the access time of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
239 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
240 public void touch() { |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
241 if (logger.isDebugEnabled()) { |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
242 logger.debug("touching artifact id = " + getId()); |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
243 } |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
244 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
|
245 } |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
246 } // class ArtifactWithId |
14
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 * Default constructor |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
250 */ |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 public Backend() { |
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 } |
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
254 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
255 * 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
|
256 * @param cleaner The clean which periodically removes outdated |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
257 * artifacts from the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
258 */ |
30
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
259 public Backend(DatabaseCleaner cleaner) { |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
260 this.cleaner = cleaner; |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
261 } |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
262 |
128
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
263 |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
264 /** |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
265 * Returns the singleton of this Backend. |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
266 * |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
267 * @return the backend. |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
268 */ |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
269 public static synchronized Backend getInstance() { |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
270 if (instance == null) { |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
271 instance = new Backend(); |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
272 } |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
273 |
bfa65a812c7a
Made the backend singleton.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
274 return instance; |
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 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
277 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
278 * Sets the factory lookup mechanism to decouple ArtifactDatabase |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
279 * and Backend. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
280 * @param factoryLookup |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
281 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
282 public void setFactoryLookup(FactoryLookup factoryLookup) { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
283 this.factoryLookup = factoryLookup; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
284 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
285 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
286 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
287 * Sets the database cleaner explicitly. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
288 * @param cleaner The database cleaner |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
289 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
290 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
|
291 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
|
292 } |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
293 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
294 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
295 * Returns a new unique identifier to external identify |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
296 * the artifact across the system. This implementation |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
297 * uses random UUIDs v4 to achieve this target. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
298 * @return the new identifier |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
299 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
300 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
|
301 // 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
|
302 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
|
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 * Stores a new artifact into the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
307 * @param artifact The artifact to be stored |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
308 * @param factory The factory which build the artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
309 * @param ttl The initial time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
310 * @return A persistent wrapper around the living |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
311 * artifact to be able to write modification later. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
312 * @throws Exception Thrown if something went wrong with the |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
313 * storage process. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
314 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
315 public PersistentArtifact storeInitially( |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
316 Artifact artifact, |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
317 ArtifactFactory factory, |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
318 Long ttl |
47
4ae4dc99127d
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
46
diff
changeset
|
319 ) |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
320 throws Exception |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
321 { |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
322 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
|
323 artifact, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
324 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
|
325 ttl, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
326 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
|
327 } |
47
4ae4dc99127d
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
46
diff
changeset
|
328 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
329 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
330 * 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
|
331 * If it exists there it is only updated. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
332 * @param artifact The artifact to store/update. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
333 * @param factory The factory which created the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
334 * @param ttl The initial time to live of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
335 * @return A persistent version of the artifact to be able |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
336 * to store a modification later. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
337 * @throws Exception Thrown if something went wrong during |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
338 * storing/updating. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
339 */ |
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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 ) |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
345 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
|
346 { |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
347 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 } |
8447467cef86
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 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
354 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
355 * Implementors of this interface are able to process the raw |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
356 * artifact data from the database for loading. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
357 */ |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
358 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
|
359 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
360 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
361 * Creates a custom object from the raw artifact database data. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
362 * @param factory The factory that created this artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
363 * @param ttl The current time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
364 * @param bytes The raw artifact bytes from the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
365 * @param id The database id of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
366 * @return The custom object created by the implementation. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
367 */ |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
368 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
|
369 |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
370 } // 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
|
371 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
372 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
373 * Fetches an artifact from the database identified by the |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
374 * given identifier. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
375 * @param identifer The identifier of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
376 * @return A persistent wrapper around the found artifact |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
377 * 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
|
378 * if no artifact is found for this identifier. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
379 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
380 public PersistentArtifact getArtifact(String identifer) { |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
381 |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
382 return (PersistentArtifact)loadArtifact( |
86
b2e0cb83631c
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
84
diff
changeset
|
383 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
|
384 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
|
385 |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
386 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 ) { |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
392 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
|
393 |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
394 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
|
395 |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
396 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
|
397 ? null |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
398 : 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
|
399 } |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
400 }); |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
401 } |
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
402 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
403 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
404 * More general loading mechanism for artifacts. The concrete |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
405 * load processing is delegated to the given loader. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
406 * @param identifer The identifier of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
407 * @param loader The loader which processes the raw database data. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
408 * @return The object created by the loader. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
409 */ |
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 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
|
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 if (!StringUtils.checkUUID(identifer)) { |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
413 return null; |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
414 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
415 |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
416 Connection connection = null; |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
417 PreparedStatement stmnt_load = null; |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
418 ResultSet load_result = null; |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
419 |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
420 DataSource dataSource = DBConnection.getDataSource(); |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
421 try { |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
422 connection = dataSource.getConnection(); |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
423 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
|
424 stmnt_load.setString(1, identifer); |
15
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 load_result = stmnt_load.executeQuery(); |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
427 |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
428 if (!load_result.next()) { |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
429 return 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 |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
432 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
|
433 long ttlX = load_result.getLong(3); |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
434 |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
435 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
|
436 |
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
437 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
|
438 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
|
439 if (last_access + ttlX < System.currentTimeMillis()) { |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
440 artifactOutdated(id); |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
441 return null; |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
442 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
443 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
444 |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
445 String factoryName = load_result.getString(4); |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
446 |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
447 if (factoryLookup == null) { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
448 logger.error("factory lookup == null"); |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
449 return null; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
450 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
451 |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
452 ArtifactFactory factory = factoryLookup |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
453 .getArtifactFactory(factoryName); |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
454 |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
455 if (factory == null) { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
456 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
|
457 return null; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
458 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
459 |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
460 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
|
461 |
84
72e2dd4feb31
Added the time to live of an artifact to the CallContext.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
80
diff
changeset
|
462 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
|
463 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
464 catch (SQLException sqle) { |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
15
diff
changeset
|
465 logger.error(sqle.getLocalizedMessage(), sqle); |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
466 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
467 finally { |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
468 if (load_result != null) { |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
469 try { load_result.close(); } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
470 catch (SQLException sqle) {} |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
471 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
472 if (stmnt_load != null) { |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
473 try { load_result.close(); } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
474 catch (SQLException sqle) {} |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
475 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
476 if (connection != null) { |
47
4ae4dc99127d
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
46
diff
changeset
|
477 try { connection.close(); } |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
478 catch (SQLException sqle) {} |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
479 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
480 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
481 return null; |
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 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
484 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
485 * Called if the load mechanism found an outdated artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
486 * It wakes up the database cleaner. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
487 * @param id The id of the outdated artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
488 */ |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
489 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
|
490 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
|
491 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
|
492 } |
30
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
493 if (cleaner != null) { |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
494 cleaner.wakeup(); |
88972c6daa4f
Added a cleanup thread which periodically removes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
495 } |
15
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
496 } |
9ad6ec2d09c3
Implemented restoring artifacts from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
14
diff
changeset
|
497 |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
498 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
|
499 if (factoryLookup == null) { |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
500 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
|
501 return null; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
502 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
503 ArtifactFactory factory = factoryLookup |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
504 .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
|
505 |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
506 if (factory == null) { |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
507 logger.error( |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
508 "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
|
509 return null; |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
510 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
511 |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
512 ArtifactSerializer serializer = factory.getSerializer(); |
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 return serializer.fromBytes(bytes); |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
515 } |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
516 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
517 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
518 * Internal method to store/replace an artifact inside the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
519 * 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
|
520 * created else only the content data is updated. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
521 * @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
|
522 * @param factory The factory that created the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
523 * @param ttl The initial time to life of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
524 * @return The database id of the stored/updated artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
525 */ |
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
|
526 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
|
527 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
|
528 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
|
529 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
|
530 ) { |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
531 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
|
532 |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
533 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
|
534 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
|
535 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
536 |
8447467cef86
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 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
|
538 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
|
539 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
|
540 |
8447467cef86
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 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
|
542 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
|
543 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
|
544 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
|
545 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
|
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 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
|
548 |
8447467cef86
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 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
|
550 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
|
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 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
|
553 ? 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
|
554 : 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
|
555 |
8447467cef86
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 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
|
557 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
|
558 |
8447467cef86
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 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
|
560 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
|
561 |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
562 stmnt = 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
|
563 |
8447467cef86
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 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
|
565 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
|
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 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
|
568 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
|
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 |
8447467cef86
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 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
|
572 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
|
573 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
|
574 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
|
575 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
|
576 |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
577 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
|
578 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
|
579 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
|
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 = 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
|
583 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
|
584 |
8447467cef86
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 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
|
586 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
|
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 |
8447467cef86
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 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
|
590 |
8447467cef86
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 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
|
592 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
|
593 |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
594 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
|
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 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
|
597 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
|
598 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
|
599 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
|
600 } |
8447467cef86
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 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
|
602 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
|
603 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
604 |
8447467cef86
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.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
|
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.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
|
608 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
|
609 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
|
610 |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
611 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
|
612 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
|
613 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
|
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 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
|
616 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
|
617 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
|
618 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
619 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
620 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
|
621 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
|
622 } |
8447467cef86
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 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
|
624 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
|
625 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
|
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 } |
8447467cef86
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 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
|
629 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
|
630 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
|
631 } |
8447467cef86
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 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
|
633 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
|
634 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
|
635 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
636 } |
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
637 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
|
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 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
640 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
641 * Internal method to store an artifact inside the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
642 * @param artifact The artifact to be stored. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
643 * @param factory The factory which created the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
644 * @param ttl The initial time to live of the artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
645 * @return The database id of the stored artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
646 */ |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
647 protected int insertDatabase( |
47
4ae4dc99127d
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
46
diff
changeset
|
648 Artifact artifact, |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
649 ArtifactFactory factory, |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
650 Long ttl |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
651 ) { |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
652 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
|
653 |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
654 Connection connection = null; |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
655 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
|
656 PreparedStatement stmnt_insert = null; |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
657 ResultSet res_id = null; |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
658 |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
659 DataSource dataSource = DBConnection.getDataSource(); |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
660 try { |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
661 connection = dataSource.getConnection(); |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
662 try { |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
663 connection.setAutoCommit(false); |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
664 |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
665 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
|
666 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
|
667 |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
668 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
|
669 |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
670 if (!res_id.next()) { |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
671 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
|
672 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
673 |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
674 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
|
675 |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
676 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
|
677 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
|
678 if (ttl == null) { |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
679 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
|
680 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
681 else { |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
682 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
|
683 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
684 |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
685 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
|
686 |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
687 stmnt_insert.setBytes( |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
688 5, |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
689 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
|
690 |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
691 stmnt_insert.execute(); |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
692 |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
693 connection.commit(); |
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 return id; |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
696 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
697 catch (SQLException sqle) { |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
698 connection.rollback(); |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
699 throw sqle; |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
700 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
701 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
702 catch (SQLException sqle) { |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
15
diff
changeset
|
703 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
|
704 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
705 finally { |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
706 if (res_id != null) { |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
707 try { res_id.close(); } |
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 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
710 if (stmnt_insert != null) { |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
711 try { stmnt_insert.close(); } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
712 catch (SQLException sqle) {} |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
713 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
714 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
|
715 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
|
716 catch (SQLException sqle) {} |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
717 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
718 if (connection != null) { |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
719 try { connection.close(); } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
720 catch (SQLException sqle) {} |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
721 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
722 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
723 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
|
724 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
725 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
726 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
727 * Touches the access timestamp of a given artifact to prevent |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
728 * 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
|
729 * @param artifact The persistent wrapper around the living artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
730 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
731 public void touch(PersistentArtifact artifact) { |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
732 |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
733 try { |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
734 Connection connection = null; |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
735 PreparedStatement stmnt_touch = null; |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
736 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
|
737 try { |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
738 connection = dataSource.getConnection(); |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
739 try { |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
740 connection.setAutoCommit(false); |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
741 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
|
742 stmnt_touch.setInt(1, artifact.getId()); |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
743 stmnt_touch.execute(); |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
744 connection.commit(); |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
745 } |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
746 catch (SQLException sqle) { |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
747 connection.rollback(); |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
748 } |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
749 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
750 catch (SQLException sqle) { |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
751 logger.error(sqle.getLocalizedMessage(), sqle); |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
752 } |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
753 finally { |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
754 if (stmnt_touch != null) { |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
755 try { stmnt_touch.close(); } |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
756 catch (SQLException sqle) {} |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
757 } |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
758 if (connection != null) { |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
759 try { connection.close(); } |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
760 catch (SQLException sqle) {} |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
761 } |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
762 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
763 } |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
764 catch (Exception e) { |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
765 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
|
766 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
767 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
768 |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
769 /** |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
770 * Writes modification of an artifact back to the database. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
771 * @param artifact The persistent wrapper around a living |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
772 * artifact. |
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
86
diff
changeset
|
773 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
31
diff
changeset
|
774 public void store(PersistentArtifact artifact) { |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
775 |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
776 try { |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
777 Connection connection = null; |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
778 PreparedStatement stmnt_update = null; |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
779 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
|
780 try { |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
781 connection = dataSource.getConnection(); |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
782 try { |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
783 connection.setAutoCommit(false); |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
784 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
|
785 stmnt_update.setInt(2, artifact.getId()); |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
786 |
41
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
787 byte [] bytes = artifact |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
788 .getSerializer() |
5e4bc24ea438
Made serilization more flexible. DB update required!!!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
789 .toBytes(artifact.getArtifact()); |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
790 |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
791 stmnt_update.setBytes(1, bytes); |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
792 stmnt_update.execute(); |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
793 connection.commit(); |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
794 } |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
795 catch (SQLException sqle) { |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
796 connection.rollback(); |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
797 } |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
798 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
799 catch (SQLException sqle) { |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
800 logger.error(sqle.getLocalizedMessage(), sqle); |
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 finally { |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
803 if (stmnt_update != null) { |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
804 try { stmnt_update.close(); } |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
805 catch (SQLException sqle) {} |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
806 } |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
807 if (connection != null) { |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
808 try { connection.close(); } |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
809 catch (SQLException sqle) {} |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
810 } |
14
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
811 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
812 } |
26
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
813 catch (Exception e) { |
83a059c204f8
Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
24
diff
changeset
|
814 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
|
815 } |
0d16d1bb2df0
Initial checkin of artigact persistents back by database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
816 } |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
817 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
818 public User createUser( |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
819 String name, |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
820 Document role |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
821 ) { |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
822 Connection connection = null; |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
823 PreparedStatement stmnt_next_id = null; |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
824 PreparedStatement stmnt_insert = null; |
145
c0d025df722d
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
144
diff
changeset
|
825 ResultSet result = null; |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
826 |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
827 String identifier = newIdentifier(); |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
828 |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
829 DataSource dataSource = DBConnection.getDataSource(); |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
830 try { |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
831 connection = dataSource.getConnection(); |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
832 try { |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
833 connection.setAutoCommit(false); |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
834 |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
835 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
|
836 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
|
837 |
145
c0d025df722d
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
144
diff
changeset
|
838 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
|
839 |
146
967dc552455d
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
145
diff
changeset
|
840 if (!result.next()) { |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
841 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
|
842 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
843 |
145
c0d025df722d
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
144
diff
changeset
|
844 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
|
845 |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
846 stmnt_insert.setInt(1, id); |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
847 stmnt_insert.setString(2, identifier); |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
848 stmnt_insert.setString(3, name); |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
849 |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
850 byte [] roleData = role == null |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
851 ? null |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
852 : XMLUtils.toByteArray(role); |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
853 |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
854 if (roleData == null) { |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
855 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
|
856 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
857 else { |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
858 stmnt_insert.setBytes(4, roleData); |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
859 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
860 |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
861 stmnt_insert.execute(); |
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 connection.commit(); |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
864 |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
865 return new DefaultUser(identifier, name, 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 catch (SQLException sqle) { |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
868 connection.rollback(); |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
869 throw sqle; |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
870 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
871 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
872 catch (SQLException sqle) { |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
873 logger.error(sqle.getLocalizedMessage(), sqle); |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
874 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
875 finally { |
145
c0d025df722d
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
144
diff
changeset
|
876 if (result != null) { |
c0d025df722d
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
144
diff
changeset
|
877 try { result.close(); } |
138
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
878 catch (SQLException sqle) {} |
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 if (stmnt_insert != null) { |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
881 try { stmnt_insert.close(); } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
882 catch (SQLException 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 if (stmnt_next_id != null) { |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
885 try { stmnt_next_id.close(); } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
886 catch (SQLException 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 if (connection != null) { |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
889 try { connection.close(); } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
890 catch (SQLException sqle) {} |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
891 } |
b90e831d3dfe
Call database to create a new user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
133
diff
changeset
|
892 } |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
893 return null; |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
894 } |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
895 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
896 public void deleteUser(User user) { |
144
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
897 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
898 Connection conn = null; |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
899 ResultSet result = null; |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
900 PreparedStatement stmnt = null; |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
901 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
902 String identifier = user.identifier(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
903 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
904 DataSource dataSource = DBConnection.getDataSource(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
905 try { |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
906 conn = dataSource.getConnection(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
907 try { |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
908 conn.setAutoCommit(false); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
909 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
910 // fetch user id |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
911 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
|
912 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
913 stmnt.setString(1, identifier); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
914 result = stmnt.executeQuery(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
915 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
916 if (!result.next()) { // No such user |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
917 return; |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
918 } |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
919 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
920 int id = result.getInt(1); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
921 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
922 result.close(); result = null; |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
923 stmnt.close(); stmnt = null; |
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 // 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
|
926 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
927 stmnt = conn.prepareStatement(SQL_OUTDATE_ARTIFACTS_USER); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
928 stmnt.setInt(1, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
929 stmnt.setInt(2, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
930 stmnt.execute(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
931 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
932 stmnt.close(); stmnt = null; |
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 // delete the collection items of the user |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
935 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
936 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
|
937 stmnt.setInt(1, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
938 stmnt.execute(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
939 stmnt.close(); stmnt = null; |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
940 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
941 // delete the collections of the user |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
942 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
943 stmnt = conn.prepareStatement(SQL_USERS_COLLECTIONS); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
944 stmnt.setInt(1, 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 stmnt.close(); stmnt = null; |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
947 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
948 // delete the user |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
949 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
950 stmnt = conn.prepareStatement(SQL_USERS_DELETE_ID); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
951 stmnt.setInt(1, id); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
952 stmnt.execute(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
953 |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
954 conn.commit(); |
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 catch (SQLException sqle) { |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
957 conn.rollback(); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
958 throw sqle; |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
959 } |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
960 } |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
961 catch (SQLException sqle) { |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
962 logger.error(sqle.getLocalizedMessage(), sqle); |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
963 } |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
964 finally { |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
965 if (result != null) { |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
966 try { result.close(); } |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
967 catch (SQLException sqle) {} |
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 if (stmnt != null) { |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
970 try { stmnt.close(); } |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
971 catch (SQLException sqle) {} |
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 if (conn != null) { |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
974 try { conn.close(); } |
5369582d4fbf
Enable backend to delete users
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
138
diff
changeset
|
975 catch (SQLException 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 } |
133
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
978 } |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
979 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
980 public User getUser(String identifier) { |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
981 // TODO: implement me! |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
982 return null; |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
983 } |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
984 |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
985 public User [] getUsers() { |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
986 // TODO: implement me! |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
987 return null; |
2950c6011afa
Fixed typo in keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
128
diff
changeset
|
988 } |
13
0d6badf6af42
Added not yet working backend to artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
989 } |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
47
diff
changeset
|
990 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |