diff 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
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java	Wed Aug 10 14:20:31 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java	Wed Aug 10 14:57:12 2011 +0000
@@ -7,6 +7,7 @@
 import java.sql.SQLException;
 import java.sql.PreparedStatement;
 import java.sql.Types;
+import java.sql.Timestamp;
 
 import de.intevation.artifacts.GlobalContext;
 import de.intevation.artifacts.ArtifactCollection;
@@ -121,9 +122,10 @@
             FLYSArtifact flysArtifact = (FLYSArtifact)artifact;
 
             Integer uId = getUserId(userId);
-            Integer cId = getCollectionId(collectionId, uId, collectionName);
+            Integer cId = getCollectionId(
+                collectionId, uId, collectionName, collectionCreated);
 
-            storeArtifact(artifactId, cId, flysArtifact);
+            storeArtifact(artifactId, cId, flysArtifact, artifactCreated);
         }
 
         protected Integer getId(
@@ -163,7 +165,8 @@
         protected void storeArtifact(
             final String       artifactId,
             Integer            collectionId,
-            final FLYSArtifact artifact
+            final FLYSArtifact artifact,
+            final Date         artifactCreated
         ) {
             Integer aId = getId(artifacts, artifactId, SQL_ARTIFACT_BY_GID);
 
@@ -190,6 +193,10 @@
                     stmnt.setInt   (1, res[0]);
                     stmnt.setString(2, artifactId);
                     stmnt.setString(3, artifact.getCurrentStateId());
+                    Timestamp timestamp = new Timestamp(artifactCreated != null
+                        ? artifactCreated.getTime()
+                        : System.currentTimeMillis());
+                    stmnt.setTimestamp(4, timestamp);
                     stmnt.execute();
                     conn.commit();
                     return true;
@@ -243,7 +250,8 @@
         protected Integer getCollectionId(
             final String  collectionId,
             final Integer ownerId,
-            final String  collectionName
+            final String  collectionName,
+            final Date    collectionCreated
         ) {
             Integer c = getId(collections, collectionId, SQL_COLLECTION_BY_GID);
 
@@ -268,6 +276,10 @@
                     stmnt.setString(2, collectionId);
                     stmnt.setInt   (3, ownerId);
                     setString(stmnt, 4, collectionName);
+                    Timestamp timestamp = new Timestamp(collectionCreated != null
+                        ? collectionCreated.getTime()
+                        : System.currentTimeMillis());
+                    stmnt.setTimestamp(5, timestamp);
                     stmnt.execute();
                     conn.commit();
                     return true;
@@ -497,9 +509,11 @@
                 res[0] = result.getInt(1);
                 reset();
                 prepareStatement(SQL_INSERT_ARTIFACT);
-                stmnt.setInt   (1, res[0]);
-                stmnt.setString(2, flys.identifier());
-                stmnt.setString(3, flys.getCurrentStateId());
+                stmnt.setInt      (1, res[0]);
+                stmnt.setString   (2, flys.identifier());
+                stmnt.setString   (3, flys.getCurrentStateId());
+                stmnt.setTimestamp(4,
+                    new Timestamp(System.currentTimeMillis()));
                 stmnt.execute();
                 conn.commit();
                 return true;
@@ -691,6 +705,8 @@
                 stmnt.setString(2, identifier);
                 stmnt.setInt(3, uId);
                 setString(stmnt, 4, name);
+                stmnt.setTimestamp(5,
+                    new Timestamp(System.currentTimeMillis()));
                 stmnt.execute();
 
                 conn.commit();

http://dive4elements.wald.intevation.org