Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 170:ac0f8bd97277
Fix parameter propagation of creation time ond collection names.
artifacts/trunk@1395 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 04 Mar 2011 10:51:10 +0000 |
parents | c9c27aca2f70 |
children | 25d472a67a9f |
comparison
equal
deleted
inserted
replaced
169:2f575d594fdb | 170:ac0f8bd97277 |
---|---|
20 | 20 |
21 import java.sql.Connection; | 21 import java.sql.Connection; |
22 import java.sql.PreparedStatement; | 22 import java.sql.PreparedStatement; |
23 import java.sql.ResultSet; | 23 import java.sql.ResultSet; |
24 import java.sql.SQLException; | 24 import java.sql.SQLException; |
25 import java.sql.Timestamp; | |
25 import java.sql.Types; | 26 import java.sql.Types; |
26 | 27 |
27 import java.util.ArrayList; | 28 import java.util.ArrayList; |
29 import java.util.Date; | |
28 | 30 |
29 import javax.sql.DataSource; | 31 import javax.sql.DataSource; |
30 | 32 |
31 import org.apache.log4j.Logger; | 33 import org.apache.log4j.Logger; |
32 | 34 |
144 public static final String SQL_COLLECTIONS_SELECT_USER = | 146 public static final String SQL_COLLECTIONS_SELECT_USER = |
145 SQL.get("collections.select.user"); | 147 SQL.get("collections.select.user"); |
146 | 148 |
147 public static final String SQL_COLLECTIONS_SELECT_ALL = | 149 public static final String SQL_COLLECTIONS_SELECT_ALL = |
148 SQL.get("collections.select.all"); | 150 SQL.get("collections.select.all"); |
151 | |
152 public static final String SQL_COLLECTIONS_CREATION_TIME = | |
153 SQL.get("collection.creation.time"); | |
149 | 154 |
150 /** The singleton.*/ | 155 /** The singleton.*/ |
151 protected static Backend instance; | 156 protected static Backend instance; |
152 | 157 |
153 /** | 158 /** |
1173 } | 1178 } |
1174 | 1179 |
1175 stmnt.execute(); | 1180 stmnt.execute(); |
1176 conn.commit(); | 1181 conn.commit(); |
1177 | 1182 |
1183 stmnt.close(); stmnt = null; | |
1184 | |
1185 // fetch creation time from database | |
1186 // done this way to use the time system | |
1187 // of the database. | |
1188 | |
1189 stmnt = conn.prepareStatement(SQL_COLLECTIONS_CREATION_TIME); | |
1190 stmnt.setInt(1, id); | |
1191 | |
1192 result = stmnt.executeQuery(); | |
1193 | |
1194 Date creationTime = null; | |
1195 | |
1196 if (result.next()) { | |
1197 Timestamp timestamp = result.getTimestamp(1); | |
1198 creationTime = new Date(timestamp.getTime()); | |
1199 } | |
1200 | |
1178 return factory.createCollection( | 1201 return factory.createCollection( |
1179 identifier, name, data, context); | 1202 identifier, name, creationTime, data, context); |
1180 } | 1203 } |
1181 catch (SQLException sqle) { | 1204 catch (SQLException sqle) { |
1182 conn.rollback(); | 1205 conn.rollback(); |
1183 throw sqle; | 1206 throw sqle; |
1184 } | 1207 } |
1237 result = stmnt.executeQuery(); | 1260 result = stmnt.executeQuery(); |
1238 | 1261 |
1239 while (result.next()) { | 1262 while (result.next()) { |
1240 String collectionIdentifier = result.getString(1); | 1263 String collectionIdentifier = result.getString(1); |
1241 String collectionName = result.getString(2); | 1264 String collectionName = result.getString(2); |
1242 long creationTime = result.getLong(3); | 1265 Date creationTime = |
1266 new Date(result.getTimestamp(3).getTime()); | |
1243 String userIdentifier = result.getString(4); | 1267 String userIdentifier = result.getString(4); |
1244 | 1268 |
1245 ArtifactCollection collection = | 1269 ArtifactCollection collection = |
1246 collectionFactory.createCollection( | 1270 collectionFactory.createCollection( |
1247 collectionIdentifier, | 1271 collectionIdentifier, |
1248 collectionName, | 1272 collectionName, |
1273 creationTime, | |
1249 data, | 1274 data, |
1250 context); | 1275 context); |
1251 | 1276 |
1252 if (userIdentifier != null) { | 1277 if (userIdentifier != null) { |
1253 collection.setUser(new LazyBackendUser( | 1278 collection.setUser(new LazyBackendUser( |