public override void Commit() { base.Commit(); LogMessage message = new LogMessage("Committing local transaction"); LogMessage verbose = new LogMessage("Data source: {0}, Auto persist: {1}" , m_DataSource.Name , this.AutoPersistAllOnCommit ); this.Context.LogManager.Info(this, message , verbose); // do not localize TransactionCancelEventArgs e = new TransactionCancelEventArgs(this, m_DataSource, this.IsolationLevel, this.AutoPersistAllOnCommit); this.Context.EventManager.OnCommittingTransaction(this, e); if (e.Cancel) { return; } this.AutoPersistAllOnCommit = e.AutoPersistAllOnCommit; if (this.AutoPersistAllOnCommit) { this.Context.Commit(); } m_DbTransaction.Commit(); this.Context.OnTransactionComplete(this); m_DataSource.KeepConnectionOpen = m_OriginalKeepOpen; m_DataSource.ReturnConnection(); TransactionEventArgs e2 = new TransactionEventArgs(this, m_DataSource, this.AutoPersistAllOnCommit); this.Context.EventManager.OnCommittedTransaction(this, e2); }
public virtual object ExecuteArray(string sql, IDataSource dataSource, IList parameters) { LogMessage message = new LogMessage("Executing sql query and returning array"); LogMessage verbose = new LogMessage("Sql: {0}", sql); this.Context.LogManager.Info(this, message, verbose); // do not localize IDbConnection connection; IDbCommand cmd; IDataReader dr; object result = null; ITransaction transaction; SqlExecutorCancelEventArgs e = new SqlExecutorCancelEventArgs(sql, dataSource, parameters); this.Context.EventManager.OnExecutingSql(this, e); if (e.Cancel) { message = new LogMessage("Executing sql query and returning array canceled by observer!"); verbose = new LogMessage("Sql: {0}", sql); this.Context.LogManager.Info(this, message, verbose); // do not localize return null; } sql = e.Sql; parameters = e.Parameters; if (!(m_ExecutionMode == ExecutionMode.NoExecution)) { ExecuteBatchedStatements(dataSource); connection = dataSource.GetConnection(); cmd = connection.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = sql; AddParametersToCommand(cmd, parameters); transaction = this.Context.GetTransaction(connection); if (transaction != null) { cmd.Transaction = transaction.DbTransaction; } dr = cmd.ExecuteReader(); result = ReaderToArray(dr); dr.Close(); dataSource.ReturnConnection(); } SqlExecutorEventArgs e2 = new SqlExecutorEventArgs(sql, dataSource, parameters); this.Context.EventManager.OnExecutedSql(this, e2); return result; }
public virtual void Fatal(LogMessage message, LogMessage verbose) { foreach (ILogger logger in loggers) { logger.Fatal(message.ToString(), verbose.ToString()); } }
protected virtual void PerformRemoveAction(InverseAction action) { object obj = action.Obj; string propertyName = action.PropertyName; object value = action.Value; IPropertyMap propertyMap = this.Context.DomainMap.MustGetClassMap(obj.GetType()).MustGetPropertyMap(propertyName); IObjectManager om = this.Context.ObjectManager; IList list; IInterceptableList mList; bool stackMute = false; om.EnsurePropertyIsLoaded(obj, propertyMap); list = (IList) om.GetPropertyValue(obj, propertyName); mList = list as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } list.Remove(value); if (mList != null) { mList.MuteNotify = stackMute; } om.SetUpdatedStatus(obj, propertyName, true); LogMessage message = new LogMessage("Performed cached inverse action"); LogMessage verbose = new LogMessage("Action type: {0}, Wrote to object of type: {1}, Property: {2}, Value object type: {3}" , action.ActionType,obj.GetType(),propertyName ,value.GetType()); this.Context.LogManager.Debug(this,message , verbose); // do not localize }
protected virtual void HandleSlaveManyOnePropertySet(object obj, IPropertyMap propertyMap, IList newList, IList oldList) { LogMessage message = new LogMessage("Managing inverse many-one property relationship synchronization"); LogMessage verbose = new LogMessage("Writing to object of type: {0}, Property: {1}", obj.GetType(), propertyMap.Name); this.Context.LogManager.Info(this, message,verbose); // do not localize IPropertyMap invPropertyMap = propertyMap.GetInversePropertyMap(); if ( invPropertyMap == null) { return ;} ArrayList added = GetListDiff(oldList, newList) ; ArrayList removed = GetListDiff(newList, oldList) ; IObjectManager om = this.Context.ObjectManager; IUnitOfWork uow = this.Context.UnitOfWork; IList list; IInterceptableList mList; object value; object oldObj; bool stackMute = false; foreach (object iValue in added) { value = iValue; om.EnsurePropertyIsLoaded(value, invPropertyMap); oldObj = om.GetPropertyValue(value, invPropertyMap.Name); if (!(oldObj == obj)) { om.SetPropertyValue(value, invPropertyMap.Name, obj); om.SetNullValueStatus(value, invPropertyMap.Name, obj == null); om.SetUpdatedStatus(value, invPropertyMap.Name, true); message = new LogMessage("Wrote back-reference in inverse property"); verbose = new LogMessage("Wrote to object of type: {0}, Inverse Property: {1}", value.GetType(),invPropertyMap.Name); this.Context.LogManager.Debug(this,message , verbose); // do not localize uow.RegisterDirty(value); if (oldObj != null) { om.EnsurePropertyIsLoaded(oldObj, propertyMap); list = (IList) om.GetPropertyValue(oldObj, propertyMap.Name); mList = list as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } list.Remove(value); if (mList != null) { mList.MuteNotify = stackMute; } uow.RegisterDirty(oldObj); om.SetUpdatedStatus(oldObj, invPropertyMap.Name, true); message = new LogMessage("Removed back-reference in inverse property"); verbose = new LogMessage("Wrote to object of type: {0}, Inverse Property: {1}" , oldObj.GetType(), propertyMap.Name); this.Context.LogManager.Debug(this, message, verbose); // do not localize } } } foreach (object iValue in removed) { value = iValue; om.EnsurePropertyIsLoaded(value, invPropertyMap); oldObj = om.GetPropertyValue(value, invPropertyMap.Name); om.SetPropertyValue(value, invPropertyMap.Name, null); om.SetNullValueStatus(value, invPropertyMap.Name, true); om.SetUpdatedStatus(value, invPropertyMap.Name, true); uow.RegisterDirty(value); if (oldObj != null) { om.EnsurePropertyIsLoaded(oldObj, propertyMap); list = (IList) om.GetPropertyValue(oldObj, propertyMap.Name); mList = list as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } list.Remove(value); if (mList != null) { mList.MuteNotify = stackMute; } uow.RegisterDirty(oldObj); om.SetUpdatedStatus(oldObj, invPropertyMap.Name, true); } } }
protected virtual void HandleOneManyPropertySet(object obj, IPropertyMap propertyMap, object value, object oldValue) { LogMessage message = new LogMessage("Managing inverse one-many property relationship synchronization"); LogMessage verbose = new LogMessage("Writing to object of type: {0}, Property: {1}", obj.GetType(), propertyMap.Name); this.Context.LogManager.Info(this, message, verbose); // do not localize PropertyStatus propStatus; IPropertyMap invPropertyMap = propertyMap.GetInversePropertyMap(); if ( invPropertyMap == null) { return ;} IObjectManager om = this.Context.ObjectManager; IList list; IInterceptableList mList; bool stackMute = false; if (value == null && oldValue == null) return; if (value == oldValue) return; if (value != null) { propStatus = om.GetPropertyStatus(value, invPropertyMap.Name); if (propStatus == PropertyStatus.NotLoaded) { AddAction(InverseActionType.Add, value, invPropertyMap.Name, obj, obj); } else { om.EnsurePropertyIsLoaded(value, invPropertyMap); list = (IList) om.GetPropertyValue(value, invPropertyMap.Name); mList = list as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } list.Add(obj); if (mList != null) { mList.MuteNotify = stackMute; } om.SetUpdatedStatus(value, invPropertyMap.Name, true); ObjectPersistenceEngine objectPersistenceEngine = this.Context.PersistenceEngine as ObjectPersistenceEngine; if (objectPersistenceEngine != null) { if (objectPersistenceEngine.SourceContext != null) { this.Context.UnitOfWork.RegisterDirty(value); } } } } if (oldValue != null) { propStatus = om.GetPropertyStatus(oldValue, invPropertyMap.Name); if (propStatus == PropertyStatus.NotLoaded) { AddAction(InverseActionType.Remove, oldValue, invPropertyMap.Name, obj, obj); } else { om.EnsurePropertyIsLoaded(oldValue, invPropertyMap); list = (IList) om.GetPropertyValue(oldValue, invPropertyMap.Name); mList = list as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } list.Remove(obj); if (mList != null) { mList.MuteNotify = stackMute; } } } }
protected virtual void AddAction(InverseActionType actionType, object obj, string propertyName, object value, object master) { if (value == null) { LogMessage message = new LogMessage("Caching inverse action"); LogMessage verbose = new LogMessage("Action type: {0}, Object of type: {1}, Property: {2}, Value: null" , actionType, obj.GetType(),propertyName ); this.Context.LogManager.Debug(this, message,verbose ); // do not localize } else { LogMessage message = new LogMessage("Caching inverse action"); LogMessage verbose = new LogMessage("Action type: {0}, Object of type: {1}, Property: {2}, Value type: {3}" , actionType, obj.GetType(),propertyName,value.GetType()) ; this.Context.LogManager.Debug(this, message,verbose ); // do not localize } InverseAction action = new InverseAction() ; action.ActionType = actionType ; action.Obj = obj; action.PropertyName = propertyName; action.Value = value; action.Master = master; Hashtable objActions; ArrayList propActions; ArrayList masterActions; if (!(inverseActions.ContainsKey(obj))) { inverseActions[obj] = new Hashtable(); } objActions = (Hashtable) inverseActions[obj] ; if (!(objActions.ContainsKey(propertyName))) { objActions[propertyName] = new ArrayList(); } propActions = (ArrayList) objActions[propertyName] ; propActions.Add(action); if (!(inverseMasters.ContainsKey(master))) { inverseMasters[master] = new ArrayList(); } masterActions = (ArrayList) inverseMasters[master] ; masterActions.Add(action); }
protected virtual XmlNode LoadObjectNodeFromClassFile(object obj, IClassMap classMap) { string fileName = GetFileNamePerClass(classMap); LogMessage message = new LogMessage("Removing object from file"); LogMessage verbose = new LogMessage("File: {0}, Object Type: {1}",fileName , obj.GetType()); this.Context.LogManager.Debug(this, message,verbose); // do not localize // // if (!(File.Exists(fileName))) // throw new NPersistException("The file '" + fileName + "' could not be found!"); // do not localize XmlDocument xmlDoc; if (File.Exists(fileName)) xmlDoc = GetXmlDocument(fileName); else if (HasXmlDocument(fileName)) xmlDoc = GetXmlDocument(fileName); else xmlDoc = CreateClassXmlDocument(classMap, fileName); XmlNode xmlRoot = xmlDoc.SelectSingleNode(classMap.GetDocRoot() ); XmlNode xmlObject = GetNodeForObject(xmlRoot, obj, classMap ); return xmlObject; }
public virtual void RegisterLoadedObject(object obj) { if (obj == null) throw new NullReferenceException("Can't register null object as loaded!"); // do not localize //This may throw if ReadConsistency is Pessimistic and a tx guid has already been set... SetTransactionGuid(obj); IContext ctx = this.Context; KeyStruct key = GetKey(obj); IObjectCache cache = GetObjectCache(); object result = cache.UnloadedObjects[key]; if (result != null) cache.UnloadedObjects[key] = null; else { result = cache.LoadedObjects[key]; if (result == null) { if (cache.AllObjects != null) cache.AllObjects.Add(obj); } } cache.LoadedObjects[key] = obj; this.Context.ReadOnlyObjectCacheManager.SaveObject(obj); if (this.Context.GetObjectStatus(obj) != ObjectStatus.Dirty) { ctx.ObjectManager.SetObjectStatus(obj, ObjectStatus.Clean); } LogMessage message = new LogMessage("Registered loaded object"); LogMessage verbose = new LogMessage("Type: {0}, Key: {1}" , obj.GetType(), key ); ctx.LogManager.Info(this, message, verbose); // do not localize }
public virtual void RegisterCreatedObject(object obj) { if (obj == null) throw new NullReferenceException("Can't register null object as created!"); // do not localize //This may throw if ReadConsistency is Pessimistic and a tx guid has already been set... SetTransactionGuid(obj); IContext ctx = this.Context; KeyStruct key = GetKey(obj); IObjectCache cache = GetObjectCache(); object result = cache.LoadedObjects[key]; if (result != null) throw new IdentityMapException("An object with the key " + key + " is already registered in the identity map!"); result = cache.UnloadedObjects[key]; if (result != null) throw new IdentityMapException("An object with the key " + key + " is already registered in the identity map!"); if (cache.AllObjects != null) cache.AllObjects.Add(obj); cache.LoadedObjects[key] = obj; LogMessage message = new LogMessage("Registered created object"); LogMessage verbose = new LogMessage( "Type: {0}, Key: {1}" , obj.GetType(), key ); ctx.LogManager.Info(this, message,verbose); // do not localize }
public virtual void LoadProperty(object obj, string propertyName) { LogMessage message = new LogMessage("Loading property"); LogMessage verbose = new LogMessage("Property: {0}, Object Type: {1}" ,propertyName , obj.GetType()); this.SqlEngineManager.Context.LogManager.Info(this, message , verbose); // do not localize IList parameters; object value; object orgValue; IContext ctx = m_SqlEngineManager.Context; PropertyCancelEventArgs e = new PropertyCancelEventArgs(obj, propertyName); ctx.EventManager.OnLoadingProperty(this, e); if (e.Cancel) { return; } IClassMap classMap = ctx.DomainMap.MustGetClassMap(obj.GetType()); IPropertyMap propertyMap = classMap.MustGetPropertyMap(propertyName); bool loaded = false; if (propertyMap.IsCollection) { LoadCollectionProperty(obj, propertyMap); loaded = true; } if (!loaded) { if (!(propertyMap.ReferenceType == ReferenceType.None)) { LoadReferenceProperty(obj, propertyMap); loaded = true; } } if (!loaded) { if (!(propertyMap.MustGetTableMap() == classMap.MustGetTableMap())) { LoadNonPrimaryProperty(obj, propertyMap); loaded = true; } } if (!loaded) { parameters = new ArrayList() ; IObjectManager om = ctx.ObjectManager; IPersistenceManager pm = ctx.PersistenceManager; string sql = GetSelectPropertyStatement(obj, propertyName, parameters); IDataSource ds = ctx.DataSourceManager.GetDataSource(obj); object[,] result = (object[,]) ctx.SqlExecutor.ExecuteArray(sql, ds, parameters); if (Util.IsArray(result)) { orgValue = result[0, 0]; value = pm.ManageLoadedValue(obj, propertyMap, orgValue); om.SetPropertyValue(obj, propertyName, value); om.SetOriginalPropertyValue(obj, propertyName, orgValue); om.SetNullValueStatus(obj, propertyName, DBNull.Value.Equals(orgValue)); } else { throw new ObjectNotFoundException("Object not found!"); // do not localize } } PropertyEventArgs e2 = new PropertyEventArgs(obj, propertyName); ctx.EventManager.OnLoadedProperty(this, e2); }
public object CreateObject(IContainer owner) { object[] ctorParams = new object[this.CtorParameterConfigurations.Count]; ParameterInfo[] ctorParameterInfos = this.Constructor.GetParameters(); for (int i = 0; i < ctorParams.Length; i++) { ParameterConfiguration paramConfig = (ParameterConfiguration) this.CtorParameterConfigurations[i]; paramConfig.Type = ctorParameterInfos[i].ParameterType; object res = paramConfig.GetValue(owner); ctorParams[i] = res; } object instance = null; try { instance = owner.ObjectFactory.CreateInstance(aopEngine , this.Type, ctorParams); LogMessage message = new LogMessage("Creating instance of type '{0}' from config '{1}'", this.Type, this.Name); owner.LogManager.Info(this, message); } catch { LogMessage message = new LogMessage("Failed to create instance of type '{0}' from config '{1}'", this.Type, this.Name); owner.LogManager.Fatal(this, message); throw; } return instance; }
public virtual void Warn(object sender, LogMessage message) { foreach (ILogger logger in loggers) { logger.Warn(sender, message.ToString(), ""); } }
public virtual void Warn(LogMessage message, LogMessage verbose, Exception t) { foreach (ILogger logger in loggers) { logger.Warn(message.ToString(), verbose.ToString(), t); } }
public virtual void Info(object sender, LogMessage message, LogMessage verbose) { foreach (ILogger logger in loggers) { logger.Info(sender, message.ToString(), verbose.ToString()); } }
public virtual void UpdateObject(object obj, IList stillDirty) { LogMessage message = new LogMessage("Updating object"); LogMessage verbose = new LogMessage("Type: {0}" , obj.GetType()); this.Context.LogManager.Info(this,message ,verbose); // do not localize IClassMap classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType() ); if (classMap.DocClassMapMode == DocClassMapMode.PerDomain) { SavePerDomain(obj, classMap, false); } else if (classMap.DocClassMapMode == DocClassMapMode.PerClass) { SavePerClass(obj, classMap, false); } else if (classMap.DocClassMapMode == DocClassMapMode.Default || classMap.DocClassMapMode == DocClassMapMode.PerObject) { SavePerObject(obj, classMap, false); } }
//non-cached protected virtual string LoadFile(Type type, string fileName) { LogMessage message = new LogMessage("Loading objects from file"); LogMessage verbose = new LogMessage("File: {0}, Object Type: {1}", fileName, type); this.Context.LogManager.Debug(this, message, verbose); // do not localize if (!(File.Exists(fileName))) return ""; else { StreamReader fileReader = File.OpenText(fileName); string xml = fileReader.ReadToEnd(); fileReader.Close(); return xml; } }
public virtual void UnRegisterCreatedObject(object obj) { if (obj == null) throw new NullReferenceException("Can't unregister null object!"); // do not localize IContext ctx = this.Context; IObjectCache cache = GetObjectCache(); cache.AllObjects.Remove(obj); KeyStruct key = GetKey(obj); cache.LoadedObjects.Remove(key); ctx.ObjectManager.SetObjectStatus(obj, ObjectStatus.NotRegistered); IIdentityHelper identityHelper = obj as IIdentityHelper; if (identityHelper == null) throw new NPersistException(string.Format("Object of type {0} does not implement IIdentityHelper", obj.GetType())); identityHelper.Reset(); LogMessage message = new LogMessage("Unregistered created object"); LogMessage verbose = new LogMessage("Type: {0}, Key: {1}" , obj.GetType(), key ); ctx.LogManager.Info(this,message ,verbose ); // do not localize }
protected virtual XmlNode LoadObjectNodeFromDomainFile(object obj, IClassMap classMap) { string fileName = GetFileNamePerDomain(classMap); LogMessage message = new LogMessage("Saving object to file", "File: {0}, Object Type: {1}" , fileName , obj.GetType()); this.Context.LogManager.Debug(this, message); // do not localize XmlDocument xmlDoc; if (File.Exists(fileName)) xmlDoc = GetXmlDocument(fileName); else if (HasXmlDocument(fileName)) xmlDoc = GetXmlDocument(fileName); else xmlDoc = CreateDomainXmlDocument(classMap, fileName); XmlNode xmlRoot = xmlDoc.SelectSingleNode(classMap.GetDocSourceMap().GetDocRoot() ); XmlNode xmlClass = GetNode(xmlRoot, classMap.GetDocRoot() ); XmlNode xmlObject = GetNodeForObject(xmlClass, obj, classMap ); return xmlObject; }
public virtual void UpdateIdentity(object obj, string previousIdentity, string newIdentity) { if (obj == null) throw new NullReferenceException("Can't update temporary identity for null object!"); // do not localize KeyStruct key = GetKey(obj, newIdentity); KeyStruct prevKey = GetOldKey(obj, previousIdentity); IObjectCache cache = GetObjectCache( ); object result = cache.LoadedObjects[prevKey]; if (result != null) { cache.LoadedObjects[key] = obj; cache.LoadedObjects[prevKey] = null; } else { result = cache.UnloadedObjects[prevKey]; if (result != null) { cache.UnloadedObjects[key] = obj; cache.UnloadedObjects[prevKey] = null; } } LogMessage message = new LogMessage("Updated identity"); LogMessage verbose = new LogMessage("Type: {0}, New Key: {1}, Previous Key: {2}", obj.GetType(), key , prevKey); this.Context.LogManager.Debug(this,message , verbose); // do not localize }
//Follow all bi-directional references from the //object, setting the nullable, clean back references to null public virtual void RemoveInverseReferences(object obj) { LogMessage message = new LogMessage("Removing inverse references"); LogMessage verbose = new LogMessage(obj.GetType()); this.Context.LogManager.Info(this, message, verbose); // do not localize IObjectManager om = this.Context.ObjectManager; IClassMap classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType()); IPropertyMap invPropertyMap; foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps()) { if (!(propertyMap.ReferenceType == ReferenceType.None)) { if (propertyMap.Inverse.Length > 0) { invPropertyMap = propertyMap.GetInversePropertyMap(); if (invPropertyMap != null) { if (invPropertyMap.ReferenceType == ReferenceType.ManyToOne || invPropertyMap.ReferenceType == ReferenceType.ManyToMany || invPropertyMap.GetIsNullable() ) { NullifyInverseReference(propertyMap, obj, invPropertyMap, om); } } } } } }
protected virtual void RemovePerObject(object obj, IClassMap classMap) { string fileName = GetFileNamePerObject(obj, classMap); LogMessage message = new LogMessage("Removing file for object"); LogMessage verbose = new LogMessage("File: {0},, Object Type: {1}" , fileName , obj.GetType()); this.Context.LogManager.Debug(this, message,verbose); // do not localize if (!(File.Exists(fileName))) throw new NPersistException("The file '" + fileName + "' could not be found!"); // do not localize File.Delete(fileName); }
protected virtual void HandleManyManyPropertySet(object obj, IPropertyMap propertyMap, IList newList, IList oldList) { LogMessage message = new LogMessage("Managing inverse many-many property relationship synchronization"); LogMessage verbose = new LogMessage("Writing to object of type: {0}, Property: {1}", obj.GetType(),propertyMap.Name); this.Context.LogManager.Info(this, message, verbose); // do not localize PropertyStatus propStatus; IPropertyMap invPropertyMap = propertyMap.GetInversePropertyMap(); if ( invPropertyMap == null) { return ;} ArrayList added = GetListDiff(oldList, newList) ; ArrayList removed = GetListDiff(newList, oldList) ; IObjectManager om = this.Context.ObjectManager; IList list; IInterceptableList mList; bool stackMute = false; object value; foreach (object iValue in added) { value = iValue; propStatus = om.GetPropertyStatus(value, invPropertyMap.Name); if (propStatus == PropertyStatus.NotLoaded) { value = iValue; AddAction(InverseActionType.Add, value, invPropertyMap.Name, obj, obj); } else { //we still ensure so that the object is also always loaded... om.EnsurePropertyIsLoaded(value, invPropertyMap); list = (IList) om.GetPropertyValue(value, invPropertyMap.Name); mList = list as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } list.Add(obj); if (mList != null) { mList.MuteNotify = stackMute; } om.SetUpdatedStatus(value, invPropertyMap.Name, true); } } foreach (object iValue in removed) { value = iValue; propStatus = om.GetPropertyStatus(value, invPropertyMap.Name); if (propStatus == PropertyStatus.NotLoaded) { value = iValue; AddAction(InverseActionType.Remove, value, invPropertyMap.Name, obj, obj); } else { //we still ensure so that the object is also always loaded... om.EnsurePropertyIsLoaded(value, invPropertyMap); list = (IList) om.GetPropertyValue(value, invPropertyMap.Name); mList = list as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } list.Remove(obj); if (mList != null) { mList.MuteNotify = stackMute; } om.SetUpdatedStatus(value, invPropertyMap.Name, true); } } }
protected virtual void SavePerObject(object obj, IClassMap classMap, bool creating) { string fileName = GetFileNamePerObject(obj, classMap); LogMessage message = new LogMessage("Saving object to file"); LogMessage verbose = new LogMessage("File: {0},, Object Type: {1}" , fileName , obj.GetType()); this.Context.LogManager.Debug(this, message, verbose); // do not localize XmlDocument xmlDoc; if (creating) { if (File.Exists(fileName)) throw new NPersistException("The file '" + fileName + "' already exists!"); // do not localize xmlDoc = CreateObjectXmlDocument(classMap, fileName); } else { if (!(File.Exists(fileName))) throw new NPersistException("The file '" + fileName + "' could not be found!"); // do not localize xmlDoc = GetXmlDocument(fileName); } XmlNode xmlObject = xmlDoc.SelectSingleNode(classMap.GetDocElement() ); SerializeObject(xmlObject, obj, classMap, creating); }
protected virtual void HandleOneOnePropertySet(object obj, IPropertyMap propertyMap, object value, object oldValue) { LogMessage message = new LogMessage("Managing inverse one-one property relationship synchronization"); LogMessage verbose = new LogMessage("Writing to object of type: {0}, Property: {1}" , obj.GetType(), propertyMap.Name); this.Context.LogManager.Info(this, message, verbose); // do not localize PropertyStatus propStatus; IPropertyMap invPropertyMap = propertyMap.GetInversePropertyMap(); if ( invPropertyMap == null) { return ;} IObjectManager om = this.Context.ObjectManager; if (value == null && oldValue == null) return; if (value == oldValue) return; if (value != null) { propStatus = om.GetPropertyStatus(value, invPropertyMap.Name); if (propStatus == PropertyStatus.NotLoaded) { AddAction(InverseActionType.Set, value, invPropertyMap.Name, obj, obj); } else { om.EnsurePropertyIsLoaded(value, invPropertyMap); om.SetPropertyValue(value, invPropertyMap.Name, obj); om.SetNullValueStatus(value, invPropertyMap.Name, false); om.SetUpdatedStatus(value, invPropertyMap.Name, true); } } if (oldValue != null) { propStatus = om.GetPropertyStatus(oldValue, invPropertyMap.Name); if (propStatus == PropertyStatus.NotLoaded) { AddAction(InverseActionType.Set, oldValue, invPropertyMap.Name, null, obj); } else { om.EnsurePropertyIsLoaded(oldValue, invPropertyMap); om.SetPropertyValue(oldValue, invPropertyMap.Name, null); om.SetNullValueStatus(oldValue, invPropertyMap.Name, false); om.SetUpdatedStatus(oldValue, invPropertyMap.Name, true); } } }
public virtual void LoadObject(ref object obj) { LogMessage message = new LogMessage("Loading object by id"); LogMessage verbose = new LogMessage ("Type: {0}" , obj.GetType()); this.Context.LogManager.Info(this, message, verbose); // do not localize IClassMap classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType() ); if (classMap.DocClassMapMode == DocClassMapMode.PerDomain) { LoadPerDomain(ref obj, classMap); } else if (classMap.DocClassMapMode == DocClassMapMode.PerClass) { LoadPerClass(ref obj, classMap); } else if (classMap.DocClassMapMode == DocClassMapMode.Default || classMap.DocClassMapMode == DocClassMapMode.PerObject) { LoadPerObject(ref obj, classMap); } if (obj != null) this.Context.IdentityMap.RegisterLoadedObject(obj); }
protected virtual void HandleSlaveOneOnePropertySet(object obj, IPropertyMap propertyMap, object value, object oldValue) { LogMessage message = new LogMessage("Managing inverse one-one property relationship synchronization"); LogMessage verbose = new LogMessage("Writing to object of type: {0}, Property: {1}" , obj.GetType(),propertyMap.Name); this.Context.LogManager.Info(this, message, verbose); // do not localize IPropertyMap invPropertyMap = propertyMap.GetInversePropertyMap(); if ( invPropertyMap == null) { return ;} IObjectManager om = this.Context.ObjectManager; IUnitOfWork uow = this.Context.UnitOfWork; if (value != null) { om.EnsurePropertyIsLoaded(value, invPropertyMap); om.SetPropertyValue(value, invPropertyMap.Name, obj); om.SetNullValueStatus(value, invPropertyMap.Name, false); om.SetUpdatedStatus(value, invPropertyMap.Name, true); uow.RegisterDirty(value); message = new LogMessage("Wrote back-reference to inverse property"); verbose = new LogMessage( "Wrote to object of type: {0}, Inverse Property: {1}" , value.GetType(), invPropertyMap.Name); this.Context.LogManager.Debug(this,message ,verbose); // do not localize } if (oldValue != null) { om.EnsurePropertyIsLoaded(oldValue, invPropertyMap); om.SetPropertyValue(oldValue, invPropertyMap.Name, null); om.SetNullValueStatus(oldValue, invPropertyMap.Name, false); om.SetUpdatedStatus(oldValue, invPropertyMap.Name, true); uow.RegisterDirty(oldValue); message = new LogMessage("Wrote null to inverse property"); verbose = new LogMessage("Wrote to object of type: {0}, Inverse Property: " , oldValue.GetType(),invPropertyMap.Name); this.Context.LogManager.Debug(this, message,verbose); // do not localize } }
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; }
protected virtual void PerformSetAction(InverseAction action) { object obj = action.Obj; string propertyName = action.PropertyName; object value = action.Value; IPropertyMap propertyMap = this.Context.DomainMap.MustGetClassMap(obj.GetType()).MustGetPropertyMap(propertyName); IObjectManager om = this.Context.ObjectManager; om.EnsurePropertyIsLoaded(obj, propertyMap); om.SetPropertyValue(obj, propertyName, value); om.SetNullValueStatus(obj, propertyName, false); om.SetUpdatedStatus(obj, propertyName, true); if (value == null) { LogMessage message = new LogMessage("Performed cached inverse action"); LogMessage verbose = new LogMessage("Action type: {0}, Wrote to object of type: {1}, Property: {2}, Value: null" , action.ActionType , obj.GetType(), propertyName); this.Context.LogManager.Debug(this, message,verbose ); // do not localize } else { LogMessage message = new LogMessage("Performed cached inverse action"); LogMessage verbose = new LogMessage("Action type: {0}, Wrote to object of type: {1}, Property: {2}, Value object type: {3}" , action.ActionType, obj.GetType(), propertyName , value.GetType()); this.Context.LogManager.Debug(this,message ,verbose); // do not localize } }
public virtual void LoadProperty(object obj, string propertyName) { LogMessage message = new LogMessage("Loading property"); LogMessage verbose = new LogMessage("Property: {0}, Object Type: {1}" , propertyName , obj.GetType()); this.Context.LogManager.Info(this, message, verbose); // do not localize IClassMap classMap = this.Context.DomainMap.MustGetClassMap(obj.GetType() ); IPropertyMap propertyMap = classMap.MustGetPropertyMap(propertyName); //if (propertyMap.DocPropertyMapMode == DocPropertyMapMode.Default || propertyMap.DocPropertyMapMode == DocPropertyMapMode.Inline) if (propertyMap.DocPropertyMapMode == DocPropertyMapMode.Inline) LoadObject(ref obj); }