public CachedListUpdate(IList cachedList, IList originalList, object obj, string propertyName, PropertyStatus propertyStatus, RefreshBehaviorType refreshBehavior)
 {
     this.cachedList = cachedList;
     this.originalList = originalList;
     this.obj = obj;
     this.propertyName = propertyName;
     this.propertyStatus = propertyStatus;
     this.refreshBehavior = refreshBehavior;
 }
Exemplo n.º 2
0
 protected QueryBase(string query, Type primaryType, IList parameters, RefreshBehaviorType refreshBehavior)
     : base()
 {
     m_Query = query;
     m_PrimaryType = primaryType;
     this.refreshBehavior = refreshBehavior;
     if (parameters != null)
         this.parameters = parameters;
 }
Exemplo n.º 3
0
 protected QueryBase(string query, Type primaryType, IList parameters, RefreshBehaviorType refreshBehavior) : base()
 {
     m_Query              = query;
     m_PrimaryType        = primaryType;
     this.refreshBehavior = refreshBehavior;
     if (parameters != null)
     {
         this.parameters = parameters;
     }
 }
Exemplo n.º 4
0
        public virtual IList LoadObjects(Type type, RefreshBehaviorType refreshBehavior, IList listToFill)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            string npath = "Select * From " + type.Name;

            return(LoadObjects(new NPathQuery(npath, type, null, refreshBehavior), listToFill));
        }
        //Two pass operation - first deserialise all objects, the set up relationships
        public virtual IList ToObjectList(MarshalObjectList marshalObjectList, RefreshBehaviorType refreshBehavior, IList listToFill)
        {
            foreach (MarshalObject mo in marshalObjectList.Objects)
            {
                GetObjectListObject(mo, 1, refreshBehavior);
            }

            foreach (MarshalObject mo in marshalObjectList.Objects)
            {
                object obj = GetObjectListObject(mo, 2, refreshBehavior);
                listToFill.Add(obj);
            }

            return(listToFill);
        }
        private void ToReference(object targetObject, MarshalReference mr, IPropertyMap propertyMap, RefreshBehaviorType refreshBehavior)
        {
            object value = null;

            if (mr.Type.Length > 0 && mr.IsNull == false)
            {
                value = ToReferenceValue(targetObject, mr.Type, mr.Value, mr, propertyMap);
            }

            Context.ObjectManager.SetPropertyValue(targetObject, propertyMap.Name, value);
            if (mr.HasOriginal)
            {
                object orgValue = null;
                if (mr.OriginalType.Length > 0 && mr.WasNull == false)
                {
                    orgValue = ToReferenceValue(targetObject, mr.OriginalType, mr.OriginalValue, mr, propertyMap);
                }

                Context.ObjectManager.SetOriginalPropertyValue(targetObject, propertyMap.Name, orgValue);
                if (mr.IsNull != mr.WasNull || (value != null && orgValue != null && value.Equals(orgValue) == false))
                {
                    this.Context.ObjectManager.SetUpdatedStatus(targetObject, propertyMap.Name, true);
                    //redundant, done once for object by outer caller
                    //this.Context.UnitOfWork.RegisterDirty(targetObject, propertyMap.Name, true);
                }
            }
            Context.ObjectManager.SetNullValueStatus(targetObject, propertyMap.Name, mr.IsNull);
        }
        //TODO: The whole refresh thingy...
        public void ToProperty(object targetObject, MarshalProperty mp, IPropertyMap propertyMap, RefreshBehaviorType refreshBehavior)
        {
            IObjectManager      om = this.Context.ObjectManager;
            IPersistenceManager pm = this.Context.PersistenceManager;

            object value = null;

            if (!mp.IsNull)
            {
                value = ToPropertyValue(targetObject, mp.Value, mp, propertyMap);
            }

            bool doWrite    = false;
            bool doWriteOrg = false;

            RefreshProperty(om, targetObject, propertyMap, pm, refreshBehavior, value, out doWrite, out doWriteOrg);
            if (doWrite || doWriteOrg)
            {
                //To keep inverse management correct,
                //We really should pick out a ref to any
                //eventual already referenced object here (in the
                //case of MergeBehaviorType.OverwriteDirty)
                //and perform proper inverse management on that object...

                if (doWrite)
                {
                    if (mp.IsNull != true)
                    {
                        om.SetPropertyValue(targetObject, propertyMap.Name, value);
                    }
                    Context.ObjectManager.SetNullValueStatus(targetObject, propertyMap.Name, mp.IsNull);
                }
                if (doWriteOrg)
                {
                    if (mp.HasOriginal)
                    {
                        object orgValue = DBNull.Value;
                        if (mp.WasNull != true)
                        {
                            orgValue = ToPropertyValue(targetObject, mp.OriginalValue, mp, propertyMap);
                        }

                        if (propertyMap.ReferenceType == ReferenceType.None)
                        {
                            om.SetOriginalPropertyValue(targetObject, propertyMap.Name, orgValue);
                        }
                        else
                        {
                            om.SetOriginalPropertyValue(targetObject, propertyMap.Name, value);
                        }


                        if (mp.IsNull != mp.WasNull || (value != null && orgValue != null && value.Equals(orgValue) == false))
                        {
                            this.Context.ObjectManager.SetUpdatedStatus(targetObject, propertyMap.Name, true);
                            //redundant, done once for object by outer caller
                            //this.Context.UnitOfWork.RegisterDirty(targetObject, propertyMap.Name, true);
                        }
                    }
                }
//
//				if (propertyMap.ReferenceType != ReferenceType.None )
//				{
//
//					if (value != null)
//					{
//						this.Context.IdentityMap.RegisterLoadedObject(value);
//
//						//Inverse management
//						if (doWrite)
//							this.Context.InverseManager.NotifyPropertyLoad(refObj, propertyMap, value);
//					}
//				}
            }
        }
 protected virtual void LoadObjectsPerObject(Type type, RefreshBehaviorType refreshBehavior, IList listToFill, IClassMap classMap)
 {
     string directory = GetDirectoryForClass(classMap);
     string className = classMap.GetFullName().ToLower();
     foreach (string fileName in Directory.GetFiles(directory))
     {
         FileInfo file = new FileInfo(fileName);
         if (file.Extension.ToLower() == ".xml")
         {
             if (file.Name.Length > className.Length)
             {
                 if (file.Name.Substring(0, className.Length).ToLower() == className)
                 {
                     string xml = LoadFile(type, fileName);
                     if (xml != "")
                         DeserializeObject(type, listToFill, classMap, xml);
                 }
             }
         }
     }
 }
        public virtual IList LoadObjects(Type type, RefreshBehaviorType refreshBehavior, IList listToFill)
        {
            LogMessage message = new LogMessage("Loading all objects of type");
            LogMessage verbose = new LogMessage("Type: {0}", type);
            this.Context.LogManager.Info(this, message, verbose); // do not localize

            if (listToFill == null)
                listToFill = new ArrayList();

            IClassMap classMap = this.Context.DomainMap.MustGetClassMap(type);

            if (classMap.DocClassMapMode == DocClassMapMode.PerDomain)
            {
                LoadObjectsPerDomain(type, refreshBehavior, listToFill, classMap);
            }
            else if (classMap.DocClassMapMode == DocClassMapMode.PerClass)
            {
                LoadObjectsPerClass(type, refreshBehavior, listToFill, classMap);
            }
            else if (classMap.DocClassMapMode == DocClassMapMode.Default || classMap.DocClassMapMode == DocClassMapMode.PerObject)
            {
                LoadObjectsPerObject(type, refreshBehavior, listToFill, classMap);
            }

            foreach (IClassMap subClassMap in classMap.GetSubClassMaps())
            {
                Type subType = this.Context.AssemblyManager.GetTypeFromClassMap(subClassMap);
                LoadObjects(subType, refreshBehavior, listToFill);
            }

            return listToFill;
        }
Exemplo n.º 10
0
 private void RefreshProperty(object obj, string propertyName, RefreshBehaviorType refreshBehavior)
 {
     Context.RefreshProperty(obj, propertyName, refreshBehavior);
     RefreshAll();
 }
Exemplo n.º 11
0
 public SqlQuery(string query, IList parameters, RefreshBehaviorType refreshBehavior, IContext ctx) : base(query, null, parameters, refreshBehavior, ctx)
 {
 }
        private void ToReference(object targetObject, MarshalReference mr, IPropertyMap propertyMap, RefreshBehaviorType refreshBehavior)
        {
            object value = null;
            if (mr.Type.Length > 0 && mr.IsNull == false)
                value = ToReferenceValue(targetObject, mr.Type, mr.Value, mr, propertyMap);

            Context.ObjectManager.SetPropertyValue(targetObject, propertyMap.Name, value);
            if (mr.HasOriginal)
            {
                object orgValue = null;
                if (mr.OriginalType.Length > 0 && mr.WasNull == false)
                    orgValue = ToReferenceValue(targetObject, mr.OriginalType, mr.OriginalValue,mr, propertyMap);

                Context.ObjectManager.SetOriginalPropertyValue(targetObject, propertyMap.Name, orgValue);
                if (mr.IsNull != mr.WasNull || (value != null && orgValue != null && value.Equals(orgValue) == false))
                {
                    this.Context.ObjectManager.SetUpdatedStatus(targetObject, propertyMap.Name, true);
                    //redundant, done once for object by outer caller
                    //this.Context.UnitOfWork.RegisterDirty(targetObject, propertyMap.Name, true);
                }
            }
            Context.ObjectManager.SetNullValueStatus(targetObject, propertyMap.Name, mr.IsNull);
        }
Exemplo n.º 13
0
		public virtual IList GetObjectsBySql(string sqlQuery, Type type, IList idColumns, IList typeColumns, Hashtable propertyColumnMap, IList parameters, RefreshBehaviorType refreshBehavior, IList listToFill)
		{
			IDataSource ds = this.Context.DataSourceManager.GetDataSource(type);
			IDataReader dr;
			//IList colRet = new ArrayList();
			IList colRet = listToFill;
			dr = this.Context.SqlExecutor.ExecuteReader(sqlQuery, ds, parameters);
			if (dr != null)
			{
				try
				{
					FetchObjectsFromDataReader(dr, ref colRet, type, idColumns, typeColumns, propertyColumnMap, refreshBehavior);
				}
				catch (Exception ex)
				{
					dr.Close();
					ds.ReturnConnection();
					throw ex; // do not localize
				}
				dr.Close();
			}
			ds.ReturnConnection();
			return colRet;
		}
Exemplo n.º 14
0
		//From PersistenceManager
		protected virtual void InternalGetObjectsByNPath(string npathQuery, Type type, IList parameters, RefreshBehaviorType refreshBehavior, IList listToFill)
		{
			IList outParameters = new ArrayList();
			IList idColumns = new ArrayList();
			IList typeColumns = new ArrayList();
			Hashtable propertyColumnMap = new Hashtable();
			IClassMap classMap;
			IColumnMap columnMap;
			classMap = this.Context.DomainMap.MustGetClassMap(type);
//			columnMap = classMap.GetTypeColumnMap();
//			if (columnMap != null)
//			{
//				typeColumns.Add(columnMap.Name);
//			}
			foreach (IPropertyMap propertyMap in classMap.GetIdentityPropertyMaps())
			{
				columnMap = propertyMap.GetColumnMap();
				if (columnMap != null)
				{
					idColumns.Add(columnMap.Name);
				}
			}
			string sql = this.Context.NPathEngine.ToSql(npathQuery, NPathQueryType.SelectObjects, type, ref propertyColumnMap, ref outParameters, parameters);
			GetObjectsBySql(sql, type, idColumns, typeColumns, propertyColumnMap, outParameters, refreshBehavior, listToFill);
		}
Exemplo n.º 15
0
		protected virtual IList GetObjectsByNPath(string npathQuery, Type type, IList parameters, RefreshBehaviorType refreshBehavior, IList listToFill)
		{
			IClassMap classMap = this.Context.DomainMap.MustGetClassMap(type);

			//IList result = InternalGetObjectsByNPath(npathQuery, type, parameters, refreshBehavior);
			InternalGetObjectsByNPath(npathQuery, type, parameters, refreshBehavior, listToFill);

			foreach (IClassMap subClassMap in classMap.GetSubClassMaps())
			{
				if (subClassMap.InheritanceType == InheritanceType.ConcreteTableInheritance)
				{
					Type subType = this.Context.AssemblyManager.MustGetTypeFromClassMap(subClassMap);
					InternalGetObjectsByNPath(npathQuery, subType, parameters, refreshBehavior, listToFill); 						

				}					
			}

			return listToFill;
		}
Exemplo n.º 16
0
		//From Context		
		protected virtual IList GetObjectsBySql(string sqlQuery, Type type, IList parameters, RefreshBehaviorType refreshBehavior, IList listToFill)
		{
			IList idColumns = new ArrayList();
			IList typeColumns = new ArrayList();
			Hashtable propertyColumnMap = new Hashtable();
			IQuery sq = new SqlQuery(sqlQuery);
			IList outParameters = new ArrayList(); 
			//IList inParameters = new ArrayList(); 
			sq.ToSql(type, this.Context, ref idColumns, ref typeColumns, ref propertyColumnMap, ref outParameters, parameters);
			return GetObjectsBySql(sqlQuery, type, idColumns, typeColumns, propertyColumnMap, outParameters, refreshBehavior, listToFill );
		}
Exemplo n.º 17
0
		public virtual DataTable GetDataTableBySql(string sqlQuery, Type type, IList idColumns, IList typeColumns, Hashtable propertyColumnMap, IList parameters, RefreshBehaviorType refreshBehavior)
		{
			IDataSource ds = this.Context.DataSourceManager.GetDataSource(type);
			DataTable dt;
			dt = this.Context.SqlExecutor.ExecuteDataTable(sqlQuery, ds, parameters);
			return dt;
		}
Exemplo n.º 18
0
		protected virtual DataTable GetDataTableByNPath(string NPathQuery, Type type, IList parameters, RefreshBehaviorType refreshBehavior)
		{
			IList outParameters = new ArrayList();
			IList idColumns = new ArrayList();
			IList typeColumns = new ArrayList();
			Hashtable propertyColumnMap = new Hashtable();
			IClassMap classMap;
			IColumnMap columnMap;
			classMap = this.Context.DomainMap.MustGetClassMap(type);
			columnMap = classMap.GetTypeColumnMap();
			if (columnMap != null)
			{
				typeColumns.Add(columnMap.Name);
			}
			foreach (IPropertyMap propertyMap in classMap.GetIdentityPropertyMaps())
			{
				columnMap = propertyMap.GetColumnMap();
				if (columnMap != null)
				{
					idColumns.Add(columnMap.Name);
				}
			}
			string sql = this.Context.NPathEngine.ToSql(NPathQuery, type, ref propertyColumnMap, ref outParameters, parameters);
			return GetDataTableBySql(sql, type, idColumns, typeColumns, propertyColumnMap, outParameters, refreshBehavior);
		}
Exemplo n.º 19
0
 public IList GetObjectsBySql(string sqlQuery, Type type, IList idColumns, IList typeColumns, Hashtable propertyColumnMap, IList parameters, RefreshBehaviorType refreshBehavior, IList listToFill)
 {
     return(GetSqlEngine(GetSourceType(type)).GetObjectsBySql(sqlQuery, type, idColumns, typeColumns, propertyColumnMap, parameters, refreshBehavior, listToFill));
 }
Exemplo n.º 20
0
		//Maybe one day this method should be modified to take a datatable and be moved outta here, eh ?

		//TODO: Modify so that this handles composite key references!!
		//First step - decide that propertyColumnMap can have values that are columnNames or Lists of columnNames....(done!)
		//when propertyColumnMap are lists, the convention is that:
		//A) if the referenced class has a type value (and the type value is part of the composite key), it should be the first value in the list
		//B) the rest if the items should be the rest of the composite 
		protected virtual void FetchObjectsFromDataReader(IDataReader dr, ref IList colret, Type type, IList idColumns, IList typeColumns, Hashtable propertyColumnMap, RefreshBehaviorType refreshBehavior)
		{
			IObjectManager om = this.Context.ObjectManager;
			IClassMap classMap = this.Context.DomainMap.MustGetClassMap(type);
			IDomainMap dm = this.Context.DomainMap;
			IAssemblyManager am = this.Context.AssemblyManager ;
			IListManager lm = this.Context.ListManager;
			Hashtable added = new Hashtable() ;
			Hashtable addedToList = new Hashtable() ;
			int rowNr = 0;
			object obj;
			object refObj;
			object objColumnIndex;
			IPropertyMap propertyMap;
			string strPropertyName;
			string[] arr;
			int start;
			int CurrLevel;
			int iLevel;
			int MaxLevel = 0;
			object value;
			object orgValue;
			string identity;
			string sep = classMap.IdentitySeparator;
			if (sep == "")
			{
				sep = "|";
			}
			bool doWrite;
			bool doWriteOrg;
			PropertyStatus propStatus;
			string strTypeValue;
			object discriminator; //TODO: ensure disc is set
			IClassMap useClassMap;
			IClassMap refClassMap;
			Type useType;
			IPersistenceManager pm = this.Context.PersistenceManager;
			Hashtable registerLoaded = new Hashtable() ;
			
			RefreshBehaviorType useRefreshBehavior;

			Hashtable foundIdColumns = new Hashtable() ;
			
			//iterate through each column in the datareader,
			//where each row contains id columns for the new object, eventual loaded properties and also possibly columns for values (icluding ids) of referenced objects
			//each column in the row should have a property-path associated ith it in propertyColumnMap
			//(some columns may be referenced by the same property-path)
			while (dr.Read())
			{
				rowNr += 1;
				useType = type;
				useClassMap = classMap;

				//begin by seeing if a typecolumn has been supplied
				//if so, get the type value from the datareader and make sure our classMap is of this type
				foreach (string strColumnName in typeColumns)
				{
					strTypeValue = (string) dr[strColumnName];
					if (!(strTypeValue == classMap.TypeValue))
					{
						useClassMap = classMap.GetBaseClassMap().GetSubClassWithTypeValue(strTypeValue);
						useType = this.Context.AssemblyManager.MustGetTypeFromClassMap(useClassMap);
					}
				}
				identity = "";
				//iterate through the identity properties for our type, get the columnname for each from propertyColumnMap
				//and get the id values from the datareader, then concatenate the id values to an identity string using the id separator of the type
				//also add the id columns to the foundIdColumns hashtable
				//if the id columns are repeated later in the idcolumnlist they can then be ignored
				foreach (IPropertyMap idPropertyMap in useClassMap.GetIdentityPropertyMaps())
				{
					if (propertyColumnMap.ContainsKey(idPropertyMap.Name))
					{
						if (propertyColumnMap[idPropertyMap.Name] is string)
						{
							identity += Convert.ToString(dr[(string) propertyColumnMap[idPropertyMap.Name]]) + sep;
							foundIdColumns[idPropertyMap.Column.ToLower(CultureInfo.InvariantCulture)] = true;							
						}
						else
						{
							IList aliases = (IList) propertyColumnMap[idPropertyMap.Name];
							int index = 0;

							IColumnMap typeColMap = useClassMap.GetTypeColumnMap();
							if (typeColMap != null)
							{
								strTypeValue = Convert.ToString(dr[(string) aliases[0]]);
								if (!(strTypeValue == classMap.TypeValue))
								{
									//When npath adds TypeColumn to where clause, uncomment this
									//useClassMap = classMap.GetSubClassWithTypeValue(strTypeValue);
									useClassMap = classMap.GetBaseClassMap().GetSubClassWithTypeValue(strTypeValue);

									//useType = type.Assembly.GetType(useClassMap.Name);
									useType = this.Context.AssemblyManager.MustGetTypeFromClassMap(useClassMap);
								}
								index = 1;
							}

							for (int iter = index; iter < aliases.Count ; iter++ )
							{
								identity += Convert.ToString(dr[(string) aliases[iter]]) + sep;
								foundIdColumns[idPropertyMap.Column.ToLower(CultureInfo.InvariantCulture)] = true;								
							}
						}
					}
				}
				//iterate through the id columns and concatenate the id values to an identity string using the id separator of the type
				//ignore idcolumns that are aready added in the previous loop
				foreach (string strColumnName in idColumns)
					if (!(foundIdColumns.ContainsKey(strColumnName.ToLower(CultureInfo.InvariantCulture))))
						identity += Convert.ToString(dr[strColumnName]) + sep;						

				//if the identity string ends with a separator, remove the trailing separator
				if (identity.Length > sep.Length)
					identity = identity.Substring(0, identity.Length - sep.Length);

				//ask the context for the object with our identity and type 
				//this is the "root" object represented by the row
				obj = this.Context.GetObjectById(identity, useType, true);

				//add the object to the result list
				object test = added[obj];
				if (test == null)
				{
					colret.Add(obj);
					added[obj] = obj;					
				}

				if (propertyColumnMap != null)
				{
					string typeName = type.ToString();
					//Find the maximum number of levels traversed in any of the propertypaths
					foreach (string iPropertyName in propertyColumnMap.Keys)
					{
						strPropertyName = iPropertyName;
						if (strPropertyName.Length > 0)
						{
							if (strPropertyName.IndexOf(".") > 0)
							{
								arr = strPropertyName.Split('.');
								iLevel = arr.GetUpperBound(0);
								if (String.Compare(arr[0], typeName, true, CultureInfo.InvariantCulture) == 0)
									iLevel -= 1;
								if (iLevel > MaxLevel)
									MaxLevel = iLevel;
							}
						}
					}
					//go through properties level by level, filling properties in each level with values from the datareader
					//first person.FirstName, person.LastName, person.Project and person.House
					//then person.Project.Name, person.Project.Date, person.Project.Company,
					//     person.House.Street, person.House.Color, person.House.City
					//then person.Project.Company.Name, person.Project.Company.Address..
					//     person.House.City.Name, person.House.City.Country....
					//this ensures that when travelling a propertypath all the parts in it will always be loaded
					for (int Level = 0; Level <= MaxLevel; Level++)
					{
						//iterate through all the propertypaths to see which represent properties on the current level
						foreach (string iPropertyName in propertyColumnMap.Keys)
						{
							strPropertyName = iPropertyName;
							if (strPropertyName.Length > 0)
							{
								objColumnIndex = propertyColumnMap[strPropertyName];
								refObj = obj;
								//if it is a propertypath, traverse it
								if (strPropertyName.IndexOf(".") > 0)
								{
									CurrLevel = 0;
									arr = strPropertyName.Split('.');
									start = 0;
									//if the propertypath beginis with the classname, skip one level
									if (arr[0].ToLower(CultureInfo.InvariantCulture) == type.ToString().ToLower(CultureInfo.InvariantCulture))
										start = 1;

									//count the number of levels in the path
									for (int i = start; i <= arr.GetUpperBound(0) - 1; i++)
										CurrLevel += 1;

									//check if the level of the path equals the current level
									if (CurrLevel == Level)
									{
										object prevObj = obj;
										string path = "";
										//if so, traverse the propertypath (knowing that all parts in it have been loaded)
										for (int i = start; i <= arr.GetUpperBound(0) - 1; i++)
										{
											//read the next part in the path
											refObj = om.GetPropertyValue(refObj, arr[i]);
											if (refObj == null)
												break;

											path += arr[i] + ".";

											IList listObject = refObj as IList;
											if (listObject != null)
											{
												string refId = "";
												IClassMap refObjClassMap = dm.MustGetClassMap(prevObj.GetType()).MustGetPropertyMap(arr[i]).MustGetReferencedClassMap() ;
												Type refType = am.GetTypeFromClassMap(refObjClassMap);
												foreach (IPropertyMap refIdPropertyMap in refObjClassMap.GetIdentityPropertyMaps() )
												{
													string find = path + refIdPropertyMap.Name;
													if (propertyColumnMap.ContainsKey(find))
													{
														if (propertyColumnMap[find] is string)
														{
															refId += Convert.ToString(dr[(string) propertyColumnMap[find]]) + sep;
															//foundIdColumns[refIdPropertyMap.Column.ToLower(CultureInfo.InvariantCulture)] = true;							
														}
														else
														{
															IList aliases = (IList) propertyColumnMap[find];
															int index = 0;

															IColumnMap typeColMap = refObjClassMap.GetTypeColumnMap();
															if (typeColMap != null)
															{
																strTypeValue = Convert.ToString(dr[(string) aliases[0]]);
																if (!(strTypeValue == classMap.TypeValue))
																{
																	//When npath adds TypeColumn to where clause, uncomment this
																	//useClassMap = classMap.GetSubClassWithTypeValue(strTypeValue);
																	refObjClassMap = classMap.GetBaseClassMap().GetSubClassWithTypeValue(strTypeValue);

																	//useType = type.Assembly.GetType(useClassMap.Name);
																	refType = am.MustGetTypeFromClassMap(useClassMap);
																}
																index = 1;
															}

															for (int iter = index; iter < aliases.Count ; iter++ )
															{
																refId += Convert.ToString(dr[(string) aliases[iter]]) + sep;
																//foundIdColumns[refIdPropertyMap.Column.ToLower(CultureInfo.InvariantCulture)] = true;								
															}
														}
													}
												}
												
												//if the identity string ends with a separator, remove the trailing separator
												if (refId.Length > sep.Length)
													refId = refId.Substring(0, refId.Length - sep.Length);

												refObj = this.Context.GetObjectById(refId, refType, true);

												if (registerLoaded[refObj] == null)
													registerLoaded[refObj] = refObj;

												string key = path + rowNr.ToString();
												object testRef = addedToList[key] ;
												if (testRef == null)
												{
													addedToList[key] = refObj;

													bool stackMute = false;
													IInterceptableList mList = listObject as IInterceptableList;
													if (mList != null)
													{
														stackMute = mList.MuteNotify;
														mList.MuteNotify = true;
													}
													listObject.Add(refObj);
													if (mList != null)
													{
														mList.MuteNotify = stackMute ;
													}
													IList orgList = (IList) om.GetOriginalPropertyValue(refObj, arr[i]);
													if (orgList == null)
													{				
														orgList = lm.CreateList(obj, arr[i]) ;
														om.SetOriginalPropertyValue(obj, arr[i], orgList);
													}
													mList = orgList as IInterceptableList;
													if (mList != null)
													{
														stackMute = mList.MuteNotify;
														mList.MuteNotify = true;
													}
													orgList.Add(refObj);
													if (mList != null)
													{
														mList.MuteNotify = stackMute ;
													}

												}
											}
											prevObj = refObj;
										}
									}
									//make sure we have arrived at an object to work with for the property, if not break
									if (refObj == null)
										break;
									else
										strPropertyName = arr[arr.GetUpperBound(0)];										
								}
								else
								{
									CurrLevel = 0;
								}
								//if the proppath is on the current level, put a value in the property from the datareader
								if (CurrLevel == Level)
								{
									if (refObj != null)
									{
										//Check if this property is part of a composite key foreign key (ref prop)
										//If so, add it to the list for this FK
										//Check if the list is complete
										//if so, do()
										discriminator = null;
										
										//get the class map for the object holding the property we're working with
										refClassMap = classMap.DomainMap.MustGetClassMap(refObj.GetType());

										//get the property map for the property we're working with
										propertyMap = refClassMap.GetPropertyMap(strPropertyName);

										if (propertyMap != null && !(CurrLevel == 0 && propertyMap.IsIdentity))
										{
											IList listColumnIndexes = objColumnIndex as IList;
											if (listColumnIndexes != null )
											{
                                                int startIndex = 0;
												IPropertyMap inverse = propertyMap.GetInversePropertyMap();
                                                if (inverse != null)
                                                {
                                                    //HACK: roger tried to fix this
                                                    //IClassMap otherClassMap = propertyMap.GetReferencedClassMap();
                                                    IClassMap otherClassMap = inverse.ClassMap;//propertyMap.ClassMap;
                                                    IColumnMap typeColumnMap = otherClassMap.GetTypeColumnMap();
                                                    
                                                    if (typeColumnMap != null)
                                                    {
                                                        bool foundTypeCol = false;
                                                        foreach (IColumnMap idColumnMap in propertyMap.GetAllColumnMaps())
                                                            if (idColumnMap.MustGetPrimaryKeyColumnMap() == typeColumnMap)
                                                                foundTypeCol = true;

                                                        //if the referenced class has a type column our property
                                                        //has a column mapping to that type column, we should 
                                                        //assume that the first column in the column list
                                                        //is the type column, set the discriminator to this value 
                                                        //and remove it from the result
                                                        if (foundTypeCol)
                                                        {
                                                            if (Util.IsNumeric(Convert.ToString(listColumnIndexes[0])))
                                                                discriminator = dr[Convert.ToInt32(listColumnIndexes[0])];
                                                            else
                                                                discriminator = dr[Convert.ToString(listColumnIndexes[0])];
                                                            startIndex = 1;
                                                        }
                                                    }
                                                }
												orgValue = new ArrayList();
												for (int i = startIndex; i < listColumnIndexes.Count; i++)
												{
													object itemValue; 
													if (Util.IsNumeric(Convert.ToString(listColumnIndexes[i])))
														itemValue = dr[Convert.ToInt32(listColumnIndexes[i])];
													else
														itemValue = dr[Convert.ToString(listColumnIndexes[i])];												
													((IList)orgValue).Add(itemValue);
												}											
											}
											else
											{
												//get the unmanaged value from the datareader by column index, name or alias
												if (Util.IsNumeric(Convert.ToString(objColumnIndex)))
													orgValue = dr[Convert.ToInt32(objColumnIndex)];
												else
													orgValue = dr[Convert.ToString(objColumnIndex)];
											
											}

											//Manage the column value and set the managed value in a new variable
											value = pm.ManageLoadedValue( refObj, propertyMap, orgValue, discriminator);
											doWrite = false;
											doWriteOrg = false;
											propStatus = om.GetPropertyStatus(refObj, strPropertyName);

											useRefreshBehavior = pm.GetRefreshBehavior(refreshBehavior, refClassMap, propertyMap);

											if (useRefreshBehavior == RefreshBehaviorType.OverwriteNotLoaded || useRefreshBehavior == RefreshBehaviorType.DefaultBehavior)
											{
												//Overwrite both value and original for all unloaded properties
												if (propStatus == PropertyStatus.NotLoaded)
												{
													doWrite = true;
													doWriteOrg = true;
												}
											}
											else if (useRefreshBehavior == RefreshBehaviorType.OverwriteLoaded)
											{
												//Overwrite value and original for all clean or unloaded properties (but not for dirty or deleted properties)
												if (propStatus == PropertyStatus.Clean || propStatus == PropertyStatus.NotLoaded)
												{
													doWriteOrg = true;
													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(refObj, strPropertyName);
														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 { ; }
															if (!cachedValue.Equals(freshValue))
																throw new RefreshException("A refresh concurrency exception occurred when refreshing a cached object of type " + refObj.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 " + strPropertyName + ". (this exception occurs because ThrowConcurrencyExceptions refresh behavior was selected). Cashed value: " + cachedValue + ", Fresh value: " + freshValue, cachedValue, freshValue, refObj, strPropertyName); // 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
											}
											if (doWrite || doWriteOrg)
											{
												//To keep inverse management correct,
												//We really should pick out a ref to any
												//eventual already referenced object here (in the
												//case of MergeBehaviorType.OverwriteDirty)
												//and perform proper inverse management on that object...

                                                if (doWrite)
                                                {
													om.SetPropertyValue(refObj, strPropertyName, value);
													om.SetNullValueStatus(refObj, strPropertyName, DBNull.Value.Equals(orgValue));
                                                }

												if (doWriteOrg)
												{
													if (propertyMap.ReferenceType == ReferenceType.None)
														om.SetOriginalPropertyValue(refObj, strPropertyName, orgValue);
													else
														om.SetOriginalPropertyValue(refObj, strPropertyName, value);												
												}

												if (propertyMap.ReferenceType != ReferenceType.None )
												{
													if (value != null)
													{
														if (registerLoaded[value] == null)
															registerLoaded[value] = value;

														//Inverse management
														if (doWrite)
															this.Context.InverseManager.NotifyPropertyLoad(refObj, propertyMap, value);
													}
												}
											}											
										}																				
									}
								}
							}
						}
					}
				}
				if (registerLoaded[obj] == null)
					registerLoaded[obj] = obj;
			}
			foreach (object register in registerLoaded.Keys)
			{
				this.Context.IdentityMap.RegisterLoadedObject(register);				
			}
		}
Exemplo n.º 21
0
 public CachedListUpdate(IList cachedList, IList originalList, object obj, string propertyName, PropertyStatus propertyStatus, RefreshBehaviorType refreshBehavior)
 {
     this.cachedList      = cachedList;
     this.originalList    = originalList;
     this.obj             = obj;
     this.propertyName    = propertyName;
     this.propertyStatus  = propertyStatus;
     this.refreshBehavior = refreshBehavior;
 }
        private void LoadProperty(object obj, IPropertyMap propertyMap, IObjectManager om, object source, IPropertyMap sourcePropertyMap, IObjectManager sourceOm, RefreshBehaviorType refreshBehavior)
        {
            if (!Monitor.TryEnter(sourceContext, this.Context.Timeout))
                throw new NPersistTimeoutException("Could not acquire exclusive lock on root context before timeout: " + this.Context.Timeout.ToString() + " ms" );

            try
            {
                sourceOm.EnsurePropertyIsLoaded(source, sourcePropertyMap.Name);

                bool nullValueStatus;
                object value;
                if (propertyMap.ReferenceType == ReferenceType.None)
                {
                    if (!(propertyMap.IsCollection))
                    {
                        value = sourceOm.GetPropertyValue(source, sourcePropertyMap.Name);
                        nullValueStatus = sourceOm.GetNullValueStatus(source, sourcePropertyMap.Name);

                        om.SetPropertyValue(obj, propertyMap.Name, value);
                        if (nullValueStatus)
                        {
                            om.SetOriginalPropertyValue(obj, propertyMap.Name, DBNull.Value);
                        }
                        else
                        {
                            om.SetOriginalPropertyValue(obj, propertyMap.Name, value);
                        }
                        om.SetNullValueStatus(obj, propertyMap.Name, nullValueStatus);
                    }
                    else
                    {
                        //Using CloneList will work when it is only primitive values
                        //(or immutable objects such as strings and dates)
                        //that can be copied between contexts
                        IList list = (IList) sourceOm.GetPropertyValue(source, sourcePropertyMap.Name);
                        IList listClone = this.Context.ListManager.CloneList(obj, propertyMap, list);
                        //IList listCloneOrg = this.Context.ListManager.CloneList(obj, propertyMap, list);
                        IList listCloneOrg = new ArrayList( list);
                        om.SetPropertyValue(obj, propertyMap.Name, listClone);
                        om.SetOriginalPropertyValue(obj, propertyMap.Name, listCloneOrg);
                    }
                }
                else
                {
                    if (!(propertyMap.IsCollection))
                    {
                        object refObject = sourceOm.GetPropertyValue(source, sourcePropertyMap.Name);

                        if (refObject == null)
                        {
                            om.SetPropertyValue(obj, propertyMap.Name, null);
                            om.SetOriginalPropertyValue(obj, propertyMap.Name, null);

                            om.SetNullValueStatus(obj, propertyMap.Name, true);
                        }
                        else
                        {
                            string identity = sourceOm.GetObjectIdentity(refObject);

                            Type refType = ToLeafType(refObject);

                            //Impossible to solve for inheritance scenarios when mapping presentation model to domain model!!!!
                            //We could try checking which presentation domain map which class map that maps to the
                            //domain class map, but that could be a many-one relationship (many presentation model classes
                            //map to the same domain model class!)
                            //								IClassMap sourceOrgClassMap = this.sourceContext.DomainMap.GetClassMap(orgObject.GetType() );
                            //								IClassMap leafOrgClassMap = this.sourceContext.DomainMap.GetClassMap(sourceOrgClassMap.Name );
                            //								IClassMap theClassMap = this.sourceContext.DomainMap.GetClassMap (sourceOrgClassMap.Name );

                            value = this.Context.GetObjectById(identity, refType, true);
                            nullValueStatus = sourceOm.GetNullValueStatus(source, sourcePropertyMap.Name);

                            om.SetPropertyValue(obj, propertyMap.Name, value);
                            om.SetOriginalPropertyValue(obj, propertyMap.Name, value);

                            om.SetNullValueStatus(obj, propertyMap.Name, nullValueStatus);
                        }
                    }
                    else
                    {
                        //Using CloneList will not work when there are reference values (to mutable objects)
                        //that can be copied between contexts
                        IList orgList = (IList) sourceOm.GetPropertyValue(source, sourcePropertyMap.Name);
                        IList list = (IList) om.GetPropertyValue(obj, sourcePropertyMap.Name);

                        this.LoadReferenceList(list, orgList, refreshBehavior);

                        //for the org-list we can use ListManager.CloneList and clone the list of leaf objects
                        //IList listOrg = this.Context.ListManager.CloneList(obj, propertyMap, list);
                        IList listOrg = new ArrayList( list);
                        om.SetPropertyValue(obj, propertyMap.Name, list);
                        om.SetOriginalPropertyValue(obj, propertyMap.Name, listOrg);

                    }
                }
            }
            finally
            {
                Monitor.Exit(sourceContext);
            }
        }
Exemplo n.º 23
0
 public SqlQuery(string query, Type primaryType, IList parameters, RefreshBehaviorType refreshBehavior, IContext ctx) : base(query, primaryType, parameters, refreshBehavior, ctx)
 {
 }
        public virtual IList LoadObjects(Type type, RefreshBehaviorType refreshBehavior, IList listToFill)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            string npath = "Select * From " + type.Name;
            return LoadObjects(new NPathQuery(npath, type, null, refreshBehavior), listToFill);
        }
Exemplo n.º 25
0
 private void RefreshObject(object obj, RefreshBehaviorType refreshBehavior)
 {
     Context.RefreshObject(obj, refreshBehavior);
     RefreshAll();
 }
        public virtual void LoadReferenceList(IList list, IList orgList, RefreshBehaviorType refreshBehavior)
        {
            if (!Monitor.TryEnter(sourceContext, this.Context.Timeout))
                throw new NPersistTimeoutException("Could not acquire exclusive lock on root context before timeout: " + this.Context.Timeout.ToString() + " ms" );

            try
            {
                IInterceptableList mList;
                bool stackMute = false;

                mList = list as IInterceptableList;
                if (mList != null)
                {
                    stackMute = mList.MuteNotify;
                    mList.MuteNotify = true;
                }
                list.Clear() ;
                foreach (object item in orgList)
                {
                    string identity = this.sourceContext.ObjectManager.GetObjectIdentity(item);
                    Type leafType = ToLeafType(item);

                    //object sourceObject = sourceContext.GetObjectById(identity, sourceType, true);
                    object clone = this.Context.GetObjectById(identity, leafType, true);

                    LoadObject(clone, item, refreshBehavior);
                    this.Context.IdentityMap.RegisterLoadedObject(clone);

                    list.Add(clone);
                }
                if (mList != null)
                {
                    mList.MuteNotify = stackMute;
                }
            }
            finally
            {
                Monitor.Exit(sourceContext);
            }
        }
Exemplo n.º 27
0
 public abstract IList GetObjectsBySql(string sqlQuery, Type type, IList idColumns, IList typeColumns, Hashtable propertyColumnMap, IList parameters, RefreshBehaviorType refreshBehavior, IList listToFill);
        protected virtual void LoadObject(object obj, object source, RefreshBehaviorType refreshBehavior)
        {
            if (!Monitor.TryEnter(sourceContext, this.Context.Timeout))
                throw new NPersistTimeoutException("Could not acquire exclusive lock on root context before timeout: " + this.Context.Timeout.ToString() + " ms" );

            try
            {
                IDomainMap domainMap = this.Context.DomainMap;
                IObjectManager om = this.Context.ObjectManager;
                IObjectManager sourceOm = this.sourceContext.ObjectManager;
                IClassMap classMap = domainMap.MustGetClassMap(obj.GetType());
                IPropertyMap sourcePropertyMap;
                PropertyStatus sourcePropStatus;
                PropertyStatus propStatus;
                foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps())
                {
                    sourcePropertyMap = propertyMap.GetSourcePropertyMapOrSelf() ;
                    sourcePropStatus = sourceOm.GetPropertyStatus(source, sourcePropertyMap.Name ) ;
                    propStatus = om.GetPropertyStatus(obj, propertyMap.Name) ;
                    IUpdatedPropertyTracker tracker = obj as IUpdatedPropertyTracker;
                    if (tracker != null)
                    {
                        if (tracker.GetUpdatedStatus(propertyMap.Name))
                            propStatus = PropertyStatus.Dirty;
                    }

                    RefreshBehaviorType useRefreshBehavior = this.Context.PersistenceManager.GetRefreshBehavior(refreshBehavior, classMap, propertyMap);

                    if (sourcePropStatus != PropertyStatus.NotLoaded)
                    {
                        bool doLoad = false;

                        if (useRefreshBehavior == RefreshBehaviorType.DefaultBehavior || useRefreshBehavior == RefreshBehaviorType.OverwriteNotLoaded)
                        {
                            if (propStatus == PropertyStatus.NotLoaded)
                                doLoad = true;
                        }

                        if (doLoad)
                            LoadProperty(obj, propertyMap, sourceOm, source, sourcePropertyMap, om, refreshBehavior);
                    }
                }
            }
            finally
            {
                Monitor.Exit(sourceContext);
            }
        }
 protected virtual void LoadObjectsPerDomain(Type type, RefreshBehaviorType refreshBehavior, IList listToFill, IClassMap classMap)
 {
     string fileName = GetFileNamePerDomain(classMap);
     string xml = LoadFile(type, fileName);
     if (xml != "")
         DeserializeDomain(type, listToFill, classMap, xml);
 }
		public IList GetObjectsBySql(string sqlQuery, Type type, IList idColumns, IList typeColumns, Hashtable propertyColumnMap, IList parameters, RefreshBehaviorType refreshBehavior, IList listToFill)
		{
			return GetPersistenceEngine(GetSourceMap(type)).GetObjectsBySql(sqlQuery, type, idColumns, typeColumns, propertyColumnMap, parameters, refreshBehavior, listToFill);			
		}
 public virtual IList GetObjectsBySql(string sqlQuery, Type type, IList idColumns, IList typeColumns, Hashtable propertyColumnMap, IList parameters, RefreshBehaviorType refreshBehavior, IList listToFill)
 {
     throw new NPersistException("Sql query capabilities not implemented in DocumentPersistenceEngine! Please use NPath queries instead.");
 }
 public virtual IList GetObjectsBySql(string sqlQuery, Type type, IList idColumns, IList typeColumns, Hashtable propertyColumnMap, IList parameters, RefreshBehaviorType refreshBehavior, IList listToFill)
 {
     throw new IAmOpenSourcePleaseImplementMeException("Query capabilities not implemented in DocumentPersistenceEngine! Please load the entire set that you need to search into memory and use the IContext.FilterObjects() method instead.");
 }
        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
            }
        }
        //Two pass operation - first deserialise all objects, the set up relationships
        public virtual IList ToObjectList(MarshalObjectList marshalObjectList, RefreshBehaviorType refreshBehavior, IList listToFill)
        {
            foreach (MarshalObject mo in marshalObjectList.Objects)
            {
                GetObjectListObject(mo, 1, refreshBehavior);
            }

            foreach (MarshalObject mo in marshalObjectList.Objects)
            {
                object obj = GetObjectListObject(mo, 2, refreshBehavior);
                listToFill.Add(obj);
            }

            return listToFill;
        }
        //pass 0 = get all properties (for ToObject overload) , pass 1 = get only primitive props, pass 2 = get only ref props
        public virtual void ToObject(MarshalObject marshalObject, ref object targetObject, int pass, RefreshBehaviorType refreshBehavior)
        {
            IClassMap    classMap = Context.DomainMap.MustGetClassMap(targetObject.GetType());
            IPropertyMap propertyMap;

            //PropertyStatus propStatus;
            if (pass == 0 || pass == 1)
            {
                foreach (MarshalProperty mp in marshalObject.Properties)
                {
                    //propStatus = ctx.GetPropertyStatus(targetObject, mp.Name);
                    propertyMap = classMap.MustGetPropertyMap(mp.Name);
                    ToProperty(targetObject, mp, propertyMap, refreshBehavior);
                }
            }

            if (pass == 0 || pass == 2)
            {
                foreach (MarshalReference mr in marshalObject.References)
                {
                    //propStatus = ctx.GetPropertyStatus(targetObject, mp.Name);
                    propertyMap = classMap.MustGetPropertyMap(mr.Name);
                    ToReference(targetObject, mr, propertyMap, refreshBehavior);
                }
            }

            if (targetObject != null)
            {
                if (pass == 0 || pass == 1)
                {
                    this.Context.IdentityMap.RegisterLoadedObject(targetObject);
                }
            }
        }
 protected virtual object GetObjectListObject(MarshalObject marshalObject, int pass, RefreshBehaviorType refreshBehavior)
 {
     IClassMap classMap = Context.DomainMap.MustGetClassMap(marshalObject.Type);
     Type realType = Context.AssemblyManager.MustGetTypeFromClassMap(classMap);
     string id = GetIdentity(marshalObject);
     object targetObject = this.Context.GetObjectById(id, realType, true);
     ToObject(marshalObject, ref targetObject, pass, refreshBehavior);
     return targetObject;
 }
        protected virtual object GetObjectListObject(MarshalObject marshalObject, int pass, RefreshBehaviorType refreshBehavior)
        {
            IClassMap classMap     = Context.DomainMap.MustGetClassMap(marshalObject.Type);
            Type      realType     = Context.AssemblyManager.MustGetTypeFromClassMap(classMap);
            string    id           = GetIdentity(marshalObject);
            object    targetObject = this.Context.GetObjectById(id, realType, true);

            ToObject(marshalObject, ref targetObject, pass, refreshBehavior);
            return(targetObject);
        }
Exemplo n.º 38
0
 public NPathQuery(string query, Type primaryType, IList parameters, RefreshBehaviorType refreshBehavior) : base(query, primaryType, parameters, refreshBehavior)
 {
 }
        //pass 0 = get all properties (for ToObject overload) , pass 1 = get only primitive props, pass 2 = get only ref props
        public virtual void ToObject(MarshalObject marshalObject, ref object targetObject, int pass, RefreshBehaviorType refreshBehavior)
        {
            IClassMap classMap = Context.DomainMap.MustGetClassMap(targetObject.GetType());
            IPropertyMap propertyMap;
            //PropertyStatus propStatus;
            if (pass == 0 || pass == 1)
            {
                foreach (MarshalProperty mp in marshalObject.Properties)
                {
                    //propStatus = ctx.GetPropertyStatus(targetObject, mp.Name);
                    propertyMap = classMap.MustGetPropertyMap(mp.Name);
                    ToProperty(targetObject, mp, propertyMap, refreshBehavior);
                }
            }

            if (pass == 0 || pass == 2)
            {
                foreach (MarshalReference mr in marshalObject.References)
                {
                    //propStatus = ctx.GetPropertyStatus(targetObject, mp.Name);
                    propertyMap = classMap.MustGetPropertyMap(mr.Name);
                    ToReference(targetObject, mr, propertyMap, refreshBehavior);
                }
            }

            if (targetObject != null)
                if (pass == 0 || pass == 1)
                    this.Context.IdentityMap.RegisterLoadedObject(targetObject);
        }
Exemplo n.º 40
0
		public abstract IList GetObjectsBySql(string sqlQuery, Type type, IList idColumns, IList typeColumns, Hashtable propertyColumnMap, IList parameters, RefreshBehaviorType refreshBehavior, IList listToFill);
        //TODO: The whole refresh thingy...
        public void ToProperty(object targetObject, MarshalProperty mp, IPropertyMap propertyMap, RefreshBehaviorType refreshBehavior)
        {
            IObjectManager om = this.Context.ObjectManager ;
            IPersistenceManager pm = this.Context.PersistenceManager ;

            object value = null;

            if (!mp.IsNull)
                value = ToPropertyValue(targetObject, mp.Value, mp, propertyMap);

            bool doWrite = false;
            bool doWriteOrg = false;

            RefreshProperty(om, targetObject, propertyMap, pm, refreshBehavior, value, out doWrite, out doWriteOrg);
            if (doWrite || doWriteOrg)
            {
                //To keep inverse management correct,
                //We really should pick out a ref to any
                //eventual already referenced object here (in the
                //case of MergeBehaviorType.OverwriteDirty)
                //and perform proper inverse management on that object...

                if (doWrite)
                {
                    if (mp.IsNull != true)
                    {
                        om.SetPropertyValue(targetObject, propertyMap.Name, value);
                    }
                    Context.ObjectManager.SetNullValueStatus(targetObject, propertyMap.Name, mp.IsNull);
                }
                if (doWriteOrg)
                {
                    if (mp.HasOriginal)
                    {
                        object orgValue = DBNull.Value ;
                        if (mp.WasNull != true)
                            orgValue = ToPropertyValue(targetObject, mp.OriginalValue,mp, propertyMap);

                        if (propertyMap.ReferenceType == ReferenceType.None)
                            om.SetOriginalPropertyValue(targetObject, propertyMap.Name, orgValue);
                        else
                            om.SetOriginalPropertyValue(targetObject, propertyMap.Name, value);

                        if (mp.IsNull != mp.WasNull || (value != null && orgValue != null && value.Equals(orgValue) == false))
                        {
                            this.Context.ObjectManager.SetUpdatedStatus(targetObject, propertyMap.Name, true);
                            //redundant, done once for object by outer caller
                            //this.Context.UnitOfWork.RegisterDirty(targetObject, propertyMap.Name, true);
                        }
                    }
                }
            //
            //				if (propertyMap.ReferenceType != ReferenceType.None )
            //				{
            //
            //					if (value != null)
            //					{
            //						this.Context.IdentityMap.RegisterLoadedObject(value);
            //
            //						//Inverse management
            //						if (doWrite)
            //							this.Context.InverseManager.NotifyPropertyLoad(refObj, propertyMap, value);
            //					}
            //				}
            }
        }
		public virtual IList GetObjectsBySql(string sqlQuery, Type type, IList idColumns, IList typeColumns, Hashtable propertyColumnMap, IList parameters, RefreshBehaviorType refreshBehavior, IList listToFill)
		{
			throw new IAmOpenSourcePleaseImplementMeException("Query capabilities not implemented in DocumentPersistenceEngine! Please load the entire set that you need to search into memory and use the IContext.FilterObjects() method instead.");
		}
        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
            }
        }
		public virtual IList GetObjectsBySql(string sqlQuery, Type type, IList idColumns, IList typeColumns, Hashtable propertyColumnMap, IList parameters, RefreshBehaviorType refreshBehavior, IList listToFill)
		{
			if (!Monitor.TryEnter(sourceContext, this.Context.Timeout))
				throw new NPersistTimeoutException("Could not aquire exclusive lock on root context before timeout: " + this.Context.Timeout.ToString() + " ms" );

			try
			{
				return null;
			}
			finally
			{
				Monitor.Exit(sourceContext);			
			}	
		}
Exemplo n.º 45
0
		public virtual RefreshBehaviorType GetRefreshBehavior(RefreshBehaviorType refreshBehavior, IClassMap classMap, IPropertyMap propertyMap)
		{
			if (refreshBehavior == RefreshBehaviorType.DefaultBehavior)
			{
				if (this.Context.OptimisticConcurrencyMode == OptimisticConcurrencyMode.Early)
				{
					refreshBehavior = RefreshBehaviorType.ThrowConcurrencyException ;					
				}
				else
				{
					refreshBehavior = propertyMap.RefreshBehavior;
					if (refreshBehavior == RefreshBehaviorType.DefaultBehavior)
					{
						refreshBehavior = classMap.RefreshBehavior;
						if (refreshBehavior == RefreshBehaviorType.DefaultBehavior)
						{
							refreshBehavior = classMap.DomainMap.RefreshBehavior;
							if (refreshBehavior == RefreshBehaviorType.DefaultBehavior)
							{
								refreshBehavior = m_RefreshBehavior;
								if (refreshBehavior == RefreshBehaviorType.DefaultBehavior)
								{
									refreshBehavior = RefreshBehaviorType.OverwriteNotLoaded;
								}
							}
						}
					}					
				}
			}
			return refreshBehavior;
		}
 public IList LoadObjects(Type type, RefreshBehaviorType refreshBehavior, IList listToFill)
 {
     return(GetPersistenceEngine(GetSourceMap(type)).LoadObjects(type, refreshBehavior, listToFill));
 }