From: <fab...@us...> - 2009-05-14 21:10:43
|
Revision: 4305 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4305&view=rev Author: fabiomaulo Date: 2009-05-14 21:10:28 +0000 (Thu, 14 May 2009) Log Message: ----------- Applied patch NH-1777 (by Roger) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cache/FilterKey.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs trunk/nhibernate/src/NHibernate/Criterion/Example.cs trunk/nhibernate/src/NHibernate/Engine/Cascade.cs trunk/nhibernate/src/NHibernate/Engine/ExecuteUpdateResultCheckStyle.cs trunk/nhibernate/src/NHibernate/Engine/StatefulPersistenceContext.cs trunk/nhibernate/src/NHibernate/Engine/UnsavedValueFactory.cs trunk/nhibernate/src/NHibernate/Event/Default/DefaultLoadEventListener.cs trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs trunk/nhibernate/src/NHibernate/Loader/Loader.cs trunk/nhibernate/src/NHibernate/Util/ArrayHelper.cs Modified: trunk/nhibernate/src/NHibernate/Cache/FilterKey.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cache/FilterKey.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Cache/FilterKey.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -34,9 +34,11 @@ public override bool Equals(object other) { - if (!(other is FilterKey)) + var that = other as FilterKey; + if (that == null) + { return false; - FilterKey that = (FilterKey) other; + } if (!that.filterName.Equals(filterName)) return false; if (!CollectionHelper.DictionaryEquals<string, TypedValue>(that.filterParameters, filterParameters)) Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -665,9 +665,9 @@ value.SetTypeUsingReflection(className, propertyName, PropertyAccess(subnode)); // This is done here 'cos we might only know the type here (ugly!) - if (value is ToOne) + var toOne = value as ToOne; + if (toOne != null) { - ToOne toOne = (ToOne) value; string propertyRef = toOne.ReferencedPropertyName; if (propertyRef != null) mappings.AddUniquePropertyReference(toOne.ReferencedEntityName, propertyRef); Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassCompositeIdBinder.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -236,25 +236,25 @@ model.SqlType = null; } - private Mapping.Property CreateProperty(ToOne value, string propertyName, System.Type parentClass, + private Property CreateProperty(ToOne value, string propertyName, System.Type parentClass, HbmKeyManyToOne keyManyToOneSchema) { if (parentClass != null && value.IsSimpleValue) - value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName, keyManyToOneSchema.access ?? mappings.DefaultAccess); + value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName, + keyManyToOneSchema.access ?? mappings.DefaultAccess); string propertyRef = value.ReferencedPropertyName; if (propertyRef != null) mappings.AddUniquePropertyReference(value.ReferencedEntityName, propertyRef); value.CreateForeignKey(); - Mapping.Property prop = new Mapping.Property(); - prop.Value = value; + var prop = new Property {Value = value}; BindProperty(keyManyToOneSchema, prop); return prop; } - private void BindProperty(HbmKeyManyToOne keyManyToOneSchema, Mapping.Property property) + private void BindProperty(HbmKeyManyToOne keyManyToOneSchema, Property property) { property.Name = keyManyToOneSchema.name; @@ -343,30 +343,30 @@ model.SqlType = null; } - private Mapping.Property CreateProperty(SimpleValue value, string propertyName, System.Type parentClass, + private Property CreateProperty(SimpleValue value, string propertyName, System.Type parentClass, HbmKeyProperty keyPropertySchema) { if (parentClass != null && value.IsSimpleValue) - value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName, keyPropertySchema.access ?? mappings.DefaultAccess); + value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName, + keyPropertySchema.access ?? mappings.DefaultAccess); // This is done here 'cos we might only know the type here (ugly!) - if (value is ToOne) + var toOne = value as ToOne; + if (toOne != null) { - ToOne toOne = (ToOne) value; string propertyRef = toOne.ReferencedPropertyName; if (propertyRef != null) mappings.AddUniquePropertyReference(toOne.ReferencedEntityName, propertyRef); } value.CreateForeignKey(); - Mapping.Property prop = new Mapping.Property(); - prop.Value = value; + var prop = new Property {Value = value}; BindProperty(keyPropertySchema, prop); return prop; } - private void BindProperty(HbmKeyProperty keyPropertySchema, Mapping.Property property) + private void BindProperty(HbmKeyProperty keyPropertySchema, Property property) { property.Name = keyPropertySchema.name; Modified: trunk/nhibernate/src/NHibernate/Criterion/Example.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/Example.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Criterion/Example.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -417,9 +417,9 @@ // parameter passed in. if (value != null) { - if (value is string) + var stringValue = value as string; + if (stringValue != null) { - string stringValue = (string) value; if (_isIgnoreCaseEnabled) { stringValue = stringValue.ToLower(); @@ -430,7 +430,8 @@ } value = stringValue; } - list.Add(new TypedValue(type, value, EntityMode.Poco)); // TODO NH Different behavior: In H3.2 EntityMode is nullable + list.Add(new TypedValue(type, value, EntityMode.Poco)); + // TODO NH Different behavior: In H3.2 EntityMode is nullable } } Modified: trunk/nhibernate/src/NHibernate/Engine/Cascade.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Cascade.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Engine/Cascade.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -218,9 +218,11 @@ private void CascadeCollectionElements(object child, CollectionType collectionType, CascadeStyle style, IType elemType, object anything, bool isCascadeDeleteEnabled) { // we can't cascade to non-embedded elements - bool embeddedElements = eventSource.EntityMode != EntityMode.Xml || ((EntityType)collectionType.GetElementType(eventSource.Factory)).IsEmbeddedInXML; + bool embeddedElements = eventSource.EntityMode != EntityMode.Xml + || ((EntityType) collectionType.GetElementType(eventSource.Factory)).IsEmbeddedInXML; - bool reallyDoCascade = style.ReallyDoCascade(action) && embeddedElements && child != CollectionType.UnfetchedCollection; + bool reallyDoCascade = style.ReallyDoCascade(action) && embeddedElements + && child != CollectionType.UnfetchedCollection; if (reallyDoCascade) { @@ -232,8 +234,9 @@ log.Info("done cascade " + action + " for collection: " + collectionType.Role); } - bool deleteOrphans = style.HasOrphanDelete && action.DeleteOrphans && - elemType.IsEntityType && child is IPersistentCollection; //a newly instantiated collection can't have orphans + var childAsPersColl = child as IPersistentCollection; + bool deleteOrphans = style.HasOrphanDelete && action.DeleteOrphans && elemType.IsEntityType + && childAsPersColl != null; //a newly instantiated collection can't have orphans if (deleteOrphans) { @@ -244,7 +247,7 @@ // 1. newly instantiated collections // 2. arrays (we can't track orphans for detached arrays) string entityName = collectionType.GetAssociatedEntityName(eventSource.Factory); - DeleteOrphans(entityName, (IPersistentCollection)child); + DeleteOrphans(entityName, childAsPersColl); log.Info("done deleting orphans for collection: " + collectionType.Role); } Modified: trunk/nhibernate/src/NHibernate/Engine/ExecuteUpdateResultCheckStyle.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/ExecuteUpdateResultCheckStyle.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Engine/ExecuteUpdateResultCheckStyle.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -1,6 +1,5 @@ using System; using NHibernate.SqlCommand; -using System.Runtime.Serialization; namespace NHibernate.Engine { @@ -39,12 +38,14 @@ public override bool Equals(object obj) { - if (obj is ExecuteUpdateResultCheckStyle) + var castedObj = obj as ExecuteUpdateResultCheckStyle; + if (castedObj != null) { - return this.name == ((ExecuteUpdateResultCheckStyle) obj).name; + return name == castedObj.name; } return false; } + public override int GetHashCode() { return name.GetHashCode(); Modified: trunk/nhibernate/src/NHibernate/Engine/StatefulPersistenceContext.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/StatefulPersistenceContext.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Engine/StatefulPersistenceContext.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -572,14 +572,13 @@ //{ // value = wrapper.Element; //} - - if (value is INHibernateProxy) + var proxy = value as INHibernateProxy; + if (proxy != null) { if (log.IsDebugEnabled) { log.Debug("setting proxy identifier: " + id); } - INHibernateProxy proxy = (INHibernateProxy)value; ILazyInitializer li = proxy.HibernateLazyInitializer; li.Identifier = id; ReassociateProxy(li, proxy); @@ -648,18 +647,14 @@ //{ // maybeProxy = wrapper.Element; //} - - if (maybeProxy is INHibernateProxy) + var proxy = maybeProxy as INHibernateProxy; + if (proxy != null) { - INHibernateProxy proxy = (INHibernateProxy)maybeProxy; ILazyInitializer li = proxy.HibernateLazyInitializer; ReassociateProxy(li, proxy); return li.GetImplementation(); //initialize + unwrap the object } - else - { - return maybeProxy; - } + return maybeProxy; } /// <summary> Modified: trunk/nhibernate/src/NHibernate/Engine/UnsavedValueFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/UnsavedValueFactory.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Engine/UnsavedValueFactory.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -11,7 +11,7 @@ { } - private static object[] NoParameters = new object[0]; + private static readonly object[] NoParameters = new object[0]; private static object Instantiate(ConstructorInfo constructor) { @@ -45,47 +45,42 @@ object defaultValue = identifierGetter.Get(Instantiate(constructor)); return new IdentifierValue(defaultValue); } - else if (identifierGetter != null && (identifierType is PrimitiveType)) + var idTypeAsPrimitiveType = identifierType as PrimitiveType; + if (identifierGetter != null && idTypeAsPrimitiveType != null) { - object defaultValue = ((PrimitiveType) identifierType).DefaultValue; + object defaultValue = idTypeAsPrimitiveType.DefaultValue; return new IdentifierValue(defaultValue); } - else - { - return IdentifierValue.SaveNull; - } + return IdentifierValue.SaveNull; } - else if ("null" == unsavedValue) + if ("null" == unsavedValue) { return IdentifierValue.SaveNull; } - else if( "undefined" == unsavedValue ) + if ("undefined" == unsavedValue) { return IdentifierValue.Undefined; } - else if ("none" == unsavedValue) + if ("none" == unsavedValue) { return IdentifierValue.SaveNone; } - else if ("any" == unsavedValue) + if ("any" == unsavedValue) { return IdentifierValue.SaveAny; } - else + try { - try - { - return new IdentifierValue(((IIdentifierType) identifierType).StringToObject(unsavedValue)); - } - catch (InvalidCastException cce) - { - throw new MappingException("Bad identifier type: " + identifierType.Name, cce); - } - catch (Exception e) - { - throw new MappingException("Could not parse identifier unsaved-value: " + unsavedValue, e); - } + return new IdentifierValue(((IIdentifierType) identifierType).StringToObject(unsavedValue)); } + catch (InvalidCastException cce) + { + throw new MappingException("Bad identifier type: " + identifierType.Name, cce); + } + catch (Exception e) + { + throw new MappingException("Could not parse identifier unsaved-value: " + unsavedValue, e); + } } public static VersionValue GetUnsavedVersionValue( Modified: trunk/nhibernate/src/NHibernate/Event/Default/DefaultLoadEventListener.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Event/Default/DefaultLoadEventListener.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Event/Default/DefaultLoadEventListener.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -169,7 +169,8 @@ private object ReturnNarrowedProxy(LoadEvent @event, IEntityPersister persister, EntityKey keyToLoad, LoadType options, IPersistenceContext persistenceContext, object proxy) { log.Debug("entity proxy found in session cache"); - ILazyInitializer li = ((INHibernateProxy)proxy).HibernateLazyInitializer; + var castedProxy = (INHibernateProxy) proxy; + ILazyInitializer li = castedProxy.HibernateLazyInitializer; if (li.Unwrap) { return li.GetImplementation(); @@ -189,7 +190,7 @@ // NH Different behavior : NH-1252 return null; } - return persistenceContext.NarrowProxy((INHibernateProxy)proxy, persister, keyToLoad, impl); + return persistenceContext.NarrowProxy(castedProxy, persister, keyToLoad, impl); } /// <summary> Modified: trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -423,9 +423,10 @@ { throw new ArgumentNullException("obj", "null object passed to GetCurrentLockMode"); } - if (obj is INHibernateProxy) + var proxy = obj as INHibernateProxy; + if (proxy != null) { - obj = ((INHibernateProxy)obj).HibernateLazyInitializer.GetImplementation(this); + obj = proxy.HibernateLazyInitializer.GetImplementation(this); if (obj == null) { return LockMode.None; @@ -1288,14 +1289,14 @@ using (new SessionIdLoggingContext(sessionId)) { CheckAndUpdateSessionStatus(); - INHibernateProxy proxy = obj as INHibernateProxy; + var proxy = obj as INHibernateProxy; if (proxy != null) { if (!persistenceContext.ContainsProxy(proxy)) { throw new TransientObjectException("proxy was not associated with the session"); } - ILazyInitializer li = ((INHibernateProxy)obj).HibernateLazyInitializer; + ILazyInitializer li = proxy.HibernateLazyInitializer; obj = li.GetImplementation(); } @@ -1513,25 +1514,23 @@ // Actually the case for proxies will probably work even with // the session closed, but do the check here anyway, so that // the behavior is uniform. - - if (obj is INHibernateProxy) + var proxy = obj as INHibernateProxy; + if (proxy != null) { - ILazyInitializer li = ((INHibernateProxy)obj).HibernateLazyInitializer; + ILazyInitializer li = proxy.HibernateLazyInitializer; if (li.Session != this) { throw new TransientObjectException("The proxy was not associated with this session"); } return li.Identifier; } - else + + EntityEntry entry = persistenceContext.GetEntry(obj); + if (entry == null) { - EntityEntry entry = persistenceContext.GetEntry(obj); - if (entry == null) - { - throw new TransientObjectException("the instance was not associated with this session"); - } - return entry.Id; + throw new TransientObjectException("the instance was not associated with this session"); } + return entry.Id; } } @@ -1940,12 +1939,12 @@ { using (new SessionIdLoggingContext(sessionId)) { - IEntityPersister persister = Factory.GetEntityPersister(entityName); - if (!(persister is IOuterJoinLoadable)) + var persister = Factory.GetEntityPersister(entityName) as IOuterJoinLoadable; + if (persister == null) { throw new MappingException("class persister is not OuterJoinLoadable: " + entityName); } - return (IOuterJoinLoadable)persister; + return persister; } } @@ -1954,13 +1953,13 @@ using (new SessionIdLoggingContext(sessionId)) { CheckAndUpdateSessionStatus(); - - if (obj is INHibernateProxy) + var proxy = obj as INHibernateProxy; + if (proxy != null) { //do not use proxiesByKey, since not all //proxies that point to this session's //instances are in that collection! - ILazyInitializer li = ((INHibernateProxy)obj).HibernateLazyInitializer; + ILazyInitializer li = proxy.HibernateLazyInitializer; if (li.IsUninitialized) { //if it is an uninitialized proxy, pointing Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -149,11 +149,12 @@ private ISqlLoadable GetSQLLoadable(string entityName) { IEntityPersister persister = factory.GetEntityPersister(entityName); - if (!(persister is ISqlLoadable)) + var persisterAsSqlLoadable = persister as ISqlLoadable; + if (persisterAsSqlLoadable == null) { throw new MappingException("class persister is not ISqlLoadable: " + entityName); } - return (ISqlLoadable) persister; + return persisterAsSqlLoadable; } private string GenerateEntitySuffix() Modified: trunk/nhibernate/src/NHibernate/Loader/Loader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -565,8 +565,9 @@ PostLoadEvent post; if (session.IsEventSource) { - pre = new PreLoadEvent((IEventSource) session); - post = new PostLoadEvent((IEventSource) session); + var eventSourceSession = (IEventSource) session; + pre = new PreLoadEvent(eventSourceSession); + post = new PostLoadEvent(eventSourceSession); } else { Modified: trunk/nhibernate/src/NHibernate/Util/ArrayHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Util/ArrayHelper.cs 2009-05-14 17:40:11 UTC (rev 4304) +++ trunk/nhibernate/src/NHibernate/Util/ArrayHelper.cs 2009-05-14 21:10:28 UTC (rev 4305) @@ -156,23 +156,24 @@ public static string[][] To2DStringArray(ICollection coll) { - string[][] result = new string[ coll.Count ][]; + var result = new string[ coll.Count ][]; int i = 0; foreach (object row in coll) { - if (row is ICollection) + var rowAsCollection = row as ICollection; + if (rowAsCollection != null) { - result[i] = new string[((ICollection)row).Count]; + result[i] = new string[rowAsCollection.Count]; int j = 0; - foreach (object cell in (ICollection)row) + foreach (object cell in rowAsCollection) { - result[i][j++] = cell == null ? null : (string)cell; + result[i][j++] = cell == null ? null : (string) cell; } } else { result[i] = new string[1]; - result[i][0] = row == null ? null : (string)row; + result[i][0] = row == null ? null : (string) row; } i++; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |