From 2db2451d222bc868f4551cd0cac16b94181e5148 Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Wed, 22 Jun 2011 09:12:03 +0000
Subject: [PATCH] [LMS-2286] got rid of null handling for last modified date by
 setting default value in DB

SVN: 21797
---
 .../shared/PathInfoDatabaseVersionHolder.java |  4 +-
 ...hInfoProviderBasedHierarchicalContent.java |  7 ++-
 .../source/sql/postgresql/003/schema-003.sql  | 53 +++++++++++++++++++
 .../migration/migration-002-003.sql           |  8 +++
 4 files changed, 66 insertions(+), 6 deletions(-)
 create mode 100644 datastore_server/source/sql/postgresql/003/schema-003.sql
 create mode 100644 datastore_server/source/sql/postgresql/migration/migration-002-003.sql

diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/PathInfoDatabaseVersionHolder.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/PathInfoDatabaseVersionHolder.java
index 3ffc15c1bf4..4c1b858f518 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/PathInfoDatabaseVersionHolder.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/PathInfoDatabaseVersionHolder.java
@@ -18,14 +18,14 @@ package ch.systemsx.cisd.openbis.dss.generic.shared;
 
 /**
  * Holds the actual version of the pathinfo database which stores path information of data sets.
- *
+ * 
  * @author Franz-Josef Elmer
  */
 public class PathInfoDatabaseVersionHolder implements IDatabaseVersionHolder
 {
     public String getDatabaseVersion()
     {
-        return "002"; // S109
+        return "003"; // S109
     }
 
 }
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/content/PathInfoProviderBasedHierarchicalContent.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/content/PathInfoProviderBasedHierarchicalContent.java
index 7cca3c57e8f..fa0996d5425 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/content/PathInfoProviderBasedHierarchicalContent.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/content/PathInfoProviderBasedHierarchicalContent.java
@@ -21,7 +21,6 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
@@ -210,8 +209,7 @@ class PathInfoProviderBasedHierarchicalContent implements IHierarchicalContent
 
         public long getLastModified()
         {
-            Date lastModified = pathInfo.getLastModified();
-            return lastModified == null ? System.currentTimeMillis() : lastModified.getTime();
+            return pathInfo.getLastModified().getTime();
         }
 
         @Override
@@ -311,7 +309,8 @@ class PathInfoProviderBasedHierarchicalContent implements IHierarchicalContent
             IHierarchicalContentNode node = containerNode.getChildNode(relativePath);
             return asFileContentProvider(node);
         }
-        throw new IllegalArgumentException("Resource '" + FileUtilities.getRelativeFilePath(root, file)
+        throw new IllegalArgumentException("Resource '"
+                + FileUtilities.getRelativeFilePath(root, file)
                 + "' is currently unavailable. It might be in an archive.");
     }
 
diff --git a/datastore_server/source/sql/postgresql/003/schema-003.sql b/datastore_server/source/sql/postgresql/003/schema-003.sql
new file mode 100644
index 00000000000..457c34eb179
--- /dev/null
+++ b/datastore_server/source/sql/postgresql/003/schema-003.sql
@@ -0,0 +1,53 @@
+
+/* ---------------------------------------------------------------------- */
+/* Domains                                                                */
+/* ---------------------------------------------------------------------- */
+
+CREATE DOMAIN TECH_ID AS BIGINT;
+
+CREATE DOMAIN CODE AS VARCHAR(40);
+
+CREATE DOMAIN FILE_PATH AS VARCHAR(1000);
+
+CREATE DOMAIN BOOLEAN_CHAR AS BOOLEAN DEFAULT FALSE;
+
+CREATE DOMAIN TIME_STAMP AS TIMESTAMP WITH TIME ZONE;
+
+
+/* ---------------------------------------------------------------------- */
+/* Tables                                                                 */
+/* ---------------------------------------------------------------------- */
+
+CREATE TABLE DATA_SETS (
+  ID BIGSERIAL NOT NULL,
+  CODE CODE NOT NULL,
+  LOCATION FILE_PATH NOT NULL,
+
+  PRIMARY KEY (ID),
+  UNIQUE (CODE)
+);
+
+CREATE INDEX DATA_SETS_CODE_IDX ON DATA_SETS (CODE);
+
+CREATE TABLE DATA_SET_FILES (
+  ID BIGSERIAL NOT NULL,
+  DASE_ID TECH_ID NOT NULL,
+  PARENT_ID TECH_ID,
+  RELATIVE_PATH FILE_PATH NOT NULL,
+  FILE_NAME FILE_PATH NOT NULL,
+  SIZE_IN_BYTES BIGINT NOT NULL,
+  IS_DIRECTORY BOOLEAN_CHAR NOT NULL,
+  LAST_MODIFIED TIME_STAMP NOT NULL DEFAULT NOW(),
+
+  PRIMARY KEY (ID),
+  CONSTRAINT FK_DATA_SET_FILES_DATA_SETS FOREIGN KEY (DASE_ID) REFERENCES DATA_SETS (ID) ON DELETE CASCADE ON UPDATE CASCADE,
+  CONSTRAINT FK_DATA_SET_FILES_DATA_SET_FILES FOREIGN KEY (PARENT_ID) REFERENCES DATA_SET_FILES (ID) ON DELETE CASCADE ON UPDATE CASCADE
+);
+
+CREATE INDEX DATA_SET_FILES_RELATIVE_PATH_IDX ON DATA_SET_FILES (RELATIVE_PATH);
+CREATE INDEX DATA_SET_FILES_FILE_NAME_IDX ON DATA_SET_FILES (FILE_NAME);
+
+CREATE TABLE EVENTS (
+  LAST_SEEN_DELETION_EVENT_ID TECH_ID NOT NULL
+);
+
diff --git a/datastore_server/source/sql/postgresql/migration/migration-002-003.sql b/datastore_server/source/sql/postgresql/migration/migration-002-003.sql
new file mode 100644
index 00000000000..217ea7507f9
--- /dev/null
+++ b/datastore_server/source/sql/postgresql/migration/migration-002-003.sql
@@ -0,0 +1,8 @@
+----------------------------------------------------------------------
+--
+--  Migration script from version 2 to 3 of the database
+--
+----------------------------------------------------------------------
+ALTER TABLE data_set_files ALTER COLUMN last_modified SET DEFAULT NOW();
+UPDATE data_set_files SET last_modified = DEFAULT WHERE last_modified IS NULL; 
+ALTER TABLE data_set_files ALTER COLUMN last_modified SET NOT NULL; 
-- 
GitLab