From: <fab...@us...> - 2010-12-22 17:30:54
|
Revision: 5334 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5334&view=rev Author: fabiomaulo Date: 2010-12-22 17:30:48 +0000 (Wed, 22 Dec 2010) Log Message: ----------- Fix NH-2457 (thanks to Maximilian Haru Raditya for the implementation without tests) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs trunk/nhibernate/src/NHibernate/IStatelessSession.cs trunk/nhibernate/src/NHibernate/Impl/StatelessSessionImpl.cs trunk/nhibernate/src/NHibernate.Test/Stateless/StatelessSessionFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs 2010-12-19 18:40:07 UTC (rev 5333) +++ trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs 2010-12-22 17:30:48 UTC (rev 5334) @@ -71,7 +71,7 @@ /// to actually run the query.</summary> public ICriteria GetExecutableCriteria(IStatelessSession session) { - impl.Session = (ISessionImplementor)session; + impl.Session = session.GetSessionImplementation(); return impl; } Modified: trunk/nhibernate/src/NHibernate/IStatelessSession.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IStatelessSession.cs 2010-12-19 18:40:07 UTC (rev 5333) +++ trunk/nhibernate/src/NHibernate/IStatelessSession.cs 2010-12-22 17:30:48 UTC (rev 5334) @@ -1,6 +1,8 @@ using System; using System.Data; +using NHibernate.Engine; + namespace NHibernate { /// <summary> @@ -24,6 +26,18 @@ /// <summary> Get the current Hibernate transaction.</summary> ITransaction Transaction { get;} + /// <summary> + /// Gets the stateless session implementation. + /// </summary> + /// <remarks> + /// This method is provided in order to get the <b>NHibernate</b> implementation of the session from wrapper implementations. + /// Implementors of the <seealso cref="IStatelessSession"/> interface should return the NHibernate implementation of this method. + /// </remarks> + /// <returns> + /// An NHibernate implementation of the <seealso cref="ISessionImplementor"/> interface + /// </returns> + ISessionImplementor GetSessionImplementation(); + /// <summary> Close the stateless session and release the ADO.NET connection.</summary> void Close(); Modified: trunk/nhibernate/src/NHibernate/Impl/StatelessSessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/StatelessSessionImpl.cs 2010-12-19 18:40:07 UTC (rev 5333) +++ trunk/nhibernate/src/NHibernate/Impl/StatelessSessionImpl.cs 2010-12-22 17:30:48 UTC (rev 5334) @@ -543,6 +543,21 @@ set { } } + /// <summary> + /// Gets the stateless session implementation. + /// </summary> + /// <remarks> + /// This method is provided in order to get the <b>NHibernate</b> implementation of the session from wrapper implementations. + /// Implementors of the <seealso cref="IStatelessSession"/> interface should return the NHibernate implementation of this method. + /// </remarks> + /// <returns> + /// An NHibernate implementation of the <seealso cref="ISessionImplementor"/> interface + /// </returns> + public ISessionImplementor GetSessionImplementation() + { + return this; + } + /// <summary> Close the stateless session and release the ADO.NET connection.</summary> public void Close() { Modified: trunk/nhibernate/src/NHibernate.Test/Stateless/StatelessSessionFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Stateless/StatelessSessionFixture.cs 2010-12-19 18:40:07 UTC (rev 5333) +++ trunk/nhibernate/src/NHibernate.Test/Stateless/StatelessSessionFixture.cs 2010-12-22 17:30:48 UTC (rev 5334) @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Threading; +using NHibernate.Criterion; using NHibernate.Engine; using NUnit.Framework; using SharpTestsEx; @@ -189,5 +190,26 @@ impl.Batcher.BatchSize.Should().Be(37); } } + + [Test] + public void CanGetImplementor() + { + using (IStatelessSession ss = sessions.OpenStatelessSession()) + { + ss.GetSessionImplementation().Should().Be.SameInstanceAs(ss); + } + } + + [Test] + public void HavingDetachedCriteriaThenCanGetExecutableCriteriaFromStatelessSession() + { + var dc = DetachedCriteria.For<Paper>(); + using (IStatelessSession ss = sessions.OpenStatelessSession()) + { + ICriteria criteria = null; + Executing.This(()=> criteria = dc.GetExecutableCriteria(ss)).Should().NotThrow(); + criteria.Executing(c => c.List()).NotThrows(); + } + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |