private void DeleteRoot(DomainObject obj) { if (obj == null || obj.IsEmpty()) { return; } var ar = obj as IAggregateRoot; if (ar == null) { throw new DataAccessException(Strings.CanNotDeleteNonAggregateRoot); } CheckDataVersion(obj); var rootId = ar.GetIdentity(); OnPreDataDelete(obj); if (DeleteData(rootId, rootId)) { DeleteMembers(obj, obj, obj); OnDataDeleted(rootId, rootId, obj); } }
internal void Update(DomainObject obj) { if (obj == null || obj.IsEmpty()) { return; } DomainObject root = null; if (this.Type == DataTableType.AggregateRoot) { root = obj; } if (root == null || root.IsEmpty()) { throw new DomainDrivenException(string.Format(Strings.PersistentObjectError, obj.ObjectType.FullName)); } if (obj.IsDirty) { CheckDataVersion(root); OnPreDataUpdate(obj); if (UpdateData(root, null, obj)) { OnDataUpdated(root, obj); } } else { //如果对象不是脏的,但是要求修改,那么有可能是该对象的引用链上的对象发生了变化,所以我们移除该对象的缓冲 DomainBuffer.Public.Remove(obj.ObjectType, GetObjectId(obj)); } }
/// <summary> /// 插入成员数据 /// </summary> /// <param name="root"></param> /// <param name="parent"></param> /// <param name="obj"></param> /// <returns>成员有可能已经在别的引用中被插入,此时返回false,否则返回true</returns> private void InsertMember(DomainObject root, DomainObject parent, DomainObject obj) { if (obj == null || obj.IsEmpty()) { return; } //我们需要先查,看数据库中是否存在数据,如果不存在就新增,存在就增加引用次数 var existObject = QuerySingle(GetObjectId(root), GetObjectId(obj)); if (existObject.IsNull()) { OnPreDataInsert(obj); var data = InsertData(root, parent, obj); OnDataInserted(root, obj, data); } else { if (this.IsDerived) { this.InheritedRoot.IncrementAssociated(GetObjectId(root), GetObjectId(obj)); } else { //递增引用次数 IncrementAssociated(GetObjectId(root), GetObjectId(obj)); } } }
private void UpdateMember(DomainObject root, DomainObject parent, DomainObject obj) { if (obj == null || obj.IsEmpty() || !obj.IsDirty) { return; } if (UpdateData(root, parent, obj)) { OnDataUpdated(root, obj); } }
/// <summary> /// 删除成员(该方法用于删除 ValueObject,EntityObject等对象) /// </summary> /// <param name="root"></param> /// <param name="parent"></param> /// <param name="obj"></param> private void DeleteMember(DomainObject root, DomainObject parent, DomainObject obj) { if (obj == null || obj.IsEmpty()) { return; } var rootId = GetObjectId(root); var id = GetObjectId(obj); if (DeleteData(rootId, id)) { DeleteMembers(root, parent, obj); OnDataDelete(rootId, id, obj); } }
private static IEnumerable <string> GetIndexs() { DomainObject.CheckInitialized(); List <string> tables = new List <string>(); foreach (var objectType in DomainObject.TypeIndex) { if (DomainObject.IsEmpty(objectType)) { continue; } var fileds = GetObjectFields(objectType, false); tables.Add(objectType.Name); tables.AddRange(DataTable.GetRelatedNames(objectType, fileds)); } return(tables.Distinct()); }
private static IEnumerable <string> GetIndexs() { List <string> tables = new List <string>(); foreach (var objectType in DomainObject.TypeIndex) { if (DomainObject.IsEmpty(objectType)) { continue; } var fileds = DataModel.GetObjectFields(objectType, false); AddIndexName(tables, objectType.Name); var relatedNames = GetRelatedNames(objectType, fileds); foreach (var relatedName in relatedNames) { AddIndexName(tables, relatedName); } } return(tables.Distinct()); }
internal void Insert(DomainObject obj) { if (obj == null || obj.IsEmpty() || !obj.IsDirty) { return; } DomainObject root = null; if (this.Type == DataTableType.AggregateRoot) { root = obj; } if (root == null || root.IsEmpty()) { throw new DomainDrivenException(string.Format(Strings.PersistentObjectError, obj.ObjectType.FullName)); } var data = InsertData(root, null, obj); OnDataInsert(root, obj, data); }
internal void Update(DomainObject obj) { if (obj == null || obj.IsEmpty() || !obj.IsDirty) { return; } DomainObject root = null; if (this.Type == DataTableType.AggregateRoot) { root = obj; } if (root == null || root.IsEmpty()) { throw new DomainDrivenException(string.Format(Strings.PersistentObjectError, obj.ObjectType.FullName)); } CheckDataVersion(root); if (UpdateData(root, null, obj)) { OnDataUpdate(root, obj); } }