changeset 197:530a25320461

removal of text as ids in sqlite db
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 27 Nov 2012 14:59:55 +0100
parents 6d0225a26fd8
children 663cc6c46d0a
files OrthancServer/DatabaseWrapper.cpp OrthancServer/DatabaseWrapper.h OrthancServer/OrthancRestApi.cpp OrthancServer/PrepareDatabase2.sql OrthancServer/ServerEnumerations.h OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h UnitTests/ServerIndex.cpp
diffstat 8 files changed, 29 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp	Fri Nov 16 08:23:05 2012 +0100
+++ b/OrthancServer/DatabaseWrapper.cpp	Tue Nov 27 14:59:55 2012 +0100
@@ -316,7 +316,7 @@
   }
 
   void DatabaseWrapper::AttachFile(int64_t id,
-                                   const std::string& contentName,
+                                   AttachedFileType contentType,
                                    const std::string& fileUuid,
                                    uint64_t compressedSize,
                                    uint64_t uncompressedSize,
@@ -324,7 +324,7 @@
   {
     SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?)");
     s.BindInt(0, id);
-    s.BindString(1, contentName);
+    s.BindInt(1, contentType);
     s.BindString(2, fileUuid);
     s.BindInt(3, compressedSize);
     s.BindInt(4, uncompressedSize);
@@ -333,16 +333,16 @@
   }
 
   bool DatabaseWrapper::LookupFile(int64_t id,
-                                   const std::string& contentName,
+                                   AttachedFileType contentType,
                                    std::string& fileUuid,
                                    uint64_t& compressedSize,
                                    uint64_t& uncompressedSize,
                                    CompressionType& compressionType)
   {
     SQLite::Statement s(db_, SQLITE_FROM_HERE, 
-                        "SELECT uuid, compressedSize, uncompressedSize, compressionType FROM AttachedFiles WHERE id=? AND contentName=?");
+                        "SELECT uuid, compressedSize, uncompressedSize, compressionType FROM AttachedFiles WHERE id=? AND fileType=?");
     s.BindInt(0, id);
-    s.BindString(1, contentName);
+    s.BindInt(1, contentType);
 
     if (!s.Step())
     {
--- a/OrthancServer/DatabaseWrapper.h	Fri Nov 16 08:23:05 2012 +0100
+++ b/OrthancServer/DatabaseWrapper.h	Tue Nov 27 14:59:55 2012 +0100
@@ -99,22 +99,22 @@
                             const std::string& defaultValue = "");
 
     void AttachFile(int64_t id,
-                    const std::string& contentName,
+                    AttachedFileType contentType,
                     const std::string& fileUuid,
                     uint64_t compressedSize,
                     uint64_t uncompressedSize,
                     CompressionType compressionType);
 
     void AttachFile(int64_t id,
-                    const std::string& contentName,
+                    AttachedFileType contentType,
                     const std::string& fileUuid,
                     uint64_t fileSize)
     {
-      AttachFile(id, contentName, fileUuid, fileSize, fileSize, CompressionType_None);
+      AttachFile(id, contentType, fileUuid, fileSize, fileSize, CompressionType_None);
     }
 
     bool LookupFile(int64_t id,
-                    const std::string& contentName,
+                    AttachedFileType contentType,
                     std::string& fileUuid,
                     uint64_t& compressedSize,
                     uint64_t& uncompressedSize,
--- a/OrthancServer/OrthancRestApi.cpp	Fri Nov 16 08:23:05 2012 +0100
+++ b/OrthancServer/OrthancRestApi.cpp	Tue Nov 27 14:59:55 2012 +0100
@@ -572,14 +572,14 @@
       std::string fileUuid, contentType, filename;
       if (uri[2] == "file")
       {
-        existingResource = index_.GetFile(fileUuid, compressionType, uri[1], "dicom");
+        existingResource = index_.GetFile(fileUuid, compressionType, uri[1], AttachedFileType_Dicom);
         contentType = "application/dicom";
         filename = fileUuid + ".dcm";
       }
       else if (uri[2] == "tags" ||
                uri[2] == "simplified-tags")
       {
-        existingResource = index_.GetFile(fileUuid, compressionType, uri[1], "json");
+        existingResource = index_.GetFile(fileUuid, compressionType, uri[1], AttachedFileType_Json);
         contentType = "application/json";
         filename = fileUuid + ".json";
       }
@@ -644,7 +644,7 @@
     {
       std::string uuid;
       CompressionType compressionType;
-      existingResource = index_.GetFile(uuid, compressionType, uri[1], "dicom");
+      existingResource = index_.GetFile(uuid, compressionType, uri[1], AttachedFileType_Dicom);
 
       std::string action = uri[2];
 
--- a/OrthancServer/PrepareDatabase2.sql	Fri Nov 16 08:23:05 2012 +0100
+++ b/OrthancServer/PrepareDatabase2.sql	Tue Nov 27 14:59:55 2012 +0100
@@ -27,12 +27,12 @@
 
 CREATE TABLE AttachedFiles(
        id INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE,
-       contentName TEXT,
+       fileType INTEGER,
        uuid TEXT,
        compressedSize INTEGER,
        uncompressedSize INTEGER,
        compressionType INTEGER,
-       PRIMARY KEY(id, contentName)
+       PRIMARY KEY(id, fileType)
        );              
 
 CREATE TABLE Changes(
--- a/OrthancServer/ServerEnumerations.h	Fri Nov 16 08:23:05 2012 +0100
+++ b/OrthancServer/ServerEnumerations.h	Tue Nov 27 14:59:55 2012 +0100
@@ -29,7 +29,6 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  **/
 
-
 #pragma once
 
 namespace Orthanc
@@ -81,4 +80,10 @@
     ChangeType_NewStudy = 5,
     ChangeType_InvalidSeries = 6
   };
+
+  enum AttachedFileType
+  {
+    AttachedFileType_Dicom = 1,
+    AttachedFileType_Json = 2
+  };
 }
--- a/OrthancServer/ServerIndex.cpp	Fri Nov 16 08:23:05 2012 +0100
+++ b/OrthancServer/ServerIndex.cpp	Tue Nov 27 14:59:55 2012 +0100
@@ -589,8 +589,8 @@
       }
 
       // Attach the files to the newly created instance
-      db2_->AttachFile(instance, "dicom", fileUuid, uncompressedFileSize);
-      db2_->AttachFile(instance, "json", jsonUuid, 0);  // TODO "0"
+      db2_->AttachFile(instance, AttachedFileType_Dicom, fileUuid, uncompressedFileSize);
+      db2_->AttachFile(instance, AttachedFileType_Json, jsonUuid, 0);  // TODO "0"
 
       // Attach the metadata
       db2_->SetMetadata(instance, MetadataType_Instance_ReceptionDate, Toolbox::GetNowIsoString());
@@ -946,7 +946,7 @@
   bool ServerIndex::GetFile(std::string& fileUuid,
                             CompressionType& compressionType,
                             const std::string& instanceUuid,
-                            const std::string& contentName)
+                            AttachedFileType contentType)
   {
     boost::mutex::scoped_lock scoped_lock(mutex_);
 
@@ -960,7 +960,7 @@
 
     uint64_t compressedSize, uncompressedSize;
 
-    return db2_->LookupFile(id, contentName, fileUuid, compressedSize, uncompressedSize, compressionType);
+    return db2_->LookupFile(id, contentType, fileUuid, compressedSize, uncompressedSize, compressionType);
   }
 
 
--- a/OrthancServer/ServerIndex.h	Fri Nov 16 08:23:05 2012 +0100
+++ b/OrthancServer/ServerIndex.h	Tue Nov 27 14:59:55 2012 +0100
@@ -159,7 +159,7 @@
     bool GetFile(std::string& fileUuid,
                  CompressionType& compressionType,
                  const std::string& instanceUuid,
-                 const std::string& contentName);
+                 AttachedFileType contentType);
 
     void GetAllUuids(Json::Value& target,
                      ResourceType resourceType);
--- a/UnitTests/ServerIndex.cpp	Fri Nov 16 08:23:05 2012 +0100
+++ b/UnitTests/ServerIndex.cpp	Tue Nov 27 14:59:55 2012 +0100
@@ -109,9 +109,9 @@
     ASSERT_EQ("e", l.front());
   }
 
-  index.AttachFile(a[4], "_json", "my json file", 21, 42, CompressionType_Zlib);
-  index.AttachFile(a[4], "_dicom", "my dicom file", 42);
-  index.AttachFile(a[6], "_hello", "world", 44);
+  index.AttachFile(a[4], AttachedFileType_Json, "my json file", 21, 42, CompressionType_Zlib);
+  index.AttachFile(a[4], AttachedFileType_Dicom, "my dicom file", 42);
+  index.AttachFile(a[6], AttachedFileType_Dicom, "world", 44);
   index.SetMetadata(a[4], MetadataType_Instance_RemoteAet, "PINNACLE");
 
   ASSERT_EQ(21 + 42 + 44, index.GetTotalCompressedSize());
@@ -141,7 +141,7 @@
 
   uint64_t us, cs;
   CompressionType ct;
-  ASSERT_TRUE(index.LookupFile(a[4], "_json", s, cs, us, ct));
+  ASSERT_TRUE(index.LookupFile(a[4], AttachedFileType_Json, s, cs, us, ct));
   ASSERT_EQ("my json file", s);
   ASSERT_EQ(21, cs);
   ASSERT_EQ(42, us);