From: Kevin W. <kev...@us...> - 2004-12-31 22:08:36
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6679 Modified Files: INHibernateProxy.cs IProxyGenerator.cs LazyInitializer.cs Log Message: fixing xml comments and letting ReSharper do reformatting Index: LazyInitializer.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Proxy/LazyInitializer.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** LazyInitializer.cs 16 Dec 2004 21:51:48 -0000 1.4 --- LazyInitializer.cs 31 Dec 2004 22:08:25 -0000 1.5 *************** *** 1,7 **** using System; - using System.Collections; using System.Reflection; using System.Runtime.Serialization; ! using NHibernate.Engine; using NHibernate.Util; --- 1,6 ---- using System; using System.Reflection; using System.Runtime.Serialization; ! using log4net; using NHibernate.Engine; using NHibernate.Util; *************** *** 29,38 **** private object _target = null; private object _id; [NonSerialized] private ISessionImplementor _session; private System.Type _persistentClass; private PropertyInfo _identifierPropertyInfo; private bool _overridesEquals; ! /// <summary> /// Create a LazyInitializer to handle all of the Methods/Properties that are called --- 28,39 ---- private object _target = null; private object _id; + [NonSerialized] private ISessionImplementor _session; + private System.Type _persistentClass; private PropertyInfo _identifierPropertyInfo; private bool _overridesEquals; ! /// <summary> /// Create a LazyInitializer to handle all of the Methods/Properties that are called *************** *** 43,47 **** /// <param name="identifierPropertyInfo">The PropertyInfo for the <id> property.</param> /// <param name="session">The ISession this Proxy is in.</param> ! protected LazyInitializer(System.Type persistentClass, object id, PropertyInfo identifierPropertyInfo, ISessionImplementor session) { _persistentClass = persistentClass; --- 44,48 ---- /// <param name="identifierPropertyInfo">The PropertyInfo for the <id> property.</param> /// <param name="session">The ISession this Proxy is in.</param> ! protected LazyInitializer( System.Type persistentClass, object id, PropertyInfo identifierPropertyInfo, ISessionImplementor session ) { _persistentClass = persistentClass; *************** *** 49,53 **** _session = session; _identifierPropertyInfo = identifierPropertyInfo; ! _overridesEquals = ReflectHelper.OverridesEquals(_persistentClass); } --- 50,54 ---- _session = session; _identifierPropertyInfo = identifierPropertyInfo; ! _overridesEquals = ReflectHelper.OverridesEquals( _persistentClass ); } *************** *** 58,74 **** /// Thrown when the Proxy has no Session or the Session is not open. /// </exception> ! public void Initialize() { ! if( _target==null ) { ! if( _session==null ) { throw new HibernateException( "Could not initialize proxy - no Session." ); } ! else if( _session.IsOpen==false ) { throw new HibernateException( "Could not initialize proxy - the owning Session was closed." ); } ! else { _target = _session.ImmediateLoad( _persistentClass, _id ); --- 59,75 ---- /// Thrown when the Proxy has no Session or the Session is not open. /// </exception> ! public void Initialize() { ! if( _target == null ) { ! if( _session == null ) { throw new HibernateException( "Could not initialize proxy - no Session." ); } ! else if( _session.IsOpen == false ) { throw new HibernateException( "Could not initialize proxy - the owning Session was closed." ); } ! else { _target = _session.ImmediateLoad( _persistentClass, _id ); *************** *** 87,100 **** /// Thrown whenever a problem is encountered during the Initialization of the Proxy. /// </exception> ! private void InitializeWrapExceptions() { ! try { Initialize(); } ! catch( Exception e ) { ! log4net.LogManager.GetLogger(typeof(LazyInitializer)).Error("Exception initializing proxy.", e); ! throw new LazyInitializationException(e); } } --- 88,101 ---- /// Thrown whenever a problem is encountered during the Initialization of the Proxy. /// </exception> ! private void InitializeWrapExceptions() { ! try { Initialize(); } ! catch( Exception e ) { ! LogManager.GetLogger( typeof( LazyInitializer ) ).Error( "Exception initializing proxy.", e ); ! throw new LazyInitializationException( e ); } } *************** *** 110,145 **** /// itself or delegates calls to the method GetObjectData to the LazyInitializer. /// </remarks> ! protected virtual void AddSerializationInfo(SerializationInfo info) { } ! public object Identifier { get { return _id; } } ! public System.Type PersistentClass { get { return _persistentClass; } } ! public bool IsUninitialized { ! get { return (_target==null); } } ! public ISessionImplementor Session { get { return _session; } ! set { ! if(value!=_session) { ! if( _session!=null && _session.IsOpen ) { //TODO: perhaps this should be some other RuntimeException... ! throw new LazyInitializationException("Illegally attempted to associate a proxy with two open Sessions"); } ! else { _session = value; --- 111,150 ---- /// itself or delegates calls to the method GetObjectData to the LazyInitializer. /// </remarks> ! protected virtual void AddSerializationInfo( SerializationInfo info ) { } ! /// <summary></summary> ! public object Identifier { get { return _id; } } ! /// <summary></summary> ! public System.Type PersistentClass { get { return _persistentClass; } } ! /// <summary></summary> ! public bool IsUninitialized { ! get { return ( _target == null ); } } ! /// <summary></summary> ! public ISessionImplementor Session { get { return _session; } ! set { ! if( value != _session ) { ! if( _session != null && _session.IsOpen ) { //TODO: perhaps this should be some other RuntimeException... ! throw new LazyInitializationException( "Illegally attempted to associate a proxy with two open Sessions" ); } ! else { _session = value; *************** *** 153,157 **** /// </summary> /// <returns>The Persistent Object this proxy is Proxying.</returns> ! public object GetImplementation() { InitializeWrapExceptions(); --- 158,162 ---- /// </summary> /// <returns>The Persistent Object this proxy is Proxying.</returns> ! public object GetImplementation() { InitializeWrapExceptions(); *************** *** 164,171 **** /// <param name="s">The Session to get the object from.</param> /// <returns>The Persistent Object this proxy is Proxying, or <c>null</c>.</returns> ! public object GetImplementation(ISessionImplementor s) { ! Key key = new Key( Identifier, s.Factory.GetPersister(PersistentClass) ); ! return s.GetEntity(key); } --- 169,176 ---- /// <param name="s">The Session to get the object from.</param> /// <returns>The Persistent Object this proxy is Proxying, or <c>null</c>.</returns> ! public object GetImplementation( ISessionImplementor s ) { ! Key key = new Key( Identifier, s.Factory.GetPersister( PersistentClass ) ); ! return s.GetEntity( key ); } *************** *** 181,197 **** /// which indicates that the Proxy will need to forward to the real implementation. /// </returns> ! public virtual object Invoke(MethodBase method, params object[] args) { // if the Proxy Engine delegates the call of GetObjectData to the Initializer // then we need to handle it. Castle.DynamicProxy takes care of serializing // proxies for us, but other providers might not. ! if( method.Name.Equals("GetObjectData") ) { ! SerializationInfo info = (SerializationInfo)args[0]; ! StreamingContext context = (StreamingContext)args[1]; ! ! if( _target==null & _session!=null ) { ! Key key = new Key(_id, _session.Factory.GetPersister( _persistentClass ) ); _target = _session.GetEntity( key ); } --- 186,202 ---- /// which indicates that the Proxy will need to forward to the real implementation. /// </returns> ! public virtual object Invoke( MethodBase method, params object[ ] args ) { // if the Proxy Engine delegates the call of GetObjectData to the Initializer // then we need to handle it. Castle.DynamicProxy takes care of serializing // proxies for us, but other providers might not. ! if( method.Name.Equals( "GetObjectData" ) ) { ! SerializationInfo info = ( SerializationInfo ) args[ 0 ]; ! StreamingContext context = ( StreamingContext ) args[ 1 ]; // not used !?! ! ! if( _target == null & _session != null ) { ! Key key = new Key( _id, _session.Factory.GetPersister( _persistentClass ) ); _target = _session.GetEntity( key ); } *************** *** 204,208 **** return null; } ! else if( !_overridesEquals && _identifierPropertyInfo!=null && method.Name.Equals("GetHashCode") ) { // kinda dodgy, since it redefines the hashcode of the proxied object. --- 209,213 ---- return null; } ! else if( !_overridesEquals && _identifierPropertyInfo != null && method.Name.Equals( "GetHashCode" ) ) { // kinda dodgy, since it redefines the hashcode of the proxied object. *************** *** 211,230 **** return _id.GetHashCode(); } ! else if( _identifierPropertyInfo!=null && method.Equals( _identifierPropertyInfo.GetGetMethod(true) ) ) { return _id; } ! else if( method.Name.Equals( "Dispose" ) ) { return null; } ! else if ( args.Length==1 && !_overridesEquals && _identifierPropertyInfo!=null && method.Name.Equals( "Equals" ) ) { // less dodgy because NHibernate forces == to be the same as Identifier Equals ! return _id.Equals( _identifierPropertyInfo.GetValue( _target, null ) ); } ! ! else { return InvokeImplementation; --- 216,235 ---- return _id.GetHashCode(); } ! else if( _identifierPropertyInfo != null && method.Equals( _identifierPropertyInfo.GetGetMethod( true ) ) ) { return _id; } ! else if( method.Name.Equals( "Dispose" ) ) { return null; } ! else if( args.Length == 1 && !_overridesEquals && _identifierPropertyInfo != null && method.Name.Equals( "Equals" ) ) { // less dodgy because NHibernate forces == to be the same as Identifier Equals ! return _id.Equals( _identifierPropertyInfo.GetValue( _target, null ) ); } ! ! else { return InvokeImplementation; *************** *** 233,235 **** } } ! } --- 238,240 ---- } } ! } \ No newline at end of file Index: IProxyGenerator.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Proxy/IProxyGenerator.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IProxyGenerator.cs 9 Dec 2004 17:52:16 -0000 1.2 --- IProxyGenerator.cs 31 Dec 2004 22:08:25 -0000 1.3 *************** *** 1,5 **** - using System; using System.Reflection; - using NHibernate.Engine; --- 1,3 ---- *************** *** 11,15 **** public interface IProxyGenerator { - /// <summary> /// Build a proxy using the Castle.DynamicProxy library. --- 9,12 ---- *************** *** 20,25 **** /// <param name="id">The value for the Id.</param> /// <param name="session">The Session the proxy is in.</param> /// <returns>A fully built <c>INHibernateProxy</c>.</returns> ! INHibernateProxy GetProxy(System.Type persistentClass, System.Type concreteProxy, System.Type[] interfaces, PropertyInfo identifierPropertyInfo, object id, ISessionImplementor session); /// <summary> --- 17,23 ---- /// <param name="id">The value for the Id.</param> /// <param name="session">The Session the proxy is in.</param> + /// <param name="concreteProxy"></param> /// <returns>A fully built <c>INHibernateProxy</c>.</returns> ! INHibernateProxy GetProxy( System.Type persistentClass, System.Type concreteProxy, System.Type[ ] interfaces, PropertyInfo identifierPropertyInfo, object id, ISessionImplementor session ); /// <summary> *************** *** 28,32 **** /// <param name="proxy">The Proxy object</param> /// <returns>The <see cref="LazyInitializer"/> that contains the details of the Proxied object.</returns> ! LazyInitializer GetLazyInitializer(INHibernateProxy proxy); /// <summary> --- 26,30 ---- /// <param name="proxy">The Proxy object</param> /// <returns>The <see cref="LazyInitializer"/> that contains the details of the Proxied object.</returns> ! LazyInitializer GetLazyInitializer( INHibernateProxy proxy ); /// <summary> *************** *** 36,40 **** /// <param name="obj">The object to get the type of.</param> /// <returns>The Underlying Type for the object regardless of if it is a Proxy.</returns> ! System.Type GetClass(object obj); } ! } --- 34,38 ---- /// <param name="obj">The object to get the type of.</param> /// <returns>The Underlying Type for the object regardless of if it is a Proxy.</returns> ! System.Type GetClass( object obj ); } ! } \ No newline at end of file Index: INHibernateProxy.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Proxy/INHibernateProxy.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** INHibernateProxy.cs 16 Dec 2004 21:51:48 -0000 1.3 --- INHibernateProxy.cs 31 Dec 2004 22:08:25 -0000 1.4 *************** *** 1,4 **** - using System; - namespace NHibernate.Proxy { --- 1,2 ---- *************** *** 21,23 **** { } ! } --- 19,21 ---- { } ! } \ No newline at end of file |