Preparation for Session to use DocumentChanges
parent
cb1c109f50
commit
947737fb9c
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using ln.types.odb.values;
|
||||
using ln.logging;
|
||||
using System.Linq;
|
||||
namespace ln.types.odb.ng
|
||||
{
|
||||
public class Session : IStorageContainer
|
||||
|
@ -86,7 +87,7 @@ namespace ln.types.odb.ng
|
|||
}
|
||||
}
|
||||
|
||||
public void Save(Document document)
|
||||
public void Save(Document document)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
|
@ -102,35 +103,20 @@ namespace ln.types.odb.ng
|
|||
{
|
||||
Document storageDocument = Storage.Load(document.ID);
|
||||
Document cacheDocument = documentCache[document.ID].CachedCopy;
|
||||
bool changedFlag = false;
|
||||
|
||||
foreach (ODBValue propertyName in document.Keys)
|
||||
{
|
||||
if (!document[propertyName].Equals(cacheDocument[propertyName]))
|
||||
{
|
||||
//Logging.Log(LogLevel.DEBUG, "SessionCache: Save(): found changed field for Document {0}: {1}={2}", document.ID, propertyName, document[propertyName]);
|
||||
storageDocument[propertyName] = document[propertyName];
|
||||
changedFlag = true;
|
||||
}
|
||||
}
|
||||
foreach (ODBValue propertyName in cacheDocument.Keys)
|
||||
{
|
||||
if (!document.Contains(propertyName))
|
||||
{
|
||||
storageDocument[propertyName] = ODBNull.Instance;
|
||||
changedFlag = true;
|
||||
}
|
||||
}
|
||||
// if (SyncDocument(cacheDocument,storageDocument))
|
||||
//{
|
||||
// Storage.Save(storageDocument);
|
||||
// documentCache[document.ID] = new CachedDocument(document.Clone() as Document,document);
|
||||
//}
|
||||
|
||||
DocumentChanges storageChanges = new DocumentChanges(cacheDocument, storageDocument);
|
||||
DocumentChanges sessionChanges = new DocumentChanges(cacheDocument, document);
|
||||
|
||||
Logging.Log(LogLevel.DEBUG, "Session.Save(): sessionChanges:");
|
||||
Logging.Log(LogLevel.DEBUG, "\n{0}",String.Join("\n", sessionChanges.Changes.Select((x) => x.ToString())));
|
||||
|
||||
|
||||
if (changedFlag)
|
||||
{
|
||||
Storage.Save(storageDocument);
|
||||
documentCache[document.ID] = new CachedDocument(document.Clone() as Document,document);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Logging.Log(LogLevel.DEBUG, "SessionCache: Save(): No changes to be saved for document {0}",document.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +157,33 @@ namespace ln.types.odb.ng
|
|||
Close();
|
||||
}
|
||||
|
||||
|
||||
private bool SyncDocument(Document src,Document dst)
|
||||
{
|
||||
Boolean changedFlag = false;
|
||||
|
||||
foreach (ODBValue propertyName in src.Keys)
|
||||
{
|
||||
if (!src[propertyName].Equals(dst[propertyName]))
|
||||
{
|
||||
//Logging.Log(LogLevel.DEBUG, "SessionCache: Save(): found changed field for Document {0}: {1}={2}", document.ID, propertyName, document[propertyName]);
|
||||
dst[propertyName] = src[propertyName];
|
||||
changedFlag = true;
|
||||
}
|
||||
}
|
||||
foreach (ODBValue propertyName in dst.Keys)
|
||||
{
|
||||
if (!src.Contains(propertyName))
|
||||
{
|
||||
dst[propertyName] = ODBNull.Instance;
|
||||
changedFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changedFlag;
|
||||
}
|
||||
|
||||
|
||||
struct CachedDocument
|
||||
{
|
||||
public Document CachedCopy;
|
||||
|
|
Loading…
Reference in New Issue