commit ab2f6f7915af9731514edb4e288e3e332defeebc
Author: Panagiotis Kanavos <pkanavos@gmail.com>
Date:   Thu Jan 5 17:20:27 2012 +0200

    Changes to NHibernate/Activerecord storage code

diff --git a/trunk/Pithos.Core/FileState.cs b/trunk/Pithos.Core/FileState.cs
index c1be0fd..54e44a3 100644
--- a/trunk/Pithos.Core/FileState.cs
+++ b/trunk/Pithos.Core/FileState.cs
@@ -110,6 +110,140 @@ namespace Pithos.Core
             
         }
 
+        public static void StoreFileStatus(string absolutePath, FileStatus newStatus)
+        {
+            if (string.IsNullOrWhiteSpace(absolutePath))
+                throw new ArgumentNullException("absolutePath");
+            Contract.EndContractBlock();
+
+            Execute((session, instance) =>
+            {
+                const string hqlUpdate = "update FileState set FileStatus= :status where FilePath = :path  ";
+                var updatedEntities = session.CreateQuery(hqlUpdate)
+                        .SetString("path", absolutePath.ToLower())
+                        .SetEnum("status", newStatus)
+                        .ExecuteUpdate();
+                if (updatedEntities == 0)
+                {
+                    var newState = new FileState { FilePath = absolutePath, Id = Guid.NewGuid(), FileStatus = newStatus };
+                    newState.CreateAndFlush();
+                }
+                return null;
+            }, null);
+
+        }
+
+        public static void StoreOverlayStatus(string absolutePath, FileOverlayStatus newStatus)
+        {
+            if (string.IsNullOrWhiteSpace(absolutePath))
+                throw new ArgumentNullException("absolutePath");
+            Contract.EndContractBlock();
+
+            Execute((session, instance) =>
+            {
+                const string hqlUpdate = "update FileState set OverlayStatus= :status where FilePath = :path  ";
+                var updatedEntities = session.CreateQuery(hqlUpdate)
+                        .SetString("path", absolutePath.ToLower())
+                        .SetEnum("status", newStatus)
+                        .ExecuteUpdate();
+                if (updatedEntities == 0)
+                {
+                    var newState = new FileState { FilePath = absolutePath, Id = Guid.NewGuid(), OverlayStatus = newStatus };
+                    newState.CreateAndFlush();
+                }
+                return null;
+            }, null);
+
+        }
+
+        public static void UpdateStatus(string absolutePath, FileStatus fileStatus, FileOverlayStatus overlayStatus)
+        {
+            if (string.IsNullOrWhiteSpace(absolutePath))
+                throw new ArgumentNullException("absolutePath");
+            Contract.EndContractBlock();
+
+            Execute((session, instance) =>
+            {
+                const string hqlUpdate = "update FileState set OverlayStatus= :overlayStatus, FileStatus= :fileStatus where FilePath = :path  ";
+                var updatedEntities = session.CreateQuery(hqlUpdate)
+                        .SetString("path", absolutePath.ToLower())
+                        .SetEnum("fileStatus", fileStatus)
+                        .SetEnum("overlayStatus", overlayStatus)
+                        .ExecuteUpdate();
+                return null;
+            }, null);
+
+        }
+        public static void UpdateStatus(string absolutePath, FileStatus fileStatus)
+        {
+            if (string.IsNullOrWhiteSpace(absolutePath))
+                throw new ArgumentNullException("absolutePath");
+            Contract.EndContractBlock();
+
+            Execute((session, instance) =>
+            {
+                const string hqlUpdate = "update FileState set FileStatus= :fileStatus where FilePath = :path  ";
+                var updatedEntities = session.CreateQuery(hqlUpdate)
+                        .SetString("path", absolutePath.ToLower())
+                        .SetEnum("fileStatus", fileStatus)                        
+                        .ExecuteUpdate();
+                return updatedEntities;
+            }, null);
+
+        }
+
+        public static void RenameState(string oldPath, string newPath)
+        {
+            if (string.IsNullOrWhiteSpace(oldPath))
+                throw new ArgumentNullException("oldPath");
+            Contract.EndContractBlock();
+
+            Execute((session, instance) =>
+            {
+                const string hqlUpdate = "update FileState set FilePath= :newPath where FilePath = :oldPath  ";
+                var updatedEntities = session.CreateQuery(hqlUpdate)
+                        .SetString("oldPath", oldPath.ToLower())
+                        .SetString("newPath", newPath.ToLower())                                          
+                        .ExecuteUpdate();
+                return updatedEntities;
+            }, null);
+
+        }
+
+        public static void UpdateStatus(Guid id, FileStatus fileStatus)
+        {
+            Contract.EndContractBlock();
+
+            Execute((session, instance) =>
+            {
+                const string hqlUpdate = "update FileState set FileStatus= :fileStatus where Id = :id  ";
+                var updatedEntities = session.CreateQuery(hqlUpdate)
+                        .SetGuid("id", id)
+                        .SetEnum("fileStatus", fileStatus)                        
+                        .ExecuteUpdate();
+                return null;
+            }, null);
+
+        }
+
+        public static void UpdateChecksum(string absolutePath, string checksum)
+        {
+            if (string.IsNullOrWhiteSpace(absolutePath))
+                throw new ArgumentNullException("absolutePath");
+            Contract.EndContractBlock();
+
+            Execute((session, instance) =>
+            {
+                const string hqlUpdate = "update FileState set Checksum= :checksum where FilePath = :path  ";
+                var updatedEntities = session.CreateQuery(hqlUpdate)
+                        .SetString("path", absolutePath.ToLower())
+                        .SetString("checksum", checksum)                        
+                        .ExecuteUpdate();
+                return null;
+            }, null);
+
+        }
+
         public static void ChangeRootPath(string oldPath,string newPath)
         {
             if (String.IsNullOrWhiteSpace(oldPath))
