From: <fab...@us...> - 2009-03-14 03:09:42
|
Revision: 4125 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4125&view=rev Author: fabiomaulo Date: 2009-03-14 03:09:32 +0000 (Sat, 14 Mar 2009) Log Message: ----------- Improvement by Erich Eichinger Modified Paths: -------------- trunk/nhibernate/src/NHibernate.ByteCode.Spring/LazyInitializer.cs trunk/nhibernate/src/NHibernate.ByteCode.Spring/ProxyFactory.cs Modified: trunk/nhibernate/src/NHibernate.ByteCode.Spring/LazyInitializer.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Spring/LazyInitializer.cs 2009-03-11 21:26:06 UTC (rev 4124) +++ trunk/nhibernate/src/NHibernate.ByteCode.Spring/LazyInitializer.cs 2009-03-14 03:09:32 UTC (rev 4125) @@ -15,60 +15,35 @@ private static readonly MethodInfo exceptionInternalPreserveStackTrace = typeof (Exception).GetMethod("InternalPreserveStackTrace", BindingFlags.Instance | BindingFlags.NonPublic); - private static MethodInfo MapInterfaceMethodToImplementationIfNecessary(MethodInfo methodInfo, - System.Type implementingType) - { - MethodInfo concreteMethodInfo = methodInfo; - - if (methodInfo!= null && methodInfo.DeclaringType.IsInterface) - { - InterfaceMapping interfaceMapping = implementingType.GetInterfaceMap(methodInfo.DeclaringType); - int methodIndex = Array.IndexOf(interfaceMapping.InterfaceMethods, methodInfo); - concreteMethodInfo = interfaceMapping.TargetMethods[methodIndex]; - } - - return concreteMethodInfo; - } - public LazyInitializer(string entityName, System.Type persistentClass, object id, MethodInfo getIdentifierMethod, MethodInfo setIdentifierMethod, IAbstractComponentType componentIdType, ISessionImplementor session) : base( - entityName, persistentClass, id, MapInterfaceMethodToImplementationIfNecessary(getIdentifierMethod, persistentClass), - MapInterfaceMethodToImplementationIfNecessary(setIdentifierMethod, persistentClass), componentIdType, session) - { - InterceptCalls = true; - } + entityName, persistentClass.IsInterface ? typeof (object) : persistentClass, id, getIdentifierMethod, + setIdentifierMethod, componentIdType, session) {} - public bool InterceptCalls { get; set; } - #region Implementation of IInterceptor public object Invoke(IMethodInvocation info) { - object returnValue; try { - var methodInfo = info.Method; - returnValue = base.Invoke(methodInfo, info.Arguments, info.Proxy); + MethodInfo methodInfo = info.Method; + object returnValue = base.Invoke(methodInfo, info.Arguments, info.Proxy); if (returnValue != InvokeImplementation) { return returnValue; } - if (InterceptCalls) - { - var method = new SafeMethod(methodInfo); - return method.Invoke(GetImplementation(), info.Arguments); - } + + var method = new SafeMethod(methodInfo); + return method.Invoke(GetImplementation(), info.Arguments); } catch (TargetInvocationException ex) { - exceptionInternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] { }); + exceptionInternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] {}); throw ex.InnerException; } - - return returnValue; } #endregion @@ -77,17 +52,14 @@ object ITargetSource.GetTarget() { - return Target ?? this; + return Target; } - void ITargetSource.ReleaseTarget(object target) - { - //throw new System.NotImplementedException(); - } + void ITargetSource.ReleaseTarget(object target) {} System.Type ITargetSource.TargetType { - get { return base.PersistentClass; } + get { return PersistentClass; } } bool ITargetSource.IsStatic Modified: trunk/nhibernate/src/NHibernate.ByteCode.Spring/ProxyFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Spring/ProxyFactory.cs 2009-03-11 21:26:06 UTC (rev 4124) +++ trunk/nhibernate/src/NHibernate.ByteCode.Spring/ProxyFactory.cs 2009-03-14 03:09:32 UTC (rev 4125) @@ -13,7 +13,7 @@ /// <author>Erich Eichinger (Spring.NET Team)</author> public class ProxyFactory : AbstractProxyFactory { - private static readonly ILog log = LogManager.GetLogger(typeof(ProxyFactory)); + private static readonly ILog log = LogManager.GetLogger(typeof (ProxyFactory)); [Serializable] private class SerializableProxyFactory : global::Spring.Aop.Framework.ProxyFactory @@ -31,17 +31,14 @@ { try { - var initializer = new LazyInitializer(EntityName, PersistentClass, id, GetIdentifierMethod, SetIdentifierMethod, - ComponentIdType, session); + var initializer = new LazyInitializer(EntityName, PersistentClass.IsInterface ? typeof (object) : PersistentClass, + id, GetIdentifierMethod, SetIdentifierMethod, ComponentIdType, session); var proxyFactory = new SerializableProxyFactory {Interfaces = Interfaces, TargetSource = initializer, ProxyTargetType = IsClassProxy}; proxyFactory.AddAdvice(initializer); object proxyInstance = proxyFactory.GetProxy(); - - initializer.InterceptCalls = true; - return (INHibernateProxy) proxyInstance; } catch (Exception ex) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |