Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java @ 1025:02c327ffbad7
Datacage: Extended schema for artifacts and collections
to have creation times, too.
flys-artifacts/trunk@2484 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 10 Aug 2011 14:57:12 +0000 |
parents | ba88157c6aa3 |
children | eccf966fb677 |
comparison
equal
deleted
inserted
replaced
1024:ba88157c6aa3 | 1025:02c327ffbad7 |
---|---|
5 import java.util.Date; | 5 import java.util.Date; |
6 | 6 |
7 import java.sql.SQLException; | 7 import java.sql.SQLException; |
8 import java.sql.PreparedStatement; | 8 import java.sql.PreparedStatement; |
9 import java.sql.Types; | 9 import java.sql.Types; |
10 import java.sql.Timestamp; | |
10 | 11 |
11 import de.intevation.artifacts.GlobalContext; | 12 import de.intevation.artifacts.GlobalContext; |
12 import de.intevation.artifacts.ArtifactCollection; | 13 import de.intevation.artifacts.ArtifactCollection; |
13 import de.intevation.artifacts.User; | 14 import de.intevation.artifacts.User; |
14 | 15 |
119 } | 120 } |
120 | 121 |
121 FLYSArtifact flysArtifact = (FLYSArtifact)artifact; | 122 FLYSArtifact flysArtifact = (FLYSArtifact)artifact; |
122 | 123 |
123 Integer uId = getUserId(userId); | 124 Integer uId = getUserId(userId); |
124 Integer cId = getCollectionId(collectionId, uId, collectionName); | 125 Integer cId = getCollectionId( |
125 | 126 collectionId, uId, collectionName, collectionCreated); |
126 storeArtifact(artifactId, cId, flysArtifact); | 127 |
128 storeArtifact(artifactId, cId, flysArtifact, artifactCreated); | |
127 } | 129 } |
128 | 130 |
129 protected Integer getId( | 131 protected Integer getId( |
130 LRUCache<String, Integer> cache, | 132 LRUCache<String, Integer> cache, |
131 final String idString, | 133 final String idString, |
161 } | 163 } |
162 | 164 |
163 protected void storeArtifact( | 165 protected void storeArtifact( |
164 final String artifactId, | 166 final String artifactId, |
165 Integer collectionId, | 167 Integer collectionId, |
166 final FLYSArtifact artifact | 168 final FLYSArtifact artifact, |
169 final Date artifactCreated | |
167 ) { | 170 ) { |
168 Integer aId = getId(artifacts, artifactId, SQL_ARTIFACT_BY_GID); | 171 Integer aId = getId(artifacts, artifactId, SQL_ARTIFACT_BY_GID); |
169 | 172 |
170 if (aId != null) { | 173 if (aId != null) { |
171 // We've already stored it. Just create the collection item. | 174 // We've already stored it. Just create the collection item. |
188 reset(); | 191 reset(); |
189 prepareStatement(SQL_INSERT_ARTIFACT); | 192 prepareStatement(SQL_INSERT_ARTIFACT); |
190 stmnt.setInt (1, res[0]); | 193 stmnt.setInt (1, res[0]); |
191 stmnt.setString(2, artifactId); | 194 stmnt.setString(2, artifactId); |
192 stmnt.setString(3, artifact.getCurrentStateId()); | 195 stmnt.setString(3, artifact.getCurrentStateId()); |
196 Timestamp timestamp = new Timestamp(artifactCreated != null | |
197 ? artifactCreated.getTime() | |
198 : System.currentTimeMillis()); | |
199 stmnt.setTimestamp(4, timestamp); | |
193 stmnt.execute(); | 200 stmnt.execute(); |
194 conn.commit(); | 201 conn.commit(); |
195 return true; | 202 return true; |
196 } | 203 } |
197 }; | 204 }; |
241 } | 248 } |
242 | 249 |
243 protected Integer getCollectionId( | 250 protected Integer getCollectionId( |
244 final String collectionId, | 251 final String collectionId, |
245 final Integer ownerId, | 252 final Integer ownerId, |
246 final String collectionName | 253 final String collectionName, |
254 final Date collectionCreated | |
247 ) { | 255 ) { |
248 Integer c = getId(collections, collectionId, SQL_COLLECTION_BY_GID); | 256 Integer c = getId(collections, collectionId, SQL_COLLECTION_BY_GID); |
249 | 257 |
250 if (c != null) { | 258 if (c != null) { |
251 return c; | 259 return c; |
266 prepareStatement(SQL_INSERT_COLLECTION); | 274 prepareStatement(SQL_INSERT_COLLECTION); |
267 stmnt.setInt (1, res[0]); | 275 stmnt.setInt (1, res[0]); |
268 stmnt.setString(2, collectionId); | 276 stmnt.setString(2, collectionId); |
269 stmnt.setInt (3, ownerId); | 277 stmnt.setInt (3, ownerId); |
270 setString(stmnt, 4, collectionName); | 278 setString(stmnt, 4, collectionName); |
279 Timestamp timestamp = new Timestamp(collectionCreated != null | |
280 ? collectionCreated.getTime() | |
281 : System.currentTimeMillis()); | |
282 stmnt.setTimestamp(5, timestamp); | |
271 stmnt.execute(); | 283 stmnt.execute(); |
272 conn.commit(); | 284 conn.commit(); |
273 return true; | 285 return true; |
274 } | 286 } |
275 }; | 287 }; |
495 return false; | 507 return false; |
496 } | 508 } |
497 res[0] = result.getInt(1); | 509 res[0] = result.getInt(1); |
498 reset(); | 510 reset(); |
499 prepareStatement(SQL_INSERT_ARTIFACT); | 511 prepareStatement(SQL_INSERT_ARTIFACT); |
500 stmnt.setInt (1, res[0]); | 512 stmnt.setInt (1, res[0]); |
501 stmnt.setString(2, flys.identifier()); | 513 stmnt.setString (2, flys.identifier()); |
502 stmnt.setString(3, flys.getCurrentStateId()); | 514 stmnt.setString (3, flys.getCurrentStateId()); |
515 stmnt.setTimestamp(4, | |
516 new Timestamp(System.currentTimeMillis())); | |
503 stmnt.execute(); | 517 stmnt.execute(); |
504 conn.commit(); | 518 conn.commit(); |
505 return true; | 519 return true; |
506 } | 520 } |
507 }; | 521 }; |
689 prepareStatement(SQL_INSERT_COLLECTION); | 703 prepareStatement(SQL_INSERT_COLLECTION); |
690 stmnt.setInt(1, cId); | 704 stmnt.setInt(1, cId); |
691 stmnt.setString(2, identifier); | 705 stmnt.setString(2, identifier); |
692 stmnt.setInt(3, uId); | 706 stmnt.setInt(3, uId); |
693 setString(stmnt, 4, name); | 707 setString(stmnt, 4, name); |
708 stmnt.setTimestamp(5, | |
709 new Timestamp(System.currentTimeMillis())); | |
694 stmnt.execute(); | 710 stmnt.execute(); |
695 | 711 |
696 conn.commit(); | 712 conn.commit(); |
697 return true; | 713 return true; |
698 } | 714 } |