public SaveMappedObject ( IMappedObject obj ) : void | ||
obj | IMappedObject | /// The MappedObject instance. /// |
return | void |
public void SaveMappedObject(IMappedObject obj) {
string id = this.GetId(obj);
using(var tran = this.engine.GetTransaction()) {
var byteGuid = obj.Guid.ToByteArray();
var row = tran.Select<byte[], string>(MappedObjectsGuidsTable, byteGuid);
if (row.Exists && row.Value != id) {
tran.Rollback();
throw new DublicateGuidException(string.Format("An entry with Guid {0} already exists", obj.Guid));
}
if (this.fullValidationOnEachManipulation && obj.ParentId != null) {
DbCustomSerializer<MappedObject> value = tran.Select<string, DbCustomSerializer<MappedObject>>(MappedObjectsTable, obj.ParentId).Value;
if (value == null) {
tran.Rollback();
throw new InvalidDataException();
}
}
obj.LastTimeStoredInStorage = DateTime.UtcNow;
tran.Insert<string, DbCustomSerializer<MappedObject>>(MappedObjectsTable, id, obj as MappedObject);
if (!obj.Guid.Equals(Guid.Empty)) {
tran.Insert<byte[], string>(MappedObjectsGuidsTable, obj.Guid.ToByteArray(), id);
}
tran.Commit();
}
this.ValidateObjectStructureIfFullValidationIsEnabled();
}
public void FindRootFolder([Values(true, false)]bool withValidation) { string id = "id"; string path = Path.GetTempPath(); var fsInfo = new DirectoryInfoWrapper(new DirectoryInfo(path)); var matcher = new PathMatcher(path, "/"); var storage = new MetaDataStorage(this.engine, matcher, withValidation); var rootFolder = new MappedObject("/", id, MappedObjectType.Folder, null, "token"); storage.SaveMappedObject(rootFolder); Assert.That(storage.GetObjectByRemoteId(id), Is.Not.Null, "Not findable by ID"); Assert.That(storage.GetObjectByLocalPath(fsInfo), Is.Not.Null, "Not findable by path"); }