using Castle.ActiveRecord.Framework;
using Castle.ActiveRecord.Framework.Config;
using Castle.ActiveRecord.Queries;
+using NHibernate;
using NHibernate.ByteCode.Castle;
using NHibernate.Cfg;
using NHibernate.Cfg.Loquacious;
{
try
{
-
- using (var connection = GetConnection())
- using(var tx=connection.BeginTransaction())
- using (var command = new SQLiteCommand(connection))
- {
+ using (var session = ActiveRecordMediator.GetSessionFactoryHolder().CreateSession(typeof(FileState)))
+ using (session.BeginTransaction(IsolationLevel.ReadCommitted))
+ {
+
+ var walquery = session.CreateSQLQuery("PRAGMA journal_mode=WAL");
+ walquery.List();
+
+ Func<IQuery, IQuery> setCriteria = q => q
+ .SetString("path", path)
+ .SetString("checksum",objectInfo.X_Object_Hash)
+ .SetString("etag", objectInfo.ETag)
+ .SetInt64("version", objectInfo.Version.Value)
+ .SetDateTime("versionTimeStamp",objectInfo.VersionTimestamp.Value)
+ .SetEnum("fileStatus", FileStatus.Unchanged)
+ .SetEnum("overlayStatus",FileOverlayStatus.Normal)
+ .SetString("objectID", objectInfo.UUID);
+ IQuery updatecmd = session.CreateSQLQuery(
+ "update FileState set FilePath=:path,FileStatus= :fileStatus,OverlayStatus= :overlayStatus, Checksum=:checksum, ETag=:etag,LastMD5=:etag,Version=:version,VersionTimeStamp=:versionTimeStamp where ObjectID = :objectID ");
+ updatecmd = setCriteria(updatecmd);
+ var affected = updatecmd.ExecuteUpdate();
+
//If the ID exists, update the status
- command.CommandText ="update FileState set FilePath=:path,FileStatus= :fileStatus, Checksum=:checksum, ETag=:etag,LastMD5=:etag,Version=:version,VersionTimeStamp=:versionTimeStamp where ObjectID = :objectID ";
- command.Parameters.AddWithValue("path", path);
- command.Parameters.AddWithValue("checksum", objectInfo.X_Object_Hash);
- command.Parameters.AddWithValue("etag", objectInfo.ETag);
- command.Parameters.AddWithValue("version", objectInfo.Version);
- command.Parameters.AddWithValue("versionTimeStamp", objectInfo.VersionTimestamp);
- command.Parameters.AddWithValue("fileStatus", FileStatus.Unchanged);
- command.Parameters.AddWithValue("overlayStatus", FileOverlayStatus.Normal);
- command.Parameters.AddWithValue("objectID",objectInfo.UUID);
- var affected = command.ExecuteNonQuery();
if (affected == 0)
{
//If the ID doesn't exist, try to update using the path, and store the ID as well.
- command.CommandText =
- "update FileState set FileStatus= :fileStatus, ObjectID=:objectID, Checksum=:checksum, ETag=:etag,LastMD5=:etag,Version=:version,VersionTimeStamp=:versionTimeStamp where FilePath = :path COLLATE NOCASE ";
- affected = command.ExecuteNonQuery();
+ updatecmd = session.CreateSQLQuery(
+ "update FileState set FileStatus= :fileStatus,OverlayStatus= :overlayStatus, ObjectID=:objectID, Checksum=:checksum, ETag=:etag,LastMD5=:etag,Version=:version,VersionTimeStamp=:versionTimeStamp where FilePath = :path COLLATE NOCASE ");
+ updatecmd=setCriteria(updatecmd);
+ affected = updatecmd.ExecuteUpdate();
}
if (affected==0)
{
- command.CommandText =
- "INSERT INTO FileState (Id,FilePath,Checksum,Version,VersionTimeStamp,ETag,LastMD5,FileStatus,OverlayStatus,ObjectID) VALUES (:id,:path,:checksum,:version,:versionTimeStamp,:etag,:etag,:fileStatus,:overlayStatus,:objectID)";
- command.Parameters.AddWithValue("id", Guid.NewGuid());
- affected = command.ExecuteNonQuery();
+ IQuery insertCmd=session.CreateSQLQuery(
+ "INSERT INTO FileState (Id,FilePath,Checksum,Version,VersionTimeStamp,ETag,LastMD5,FileStatus,OverlayStatus,ObjectID) VALUES (:id,:path,:checksum,:version,:versionTimeStamp,:etag,:etag,:fileStatus,:overlayStatus,:objectID)");
+ insertCmd=setCriteria(insertCmd).SetGuid("id", Guid.NewGuid());
+ affected = insertCmd.ExecuteUpdate();
}
}