Revision ab2f6f79 trunk/Pithos.Core/FileState.cs

b/trunk/Pithos.Core/FileState.cs
110 110
            
111 111
        }
112 112

  
113
        public static void StoreFileStatus(string absolutePath, FileStatus newStatus)
114
        {
115
            if (string.IsNullOrWhiteSpace(absolutePath))
116
                throw new ArgumentNullException("absolutePath");
117
            Contract.EndContractBlock();
118

  
119
            Execute((session, instance) =>
120
            {
121
                const string hqlUpdate = "update FileState set FileStatus= :status where FilePath = :path  ";
122
                var updatedEntities = session.CreateQuery(hqlUpdate)
123
                        .SetString("path", absolutePath.ToLower())
124
                        .SetEnum("status", newStatus)
125
                        .ExecuteUpdate();
126
                if (updatedEntities == 0)
127
                {
128
                    var newState = new FileState { FilePath = absolutePath, Id = Guid.NewGuid(), FileStatus = newStatus };
129
                    newState.CreateAndFlush();
130
                }
131
                return null;
132
            }, null);
133

  
134
        }
135

  
136
        public static void StoreOverlayStatus(string absolutePath, FileOverlayStatus newStatus)
137
        {
138
            if (string.IsNullOrWhiteSpace(absolutePath))
139
                throw new ArgumentNullException("absolutePath");
140
            Contract.EndContractBlock();
141

  
142
            Execute((session, instance) =>
143
            {
144
                const string hqlUpdate = "update FileState set OverlayStatus= :status where FilePath = :path  ";
145
                var updatedEntities = session.CreateQuery(hqlUpdate)
146
                        .SetString("path", absolutePath.ToLower())
147
                        .SetEnum("status", newStatus)
148
                        .ExecuteUpdate();
149
                if (updatedEntities == 0)
150
                {
151
                    var newState = new FileState { FilePath = absolutePath, Id = Guid.NewGuid(), OverlayStatus = newStatus };
152
                    newState.CreateAndFlush();
153
                }
154
                return null;
155
            }, null);
156

  
157
        }
158

  
159
        public static void UpdateStatus(string absolutePath, FileStatus fileStatus, FileOverlayStatus overlayStatus)
160
        {
161
            if (string.IsNullOrWhiteSpace(absolutePath))
162
                throw new ArgumentNullException("absolutePath");
163
            Contract.EndContractBlock();
164

  
165
            Execute((session, instance) =>
166
            {
167
                const string hqlUpdate = "update FileState set OverlayStatus= :overlayStatus, FileStatus= :fileStatus where FilePath = :path  ";
168
                var updatedEntities = session.CreateQuery(hqlUpdate)
169
                        .SetString("path", absolutePath.ToLower())
170
                        .SetEnum("fileStatus", fileStatus)
171
                        .SetEnum("overlayStatus", overlayStatus)
172
                        .ExecuteUpdate();
173
                return null;
174
            }, null);
175

  
176
        }
177
        public static void UpdateStatus(string absolutePath, FileStatus fileStatus)
178
        {
179
            if (string.IsNullOrWhiteSpace(absolutePath))
180
                throw new ArgumentNullException("absolutePath");
181
            Contract.EndContractBlock();
182

  
183
            Execute((session, instance) =>
184
            {
185
                const string hqlUpdate = "update FileState set FileStatus= :fileStatus where FilePath = :path  ";
186
                var updatedEntities = session.CreateQuery(hqlUpdate)
187
                        .SetString("path", absolutePath.ToLower())
188
                        .SetEnum("fileStatus", fileStatus)                        
189
                        .ExecuteUpdate();
190
                return updatedEntities;
191
            }, null);
192

  
193
        }
194

  
195
        public static void RenameState(string oldPath, string newPath)
196
        {
197
            if (string.IsNullOrWhiteSpace(oldPath))
198
                throw new ArgumentNullException("oldPath");
199
            Contract.EndContractBlock();
200

  
201
            Execute((session, instance) =>
202
            {
203
                const string hqlUpdate = "update FileState set FilePath= :newPath where FilePath = :oldPath  ";
204
                var updatedEntities = session.CreateQuery(hqlUpdate)
205
                        .SetString("oldPath", oldPath.ToLower())
206
                        .SetString("newPath", newPath.ToLower())                                          
207
                        .ExecuteUpdate();
208
                return updatedEntities;
209
            }, null);
210

  
211
        }
212

  
213
        public static void UpdateStatus(Guid id, FileStatus fileStatus)
214
        {
215
            Contract.EndContractBlock();
216

  
217
            Execute((session, instance) =>
218
            {
219
                const string hqlUpdate = "update FileState set FileStatus= :fileStatus where Id = :id  ";
220
                var updatedEntities = session.CreateQuery(hqlUpdate)
221
                        .SetGuid("id", id)
222
                        .SetEnum("fileStatus", fileStatus)                        
223
                        .ExecuteUpdate();
224
                return null;
225
            }, null);
226

  
227
        }
228

  
229
        public static void UpdateChecksum(string absolutePath, string checksum)
230
        {
231
            if (string.IsNullOrWhiteSpace(absolutePath))
232
                throw new ArgumentNullException("absolutePath");
233
            Contract.EndContractBlock();
234

  
235
            Execute((session, instance) =>
236
            {
237
                const string hqlUpdate = "update FileState set Checksum= :checksum where FilePath = :path  ";
238
                var updatedEntities = session.CreateQuery(hqlUpdate)
239
                        .SetString("path", absolutePath.ToLower())
240
                        .SetString("checksum", checksum)                        
241
                        .ExecuteUpdate();
242
                return null;
243
            }, null);
244

  
245
        }
246

  
113 247
        public static void ChangeRootPath(string oldPath,string newPath)
114 248
        {
115 249
            if (String.IsNullOrWhiteSpace(oldPath))

Also available in: Unified diff