Ejemplo n.º 1
0
        public IObjectClone CloneObject(object obj)
        {
            IObjectManager om    = this.Context.ObjectManager;
            IObjectClone   clone = new ObjectClone();

            IClassMap classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType());

            foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps())
            {
                if (propertyMap.IsCollection)
                {
                }
                else
                {
                    if (om.HasOriginalValues(obj, propertyMap.Name))
                    {
                        clone.SetPropertyValue(propertyMap.Name, om.GetPropertyValue(obj, propertyMap.Name));
                        clone.SetOriginalPropertyValue(propertyMap.Name, om.GetOriginalPropertyValue(obj, propertyMap.Name));
                        clone.SetNullValueStatus(propertyMap.Name, om.GetNullValueStatus(obj, propertyMap.Name));
                        clone.SetUpdatedStatus(propertyMap.Name, om.GetUpdatedStatus(obj, propertyMap.Name));
                    }
                }
            }

            clone.SetObjectStatus(om.GetObjectStatus(obj));

            this.clonedObjects.Add(obj);

            return(clone);
        }
Ejemplo n.º 2
0
        private void ExamineDeletedObject(Hashtable hashDeleted, IObjectManager om, object delObj)
        {
            IClassMap delObjClassMap = this.Context.DomainMap.MustGetClassMap(delObj.GetType());

            foreach (IPropertyMap propertyMap in delObjClassMap.GetAllPropertyMaps())
            {
                if (!propertyMap.IsReadOnly && !propertyMap.IsSlave)
                {
                    if (propertyMap.ReferenceType != ReferenceType.None)
                    {
                        if (propertyMap.IsCollection)
                        {
                            //It is the value in the database, not the current value, that is of importance
                            //for avoiding violations of the foreign key constraint
                            //IList list = (IList) om.GetPropertyValue(delObj, propertyMap.Name);
                            IList list = (IList)om.GetOriginalPropertyValue(delObj, propertyMap.Name);
                            if (list != null)
                            {
                                foreach (object itemRefObj in list)
                                {
                                    object isDeleted = hashDeleted[itemRefObj];
                                    if (isDeleted != null)
                                    {
                                        m_topologicalDelete.AddNode(itemRefObj, delObj);
                                    }
                                }
                            }
                        }
                        else
                        {
                            //It is the value in the database, not the current value, that is of importance
                            //for avoiding violations of the foreign key constraint
                            //object refObj = om.GetPropertyValue(delObj, propertyMap.Name);
                            object refObj = om.GetOriginalPropertyValue(delObj, propertyMap.Name);
                            if (refObj != null)
                            {
                                object isDeleted = hashDeleted[refObj];
                                if (isDeleted != null)
                                {
                                    m_topologicalDelete.AddNode(refObj, delObj);
                                }
                            }
                        }
                    }
                }
            }
        }
        public virtual bool IsDirtyProperty(object obj, string propertyName)
        {
            if (!(m_ObjectManager.HasOriginalValues(obj, propertyName)))
            {
                return(false);
            }
            object orgValue = m_ObjectManager.GetOriginalPropertyValue(obj, propertyName);

            if (Convert.IsDBNull(orgValue))
            {
                if (!(m_ObjectManager.GetNullValueStatus(obj, propertyName)))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (m_ObjectManager.GetNullValueStatus(obj, propertyName))
                {
                    return(true);
                }
            }
            //			if (obj is IProxy)
            //			{
            if (this.ObjectManager.GetUpdatedStatus(obj, propertyName))
            {
                object value = m_ObjectManager.GetPropertyValue(obj, propertyName);
                if (!(ComparePropertyValues(obj, propertyName, value, orgValue)))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
            //			}
            //			else
            //			{
            //				object value = m_ObjectManager.GetPropertyValue(obj, propertyName);
            //				if (!(ComparePropertyValues(obj, propertyName, value, orgValue)))
            //				{
            //					return true;
            //				}
            //				else
            //				{
            //					return false;
            //				}
            //			}
        }
Ejemplo n.º 4
0
        public IObjectClone CloneObject(object obj)
        {
            IObjectManager om    = this.Context.ObjectManager;
            IObjectClone   clone = new ObjectClone();

            IClassMap classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType());

            foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps())
            {
                if (propertyMap.IsCollection)
                {
                    //TODO: Implement this
                }
                else
                {
                    clone.SetPropertyValue(propertyMap.Name, om.GetPropertyValue(obj, propertyMap.Name));
                    clone.SetNullValueStatus(propertyMap.Name, om.GetNullValueStatus(obj, propertyMap.Name));
                    clone.SetUpdatedStatus(propertyMap.Name, om.GetUpdatedStatus(obj, propertyMap.Name));

                    if (om.HasOriginalValues(obj, propertyMap.Name))
                    {
                        clone.SetOriginalPropertyValue(propertyMap.Name, om.GetOriginalPropertyValue(obj, propertyMap.Name));
                    }
                }
            }

            clone.SetObjectStatus(om.GetObjectStatus(obj));

            IIdentityHelper identityHelper = obj as IIdentityHelper;

            if (identityHelper != null)
            {
                clone.SetIdentity(identityHelper.GetIdentity());

                if (identityHelper.HasIdentityKeyParts())
                {
                    foreach (object keyPart in identityHelper.GetIdentityKeyParts())
                    {
                        clone.GetIdentityKeyParts().Add(keyPart);
                    }
                }
                if (identityHelper.HasKeyStruct())
                {
                    clone.SetKeyStruct(identityHelper.GetKeyStruct());
                }
            }

            this.clonedObjects.Add(obj);

            return(clone);
        }
Ejemplo n.º 5
0
        protected void AddSpeciallyUpdated(object obj)
        {
            Hashtable cachedOriginals = (Hashtable)m_hashSpeciallyUpdated[obj];

            if (cachedOriginals != null)
            {
                return;
            }

            cachedOriginals             = new Hashtable();
            m_hashSpeciallyUpdated[obj] = cachedOriginals;

            IObjectManager om       = this.Context.ObjectManager;
            IListManager   lm       = this.Context.ListManager;
            IClassMap      classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType());

            foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps())
            {
                cachedOriginals[propertyMap.Name] = om.GetOriginalPropertyValue(obj, propertyMap.Name);
                CopyValuesToOriginals(propertyMap, lm, obj, om);
            }
        }
Ejemplo n.º 6
0
		private void MergePrimitiveProperty(IObjectManager om, object obj, IClassMap classMap, IPropertyMap propertyMap, object existing, bool forOrgValue, PropertyStatus propStatus, PropertyStatus extPropStatus, MergeBehaviorType mergeBehavior)
		{
			if (forOrgValue)
			{
				object value = om.GetPropertyValue(obj, propertyMap.Name);
				object extValue = om.GetPropertyValue(existing, propertyMap.Name);
				MergePrimitivePropertyValues(value, extValue, propStatus, extPropStatus, om, existing, classMap, propertyMap, obj, forOrgValue, mergeBehavior);
			}
			else
			{
				object orgValue = om.GetOriginalPropertyValue(obj, propertyMap.Name);
				object extOrgValue = om.GetOriginalPropertyValue(existing, propertyMap.Name);
				MergePrimitivePropertyValues(orgValue, extOrgValue, propStatus, extPropStatus, om, existing, classMap, propertyMap, obj, forOrgValue, mergeBehavior);
			}
		}
Ejemplo n.º 7
0
		private void MergeSingleRefProperty(IObjectManager om, object obj, IClassMap classMap, IPropertyMap propertyMap, object existing, bool forOrgValue, PropertyStatus propStatus, PropertyStatus extPropStatus, MergeBehaviorType mergeBehavior)
		{
			string extOrgObjId;
			string refObjId;
			object extRefObj;
			object refObj;
			object extOrgObj;
			if (forOrgValue)
			{
				refObj = om.GetOriginalPropertyValue(obj, propertyMap.Name);
				extOrgObj = om.GetOriginalPropertyValue(existing, propertyMap.Name);				
			}
			else
			{
				refObj = om.GetPropertyValue(obj, propertyMap.Name);
				extOrgObj = om.GetPropertyValue(existing, propertyMap.Name);			
			}	
			if (refObj != null && DBNull.Value.Equals(refObj) != true)
			{
				refObjId = om.GetObjectIdentity(refObj);
				extOrgObjId = "";
				if (extOrgObj != null)
					extOrgObjId = om.GetObjectIdentity(extOrgObj);

				if (!refObjId.Equals(extOrgObjId))
				{
					bool keepExisting = KeepExistingValue(refObj, extOrgObj, mergeBehavior, classMap, propertyMap, existing, obj, propStatus, extPropStatus, forOrgValue);
					if (keepExisting != true)
					{
						extRefObj = this.Context.GetObjectById(refObjId, refObj.GetType());

						SetSingleRefPropetyValue(forOrgValue, om, existing, propertyMap, extRefObj, propStatus);
					}
				}
			}
			else
			{
				if (extOrgObj != null)
				{
					bool keepExisting = KeepExistingValue(refObj, extOrgObj, mergeBehavior, classMap, propertyMap, existing, obj, propStatus, extPropStatus, forOrgValue);
					if (keepExisting)
					{
						SetSingleRefPropetyValue(forOrgValue, om, existing, propertyMap, null, propStatus);
					}
				}
			}
		}
        private void RefreshProperty(IObjectManager om, object targetObject, IPropertyMap propertyMap, IPersistenceManager pm, RefreshBehaviorType refreshBehavior, object value, out bool doWrite, out bool doWriteOrg)
        {
            doWrite = false;
            doWriteOrg = false;
            PropertyStatus propStatus = om.GetPropertyStatus(targetObject, propertyMap.Name);
            IClassMap classMap = this.Context.DomainMap.MustGetClassMap(targetObject.GetType());

            RefreshBehaviorType useRefreshBehavior = pm.GetRefreshBehavior(refreshBehavior, classMap, propertyMap);

            if (useRefreshBehavior == RefreshBehaviorType.OverwriteNotLoaded || useRefreshBehavior == RefreshBehaviorType.DefaultBehavior)
            {
                //Overwrite both value and original far all unloaded properties
                if (propStatus == PropertyStatus.NotLoaded)
                {
                    doWrite = true;
                    doWriteOrg = true;
                }
            }
            else if (useRefreshBehavior == RefreshBehaviorType.OverwriteLoaded)
            {
                //Overwrite original for all properties
                //Overwrite value for all clean or unloaded properties (but not for dirty or deleted properties)
                doWriteOrg = true;
                if (propStatus == PropertyStatus.Clean || propStatus == PropertyStatus.NotLoaded)
                    doWrite = true;
            }
            else if (useRefreshBehavior == RefreshBehaviorType.ThrowConcurrencyException)
            {
                //Overwrite original for all properties unless the old originial value and the fresh value from the
                //database mismatch, in that case raise an exception
                //Overwrite value for all clean or unloaded properties (but not for dirty or deleted properties)
                if (propStatus == PropertyStatus.Clean || propStatus == PropertyStatus.NotLoaded || propStatus == PropertyStatus.Dirty)
                {
                    if (!(propStatus == PropertyStatus.NotLoaded))
                    {
                        object testValue = om.GetOriginalPropertyValue(targetObject,propertyMap.Name);
                        object testValue2 = value;
                        if (DBNull.Value.Equals(testValue)) { testValue = null; }
                        if (DBNull.Value.Equals(testValue2)) { testValue2 = null; }
                        if (testValue2 != testValue)
                        {
                            string cachedValue = "null";
                            string freshValue = "null";
                            try
                            {
                                if (testValue != null)
                                    cachedValue = testValue.ToString() ;
                            }
                            catch { ; }
                            try
                            {
                                if (value != null)
                                    freshValue = value.ToString() ;
                            }
                            catch { ; }
                            throw new RefreshException("A refresh concurrency exception occurred when refreshing a cached object of type " + targetObject.GetType().ToString() + " with fresh data from the data source. The data source row has been modified since the last time this version of the object was loaded, specifically the value for property " + propertyMap.Name + ". (this exception occurs because ThrowConcurrencyExceptions refresh behavior was selected). Cashed value: " + cachedValue + ", Fresh value: " + freshValue, cachedValue, freshValue, targetObject, propertyMap.Name); // do not localize
                        }
                    }
                    if (!(propStatus == PropertyStatus.Dirty))
                        doWrite = true;
                }
            }
            else if (useRefreshBehavior == RefreshBehaviorType.OverwriteDirty)
            {
                //Overwrite original for all properties
                //Overwrite value for all clean, unloaded or dirty properties (but not for deleted properties)
                doWriteOrg = true;
                if (!(propStatus == PropertyStatus.Deleted))
                    doWrite = true;
            }
            else
            {
                throw new NPersistException("Unknown object refresh behavior specified!"); // do not localize
            }
        }
        private void RefreshProperty(IObjectManager om, object targetObject, IPropertyMap propertyMap, IPersistenceManager pm, RefreshBehaviorType refreshBehavior, object value, out bool doWrite, out bool doWriteOrg)
        {
            doWrite    = false;
            doWriteOrg = false;
            PropertyStatus propStatus = om.GetPropertyStatus(targetObject, propertyMap.Name);
            IClassMap      classMap   = this.Context.DomainMap.MustGetClassMap(targetObject.GetType());

            RefreshBehaviorType useRefreshBehavior = pm.GetRefreshBehavior(refreshBehavior, classMap, propertyMap);

            if (useRefreshBehavior == RefreshBehaviorType.OverwriteNotLoaded || useRefreshBehavior == RefreshBehaviorType.DefaultBehavior)
            {
                //Overwrite both value and original far all unloaded properties
                if (propStatus == PropertyStatus.NotLoaded)
                {
                    doWrite    = true;
                    doWriteOrg = true;
                }
            }
            else if (useRefreshBehavior == RefreshBehaviorType.OverwriteLoaded)
            {
                //Overwrite original for all properties
                //Overwrite value for all clean or unloaded properties (but not for dirty or deleted properties)
                doWriteOrg = true;
                if (propStatus == PropertyStatus.Clean || propStatus == PropertyStatus.NotLoaded)
                {
                    doWrite = true;
                }
            }
            else if (useRefreshBehavior == RefreshBehaviorType.ThrowConcurrencyException)
            {
                //Overwrite original for all properties unless the old originial value and the fresh value from the
                //database mismatch, in that case raise an exception
                //Overwrite value for all clean or unloaded properties (but not for dirty or deleted properties)
                if (propStatus == PropertyStatus.Clean || propStatus == PropertyStatus.NotLoaded || propStatus == PropertyStatus.Dirty)
                {
                    if (!(propStatus == PropertyStatus.NotLoaded))
                    {
                        object testValue  = om.GetOriginalPropertyValue(targetObject, propertyMap.Name);
                        object testValue2 = value;
                        if (DBNull.Value.Equals(testValue))
                        {
                            testValue = null;
                        }
                        if (DBNull.Value.Equals(testValue2))
                        {
                            testValue2 = null;
                        }
                        if (testValue2 != testValue)
                        {
                            string cachedValue = "null";
                            string freshValue  = "null";
                            try
                            {
                                if (testValue != null)
                                {
                                    cachedValue = testValue.ToString();
                                }
                            }
                            catch {; }
                            try
                            {
                                if (value != null)
                                {
                                    freshValue = value.ToString();
                                }
                            }
                            catch {; }
                            throw new RefreshException("A refresh concurrency exception occurred when refreshing a cached object of type " + targetObject.GetType().ToString() + " with fresh data from the data source. The data source row has been modified since the last time this version of the object was loaded, specifically the value for property " + propertyMap.Name + ". (this exception occurs because ThrowConcurrencyExceptions refresh behavior was selected). Cashed value: " + cachedValue + ", Fresh value: " + freshValue, cachedValue, freshValue, targetObject, propertyMap.Name);                             // do not localize
                        }
                    }
                    if (!(propStatus == PropertyStatus.Dirty))
                    {
                        doWrite = true;
                    }
                }
            }
            else if (useRefreshBehavior == RefreshBehaviorType.OverwriteDirty)
            {
                //Overwrite original for all properties
                //Overwrite value for all clean, unloaded or dirty properties (but not for deleted properties)
                doWriteOrg = true;
                if (!(propStatus == PropertyStatus.Deleted))
                {
                    doWrite = true;
                }
            }
            else
            {
                throw new NPersistException("Unknown object refresh behavior specified!");                 // do not localize
            }
        }
        private void MergeSingleRefProperty(IObjectManager om, object obj, IClassMap classMap, IPropertyMap propertyMap, object existing, bool forOrgValue, PropertyStatus propStatus, PropertyStatus extPropStatus, MergeBehaviorType mergeBehavior)
        {
            string extOrgObjId;
            string refObjId;
            object extRefObj;
            object refObj;
            object extOrgObj;
            if (forOrgValue)
            {
                refObj = om.GetOriginalPropertyValue(obj, propertyMap.Name);
                extOrgObj = om.GetOriginalPropertyValue(existing, propertyMap.Name);
            }
            else
            {
                refObj = om.GetPropertyValue(obj, propertyMap.Name);
                extOrgObj = om.GetPropertyValue(existing, propertyMap.Name);
            }
            if (refObj != null && DBNull.Value.Equals(refObj) != true)
            {
                //hmmmm won't this fail if we have two objects of different classes but with the same id?
                //probably the type should be included (and preferably change to KeyStruct comparisons...)
                refObjId = om.GetObjectIdentity(refObj);
                extOrgObjId = "";
                if (extOrgObj != null)
                    extOrgObjId = om.GetObjectIdentity(extOrgObj);

                if (!refObjId.Equals(extOrgObjId))
                {
                    bool keepExisting = KeepExistingValue(refObj, extOrgObj, mergeBehavior, classMap, propertyMap, existing, obj, propStatus, extPropStatus, forOrgValue);
                    if (keepExisting != true)
                    {
                        extRefObj = this.Context.GetObjectById(refObjId, refObj.GetType());

                        SetSingleRefPropetyValue(forOrgValue, om, existing, propertyMap, extRefObj, propStatus);
                    }
                }
            }
            else
            {
                if (extOrgObj != null)
                {
                    bool keepExisting = KeepExistingValue(refObj, extOrgObj, mergeBehavior, classMap, propertyMap, existing, obj, propStatus, extPropStatus, forOrgValue);
                    if (keepExisting)
                    {
                        SetSingleRefPropetyValue(forOrgValue, om, existing, propertyMap, null, propStatus);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        private void ExamineDeletedObject(Hashtable hashDeleted, IObjectManager om, object delObj)
        {
			IClassMap delObjClassMap = this.Context.DomainMap.MustGetClassMap(delObj.GetType());
			foreach (IPropertyMap propertyMap in delObjClassMap.GetAllPropertyMaps())
			{
				if (!propertyMap.IsReadOnly && !propertyMap.IsSlave)
				{
					if (propertyMap.ReferenceType != ReferenceType.None)
					{
						if (propertyMap.IsCollection)
						{
                            //It is the value in the database, not the current value, that is of importance
                            //for avoiding violations of the foreign key constraint 
							//IList list = (IList) om.GetPropertyValue(delObj, propertyMap.Name);
							IList list = (IList) om.GetOriginalPropertyValue(delObj, propertyMap.Name);
							if (list != null)
							{
								foreach (object itemRefObj in list)
								{
                                    object isDeleted = hashDeleted[itemRefObj];
									if (isDeleted != null)
									{
										m_topologicalDelete.AddNode(itemRefObj, delObj);
									}
								}
							}
						}
						else
						{
                            //It is the value in the database, not the current value, that is of importance
                            //for avoiding violations of the foreign key constraint 
							//object refObj = om.GetPropertyValue(delObj, propertyMap.Name);
							object refObj = om.GetOriginalPropertyValue(delObj, propertyMap.Name);
							if (refObj != null)
							{
                                object isDeleted = hashDeleted[refObj];
								if (isDeleted != null)
								{
									m_topologicalDelete.AddNode(refObj, delObj);
								}
							}
						}
					}
				}
			}
        }