From: <fab...@us...> - 2009-04-15 14:17:30
|
Revision: 4181 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4181&view=rev Author: fabiomaulo Date: 2009-04-15 14:17:10 +0000 (Wed, 15 Apr 2009) Log Message: ----------- - Fix NH-1741 - Fixed some other issues related with query property set from mapping Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/NamedQueryBinder.cs trunk/nhibernate/src/NHibernate/IDetachedQuery.cs trunk/nhibernate/src/NHibernate/Impl/AbstractDetachedQuery.cs trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs trunk/nhibernate/src/NHibernate/Impl/DetachedNamedQuery.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj trunk/nhibernate/src/NHibernate.Test/QueryTest/DetachedQueryFixture.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/Domain.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/NamedQueryBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/NamedQueryBinder.cs 2009-04-14 22:39:25 UTC (rev 4180) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/NamedQueryBinder.cs 2009-04-15 14:17:10 UTC (rev 4181) @@ -29,7 +29,7 @@ int timeout = string.IsNullOrEmpty(querySchema.timeout) ? RowSelection.NoValue : int.Parse(querySchema.timeout); int fetchSize = querySchema.fetchsizeSpecified ? querySchema.fetchsize : -1; bool readOnly = querySchema.readonlySpecified ? querySchema.@readonly : false; - string comment = null; + string comment = querySchema.comment; FlushMode flushMode = FlushModeConverter.GetFlushMode(querySchema); CacheMode? cacheMode = (querySchema.cachemodeSpecified) Modified: trunk/nhibernate/src/NHibernate/IDetachedQuery.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IDetachedQuery.cs 2009-04-14 22:39:25 UTC (rev 4180) +++ trunk/nhibernate/src/NHibernate/IDetachedQuery.cs 2009-04-15 14:17:10 UTC (rev 4181) @@ -1,6 +1,5 @@ using System; using System.Collections; -using NHibernate; using NHibernate.Transform; using NHibernate.Type; @@ -54,6 +53,10 @@ /// <param name="timeout"></param> IDetachedQuery SetTimeout(int timeout); + /// <summary> Set a fetch size for the underlying ADO query.</summary> + /// <param name="fetchSize">the fetch size </param> + IDetachedQuery SetFetchSize(int fetchSize); + /// <summary> /// Set the lockmode for the objects idententified by the /// given alias that appears in the <c>FROM</c> clause. @@ -62,6 +65,10 @@ /// <param name="lockMode"></param> void SetLockMode(string alias, LockMode lockMode); + /// <summary> Add a comment to the generated SQL.</summary> + /// <param name="comment">a human-readable string </param> + IDetachedQuery SetComment(string comment); + /// <summary> /// Bind a value to an indexed parameter. /// </summary> Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractDetachedQuery.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/AbstractDetachedQuery.cs 2009-04-14 22:39:25 UTC (rev 4180) +++ trunk/nhibernate/src/NHibernate/Impl/AbstractDetachedQuery.cs 2009-04-15 14:17:10 UTC (rev 4181) @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using NHibernate; using NHibernate.Engine; using NHibernate.Proxy; using NHibernate.Transform; @@ -51,6 +50,7 @@ protected IResultTransformer resultTransformer; protected bool shouldIgnoredUnknownNamedParameters; protected CacheMode? cacheMode; + protected string comment; #region IDetachedQuery Members @@ -68,30 +68,42 @@ return this; } - public IDetachedQuery SetCacheable(bool cacheable) + public virtual IDetachedQuery SetComment(string comment) { + this.comment = comment; + return this; + } + + public virtual IDetachedQuery SetCacheable(bool cacheable) + { this.cacheable = cacheable; return this; } - public IDetachedQuery SetCacheRegion(string cacheRegion) + public virtual IDetachedQuery SetCacheRegion(string cacheRegion) { this.cacheRegion = cacheRegion; return this; } - public IDetachedQuery SetReadOnly(bool readOnly) + public virtual IDetachedQuery SetReadOnly(bool readOnly) { this.readOnly = readOnly; return this; } - public IDetachedQuery SetTimeout(int timeout) + public virtual IDetachedQuery SetTimeout(int timeout) { selection.Timeout = timeout; return this; } + public virtual IDetachedQuery SetFetchSize(int fetchSize) + { + selection.FetchSize = fetchSize; + return this; + } + public void SetLockMode(string alias, LockMode lockMode) { if (string.IsNullOrEmpty(alias)) @@ -368,7 +380,7 @@ return this; } - public IDetachedQuery SetFlushMode(FlushMode flushMode) + public virtual IDetachedQuery SetFlushMode(FlushMode flushMode) { this.flushMode = flushMode; return this; @@ -389,7 +401,7 @@ /// <summary> Override the current session cache mode, just for this query. </summary> /// <param name="cacheMode">The cache mode to use. </param> /// <returns> this (for method chaining) </returns> - public IDetachedQuery SetCacheMode(CacheMode cacheMode) + public virtual IDetachedQuery SetCacheMode(CacheMode cacheMode) { this.cacheMode = cacheMode; return this; @@ -411,7 +423,10 @@ .SetCacheable(cacheable) .SetReadOnly(readOnly) .SetTimeout(selection.Timeout) - .SetFlushMode(flushMode); + .SetFlushMode(flushMode) + .SetFetchSize(selection.FetchSize); + if (!string.IsNullOrEmpty(comment)) + q.SetComment(comment); if (!string.IsNullOrEmpty(cacheRegion)) q.SetCacheRegion(cacheRegion); if (resultTransformer != null) @@ -474,6 +489,7 @@ flushMode = FlushMode.Unspecified; resultTransformer = null; shouldIgnoredUnknownNamedParameters = false; + comment = null; } private void ClearParameters() @@ -503,7 +519,10 @@ .SetCacheable(cacheable) .SetReadOnly(readOnly) .SetTimeout(selection.Timeout) - .SetFlushMode(flushMode); + .SetFlushMode(flushMode) + .SetFetchSize(selection.FetchSize); + if (!string.IsNullOrEmpty(comment)) + destination.SetComment(comment); if (!string.IsNullOrEmpty(cacheRegion)) destination.SetCacheRegion(cacheRegion); if (cacheMode.HasValue) Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-04-14 22:39:25 UTC (rev 4180) +++ trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-04-15 14:17:10 UTC (rev 4181) @@ -222,6 +222,7 @@ { query.SetComment(nqd.Comment); } + query.SetFlushMode(nqd.FlushMode); } public virtual IQuery CreateQuery(string queryString) Modified: trunk/nhibernate/src/NHibernate/Impl/DetachedNamedQuery.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/DetachedNamedQuery.cs 2009-04-14 22:39:25 UTC (rev 4180) +++ trunk/nhibernate/src/NHibernate/Impl/DetachedNamedQuery.cs 2009-04-15 14:17:10 UTC (rev 4181) @@ -1,4 +1,5 @@ using System; +using NHibernate.Engine; namespace NHibernate.Impl { @@ -13,6 +14,15 @@ public class DetachedNamedQuery : AbstractDetachedQuery { private readonly string queryName; + private bool cacheableWasSet; + private bool cacheModeWasSet; + private bool cacheRegionWasSet; + private bool readOnlyWasSet; + private bool timeoutWasSet; + private bool fetchSizeWasSet; + private bool commentWasSet; + private bool flushModeWasSet; + /// <summary> /// Create a new instance of <see cref="DetachedNamedQuery"/> for a named query string defined in the mapping file. /// </summary> @@ -39,19 +49,112 @@ public override IQuery GetExecutableQuery(ISession session) { IQuery result = session.GetNamedQuery(queryName); + SetDefaultProperties((ISessionFactoryImplementor)session.SessionFactory); SetQueryProperties(result); return result; } + private void SetDefaultProperties(ISessionFactoryImplementor factory) + { + NamedQueryDefinition nqd = factory.GetNamedQuery(queryName) ?? factory.GetNamedSQLQuery(queryName); + + if (!cacheableWasSet) + { + cacheable = nqd.IsCacheable; + } + + if (!cacheRegionWasSet) + { + cacheRegion = nqd.CacheRegion; + } + + if(!timeoutWasSet && nqd.Timeout != -1) + { + selection.Timeout= nqd.Timeout; + } + + if (!fetchSizeWasSet && nqd.FetchSize != -1) + { + selection.FetchSize = nqd.FetchSize; + } + + if (!cacheModeWasSet && nqd.CacheMode.HasValue) + { + cacheMode = nqd.CacheMode.Value; + } + + if (!readOnlyWasSet) + { + readOnly = nqd.IsReadOnly; + } + + if (!commentWasSet && nqd.Comment != null) + { + comment = nqd.Comment; + } + + if(!flushModeWasSet) + { + flushMode = nqd.FlushMode; + } + } + /// <summary> /// Creates a new DetachedNamedQuery that is a deep copy of the current instance. /// </summary> /// <returns>The clone.</returns> public DetachedNamedQuery Clone() { - DetachedNamedQuery result = new DetachedNamedQuery(queryName); + var result = new DetachedNamedQuery(queryName); CopyTo(result); return result; } + + public override IDetachedQuery SetCacheable(bool cacheable) + { + cacheableWasSet = true; + return base.SetCacheable(cacheable); + } + + public override IDetachedQuery SetCacheMode(CacheMode cacheMode) + { + cacheModeWasSet = true; + return base.SetCacheMode(cacheMode); + } + public override IDetachedQuery SetCacheRegion(string cacheRegion) + { + cacheRegionWasSet = true; + return base.SetCacheRegion(cacheRegion); + } + + public override IDetachedQuery SetReadOnly(bool readOnly) + { + readOnlyWasSet = true; + return base.SetReadOnly(readOnly); + } + + public override IDetachedQuery SetTimeout(int timeout) + { + timeoutWasSet = true; + return base.SetTimeout(timeout); + } + + public override IDetachedQuery SetFetchSize(int fetchSize) + { + fetchSizeWasSet = true; + return base.SetFetchSize(fetchSize); + } + + public override IDetachedQuery SetComment(string comment) + { + commentWasSet = true; + return base.SetComment(comment); + } + + public override IDetachedQuery SetFlushMode(FlushMode flushMode) + { + flushModeWasSet = true; + return base.SetFlushMode(flushMode); + } } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/Domain.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/Domain.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/Domain.cs 2009-04-15 14:17:10 UTC (rev 4181) @@ -0,0 +1,7 @@ +namespace NHibernate.Test.NHSpecificTest.NH1741 +{ + public class A + { + public virtual string Name { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/Fixture.cs 2009-04-15 14:17:10 UTC (rev 4181) @@ -0,0 +1,139 @@ +using System.Reflection; +using NHibernate.Engine; +using NHibernate.Impl; +using NUnit.Framework; +using NHibernate.Util; +using NUnit.Framework.SyntaxHelpers; + +namespace NHibernate.Test.NHSpecificTest.NH1741 +{ + [TestFixture] + public class Fixture: BugTestCase + { + private const string QueryName = "NH1741_All"; + + public class DetachedNamedQueryCrack : DetachedNamedQuery + { + private readonly FieldInfo fiCacheable = typeof(AbstractQueryImpl).GetField("cacheable", ReflectHelper.AnyVisibilityInstance); + private readonly FieldInfo fiCacheRegion = typeof(AbstractQueryImpl).GetField("cacheRegion", ReflectHelper.AnyVisibilityInstance); + private readonly FieldInfo fiCacheMode = typeof(AbstractQueryImpl).GetField("cacheMode", ReflectHelper.AnyVisibilityInstance); + private readonly FieldInfo fiReadOnly = typeof(AbstractQueryImpl).GetField("readOnly", ReflectHelper.AnyVisibilityInstance); + private readonly FieldInfo fiSelection = typeof(AbstractQueryImpl).GetField("selection", ReflectHelper.AnyVisibilityInstance); + private readonly FieldInfo fiComment = typeof(AbstractQueryImpl).GetField("comment", ReflectHelper.AnyVisibilityInstance); + private readonly FieldInfo fiFlushMode = typeof(AbstractQueryImpl).GetField("flushMode", ReflectHelper.AnyVisibilityInstance); + + private QueryImpl queryExecutable; + public DetachedNamedQueryCrack(string queryName) : base(queryName) { } + public override IQuery GetExecutableQuery(ISession session) + { + var result = base.GetExecutableQuery(session); + queryExecutable = (QueryImpl)result; + return result; + } + + public bool Cacheable + { + get + { + return (bool)fiCacheable.GetValue(queryExecutable); + } + } + + public string CacheRegion + { + get + { + return (string)fiCacheRegion.GetValue(queryExecutable); + } + } + + public int Timeout + { + get + { + return ((RowSelection)fiSelection.GetValue(queryExecutable)).Timeout; + } + } + + public int FetchSize + { + get + { + return ((RowSelection)fiSelection.GetValue(queryExecutable)).FetchSize; + } + } + + public CacheMode? CacheMode + { + get + { + return (CacheMode?)fiCacheMode.GetValue(queryExecutable); + } + } + + public bool ReadOnly + { + get + { + return (bool)fiReadOnly.GetValue(queryExecutable); + } + } + + public string Comment + { + get + { + return (string)fiComment.GetValue(queryExecutable); + } + } + + public FlushMode FlushMode + { + get + { + return (FlushMode)fiFlushMode.GetValue(queryExecutable); + } + } + } + + [Test] + [Description("DetachedNamedQuery should read all mapped parameters when not explicitly set.")] + public void Bug() + { + var dq = new DetachedNamedQueryCrack(QueryName); + ISession s = sessions.OpenSession(); + dq.GetExecutableQuery(s); + s.Close(); + + Assert.That(dq.Cacheable); + Assert.That(dq.CacheRegion, Is.EqualTo("region")); + Assert.That(dq.ReadOnly); + Assert.That(dq.Timeout, Is.EqualTo(10)); + Assert.That(dq.CacheMode, Is.EqualTo(CacheMode.Normal)); + Assert.That(dq.FetchSize, Is.EqualTo(11)); + Assert.That(dq.Comment, Is.EqualTo("the comment")); + Assert.That(dq.FlushMode, Is.EqualTo(FlushMode.Auto)); + } + + [Test] + [Description("DetachedNamedQuery should override all mapped parameters when explicitly set.")] + public void Override() + { + var dq = new DetachedNamedQueryCrack(QueryName); + dq.SetCacheable(false).SetCacheRegion("another region").SetReadOnly(false).SetTimeout(20).SetCacheMode( + CacheMode.Refresh).SetFetchSize(22).SetComment("another comment").SetFlushMode(FlushMode.Commit); + ISession s = sessions.OpenSession(); + dq.GetExecutableQuery(s); + s.Close(); + + Assert.That(!dq.Cacheable); + Assert.That(dq.CacheRegion, Is.EqualTo("another region")); + Assert.That(!dq.ReadOnly); + Assert.That(dq.Timeout, Is.EqualTo(20)); + Assert.That(dq.CacheMode, Is.EqualTo(CacheMode.Refresh)); + Assert.That(dq.FetchSize, Is.EqualTo(22)); + Assert.That(dq.Comment, Is.EqualTo("another comment")); + Assert.That(dq.FlushMode, Is.EqualTo(FlushMode.Commit)); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1741/Mappings.hbm.xml 2009-04-15 14:17:10 UTC (rev 4181) @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1741"> + + <class name="A"> + <id type="int"> + <generator class="native" /> + </id> + <property name="Name"/> + </class> + + <query name="NH1741_All" + cacheable="true" + cache-region="region" + read-only="true" + timeout="10" + cache-mode="normal" + fetch-size="11" + flush-mode="auto" + comment="the comment"> + from A + </query> +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-04-14 22:39:25 UTC (rev 4180) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-04-15 14:17:10 UTC (rev 4181) @@ -320,6 +320,8 @@ <Compile Include="NHSpecificTest\NH1715\ClassA.cs" /> <Compile Include="NHSpecificTest\NH1716\ClassA.cs" /> <Compile Include="NHSpecificTest\NH1716\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1741\Domain.cs" /> + <Compile Include="NHSpecificTest\NH1741\Fixture.cs" /> <Compile Include="NHSpecificTest\NH645\HQLFunctionFixture.cs" /> <Compile Include="HQL\HQLFunctions.cs" /> <Compile Include="HQL\Human.cs" /> @@ -1713,6 +1715,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1741\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1716\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\Dates\Mappings\TimeAsTimeSpan.hbm.xml" /> <EmbeddedResource Include="TypesTest\CurrencyClass.hbm.xml" /> Modified: trunk/nhibernate/src/NHibernate.Test/QueryTest/DetachedQueryFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/QueryTest/DetachedQueryFixture.cs 2009-04-14 22:39:25 UTC (rev 4180) +++ trunk/nhibernate/src/NHibernate.Test/QueryTest/DetachedQueryFixture.cs 2009-04-15 14:17:10 UTC (rev 4181) @@ -6,11 +6,12 @@ using NHibernate.Transform; using NHibernate.Util; using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; namespace NHibernate.Test.QueryTest { [TestFixture] - public class DetachedQueryFixture:TestCase + public class DetachedQueryFixture : TestCase { protected override string MappingsAssembly { @@ -23,6 +24,8 @@ } public const int totalFoo = 15; + private const string MyComment = "My Comment"; + protected override void OnSetUp() { using (ISession s = OpenSession()) @@ -50,8 +53,8 @@ { TestDetachedQuery tdq = new TestDetachedQuery(); tdq.SetMaxResults(10).SetFirstResult(5).SetCacheable(true).SetReadOnly(true).SetTimeout(444).SetFlushMode( - FlushMode.Auto).SetCacheRegion("A_REGION").SetResultTransformer(new AliasToBeanResultTransformer(typeof (NoFoo))). - SetIgnoreUknownNamedParameters(true); + FlushMode.Auto).SetCacheRegion("A_REGION").SetResultTransformer(new AliasToBeanResultTransformer(typeof(NoFoo))). + SetIgnoreUknownNamedParameters(true).SetComment(MyComment); Assert.AreEqual(10, tdq.Selection.MaxRows); Assert.AreEqual(5, tdq.Selection.FirstRow); Assert.AreEqual(444, tdq.Selection.Timeout); @@ -61,6 +64,7 @@ Assert.AreEqual("A_REGION", tdq.CacheRegion); Assert.IsNotNull(tdq.ResultTransformer); Assert.IsTrue(tdq.ShouldIgnoredUnknownNamedParameters); + Assert.That(tdq.Comment, Is.EqualTo(MyComment)); tdq.SetLockMode("LM1", LockMode.Upgrade); tdq.SetLockMode("LM2", LockMode.Write); @@ -77,7 +81,7 @@ Assert.IsTrue(tdq.OptionalUntypeParams[1].Equals(new Foo("Fulano", "De Tal"))); tdq.SetAnsiString(1, ""); - tdq.SetBinary(2, new byte[] {}); + tdq.SetBinary(2, new byte[] { }); tdq.SetBoolean(3, false); tdq.SetByte(4, 255); tdq.SetCharacter(5, 'A'); @@ -158,7 +162,7 @@ Assert.AreEqual(1, tdq.NamedUntypeParams.Count); Assert.IsTrue(tdq.NamedUntypeParams.ContainsKey("Any")); - tdq.SetParameterList("UntypedList", new int[] {1, 2, 3}); + tdq.SetParameterList("UntypedList", new int[] { 1, 2, 3 }); Assert.IsTrue(tdq.NamedUntypeListParams.ContainsKey("UntypedList")); tdq.SetParameterList("TypedList", new Int64[] { 1, 2, 3 }, NHibernateUtil.Int64); @@ -171,18 +175,19 @@ { TestDetachedQuery origin = new TestDetachedQuery(); origin.SetMaxResults(10).SetFirstResult(5).SetCacheable(true).SetReadOnly(true).SetTimeout(444).SetFlushMode - (FlushMode.Auto).SetCacheRegion("A_REGION").SetResultTransformer(new AliasToBeanResultTransformer(typeof (NoFoo))); + (FlushMode.Auto).SetCacheRegion("A_REGION").SetResultTransformer(new AliasToBeanResultTransformer(typeof(NoFoo))); + origin.SetComment(MyComment); origin.SetLockMode("LM1", LockMode.Upgrade); origin.SetProperties(new Foo("Pallino", "Pinco")); origin.SetInt64(1, 1); - origin.SetBinary(2, new byte[] {}); + origin.SetBinary(2, new byte[] { }); origin.SetBoolean(3, false); origin.SetDateTime(6, DateTime.MaxValue); origin.SetCharacter("5", 'A'); origin.SetDateTime("6", DateTime.MaxValue); origin.SetDecimal("7", 10.15m); - origin.SetParameterList("UntypedList", new int[] {1, 2, 3}); - origin.SetParameterList("TypedList", new Int64[] {1, 2, 3}, NHibernateUtil.Int64); + origin.SetParameterList("UntypedList", new int[] { 1, 2, 3 }); + origin.SetParameterList("TypedList", new Int64[] { 1, 2, 3 }, NHibernateUtil.Int64); TestDetachedQuery tdq = new TestDetachedQuery(); tdq.SetLockMode("LM1", LockMode.Read); @@ -195,9 +200,9 @@ tdq.SetDateTime("6", DateTime.MinValue); // will be override tdq.SetDouble("8", 8.1f); tdq.SetEntity("9", new Foo("Fulano", "De Tal")); - tdq.SetParameterList("UntypedList", new int[] {5, 6, 7, 8}); // will be override - tdq.SetParameterList("TypedList", new Int64[] {5, 6, 7, 8}, NHibernateUtil.Int64); // will be override - + tdq.SetParameterList("UntypedList", new int[] { 5, 6, 7, 8 }); // will be override + tdq.SetParameterList("TypedList", new Int64[] { 5, 6, 7, 8 }, NHibernateUtil.Int64); // will be override + tdq.SetComment("other comment"); // will be override origin.CopyTo(tdq); Assert.AreEqual(5, tdq.Selection.FirstRow); @@ -207,6 +212,7 @@ Assert.AreEqual(FlushMode.Auto, tdq.FlushMode); Assert.AreEqual("A_REGION", tdq.CacheRegion); Assert.IsNotNull(tdq.ResultTransformer); + Assert.That(tdq.Comment, Is.EqualTo(MyComment)); // merge/override of LockModes Assert.AreEqual(2, tdq.LockModes.Count); @@ -235,7 +241,7 @@ Assert.IsTrue(tdq.NamedParams["6"].Value.Equals(DateTime.MaxValue)); Assert.IsTrue(tdq.NamedParams["7"].Type.Equals(NHibernateUtil.Decimal)); Assert.IsTrue(tdq.NamedParams["8"].Type.Equals(NHibernateUtil.Double)); - Assert.IsTrue(tdq.NamedParams["9"].Type.Equals(NHibernateUtil.Entity(typeof (Foo)))); + Assert.IsTrue(tdq.NamedParams["9"].Type.Equals(NHibernateUtil.Entity(typeof(Foo)))); // merge/override named parameters list int expected = 1; @@ -349,7 +355,7 @@ // With UnTyped Parameter List dq = new DetachedQuery("from Foo f where f.IntValue in (:pn)"); - dq.SetParameterList("pn", new int[] {2 ,3}); + dq.SetParameterList("pn", new int[] { 2, 3 }); using (ISession s = OpenSession()) { IQuery q = dq.GetExecutableQuery(s); @@ -454,10 +460,10 @@ Console.WriteLine("DetachedQueryCycle={0} QueryCycl={1} Diff={2}", sDQStop - sDQStart, sQStop - sQStart, - (sDQStop - sDQStart) - (sQStop - sQStart)); + (sDQStop - sDQStart) - (sQStop - sQStart)); } - private class TestDetachedQuery:AbstractDetachedQuery + private class TestDetachedQuery : AbstractDetachedQuery { public Dictionary<int, object> PosUntypeParams { @@ -548,6 +554,11 @@ { (this as IDetachedQueryImplementor).OverrideInfoFrom(origin); } + + public string Comment + { + get { return comment; } + } } } @@ -593,7 +604,7 @@ } public Foo(string name, string description, int intValue) - :this(name,description) + : this(name, description) { this.intValue = intValue; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |