#endregion
using System.Diagnostics.Contracts;
using System.IO;
+using System.Reflection;
using System.Threading.Tasks;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework;
namespace Pithos.Core
{
using System;
- using System.Collections.Generic;
- using System.Linq;
+ using System.Collections.Generic;
/// <summary>
/// TODO: Update summary.
[ActiveRecord]
public class FileState : ActiveRecordLinqBase<FileState>
{
- private static readonly ILog Log = LogManager.GetLogger("FileState");
+ private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
private IList<FileTag> _tags = new List<FileTag>();
}
}
- public static void RemovePaths(IEnumerable<string> removed)
+ /// <summary>
+ /// Mark Unversioned all FileState rows from the database whose path
+ /// starts with one of the removed paths
+ /// </summary>
+ /// <param name="removed"></param>
+ public static void UnversionPaths(List<string> removed)
{
-
- var disjunction = new Disjunction();
+ if (removed == null)
+ return;
+ if (removed.Count == 0)
+ return;
+ //Create a disjunction (list of OR statements
+ var disjunction = new Disjunction();
foreach (var path in removed)
{
- disjunction.Add(Restrictions.On<FileState>(s => s.FilePath).IsLike(path, MatchMode.Start));
+ //with the restriction FileState.FilePath like '@path%'
+ disjunction.Add(Restrictions.On<FileState>(s => s.FilePath)
+ .IsLike(path, MatchMode.Start));
}
-
-
+ //Generate a query from the disjunction
var query=QueryOver.Of<FileState>().Where(disjunction);
- var aq = new ProjectionQuery<FileState,Guid>(query.DetachedCriteria,
- Projections.ProjectionList().Add(Projections.Id()));
- var ids=aq.Execute();
- FileState.DeleteAll(ids);
-
+
+ ExecuteWithRetry((session,instance)=>
+ {
+ using (var t=session.BeginTransaction())
+ {
+ var states = query.GetExecutableQueryOver(session).List();
+ foreach (var state in states)
+ {
+ state.FileStatus = FileStatus.Unversioned;
+ state.OverlayStatus = FileOverlayStatus.Unversioned;
+ state.Update();
+ }
+ t.Commit();
+ }
+ return null;
+ },null);
}
+
}
[ActiveRecord("Tags")]