Ejemplo n.º 1
0
        public virtual object GetObject(object identity, Type type, bool lazy, bool ignoreObjectNotFound)
        {
            type = AssemblyManager.GetBaseType(type);
            KeyStruct key = GetKey(type, identity);
            object obj;
            ObjectCancelEventArgs e;

            IObjectCache cache = GetObjectCache();

            obj = cache.LoadedObjects[key];
            if (obj != null)
            {
                e = new ObjectCancelEventArgs(obj);
                this.Context.EventManager.OnGettingObject(this, e);
                if (e.Cancel)
                {
                    return null;
                }
            }
            else
            {
                obj = cache.UnloadedObjects[key];
                if (obj != null)
                {
                    e = new ObjectCancelEventArgs(obj);
                    this.Context.EventManager.OnGettingObject(this, e);
                    if (e.Cancel)
                    {
                        return null;
                    }
                }
                else
                {
                    obj = this.Context.AssemblyManager.CreateInstance(type);
                    this.Context.ObjectManager.SetObjectIdentity(obj, key);
                    e = new ObjectCancelEventArgs(obj);
                    this.Context.EventManager.OnGettingObject(this, e);
                    if (e.Cancel)
                    {
                        return null;
                    }
                    if (lazy)
                    {
                        RegisterLazyLoadedObject(obj);
                        cache.UnloadedObjects[key] = obj;
                    }
                    else
                    {
                        string strIdentity = ToStringIdentity(identity);
                        LoadObject(strIdentity, ref obj, ignoreObjectNotFound, type, key);
                    }
                }
            }
            ObjectEventArgs e2 = new ObjectEventArgs(obj);
            this.Context.EventManager.OnGotObject(this, e2);
            return obj;
        }
Ejemplo n.º 2
0
		public void NotifyInstantiatingObject(object obj, ref bool cancel)
		{
			if (this.isDisposed) { return; }
			//this.Context.PersistenceManager.SetupObject(obj);
			this.Context.PersistenceManager.InitializeObject(obj);

			if (notification == Notification.Disabled) { return; }
			ObjectCancelEventArgs e = new ObjectCancelEventArgs(obj);
			this.Context.EventManager.OnInstantiatingObject(this, e);
			if (e.Cancel)
			{
				cancel = true;
				return;
			}
		}
Ejemplo n.º 3
0
 public virtual void OnGettingObject(object sender, ObjectCancelEventArgs e)
 {
 }
Ejemplo n.º 4
0
 public virtual object GetObjectByKey(string keyPropertyName, object keyValue, Type type, bool ignoreObjectNotFound)
 {
     type = AssemblyManager.GetBaseType(type);
     object obj;
     obj = this.Context.AssemblyManager.CreateInstance(type);
     ObjectCancelEventArgs e = new ObjectCancelEventArgs(obj);
     this.Context.EventManager.OnGettingObject(this, e);
     if (e.Cancel)
     {
         return null;
     }
     this.Context.ObjectManager.SetPropertyValue(obj, keyPropertyName, keyValue);
     this.Context.PersistenceEngine.LoadObjectByKey(ref obj, keyPropertyName, keyValue);
     if (obj == null)
     {
         if (ignoreObjectNotFound == false)
         {
             throw new ObjectNotFoundException("Object not found!"); // do not localize
         }
     }
     else
     {
         IList idKeyParts = this.Context.ObjectManager.GetObjectIdentityKeyParts(obj);
         KeyStruct key = GetKey(type, idKeyParts);
         IObjectCache cache = GetObjectCache();
         obj = cache.LoadedObjects[key];
         ObjectEventArgs e2 = new ObjectEventArgs(obj);
         this.Context.EventManager.OnGotObject(this, e2);
     }
     return obj;
 }
Ejemplo n.º 5
0
		public virtual object GetObjectByKey(string keyPropertyName, object keyValue, Type type, bool ignoreObjectNotFound)
		{
			type = this.Context.AssemblyManager.GetType(type);
			object obj;
			string key;
			string identity;
			obj = this.Context.AssemblyManager.CreateInstance(type);
			ObjectCancelEventArgs e = new ObjectCancelEventArgs(obj);
			this.Context.EventManager.OnGettingObject(this, e);
			if (e.Cancel)
			{
				return null;
			}
			this.Context.ObjectManager.SetPropertyValue(obj, keyPropertyName, keyValue);
			//this.Context.SqlEngineManager.LoadObjectByKey(obj, keyPropertyName, keyValue);
			this.Context.PersistenceEngine.LoadObjectByKey(ref obj, keyPropertyName, keyValue);
			if (obj == null)
			{
				if (ignoreObjectNotFound == false)
				{
					throw new ObjectNotFoundException("Object not found!"); // do not localize					
				}
			}
			else
			{
				identity = this.Context.ObjectManager.GetObjectIdentity(obj);
//				key = type.ToString() + "." + identity;
				key = GetKey(type, identity);
				IObjectCache cache = GetObjectCache();
				obj = cache.LoadedObjects[key];
//				if (m_hashLoadedObjects.ContainsKey(key))
//				{
//					obj = m_hashLoadedObjects[key];
//				}
				ObjectEventArgs e2 = new ObjectEventArgs(obj);
				this.Context.EventManager.OnGotObject(this, e2);				
			}
			return obj;
		}
Ejemplo n.º 6
0
 public virtual void OnInstantiatingObject(object sender, ObjectCancelEventArgs e)
 {
 }
Ejemplo n.º 7
0
		protected virtual void LoadObjectByIdOrKey(ref object obj, string keyPropertyName, object keyValue)
		{
			IList parameters = new ArrayList() ;
			string propName;
			object orgValue;
			object value;
			ArrayList propertyNames = new ArrayList();
			IContext ctx = m_SqlEngineManager.Context;
			ObjectCancelEventArgs e = new ObjectCancelEventArgs(obj);
			ctx.EventManager.OnLoadingObject(this, e);
			if (e.Cancel)
			{
				return;
			}
			IObjectManager om = ctx.ObjectManager;
			IPersistenceManager pm = ctx.PersistenceManager;
			IClassMap classMap = ctx.DomainMap.MustGetClassMap(obj.GetType());
			IPropertyMap propertyMap;
			string sql = GetSelectStatement(obj, propertyNames, keyPropertyName, keyValue, parameters);
			IDataSource ds = ctx.DataSourceManager.GetDataSource(obj);
			object[,] result = (object[,]) ctx.SqlExecutor.ExecuteArray(sql, ds, parameters);
			parameters.Clear();
			if (Util.IsArray(result))
			{
				
				for (int row = 0; row <= result.GetUpperBound(1); row++)
				{
					for (int col = 0; col <= result.GetUpperBound(0); col++)
					{
						propName = (string) propertyNames[col];
						propertyMap = classMap.MustGetPropertyMap(propName);
						if (propertyMap.GetAllColumnMaps().Count < 2)
						{
							orgValue = result[col, row];
							value = pm.ManageLoadedValue(obj, propertyMap, orgValue);
							om.SetPropertyValue(obj, propName, value);
							if (propertyMap.ReferenceType == ReferenceType.None)
								om.SetOriginalPropertyValue(obj, propName, orgValue);
							else
								om.SetOriginalPropertyValue(obj, propName, value);
							om.SetNullValueStatus(obj, propName, DBNull.Value.Equals(orgValue));
						}
						else
						{
//							orgValue = result[col, row];
//							value = pm.ManageLoadedValue(obj, propertyMap, orgValue);
//							om.SetPropertyValue(obj, propName, value);
//							om.SetOriginalPropertyValue(obj, propName, orgValue);							
						}
					}
				}
                ctx.IdentityMap.RegisterLoadedObject(obj);
			}
			else
			{
				//throw new ObjectNotFoundException("Object not found!"); // do not localize
				obj = null;
			}
			ObjectEventArgs e2 = new ObjectEventArgs(obj);
			ctx.EventManager.OnLoadedObject(this, e2);
		}
        public override void InsertObject(object obj, IList stillDirty)
        {
            IList parameters = new ArrayList() ;
            ArrayList propertyNames = new ArrayList();
            IPropertyMap propertyMap;

            ArrayList nonPrimaryPropertyMaps = new ArrayList();
            ArrayList collectionPropertyMaps = new ArrayList();
            ArrayList sqlStatements = new ArrayList();
            int rowsAffected;
            object autoID;
            IPropertyMap autoProp;
            IColumnMap autoPropCol;
            string autoPropName;
            string prevId;
            bool originalKeepOpen;
            IContext ctx = SqlEngineManager.Context;
            ObjectCancelEventArgs e = new ObjectCancelEventArgs(obj);
            ctx.EventManager.OnInsertingObject(this, e);
            if (e.Cancel)
            {
                return;
            }
            IObjectManager om = ctx.ObjectManager;
            IListManager lm = ctx.ListManager;
            IClassMap classMap = ctx.DomainMap.MustGetClassMap(obj.GetType());
            string sqlSelect = "";
            string sql;
            if (classMap.HasSingleIdAutoIncreaser())
            {
                sql = GetInsertStatement(obj, propertyNames, stillDirty, nonPrimaryPropertyMaps, collectionPropertyMaps, ref sqlSelect, parameters);
            }
            else
            {
                sql = GetInsertStatement(obj, propertyNames, stillDirty, nonPrimaryPropertyMaps, collectionPropertyMaps, parameters);
            }
            IDataSource ds = ctx.DataSourceManager.GetDataSource(obj);
            if (classMap.HasSingleIdAutoIncreaser())
            {
                originalKeepOpen = ds.KeepConnectionOpen;
                ds.KeepConnectionOpen = true;
                rowsAffected = ctx.SqlExecutor.ExecuteNonQuery(sql, ds, parameters);
                if (!(rowsAffected == 1))
                {
                    ds.KeepConnectionOpen = originalKeepOpen;
                    throw new NPersistException("An exception occurred when inserting the row for a new object into the data source. Exactly one row should have been affected by the insert operation. Instead " + rowsAffected + " rows were affected!"); // do not localize
                }
                object[,] result = (object[,]) ctx.SqlExecutor.ExecuteArray(sqlSelect, ds, parameters);
                if (Util.IsArray(result))
                {
                    prevId = om.GetObjectIdentity(obj);
                    autoProp = classMap.GetAutoIncreasingIdentityPropertyMap();
                    autoPropName = autoProp.Name;
                    autoPropCol = autoProp.GetColumnMap();
                    if (autoPropCol.DataType == DbType.Int64)
                    {
                        autoID = Convert.ToInt64(result[0, 0]);
                    }
                    else if (autoPropCol.DataType == DbType.Int16)
                    {
                        autoID = Convert.ToInt16(result[0, 0]);
                    }
                    else
                    {
                        autoID = Convert.ToInt32(result[0, 0]);
                    }
                    om.SetPropertyValue(obj, autoPropName, autoID);
                    //om.SetOriginalPropertyValue(obj, autoPropName, autoID);
                    om.SetNullValueStatus(obj, autoPropName, false);
                    ctx.IdentityMap.UpdateIdentity(obj, prevId);
                }
                else
                {
                    ds.KeepConnectionOpen = originalKeepOpen;
                    throw new FailedFetchingDbGeneratedValueException("Could not find auto-increasing ID for new object!"); // do not localize
                }
                ds.KeepConnectionOpen = originalKeepOpen;
            }
            else
            {
                rowsAffected = ctx.SqlExecutor.ExecuteNonQuery(sql, ds, parameters);
                if (!(rowsAffected == 1))
                {
                    throw new RowNotInsertedException("A new row was not inserted in the data source for a new object."); // do not localize
                }
            }
            //			foreach (string propName in propertyNames)
            //			{
            //				om.SetOriginalPropertyValue(obj, propName, om.GetPropertyValue(obj, propName));
            //			}
            InsertNonPrimaryProperties(obj, nonPrimaryPropertyMaps, stillDirty);
            foreach (IPropertyMap iPpropertyMap in collectionPropertyMaps)
            {
                propertyMap = iPpropertyMap;
                sqlStatements.Clear();
                GetInsertCollectionPropertyStatements(obj, propertyMap, sqlStatements, stillDirty);
                ds = ctx.DataSourceManager.GetDataSource(obj, propertyMap.Name);
                foreach (SqlStatementAndDbParameters sqlStatementAndDbParameters in sqlStatements)
                {
                    sql = sqlStatementAndDbParameters.SqlStatement;
                    rowsAffected = ctx.SqlExecutor.ExecuteNonQuery(sql, ds, sqlStatementAndDbParameters.DbParameters);
                    if (!(rowsAffected == 1))
                    {
                        throw new RowNotInsertedException("A new row was not inserted in the data source for a collection property of a new object."); // do not localize
                    }
                }
            }
            ctx.InverseManager.NotifyCreate(obj);
            ObjectEventArgs e2 = new ObjectEventArgs(obj);
            ctx.EventManager.OnInsertedObject(this, e2);
        }
Ejemplo n.º 9
0
		public virtual void UpdateObject(object obj, IList stillDirty)
		{
			this.SqlEngineManager.Context.LogManager.Info(this, "Updating object", "Type: " + obj.GetType().ToString()); // do not localize
			IList parameters = new ArrayList() ;
			IContext ctx = m_SqlEngineManager.Context;
			IObjectManager om = ctx.ObjectManager;
			IListManager lm = ctx.ListManager;
			ArrayList propertyMaps = new ArrayList();
			ArrayList nonPrimaryPropertyMaps = new ArrayList();
			ArrayList collectionPropertyMaps = new ArrayList();
			ArrayList sqlAndParamsList = new ArrayList();
			IDataSource ds;
			int rowsAffected;
			ObjectCancelEventArgs e = new ObjectCancelEventArgs(obj);
			ctx.EventManager.OnUpdatingObject(this, e);
			if (e.Cancel)
			{
				return;
			}
			IClassMap classMap = ctx.DomainMap.MustGetClassMap(obj.GetType());
			string sql = GetUpdateStatement(obj, propertyMaps, stillDirty, nonPrimaryPropertyMaps, collectionPropertyMaps, parameters);
			if (sql != "")
			{
				ds = ctx.DataSourceManager.GetDataSource(obj);
				rowsAffected = ctx.SqlExecutor.ExecuteNonQuery(sql, ds, parameters);
				if (rowsAffected < 1)
				{
					if (!(SqlEngineManager.Context.PersistenceManager.GetUpdateOptimisticConcurrencyBehavior(OptimisticConcurrencyBehaviorType.DefaultBehavior, classMap) == OptimisticConcurrencyBehaviorType.Disabled))
					{
						throw new OptimisticConcurrencyException("An optimistic concurrency exception occurred when updating the row for object " + obj.GetType().ToString() + om.GetObjectKeyOrIdentity(obj) + ". The row may have been modified or deleted by another thread or user.\r\n", obj); // do not localize
					}
				}
//				foreach (IPropertyMap propertyMap in propertyMaps)
//				{
//					if (om.GetNullValueStatus(obj, propertyMap.Name))
//					{
//						om.SetOriginalPropertyValue(obj, propertyMap.Name, System.DBNull.Value);						
//					}
//					else
//					{						
//						om.SetOriginalPropertyValue(obj, propertyMap.Name, om.GetPropertyValue(obj, propertyMap.Name));						
//					}
//				}
			}
			parameters.Clear();
			UpdateNonPrimaryProperties(obj, nonPrimaryPropertyMaps, stillDirty);
			foreach (IPropertyMap propertyMap in collectionPropertyMaps)
			{
				sqlAndParamsList.Clear();
				GetUpdateCollectionPropertyStatements(obj, propertyMap, sqlAndParamsList, stillDirty);
				ds = ctx.DataSourceManager.GetDataSource(obj, propertyMap.Name);
				foreach (SqlStatementAndDbParameters sqlAndParams in sqlAndParamsList)
				{
					sql = sqlAndParams.SqlStatement;
					rowsAffected = ctx.SqlExecutor.ExecuteNonQuery(sql, ds, sqlAndParams.DbParameters );
					if (rowsAffected < 1)
					{
						if (!(SqlEngineManager.Context.PersistenceManager.GetUpdateOptimisticConcurrencyBehavior(OptimisticConcurrencyBehaviorType.DefaultBehavior, classMap) == OptimisticConcurrencyBehaviorType.Disabled))
						{
							throw new OptimisticConcurrencyException("An optimistic concurrency exception occurred when updating a collection property for object " + obj.GetType().ToString() + om.GetObjectKeyOrIdentity(obj) + ". The property may have been modified by another thread or user.", obj); // do not localize
						}
					}
				}
			}
			ctx.InverseManager.NotifyPersist(obj);
			ObjectEventArgs e2 = new ObjectEventArgs(obj);
			ctx.EventManager.OnUpdatedObject(this, e2);
		}
Ejemplo n.º 10
0
		public virtual void RemoveObject(object obj)
		{
			this.SqlEngineManager.Context.LogManager.Info(this, "Removing object", "Type: " + obj.GetType().ToString()); // do not localize
			IList parameters = new ArrayList() ;
			IContext ctx = m_SqlEngineManager.Context;
			ObjectCancelEventArgs e = new ObjectCancelEventArgs(obj);
			ctx.EventManager.OnRemovingObject(this, e);
			if (e.Cancel)
			{
				return;
			}
			//RemoveAllReferencesToObject(obj);
			RemoveNonPrimaryProperties(obj);
			RemoveCollectionProperties(obj);
			string sql = GetDeleteStatement(obj, parameters);
			IDataSource ds = ctx.DataSourceManager.GetDataSource(obj);
			int rowsAffected = ctx.SqlExecutor.ExecuteNonQuery(sql, ds, parameters);
			parameters.Clear();
			IClassMap classMap = ctx.DomainMap.MustGetClassMap(obj.GetType());
			if (rowsAffected < 1)
			{
				if (!(SqlEngineManager.Context.PersistenceManager.GetDeleteOptimisticConcurrencyBehavior(OptimisticConcurrencyBehaviorType.DefaultBehavior, classMap) == OptimisticConcurrencyBehaviorType.Disabled))
				{
					throw new OptimisticConcurrencyException("An optimistic concurrency exception occurred when deleting the row for object " + obj.GetType().ToString() + this.Context.ObjectManager.GetObjectKeyOrIdentity(obj) + " in the data source. The row may have been modified by another thread or user or is already deleted.", obj); // do not localize
				}
			}
			ctx.InverseManager.NotifyDelete(obj);
			ObjectEventArgs e2 = new ObjectEventArgs(obj);
			ctx.EventManager.OnRemovedObject(this, e2);
		}
Ejemplo n.º 11
0
		public virtual void InsertObject(object obj, IList stillDirty)
		{
			this.SqlEngineManager.Context.LogManager.Info(this, "Inserting object", "Type: " + obj.GetType().ToString()); // do not localize

			ArrayList propertyNames = new ArrayList();
			IList parameters = new ArrayList() ;
			ArrayList nonPrimaryPropertyMaps = new ArrayList();
			ArrayList collectionPropertyMaps = new ArrayList();
			ArrayList sqlAndParamsList = new ArrayList();
			int rowsAffected;
			IPropertyMap autoProp;
			IContext ctx = m_SqlEngineManager.Context;
			ObjectCancelEventArgs e = new ObjectCancelEventArgs(obj);
			ctx.EventManager.OnInsertingObject(this, e);
			if (e.Cancel)
			{
				return;
			}
			IObjectManager om = ctx.ObjectManager;
			IListManager lm = ctx.ListManager;
			IClassMap classMap = ctx.DomainMap.MustGetClassMap(obj.GetType());
			IDataSource ds = ctx.DataSourceManager.GetDataSource(obj);
			if (classMap.HasSingleIdAutoIncreaser() && this.AutoIncreaserStrategy == AutoIncreaserStrategy.SelectNextSequence)
			{
				autoProp = classMap.GetAutoIncreasingIdentityPropertyMap();
				IColumnMap seqColMap = autoProp.MustGetColumnMap();
				string seqName = seqColMap.Sequence ;
				if (seqName.Length < 1)
					throw new Exception("The column " + seqColMap.Name + " must have a sequence name associated with it (sequence=\"my_seq_name\" in the xml map file) since the column is marked as an autoincreaser and the SelectNextSequence AutoIncreasingStrategy is used!");

				string sqlSeq = GetSelectNextSequence(seqName);
				object newId = ctx.SqlExecutor.ExecuteScalar(sqlSeq, ds, new ArrayList() );					
				UpdateAutoIncIdProperty(om, obj, classMap, newId);
				
			}			
			string sql = GetInsertStatement(obj, propertyNames, stillDirty, nonPrimaryPropertyMaps, collectionPropertyMaps, parameters);
			if (classMap.HasSingleIdAutoIncreaser() && this.AutoIncreaserStrategy == AutoIncreaserStrategy.SelectNewIdentity)
			{
				sql += this.StatementDelimiter + this.SelectNewIdentity;

				object[,] result = (object[,]) ctx.SqlExecutor.ExecuteArray(sql, ds, parameters);					
				if (Util.IsArray(result))
				{
					object newId = result[0, 0];
					UpdateAutoIncIdProperty(om, obj, classMap, newId);
				}
				else
				{
					throw new FailedFetchingDbGeneratedValueException("Could not find auto-increasing ID for new object!"); // do not localize
				}
			}
			else
			{
				rowsAffected = ctx.SqlExecutor.ExecuteNonQuery(sql, ds, parameters);
				if (rowsAffected < 1)
				{
					throw new RowNotInsertedException("A new row was not inserted in the data source for a new object."); // do not localize
				}
			}
			parameters.Clear();
//			foreach (string propName in propertyNames)
//			{
//				if (om.GetNullValueStatus(obj, propName))
//				{
//					om.SetOriginalPropertyValue(obj, propName, System.DBNull.Value);						
//				}
//				else
//				{						
//					om.SetOriginalPropertyValue(obj, propName, om.GetPropertyValue(obj, propName));
//				}
//			}
			InsertNonPrimaryProperties(obj, nonPrimaryPropertyMaps, stillDirty);
			foreach (IPropertyMap propertyMap in collectionPropertyMaps)
			{
				sqlAndParamsList.Clear();
				GetInsertCollectionPropertyStatements(obj, propertyMap, sqlAndParamsList, stillDirty);
				ds = ctx.DataSourceManager.GetDataSource(obj, propertyMap.Name);
				foreach (SqlStatementAndDbParameters sqlAndParams in sqlAndParamsList)
				{
					sql = sqlAndParams.SqlStatement;
					rowsAffected = ctx.SqlExecutor.ExecuteNonQuery(sql, ds, sqlAndParams.DbParameters);
					if (rowsAffected < 1)
					{
						throw new RowNotInsertedException("A new row was not inserted in the data source for a collection property of a new object."); // do not localize
					}
				}
			}
			if (stillDirty.Count > 0)
			{
				ctx.UnitOfWork.RegisterDirty(obj);
			}
			ctx.InverseManager.NotifyCreate(obj);
			ObjectEventArgs e2 = new ObjectEventArgs(obj);
			ctx.EventManager.OnInsertedObject(this, e2);
		}
Ejemplo n.º 12
0
        protected virtual void LoadObjectByIdOrKey(ref object obj, string keyPropertyName, object keyValue)
        {
            try
            {
                IList parameters = new ArrayList();
                string propName;
                object orgValue;
                object value;
                ArrayList propertyNames = new ArrayList();
                IContext ctx = m_SqlEngineManager.Context;
                ObjectCancelEventArgs e = new ObjectCancelEventArgs(obj);
                ctx.EventManager.OnLoadingObject(this, e);
                if (e.Cancel)
                {
                    return;
                }
                IObjectManager om = ctx.ObjectManager;
                IPersistenceManager pm = ctx.PersistenceManager;
                IClassMap classMap = ctx.DomainMap.MustGetClassMap(obj.GetType());
                IPropertyMap propertyMap;
                string sql = GetSelectStatement(obj, propertyNames, keyPropertyName, keyValue, parameters);
                IDataSource ds = ctx.DataSourceManager.GetDataSource(obj);
                object[,] result = (object[,])ctx.SqlExecutor.ExecuteArray(sql, ds, parameters);
                parameters.Clear();
                if (Util.IsArray(result))
                {

                    for (int row = 0; row <= result.GetUpperBound(1); row++)
                    {
                        for (int col = 0; col <= result.GetUpperBound(0); col++)
                        {
                            propName = (string)propertyNames[col];
                            propertyMap = classMap.MustGetPropertyMap(propName);
                            if (propertyMap.IsCollection)
                            {
                                orgValue = result[col, row];
                                pm.ManageLoadedValue(obj, propertyMap, orgValue);
                            }
                            else
                            {
                                if (propertyMap.GetAllColumnMaps().Count < 2)
                                {
                                    orgValue = result[col, row];
                                    value = pm.ManageLoadedValue(obj, propertyMap, orgValue);
                                    om.SetPropertyValue(obj, propName, value);
                                    if (propertyMap.ReferenceType == ReferenceType.None)
                                        om.SetOriginalPropertyValue(obj, propName, orgValue);
                                    else
                                        om.SetOriginalPropertyValue(obj, propName, value);
                                    om.SetNullValueStatus(obj, propName, DBNull.Value.Equals(orgValue));

                                    if (propertyMap.ReferenceType != ReferenceType.None)
                                        this.Context.InverseManager.NotifyPropertyLoad(obj, propertyMap, value);
                                }
                                else
                                {
                                    //TODO: Add immediate ghost loading of refernced composite key objects.
                                    //							orgValue = result[col, row];
                                    //							value = pm.ManageLoadedValue(obj, propertyMap, orgValue);
                                    //							om.SetPropertyValue(obj, propName, value);
                                    //							om.SetOriginalPropertyValue(obj, propName, orgValue);
                                }
                            }
                        }
                    }
                    ctx.IdentityMap.RegisterLoadedObject(obj);
                }
                else
                {
                    //throw new ObjectNotFoundException("Object not found!"); // do not localize
                    obj = null;
                }
                ObjectEventArgs e2 = new ObjectEventArgs(obj);
                ctx.EventManager.OnLoadedObject(this, e2);
            }
            catch(Exception x)
            {
                string message = string.Format("Failed to load object {0}.{1}\r\nMake sure mappings and actual data are intact", AssemblyManager.GetBaseType(obj).Name, this.Context.ObjectManager.GetObjectKeyOrIdentity(obj));
                throw new LoadException (message,x,obj);
            }
        }
Ejemplo n.º 13
0
		public virtual void OnCommittingObject(object sender, ObjectCancelEventArgs e)
		{
			IClassMap classMap;
			IObjectManager om = this.Context.ObjectManager;
			classMap = this.Context.DomainMap.MustGetClassMap(e.EventObject.GetType());
			foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps())
			{
				EvaluatePropertySpecialBehavior(e.EventObject, propertyMap, propertyMap.OnPersistBehavior, om);
			}
			if (this.ValidationManager.ValidateOnBeforePersist)
			{
				if (e.EventObject is IValidatable)
				{
					((IValidatable) (e.EventObject)).Validate();
				}
			}
			if (!(m_RaiseEvents))
			{
				return;
			}
			if (!(m_RaiseBeforeEvents))
			{
				return;
			}
			if (!(m_RaiseObjectEvents))
			{
				return;
			}
			foreach (IObserver observer in m_Observers)
			{
				observer.OnCommittingObject(sender, e);
			}
			foreach (IObserver observer in m_AllTypeObservers)
			{
				observer.OnCommittingObject(sender, e);
			}
			foreach (IObserver observer in GetTypeObservers(e.EventObject))
			{
				observer.OnCommittingObject(sender, e);
			}
			foreach (IObserver observer in GetObjectObservers(e.EventObject))
			{
				observer.OnCommittingObject(sender, e);
			}
			if (e.EventObject is IObservable)
			{
				foreach (IEventListener eventListener in ((IObservable) (e.EventObject)).GetEventListeners())
				{
					eventListener.OnCommittingObject(sender, e);
				}
			}
			this.Observer.OnCommittingObject(sender, e);
			if (e.EventObject is IEventListener)
			{
				((IEventListener) (e.EventObject)).OnCommittingObject(sender, e);
			}
		}
Ejemplo n.º 14
0
		public virtual void OnRemovingObject(object sender, ObjectCancelEventArgs e)
		{
			if (this.ValidationManager.ValidateOnBeforeRemove)
			{
				if (e.EventObject is IValidatable)
				{
					((IValidatable) (e.EventObject)).Validate();
				}
			}
			if (!(m_RaiseEvents))
			{
				return;
			}
			if (!(m_RaiseBeforeEvents))
			{
				return;
			}
			if (!(m_RaiseObjectEvents))
			{
				return;
			}
			foreach (IObserver observer in m_Observers)
			{
				observer.OnRemovingObject(sender, e);
			}
			foreach (IObserver observer in m_AllTypeObservers)
			{
				observer.OnRemovingObject(sender, e);
			}
			foreach (IObserver observer in GetTypeObservers(e.EventObject))
			{
				observer.OnRemovingObject(sender, e);
			}
			foreach (IObserver observer in GetObjectObservers(e.EventObject))
			{
				observer.OnRemovingObject(sender, e);
			}
			if (e.EventObject is IObservable)
			{
				foreach (IEventListener eventListener in ((IObservable) (e.EventObject)).GetEventListeners())
				{
					eventListener.OnRemovingObject(sender, e);
				}
			}
			this.Observer.OnRemovingObject(sender, e);
			if (e.EventObject is IEventListener)
			{
				((IEventListener) (e.EventObject)).OnRemovingObject(sender, e);
			}
		}
Ejemplo n.º 15
0
		public void OnInstantiatingObject(object sender, ObjectCancelEventArgs e)
		{
			if (!(m_RaiseEvents))
			{
				return;
			}
			if (!(m_RaiseBeforeEvents))
			{
				return;
			}
			if (!(m_RaisePropertyEvents))
			{
				return;
			}
			foreach (IObserver observer in m_Observers)
			{
				observer.OnInstantiatingObject(sender, e);
			}
			foreach (IObserver observer in m_AllTypeObservers)
			{
				observer.OnInstantiatingObject(sender, e);
			}
			foreach (IObserver observer in GetTypeObservers(e.EventObject))
			{
				observer.OnInstantiatingObject(sender, e);
			}
			foreach (IObserver observer in GetObjectObservers(e.EventObject))
			{
				observer.OnInstantiatingObject(sender, e);
			}
			if (e.EventObject is IObservable)
			{
				foreach (IEventListener eventListener in ((IObservable) (e.EventObject)).GetEventListeners())
				{
					eventListener.OnInstantiatingObject(sender, e);
				}
			}
			this.Observer.OnInstantiatingObject(sender, e);
			if (e.EventObject is IEventListener)
			{
				((IEventListener) (e.EventObject)).OnInstantiatingObject(sender, e);
			}
		}