From: Sergey K. <jus...@us...> - 2005-02-11 21:27:34
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5205/src/NHibernate/Impl Modified Files: SessionImpl.cs Log Message: ISession.Get implementation (both overloads), including a test Index: SessionImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionImpl.cs,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** SessionImpl.cs 7 Feb 2005 01:34:41 -0000 1.65 --- SessionImpl.cs 11 Feb 2005 21:26:23 -0000 1.66 *************** *** 2334,2350 **** /// Load the data for the object with the specified id into a newly created object /// using "for update", if supported. A new key will be assigned to the object. ! /// This should return an existing proxy where appropriate. /// </summary> /// <param name="clazz"></param> /// <param name="id"></param> /// <param name="lockMode"></param> /// <returns></returns> ! public object Load( System.Type clazz, object id, LockMode lockMode ) { - if( lockMode == LockMode.Write ) - { - throw new HibernateException( "invalid lock mode for Load()" ); - } - if( log.IsDebugEnabled ) { --- 2334,2347 ---- /// Load the data for the object with the specified id into a newly created object /// using "for update", if supported. A new key will be assigned to the object. ! /// This method always hits the db, and does not create proxies. It should return ! /// an existing proxy where appropriate. /// </summary> /// <param name="clazz"></param> /// <param name="id"></param> /// <param name="lockMode"></param> + /// <param name="allowNull"></param> /// <returns></returns> ! private object DoLoad( System.Type clazz, object id, LockMode lockMode, bool allowNull ) { if( log.IsDebugEnabled ) { *************** *** 2376,2386 **** } ! ThrowObjectNotFound( result, id, persister.MappedClass ); ! // retunr existing proxy (if one exists) return ProxyFor( persister, new Key( id, persister ), result ); } /// <summary> /// Actually do all the hard work of loading up an object /// </summary> --- 2373,2440 ---- } ! if( !allowNull ) ThrowObjectNotFound( result, id, persister.MappedClass ); ! // return existing proxy (if one exists) return ProxyFor( persister, new Key( id, persister ), result ); } /// <summary> + /// Load the data for the object with the specified id into a newly created object + /// using "for update", if supported. A new key will be assigned to the object. + /// This should return an existing proxy where appropriate. + /// + /// If the object does not exist in the database, an exception is thrown. + /// </summary> + /// <param name="clazz"></param> + /// <param name="id"></param> + /// <param name="lockMode"></param> + /// <returns></returns> + /// <exception cref="ObjectNotFoundException"> + /// Thrown when the object with the specified id does not exist in the database. + /// </exception> + public object Load( System.Type clazz, object id, LockMode lockMode ) + { + if( lockMode == LockMode.Write ) + { + throw new HibernateException( "invalid lock mode for Load()" ); + } + + if( lockMode == LockMode.None ) + { + // we don't necessarily need to hit the db in this case + return Load( clazz, id ); + } + + return DoLoad( clazz, id, lockMode, false ); + } + + /// <summary> + /// Load the data for the object with the specified id into a newly created object + /// using "for update", if supported. A new key will be assigned to the object. + /// This should return an existing proxy where appropriate. + /// + /// If the object does not exist in the database, null is returned. + /// </summary> + /// <param name="clazz"></param> + /// <param name="id"></param> + /// <param name="lockMode"></param> + /// <returns></returns> + public object Get( System.Type clazz, object id, LockMode lockMode ) + { + if( lockMode == LockMode.Write ) + { + throw new HibernateException( "invalid lock mode for Get()" ); + } + + if( lockMode == LockMode.None ) + { + // we don't necessarily need to hit the db in this case + return Load( clazz, id ); + } + + return DoLoad( clazz, id, lockMode, true ); + } + + /// <summary> /// Actually do all the hard work of loading up an object /// </summary> |