public bool CompareListsById(IList newList, IList oldList) { if (newList == null || oldList == null) { if (!((newList == null && oldList == null))) { return(false); } else { return(true); } } if (!(oldList.Count == newList.Count)) { return(false); } IObjectManager om = this.Context.ObjectManager; IDomainMap dm = this.Context.DomainMap; Hashtable ids = new Hashtable(); foreach (object value in newList) { IClassMap classMap = dm.MustGetClassMap(value.GetType()); string id = classMap.GetFullName() + om.GetObjectIdentity(value); ids[id] = id; } foreach (object value in oldList) { IClassMap classMap = dm.MustGetClassMap(value.GetType()); string id = classMap.GetFullName() + om.GetObjectIdentity(value); if (!(ids.ContainsKey(id))) { return(false); } } ids = new Hashtable(); foreach (object value in oldList) { IClassMap classMap = dm.MustGetClassMap(value.GetType()); string id = classMap.GetFullName() + om.GetObjectIdentity(value); ids[id] = id; } foreach (object value in newList) { IClassMap classMap = dm.MustGetClassMap(value.GetType()); string id = classMap.GetFullName() + om.GetObjectIdentity(value); if (!(ids.ContainsKey(id))) { return(false); } } return(true); }
private NPathQuery CreateQuery(Type type, IDictionary <string, object> match) { IDomainMap domainMap = GetContext().DomainMap; IClassMap classMap = domainMap.MustGetClassMap(type); StringBuilder query = new StringBuilder(); query.Append("Select * From " + classMap.Name); if (match != null) { if (match.Keys.Count > 0) { query.Append(" Where "); foreach (string propertyName in match.Keys) { query.Append(propertyName + " = "); query.Append("'"); query.Append(match[propertyName].ToString()); query.Append("'"); query.Append(" And "); } query.Length -= 5; } } return(new NPathQuery(query.ToString(), type)); }
public virtual void RemoveNonInverseReferences(object obj) { IDomainMap domainMap = this.Context.DomainMap; IClassMap classMap = domainMap.MustGetClassMap(obj.GetType()); IList classMaps = this.Context.DomainMap.GetClassMapsWithUniDirectionalReferenceTo(classMap, true); NullifyUniReferences(obj, classMap, classMaps); //NullifyReferencesInCache(obj, classMap, classMaps); }
public virtual IClassMap GetRootClassMap(string npath, IDomainMap domainMap) { NPathParser parser = new NPathParser() ; NPathSelectQuery query = parser.ParseSelectQuery(npath) ; string className = ((NPathClassName)query.From.Classes[0]).Name; IClassMap rootClassMap = domainMap.MustGetClassMap(className); return rootClassMap; }
protected virtual void SerializeInlineObjectElement(XmlNode xmlObject, object obj, XmlNode xmlInline, object value, bool creating) { IDomainMap domainMap = this.Context.DomainMap; IClassMap classMap = domainMap.MustGetClassMap(value.GetType()); SerializeObject(xmlInline, value, classMap, creating, true); //hmmmmmmmmmmmmm................... this.Context.UnitOfWork.RegisterClean(value); }
private NPathQuery CreateQuery(Type type, string where) { IDomainMap domainMap = GetContext().DomainMap; IClassMap classMap = domainMap.MustGetClassMap(type); StringBuilder query = new StringBuilder(); query.Append("Select * From " + classMap.Name); query.Append(" Where " + where); return(new NPathQuery(query.ToString(), type)); }
public virtual IClassMap GetRootClassMap(string npath, IDomainMap domainMap) { NPathParser parser = new NPathParser(); NPathSelectQuery query = parser.ParseSelectQuery(npath); string className = ((NPathClassName)query.From.Classes[0]).Name; IClassMap rootClassMap = domainMap.MustGetClassMap(className); return(rootClassMap); }
protected virtual void RemoveInsertedReferences(object obj) { IDomainMap domainMap = this.Context.DomainMap; IClassMap classMap = domainMap.MustGetClassMap(obj.GetType()); IUnitOfWork uow = this.Context.UnitOfWork; foreach (object test in uow.GetCreatedObjects()) { NullifyReferencesInInsertedObject(obj, classMap, test); } }
protected virtual void SerializeInlineReferenceElement(object obj, XmlNode xmlElement, object value) { IObjectManager om = this.Context.ObjectManager; IDomainMap domainMap = this.Context.DomainMap; IClassMap classMap = domainMap.MustGetClassMap(value.GetType()); SetAttributeValue(xmlElement, "id", om.GetObjectIdentity(value)); SetAttributeValue(xmlElement, "class", classMap.Name); IPropertyMap parent = classMap.GetDocParentPropertyMap(); if (parent != null) { object rootObject = GetRootObject(value, parent); if (rootObject == null) { throw new NPersistException("Could not find root object!"); // do not localize } SetAttributeValue(xmlElement, "root-id", om.GetObjectIdentity(rootObject)); SetAttributeValue(xmlElement, "root-class", domainMap.MustGetClassMap(rootObject.GetType()).Name); } }
protected virtual void NullifyReferencesInInsertedObject(object obj, IClassMap classMap, object refering) { IDomainMap domainMap = this.Context.DomainMap; IClassMap referingClassMap = domainMap.MustGetClassMap(refering.GetType()); IObjectManager om = this.Context.ObjectManager; foreach (IPropertyMap refPropertyMap in referingClassMap.GetAllPropertyMaps()) { if (!(refPropertyMap.ReferenceType == ReferenceType.None)) { NullifyReferenceInInsertedObject(obj, refering, refPropertyMap, om); } } }
protected virtual object ManageInlineReference(XmlNode xmlNode, object obj, XmlNode xmlItem) { IDomainMap domainMap = this.Context.DomainMap; if (xmlItem == null) { return(null); } string identity = xmlItem.Attributes["id"].Value; string className = xmlItem.Attributes["class"].Value; IClassMap classMap = domainMap.MustGetClassMap(className); Type type = this.Context.AssemblyManager.MustGetTypeFromClassMap(classMap); object value = this.Context.GetObjectById(identity, type, true); return(value); }
protected virtual void NullifyUniReferences(object obj, IClassMap classMap, IList classMapsWithUniRefs) { if (classMapsWithUniRefs.Count < 1) { return; } IDomainMap domainMap = this.Context.DomainMap; IPersistenceEngine pe = this.Context.PersistenceEngine; IAssemblyManager am = this.Context.AssemblyManager; foreach (IClassMap classMapWithUniRef in classMapsWithUniRefs) { Type classWithUniRef = am.GetTypeFromClassMap(classMapWithUniRef); IList objectsWithUniRefs = pe.GetObjectsOfClassWithUniReferencesToObject(classWithUniRef, obj); IList uniRefPropertyMaps = classMapWithUniRef.GetUniDirectionalReferencesTo(classMap, true); foreach (object test in objectsWithUniRefs) { IClassMap testClassMap = domainMap.MustGetClassMap(test.GetType()); NullifyUniReferencesInObject(obj, classMap, test, testClassMap, uniRefPropertyMaps); } } }
protected virtual object ManageInlineObject(XmlNode xmlItem, object obj, IPropertyMap propertyMap) { IDomainMap domainMap = this.Context.DomainMap; if (xmlItem == null) { return(null); } string className = xmlItem.Attributes["class"].Value; IClassMap classMap = domainMap.MustGetClassMap(className); Type type = this.Context.AssemblyManager.MustGetTypeFromClassMap(classMap); DeserializeObject(obj, classMap, xmlItem, true); string identity = this.Context.ObjectManager.GetObjectIdentity(obj); object value = this.Context.GetObjectById(identity, type, true); //DeserializeObject(obj, classMap, xmlItem); DeserializeObject(value, classMap, xmlItem); return(value); }
protected virtual void DeserializeClone(object obj, ReadOnlyClone clone) { IObjectManager om = this.Context.ObjectManager; IDomainMap dm = this.Context.DomainMap; IAssemblyManager am = this.Context.AssemblyManager; IClassMap classMap = dm.MustGetClassMap(obj.GetType()); IListManager lm = this.Context.ListManager; foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps()) { if (propertyMap.ReferenceType == ReferenceType.None) { if (propertyMap.IsCollection) { IList values = (IList)clone.PropertyValues[propertyMap.Name]; IList list = (IList)om.GetPropertyValue(obj, propertyMap.Name); bool stackMute = false; IInterceptableList mList = list as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } list.Clear(); foreach (object value in values) { list.Add(value); } IList cloneList = new ArrayList(list); if (mList != null) { mList.MuteNotify = stackMute; } om.SetOriginalPropertyValue(obj, propertyMap.Name, cloneList); om.SetNullValueStatus(obj, propertyMap.Name, false); } else { object value = clone.PropertyValues[propertyMap.Name]; om.SetPropertyValue(obj, propertyMap.Name, value); om.SetOriginalPropertyValue(obj, propertyMap.Name, value); om.SetNullValueStatus(obj, propertyMap.Name, (bool)clone.NullValueStatuses[propertyMap.Name]); } } else { IClassMap refClassMap = propertyMap.MustGetReferencedClassMap(); if (refClassMap.IsReadOnly) { if (propertyMap.IsCollection) { IList values = (IList)clone.PropertyValues[propertyMap.Name]; IList list = (IList)om.GetPropertyValue(obj, propertyMap.Name); bool stackMute = false; IInterceptableList mList = list as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } list.Clear(); foreach (SerializedReference refId in values) { object value = null; if (refId != null) { refClassMap = dm.MustGetClassMap(refId.Type); Type refType = am.GetTypeFromClassMap(refClassMap); value = this.Context.GetObjectById(refId.Identity, refType, true); list.Add(value); } } IList cloneList = new ArrayList(list); if (mList != null) { mList.MuteNotify = stackMute; } om.SetOriginalPropertyValue(obj, propertyMap.Name, cloneList); om.SetNullValueStatus(obj, propertyMap.Name, false); } else { object value = null; SerializedReference refId = (SerializedReference)clone.PropertyValues[propertyMap.Name]; if (refId != null) { refClassMap = dm.MustGetClassMap(refId.Type); Type refType = am.GetTypeFromClassMap(refClassMap); value = this.Context.GetObjectById(refId.Identity, refType, true); } om.SetPropertyValue(obj, propertyMap.Name, value); om.SetOriginalPropertyValue(obj, propertyMap.Name, value); om.SetNullValueStatus(obj, propertyMap.Name, (bool)clone.NullValueStatuses[propertyMap.Name]); } } } } }
protected virtual void SerializeClone(object obj, ReadOnlyClone clone, string id, string key) { IObjectManager om = this.Context.ObjectManager; IDomainMap dm = this.Context.DomainMap; IAssemblyManager am = this.Context.AssemblyManager; IClassMap classMap = dm.MustGetClassMap(obj.GetType()); IListManager lm = this.Context.ListManager; clone.Identity = id; clone.Key = key; clone.Type = classMap.GetFullName(); foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps()) { if (propertyMap.ReferenceType == ReferenceType.None) { if (propertyMap.IsCollection) { IList values = new ArrayList(); IList list = (IList)om.GetPropertyValue(obj, propertyMap.Name); foreach (object value in list) { values.Add(value); } clone.PropertyValues[propertyMap.Name] = values; clone.NullValueStatuses[propertyMap.Name] = false; } else { object value = om.GetPropertyValue(obj, propertyMap.Name); clone.PropertyValues[propertyMap.Name] = value; clone.NullValueStatuses[propertyMap.Name] = om.GetNullValueStatus(obj, propertyMap.Name); } } else { IClassMap refClassMap = propertyMap.MustGetReferencedClassMap(); if (refClassMap.IsReadOnly) { if (propertyMap.IsCollection) { IList values = new ArrayList(); IList list = (IList)om.GetPropertyValue(obj, propertyMap.Name); foreach (object value in list) { if (value != null) { refClassMap = dm.MustGetClassMap(value.GetType()); string refIdentity = om.GetObjectIdentity(value); SerializedReference refId = new SerializedReference(refIdentity, refClassMap.GetFullName()); values.Add(refId); } } clone.PropertyValues[propertyMap.Name] = values; clone.NullValueStatuses[propertyMap.Name] = false; } else { object value = om.GetPropertyValue(obj, propertyMap.Name); if (value != null) { refClassMap = dm.MustGetClassMap(value.GetType()); string refIdentity = om.GetObjectIdentity(value); SerializedReference refId = new SerializedReference(refIdentity, refClassMap.GetFullName()); value = refId; } clone.PropertyValues[propertyMap.Name] = value; clone.NullValueStatuses[propertyMap.Name] = om.GetNullValueStatus(obj, propertyMap.Name); } } } } }
protected virtual Hashtable GetConcernedTableMaps(object obj, int exceptionLimit, Hashtable tableMaps, IDomainMap dm, IObjectManager om, bool update) { if (obj == null) return null; ITableMap tableMap = null; IClassMap classMap = dm.MustGetClassMap(obj.GetType()); if (classMap.Table != "") { tableMap = classMap.GetTableMap(); if (tableMap != null) tableMaps[tableMap] = tableMap; foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps()) { if (propertyMap.Table != "") { if (!(propertyMap.IsSlave || propertyMap.IsReadOnly)) { bool ok = true; if (update) { PropertyStatus propStatus = om.GetPropertyStatus(obj, propertyMap.Name); if (propStatus != PropertyStatus.Dirty) ok = false; } if (ok) { tableMap = propertyMap.GetTableMap(); if (tableMap != null) tableMaps[tableMap] = tableMap; } } } } } return tableMaps; }