From: <fab...@us...> - 2010-10-12 17:57:36
|
Revision: 5247 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5247&view=rev Author: fabiomaulo Date: 2010-10-12 17:57:29 +0000 (Tue, 12 Oct 2010) Log Message: ----------- Re-Fix NH-2020 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2020/Fixture.cs Modified: trunk/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs 2010-10-12 17:25:31 UTC (rev 5246) +++ trunk/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs 2010-10-12 17:57:29 UTC (rev 5247) @@ -1,10 +1,11 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Data; +using System.Data.Common; using System.Reflection; using System.Text; using NHibernate.AdoNet.Util; +using NHibernate.Exceptions; namespace NHibernate.AdoNet { @@ -126,7 +127,15 @@ // this value is not a part of the ADO.NET API. // It's and ODP implementation, so it is being set by reflection SetObjectParam(currentBatch, "ArrayBindCount", arraySize); - int rowsAffected = currentBatch.ExecuteNonQuery(); + int rowsAffected; + try + { + rowsAffected = currentBatch.ExecuteNonQuery(); + } + catch (DbException e) + { + throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not execute batch command."); + } Expectations.VerifyOutcomeBatched(totalExpectedRowsAffected, rowsAffected); Modified: trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2010-10-12 17:25:31 UTC (rev 5246) +++ trunk/nhibernate/src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs 2010-10-12 17:57:29 UTC (rev 5247) @@ -1,6 +1,8 @@ using System.Data; +using System.Data.Common; using System.Text; using NHibernate.AdoNet.Util; +using NHibernate.Exceptions; using NHibernate.Util; namespace NHibernate.AdoNet @@ -82,9 +84,17 @@ Factory.Settings.SqlStatementLogger.LogBatchCommand(currentBatchCommandsLog.ToString()); currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:"); } - - int rowsAffected = currentBatch.ExecuteNonQuery(); + int rowsAffected; + try + { + rowsAffected = currentBatch.ExecuteNonQuery(); + } + catch (DbException e) + { + throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not execute batch command."); + } + Expectations.VerifyOutcomeBatched(totalExpectedRowsAffected, rowsAffected); currentBatch.Dispose(); Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2020/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2020/Fixture.cs 2010-10-12 17:25:31 UTC (rev 5246) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2020/Fixture.cs 2010-10-12 17:57:29 UTC (rev 5247) @@ -1,10 +1,8 @@ -using System; - using NUnit.Framework; - using NHibernate.Dialect; using NHibernate.Exceptions; using NHibernate.Test.ExceptionsTest; +using SharpTestsEx; namespace NHibernate.Test.NHSpecificTest.NH2020 { @@ -13,7 +11,7 @@ { protected override void Configure(Cfg.Configuration configuration) { - configuration.SetProperty(Cfg.Environment.BatchSize, "1"); + configuration.SetProperty(Cfg.Environment.BatchSize, "10"); configuration.SetProperty( Cfg.Environment.SqlExceptionConverter, typeof (MSSQLExceptionConverterExample).AssemblyQualifiedName); @@ -58,17 +56,8 @@ using (ITransaction tx = s.BeginTransaction()) { var one = s.Load<One>(oneId); - - try - { - s.Delete(one); - tx.Commit(); - Assert.Fail("DELETE should have failed"); - } - catch (Exception ex) - { - Assert.IsInstanceOf<ConstraintViolationException>(ex); - } + s.Delete(one); + tx.Executing(transaction => transaction.Commit()).Throws<ConstraintViolationException>(); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-10-13 12:55:22
|
Revision: 5250 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5250&view=rev Author: fabiomaulo Date: 2010-10-13 12:55:16 +0000 (Wed, 13 Oct 2010) Log Message: ----------- Fix NH-2376 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Event/EventListeners.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/Events/DisposableListenersTest.cs Modified: trunk/nhibernate/src/NHibernate/Event/EventListeners.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Event/EventListeners.cs 2010-10-12 21:27:00 UTC (rev 5249) +++ trunk/nhibernate/src/NHibernate/Event/EventListeners.cs 2010-10-13 12:55:16 UTC (rev 5250) @@ -626,23 +626,31 @@ return this; } - public void DestroyListeners() - { - try - { - foreach (object i in initializedListeners) - { - IDestructible destructible = i as IDestructible; - if (destructible != null) - { - destructible.Cleanup(); - } - } - } - catch (Exception e) - { - throw new HibernateException("could not destruct listeners", e); - } - } + public void DestroyListeners() + { + try + { + foreach (object i in initializedListeners) + { + var destructible = i as IDestructible; + if (destructible != null) + { + destructible.Cleanup(); + } + else + { + var disposable = i as IDisposable; + if (disposable != null) + { + disposable.Dispose(); + } + } + } + } + catch (Exception e) + { + throw new HibernateException("could not destruct/dispose listeners", e); + } + } } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/Events/DisposableListenersTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Events/DisposableListenersTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Events/DisposableListenersTest.cs 2010-10-13 12:55:16 UTC (rev 5250) @@ -0,0 +1,35 @@ +using System; +using NHibernate.Cfg; +using NHibernate.Event; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.Events +{ + public class MyDisposableListener : IPostUpdateEventListener, IDisposable + { + public void OnPostUpdate(PostUpdateEvent @event) + { + } + + public bool DisposeCalled { get; private set; } + public void Dispose() + { + DisposeCalled = true; + } + } + + public class DisposableListenersTest + { + [Test] + public void WhenCloseSessionFactoryThenCallDisposeOfListener() + { + Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration(); + var myDisposableListener = new MyDisposableListener(); + cfg.AppendListeners(ListenerType.PostUpdate, new[]{myDisposableListener}); + var sf = cfg.BuildSessionFactory(); + sf.Close(); + myDisposableListener.DisposeCalled.Should().Be.True(); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-10-12 21:27:00 UTC (rev 5249) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-10-13 12:55:16 UTC (rev 5250) @@ -196,6 +196,7 @@ <Compile Include="EngineTest\NativeSQLQueryNonScalarReturnTest.cs" /> <Compile Include="EngineTest\NativeSQLQueryScalarReturnTest.cs" /> <Compile Include="EngineTest\NativeSQLQuerySpecificationTest.cs" /> + <Compile Include="Events\DisposableListenersTest.cs" /> <Compile Include="ExceptionsTest\NullQueryTest.cs" /> <Compile Include="ExpressionTest\RestrictionsFixture.cs" /> <Compile Include="Criteria\Student.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-10-14 16:42:45
|
Revision: 5251 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5251&view=rev Author: fabiomaulo Date: 2010-10-14 16:42:37 +0000 (Thu, 14 Oct 2010) Log Message: ----------- Apply NH-2378 (by Juan Pedro Elizalde) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/TestEntity.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/TestEntityDto.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs 2010-10-13 12:55:16 UTC (rev 5250) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs 2010-10-14 16:42:37 UTC (rev 5251) @@ -200,7 +200,10 @@ case TypeCode.Boolean: SetText("bool"); break; - case TypeCode.Int32: + case TypeCode.Int16: + SetText("short"); + break; + case TypeCode.Int32: SetText("integer"); break; case TypeCode.Int64: Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/Fixture.cs 2010-10-14 16:42:37 UTC (rev 5251) @@ -0,0 +1,71 @@ +using System.Linq; +using NHibernate.Linq; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2378 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override void OnSetUp() + { + base.OnSetUp(); + using (var session = this.OpenSession()) + using (var tx = session.BeginTransaction()) + { + var entity = new TestEntity(); + entity.Id = 1; + entity.Name = "Test Entity"; + entity.TestPerson = new Person { Id = 1, Name = "TestUser" }; + session.Save(entity); + + var entity1 = new TestEntity(); + entity1.Id = 2; + entity1.Name = "Test Entity"; + entity1.TestPerson = new Person { Id = 2, Name = "TestUser" }; + session.Save(entity1); + + tx.Commit(); + } + } + + protected override void OnTearDown() + { + base.OnTearDown(); + using (ISession session = this.OpenSession()) + { + string hql = "from System.Object"; + session.Delete(hql); + session.Flush(); + } + } + + + [Test] + public void ShortEntityCanBeQueryCorrectlyUsingLinqProvider() + { + using (ISession session = this.OpenSession()) + { + IQueryable<TestEntity> query = session.Query<TestEntity>(); + IQueryable<TestEntityDto> list = query.Select(o => new TestEntityDto + { + EntityId = o.Id, + EntityName = o.Name, + PersonId = + (o.TestPerson != null) + ? o.TestPerson.Id + : (short) 0, + PersonName = + (o.TestPerson != null) + ? o.TestPerson.Name + : string.Empty + }); + + IQueryable<TestEntityDto> m = list.Where(o => o.PersonId == 2); + + + Assert.AreEqual(1, m.Count()); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/Mappings.hbm.xml 2010-10-14 16:42:37 UTC (rev 5251) @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2378" default-access="field.camelcase" + default-lazy="false"> + <class name="TestEntity"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="Name" /> + + <many-to-one name="TestPerson" cascade="save-update"> + <column name="PersonId"/> + </many-to-one> + + </class> + + <class name="Person"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="Name" /> + </class> +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/TestEntity.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/TestEntity.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/TestEntity.cs 2010-10-14 16:42:37 UTC (rev 5251) @@ -0,0 +1,45 @@ +namespace NHibernate.Test.NHSpecificTest.NH2378 +{ + public class TestEntity + { + private string name; + private int id; + private Person testPerson; + + public int Id + { + get { return id; } + set { id = value; } + } + + public string Name + { + get { return name; } + set { name = value; } + } + + public Person TestPerson + { + get { return testPerson; } + set { testPerson = value; } + } + } + + public class Person + { + private string name; + private short id; + + public short Id + { + get { return id; } + set { id = value; } + } + + public string Name + { + get { return name; } + set { name = value; } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/TestEntityDto.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/TestEntityDto.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2378/TestEntityDto.cs 2010-10-14 16:42:37 UTC (rev 5251) @@ -0,0 +1,10 @@ +namespace NHibernate.Test.NHSpecificTest.NH2378 +{ + public class TestEntityDto + { + public int EntityId { get; set; } + public string EntityName { get; set; } + public short PersonId { get; set; } + public string PersonName { get; set; } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-10-13 12:55:16 UTC (rev 5250) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-10-14 16:42:37 UTC (rev 5251) @@ -533,6 +533,9 @@ <Compile Include="NHSpecificTest\NH2344\Model.cs" /> <Compile Include="NHSpecificTest\NH2361\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2374\NH2374Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2378\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2378\TestEntity.cs" /> + <Compile Include="NHSpecificTest\NH2378\TestEntityDto.cs" /> <Compile Include="PolymorphicGetAndLoad\Domain.cs" /> <Compile Include="PolymorphicGetAndLoad\PolymorphicGetAndLoadTest.cs" /> <Compile Include="TypesTest\CharClass.cs" /> @@ -2335,6 +2338,7 @@ <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <EmbeddedResource Include="DriverTest\EntityForMs2008.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2378\Mappings.hbm.xml" /> <EmbeddedResource Include="TypesTest\XDocClass.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2374\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2328\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2010-11-07 13:37:38
|
Revision: 5260 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5260&view=rev Author: ricbrown Date: 2010-11-07 13:37:31 +0000 (Sun, 07 Nov 2010) Log Message: ----------- QueryOver - added missing overload to allow private property access to order-by Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverOrderBuilder.cs trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/IQueryOver.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverOrderBuilder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverOrderBuilder.cs 2010-11-02 11:59:09 UTC (rev 5259) +++ trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverOrderBuilder.cs 2010-11-07 13:37:31 UTC (rev 5260) @@ -18,6 +18,9 @@ public QueryOverOrderBuilder(QueryOver<TRoot,TSubType> root, Expression<Func<object>> path, bool isAlias) : base(root, path, isAlias) {} + public QueryOverOrderBuilder(QueryOver<TRoot,TSubType> root, IProjection projection) : base(root, projection) + {} + } public class IQueryOverOrderBuilder<TRoot,TSubType> : QueryOverOrderBuilderBase<IQueryOver<TRoot,TSubType>, TRoot, TSubType> @@ -29,6 +32,9 @@ public IQueryOverOrderBuilder(IQueryOver<TRoot,TSubType> root, Expression<Func<object>> path, bool isAlias) : base(root, path, isAlias) {} + public IQueryOverOrderBuilder(IQueryOver<TRoot,TSubType> root, IProjection projection) : base(root, projection) + {} + } public class QueryOverOrderBuilderBase<TReturn, TRoot, TSubType> where TReturn : IQueryOver<TRoot, TSubType> @@ -37,6 +43,7 @@ protected TReturn root; protected LambdaExpression path; protected bool isAlias; + protected IProjection projection; protected QueryOverOrderBuilderBase(TReturn root, Expression<Func<TSubType, object>> path) { @@ -52,11 +59,25 @@ this.isAlias = isAlias; } + protected QueryOverOrderBuilderBase(TReturn root, IProjection projection) + { + this.root = root; + this.projection = projection; + } + + private void AddOrder(Func<string, Order> orderStringDelegate, Func<IProjection, Order> orderDelegate) + { + if (projection != null) + root.UnderlyingCriteria.AddOrder(orderDelegate(projection)); + else + root.UnderlyingCriteria.AddOrder(ExpressionProcessor.ProcessOrder(path, orderStringDelegate, isAlias)); + } + public TReturn Asc { get { - this.root.UnderlyingCriteria.AddOrder(ExpressionProcessor.ProcessOrder(path, Order.Asc, isAlias)); + AddOrder(Order.Asc, Order.Asc); return this.root; } } @@ -65,7 +86,7 @@ { get { - this.root.UnderlyingCriteria.AddOrder(ExpressionProcessor.ProcessOrder(path, Order.Desc, isAlias)); + AddOrder(Order.Desc, Order.Desc); return this.root; } } Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-11-02 11:59:09 UTC (rev 5259) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-11-07 13:37:31 UTC (rev 5260) @@ -334,6 +334,11 @@ return new QueryOverOrderBuilder<TRoot,TSubType>(this, path, false); } + public QueryOverOrderBuilder<TRoot,TSubType> OrderBy(IProjection projection) + { + return new QueryOverOrderBuilder<TRoot,TSubType>(this, projection); + } + public QueryOverOrderBuilder<TRoot,TSubType> OrderByAlias(Expression<Func<object>> path) { return new QueryOverOrderBuilder<TRoot,TSubType>(this, path, true); @@ -349,6 +354,11 @@ return new QueryOverOrderBuilder<TRoot,TSubType>(this, path, false); } + public QueryOverOrderBuilder<TRoot,TSubType> ThenBy(IProjection projection) + { + return new QueryOverOrderBuilder<TRoot,TSubType>(this, projection); + } + public QueryOverOrderBuilder<TRoot,TSubType> ThenByAlias(Expression<Func<object>> path) { return new QueryOverOrderBuilder<TRoot,TSubType>(this, path, true); @@ -690,6 +700,9 @@ IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.OrderBy(Expression<Func<object>> path) { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, path, false); } + IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.OrderBy(IProjection projection) + { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, projection); } + IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.OrderByAlias(Expression<Func<object>> path) { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, path, true); } @@ -699,6 +712,9 @@ IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.ThenBy(Expression<Func<object>> path) { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, path, false); } + IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.ThenBy(IProjection projection) + { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, projection); } + IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.ThenByAlias(Expression<Func<object>> path) { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, path, true); } Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-11-02 11:59:09 UTC (rev 5259) +++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-11-07 13:37:31 UTC (rev 5260) @@ -263,6 +263,11 @@ IQueryOverOrderBuilder<TRoot,TSubType> OrderBy(Expression<Func<object>> path); /// <summary> + /// Order by arbitrary IProjection (e.g., to allow protected member access) + /// </summary> + IQueryOverOrderBuilder<TRoot,TSubType> OrderBy(IProjection projection); + + /// <summary> /// Add order for an aliased projection expressed as a lambda expression /// </summary> /// <param name="path">Lambda expression</param> @@ -284,6 +289,11 @@ IQueryOverOrderBuilder<TRoot,TSubType> ThenBy(Expression<Func<object>> path); /// <summary> + /// Order by arbitrary IProjection (e.g., to allow protected member access) + /// </summary> + IQueryOverOrderBuilder<TRoot,TSubType> ThenBy(IProjection projection); + + /// <summary> /// Add order for an aliased projection expressed as a lambda expression /// </summary> /// <param name="path">Lambda expression</param> Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2010-11-02 11:59:09 UTC (rev 5259) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2010-11-07 13:37:31 UTC (rev 5260) @@ -164,13 +164,15 @@ CreateTestCriteria(typeof(Person)) .SetProjection(Projections.Property("Name")) .Add(Restrictions.Eq("Name", "test name")) - .Add(Restrictions.Not(Restrictions.Eq("Name", "not test name"))); + .Add(Restrictions.Not(Restrictions.Eq("Name", "not test name"))) + .AddOrder(Order.Desc(Projections.Property("Name"))); IQueryOver<Person> actual = CreateTestQueryOver<Person>() .Select(Projections.Property("Name")) .Where(Restrictions.Eq("Name", "test name")) - .And(Restrictions.Not(Restrictions.Eq("Name", "not test name"))); + .And(Restrictions.Not(Restrictions.Eq("Name", "not test name"))) + .OrderBy(Projections.Property("Name")).Desc; AssertCriteriaAreEqual(expected, actual); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2010-11-07 15:52:15
|
Revision: 5262 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5262&view=rev Author: julian-maughan Date: 2010-11-07 15:52:07 +0000 (Sun, 07 Nov 2010) Log Message: ----------- Refactor: Moved methods from TypeFactory to new class, TypeHelper (as-per Hibernate). Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Action/EntityUpdateAction.cs trunk/nhibernate/src/NHibernate/Cache/Entry/CacheEntry.cs trunk/nhibernate/src/NHibernate/Cache/StandardQueryCache.cs trunk/nhibernate/src/NHibernate/Engine/TwoPhaseLoad.cs trunk/nhibernate/src/NHibernate/Event/Default/AbstractReassociateEventListener.cs trunk/nhibernate/src/NHibernate/Event/Default/AbstractSaveEventListener.cs trunk/nhibernate/src/NHibernate/Event/Default/DefaultDeleteEventListener.cs trunk/nhibernate/src/NHibernate/Event/Default/DefaultLoadEventListener.cs trunk/nhibernate/src/NHibernate/Event/Default/DefaultMergeEventListener.cs trunk/nhibernate/src/NHibernate/Impl/MultipleQueriesCacheAssembler.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs trunk/nhibernate/src/NHibernate/Type/ComponentType.cs trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate/Type/TypeHelper.cs Modified: trunk/nhibernate/src/NHibernate/Action/EntityUpdateAction.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Action/EntityUpdateAction.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Action/EntityUpdateAction.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -90,7 +90,7 @@ // get the updated snapshot of the entity state by cloning current state; // it is safe to copy in place, since by this time no-one else (should have) // has a reference to the array - TypeFactory.DeepCopy(state, persister.PropertyTypes, persister.PropertyCheckability, state, Session); + TypeHelper.DeepCopy(state, persister.PropertyTypes, persister.PropertyCheckability, state, Session); if (persister.HasUpdateGeneratedProperties) { // this entity defines property generation, so process those generated Modified: trunk/nhibernate/src/NHibernate/Cache/Entry/CacheEntry.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cache/Entry/CacheEntry.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Cache/Entry/CacheEntry.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -21,7 +21,7 @@ public CacheEntry(object[] state, IEntityPersister persister, bool unfetched, object version, ISessionImplementor session, object owner) { //disassembled state gets put in a new array (we write to cache by value!) - disassembledState = TypeFactory.Disassemble(state, persister.PropertyTypes, null, session, owner); + disassembledState = TypeHelper.Disassemble(state, persister.PropertyTypes, null, session, owner); subclass = persister.EntityName; lazyPropertiesAreUnfetched = unfetched || !persister.IsLazyPropertiesCacheable; this.version = version; @@ -76,7 +76,7 @@ IInterceptor interceptor, ISessionImplementor session) { //assembled state gets put in a new array (we read from cache by value!) - object[] assembledProps = TypeFactory.Assemble(values, persister.PropertyTypes, session, result); + object[] assembledProps = TypeHelper.Assemble(values, persister.PropertyTypes, session, result); //from h3.2 TODO: reuse the PreLoadEvent PreLoadEvent preLoadEvent = new PreLoadEvent((IEventSource) session); Modified: trunk/nhibernate/src/NHibernate/Cache/StandardQueryCache.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cache/StandardQueryCache.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Cache/StandardQueryCache.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -83,7 +83,7 @@ } else { - cacheable.Add(TypeFactory.Disassemble((object[]) result[i], returnTypes, null, session, null)); + cacheable.Add(TypeHelper.Disassemble((object[]) result[i], returnTypes, null, session, null)); } } queryCache.Put(key, cacheable); @@ -123,7 +123,7 @@ } else { - TypeFactory.BeforeAssemble((object[])cacheable[i], returnTypes, session); + TypeHelper.BeforeAssemble((object[])cacheable[i], returnTypes, session); } } IList result = new List<object>(cacheable.Count - 1); @@ -137,7 +137,7 @@ } else { - result.Add(TypeFactory.Assemble((object[])cacheable[i], returnTypes, session, null)); + result.Add(TypeHelper.Assemble((object[])cacheable[i], returnTypes, session, null)); } } catch (UnresolvableObjectException) Modified: trunk/nhibernate/src/NHibernate/Engine/TwoPhaseLoad.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/TwoPhaseLoad.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Engine/TwoPhaseLoad.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -128,7 +128,7 @@ else { //take a snapshot - TypeFactory.DeepCopy(hydratedState, persister.PropertyTypes, persister.PropertyUpdateability, hydratedState, session); + TypeHelper.DeepCopy(hydratedState, persister.PropertyTypes, persister.PropertyUpdateability, hydratedState, session); persistenceContext.SetEntryStatus(entityEntry, Status.Loaded); } Modified: trunk/nhibernate/src/NHibernate/Event/Default/AbstractReassociateEventListener.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Event/Default/AbstractReassociateEventListener.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Event/Default/AbstractReassociateEventListener.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -40,7 +40,7 @@ //get a snapshot object[] values = persister.GetPropertyValues(entity, source.EntityMode); - TypeFactory.DeepCopy(values, persister.PropertyTypes, persister.PropertyUpdateability, values, source); + TypeHelper.DeepCopy(values, persister.PropertyTypes, persister.PropertyUpdateability, values, source); object version = Versioning.GetVersion(values, persister); EntityEntry newEntry = source.PersistenceContext.AddEntity(entity, Status.Loaded, values, key, version, LockMode.None, true, persister, false, true); Modified: trunk/nhibernate/src/NHibernate/Event/Default/AbstractSaveEventListener.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Event/Default/AbstractSaveEventListener.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Event/Default/AbstractSaveEventListener.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -245,7 +245,7 @@ persister.SetPropertyValues(entity, values, source.EntityMode); } - TypeFactory.DeepCopy(values, types, persister.PropertyUpdateability, values, source); + TypeHelper.DeepCopy(values, types, persister.PropertyUpdateability, values, source); new ForeignKeys.Nullifier(entity, false, useIdentityColumn, source).NullifyTransientReferences(values, types); new Nullability(source).CheckNullability(values, persister, false); Modified: trunk/nhibernate/src/NHibernate/Event/Default/DefaultDeleteEventListener.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Event/Default/DefaultDeleteEventListener.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Event/Default/DefaultDeleteEventListener.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -221,7 +221,7 @@ // TypeFactory.deepCopy( currentState, propTypes, persister.getPropertyUpdateability(), deletedState, session ); bool[] copyability = new bool[propTypes.Length]; ArrayHelper.Fill(copyability, true); - TypeFactory.DeepCopy(currentState, propTypes, copyability, deletedState, session); + TypeHelper.DeepCopy(currentState, propTypes, copyability, deletedState, session); return deletedState; } Modified: trunk/nhibernate/src/NHibernate/Event/Default/DefaultLoadEventListener.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Event/Default/DefaultLoadEventListener.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Event/Default/DefaultLoadEventListener.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -463,7 +463,7 @@ IType[] types = subclassPersister.PropertyTypes; object[] values = entry.Assemble(result, id, subclassPersister, session.Interceptor, session); // intializes result by side-effect - TypeFactory.DeepCopy(values, types, subclassPersister.PropertyUpdateability, values, session); + TypeHelper.DeepCopy(values, types, subclassPersister.PropertyUpdateability, values, session); object version = Versioning.GetVersion(values, subclassPersister); if (log.IsDebugEnabled) Modified: trunk/nhibernate/src/NHibernate/Event/Default/DefaultMergeEventListener.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Event/Default/DefaultMergeEventListener.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Event/Default/DefaultMergeEventListener.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -350,7 +350,7 @@ protected virtual void CopyValues(IEntityPersister persister, object entity, object target, ISessionImplementor source, IDictionary copyCache) { object[] copiedValues = - TypeFactory.Replace(persister.GetPropertyValues(entity, source.EntityMode), + TypeHelper.Replace(persister.GetPropertyValues(entity, source.EntityMode), persister.GetPropertyValues(target, source.EntityMode), persister.PropertyTypes, source, target, copyCache); @@ -368,14 +368,14 @@ // replacement to associations types (value types were already replaced // during the first pass) copiedValues = - TypeFactory.ReplaceAssociations(persister.GetPropertyValues(entity, source.EntityMode), + TypeHelper.ReplaceAssociations(persister.GetPropertyValues(entity, source.EntityMode), persister.GetPropertyValues(target, source.EntityMode), persister.PropertyTypes, source, target, copyCache, foreignKeyDirection); } else { copiedValues = - TypeFactory.Replace(persister.GetPropertyValues(entity, source.EntityMode), + TypeHelper.Replace(persister.GetPropertyValues(entity, source.EntityMode), persister.GetPropertyValues(target, source.EntityMode), persister.PropertyTypes, source, target, copyCache, foreignKeyDirection); } Modified: trunk/nhibernate/src/NHibernate/Impl/MultipleQueriesCacheAssembler.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/MultipleQueriesCacheAssembler.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Impl/MultipleQueriesCacheAssembler.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -34,7 +34,7 @@ } else { - singleQueryCached.Add(TypeFactory.Disassemble((object[]) objToCache, assemblers, null, session, null)); + singleQueryCached.Add(TypeHelper.Disassemble((object[]) objToCache, assemblers, null, session, null)); } } cacheable.Add(singleQueryCached); @@ -59,7 +59,7 @@ } else { - queryResults.Add(TypeFactory.Assemble((object[]) fromCache, assemblers, session, owner)); + queryResults.Add(TypeHelper.Assemble((object[]) fromCache, assemblers, session, owner)); } } result.Add(queryResults); Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-11-07 15:52:07 UTC (rev 5262) @@ -412,6 +412,7 @@ <Compile Include="Type\TimeType.cs" /> <Compile Include="Type\TrueFalseType.cs" /> <Compile Include="Type\TypeFactory.cs" /> + <Compile Include="Type\TypeHelper.cs" /> <Compile Include="Type\TypeType.cs" /> <Compile Include="Type\UInt16Type.cs" /> <Compile Include="Type\UInt32Type.cs" /> Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -3515,7 +3515,7 @@ public virtual int[] FindDirty(object[] currentState, object[] previousState, object entity, ISessionImplementor session) { - int[] props = TypeFactory.FindDirty( + int[] props = TypeHelper.FindDirty( entityMetamodel.Properties, currentState, previousState, propertyColumnUpdateable, HasUninitializedLazyProperties(entity, session.EntityMode), session); if (props == null) @@ -3531,7 +3531,7 @@ public virtual int[] FindModified(object[] old, object[] current, object entity, ISessionImplementor session) { - int[] props = TypeFactory.FindModified( + int[] props = TypeHelper.FindModified( entityMetamodel.Properties, current, old, propertyColumnUpdateable, HasUninitializedLazyProperties(entity, session.EntityMode), session); if (props == null) { Modified: trunk/nhibernate/src/NHibernate/Type/ComponentType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/ComponentType.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Type/ComponentType.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -376,7 +376,7 @@ object result = target ?? Instantiate(owner, session); EntityMode entityMode = session.EntityMode; - object[] values = TypeFactory.Replace(GetPropertyValues(original, entityMode), GetPropertyValues(result, entityMode), propertyTypes, session, owner, copiedAlready); + object[] values = TypeHelper.Replace(GetPropertyValues(original, entityMode), GetPropertyValues(result, entityMode), propertyTypes, session, owner, copiedAlready); SetPropertyValues(result, values, entityMode); return result; @@ -390,7 +390,7 @@ object result = target ?? Instantiate(owner, session); EntityMode entityMode = session.EntityMode; - object[] values = TypeFactory.Replace(GetPropertyValues(original, entityMode), GetPropertyValues(result, entityMode), propertyTypes, session, owner, copyCache, foreignKeyDirection); + object[] values = TypeHelper.Replace(GetPropertyValues(original, entityMode), GetPropertyValues(result, entityMode), propertyTypes, session, owner, copyCache, foreignKeyDirection); SetPropertyValues(result, values, entityMode); return result; Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2010-11-07 15:51:01 UTC (rev 5261) +++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -8,10 +8,7 @@ using NHibernate.Bytecode; using NHibernate.Classic; using NHibernate.Engine; -using NHibernate.Intercept; -using NHibernate.Properties; using NHibernate.SqlTypes; -using NHibernate.Tuple; using NHibernate.UserTypes; using NHibernate.Util; using System.Runtime.CompilerServices; @@ -24,7 +21,7 @@ /// <remarks> /// Applications should use static methods and constants on NHibernate.NHibernateUtil if the default /// IType is good enough. For example, the TypeFactory should only be used when the String needs - /// to have a length of 300 instead of 255. At this point NHibernate.String does not get you the + /// to have a length of 300 instead of 255. At this point NHibernate.String does not get you the /// correct IType. Instead use TypeFactory.GetString(300) and keep a local variable that holds /// a reference to the IType. /// </remarks> @@ -44,11 +41,11 @@ private static readonly System.Type[] GenericCollectionSimpleSignature = new[] { typeof(string), typeof(string), typeof(bool) }; /* - * Maps the string representation of the type to the IType. The string + * Maps the string representation of the type to the IType. The string * representation is how the type will appear in the mapping file and in * name of the IType.Name. The list below provides a few examples of how * the Key/Value pair will be. - * + * * key -> value * "System.DateTime" -> instance of DateTimeType * "System.DateTime, fully assembly name" -> instance of DateTimeType @@ -86,7 +83,7 @@ RegisterType(nhibernateType, typeAliases); } - private static void RegisterType(System.Type systemType, IType nhibernateType, + private static void RegisterType(System.Type systemType, IType nhibernateType, IEnumerable<string> aliases, GetNullableTypeWithLength ctorLength) { var typeAliases = new List<string>(aliases); @@ -108,7 +105,7 @@ { var typeAliases = new List<string> { - systemType.FullName, + systemType.FullName, systemType.AssemblyQualifiedName, }; if (systemType.IsValueType) @@ -276,15 +273,15 @@ /// <returns>The Type of Classification</returns> /// <remarks> /// This parses through the string and makes the assumption that no class - /// name and no assembly name will contain the <c>"("</c>. + /// name and no assembly name will contain the <c>"("</c>. /// <para> - /// If it finds - /// the <c>"("</c> and then finds a <c>","</c> afterwards then it is a - /// <c>TypeClassification.PrecisionScale</c>. + /// If it finds + /// the <c>"("</c> and then finds a <c>","</c> afterwards then it is a + /// <c>TypeClassification.PrecisionScale</c>. /// </para> /// <para> /// If it finds the <c>"("</c> - /// and doesn't find a <c>","</c> afterwards, then it is a + /// and doesn't find a <c>","</c> afterwards, then it is a /// <c>TypeClassification.Length</c>. /// </para> /// <para> @@ -320,7 +317,7 @@ /// <summary> /// Given the name of a Hibernate type such as Decimal, Decimal(19,0) - /// , Int32, or even NHibernate.Type.DecimalType, NHibernate.Type.DecimalType(19,0), + /// , Int32, or even NHibernate.Type.DecimalType, NHibernate.Type.DecimalType(19,0), /// NHibernate.Type.Int32Type, then return an instance of NHibernate.Type.IType /// </summary> /// <param name="name">The name of the type.</param> @@ -341,7 +338,7 @@ } // if we get to here then the basic type with the length or precision/scale - // combination doesn't exists - so lets figure out which one we have and + // combination doesn't exists - so lets figure out which one we have and // invoke the appropriate delegate TypeClassification typeClassification = GetTypeClassification(name); @@ -430,8 +427,8 @@ } /// <summary> - /// Uses heuristics to deduce a NHibernate type given a string naming the - /// type. + /// Uses heuristics to deduce a NHibernate type given a string naming the + /// type. /// </summary> /// <param name="typeName"></param> /// <returns>An instance of <c>NHibernate.Type.IType</c></returns> @@ -439,9 +436,9 @@ /// When looking for the NHibernate type it will look in the cache of the Basic types first. /// If it doesn't find it in the cache then it uses the typeName to get a reference to the /// Class (Type in .NET). Once we get the reference to the .NET class we check to see if it - /// implements IType, ICompositeUserType, IUserType, ILifecycle (Association), or + /// implements IType, ICompositeUserType, IUserType, ILifecycle (Association), or /// IPersistentEnum. If none of those are implemented then we will serialize the Type to the - /// database using NHibernate.Type.SerializableType(typeName) + /// database using NHibernate.Type.SerializableType(typeName) /// </remarks> public static IType HeuristicType(string typeName) { @@ -449,8 +446,8 @@ } /// <summary> - /// Uses heuristics to deduce a NHibernate type given a string naming the - /// type. + /// Uses heuristics to deduce a NHibernate type given a string naming the + /// type. /// </summary> /// <param name="typeName">the type name</param> /// <param name="parameters">parameters for the type</param> @@ -563,7 +560,7 @@ /// <returns>A BinaryType</returns> /// <remarks> /// In addition to returning the BinaryType it will also ensure that it has - /// been added to the basicNameMap with the keys <c>Byte[](length)</c> and + /// been added to the basicNameMap with the keys <c>Byte[](length)</c> and /// <c>NHibernate.Type.BinaryType(length)</c>. /// </remarks> [MethodImpl(MethodImplOptions.Synchronized)] @@ -621,7 +618,7 @@ /// <para> /// In addition to returning the SerializableType it will also ensure that it has /// been added to the basicNameMap with the keys <c>Type.FullName</c> (the result - /// of <c>IType.Name</c> and <c>Type.AssemblyQualifiedName</c>. This is different + /// of <c>IType.Name</c> and <c>Type.AssemblyQualifiedName</c>. This is different /// from the other items put in the basicNameMap because it is uses the AQN and the /// FQN as opposed to the short name used in the maps and the FQN. /// </para> @@ -876,284 +873,6 @@ return (CollectionType)mi.Invoke(Instance.CollectionTypeFactory, new object[] { role, propertyRef, false }); } - /// <summary> Deep copy a series of values from one array to another... </summary> - /// <param name="values">The values to copy (the source) </param> - /// <param name="types">The value types </param> - /// <param name="copy">an array indicating which values to include in the copy </param> - /// <param name="target">The array into which to copy the values </param> - /// <param name="session">The originating session </param> - public static void DeepCopy(object[] values, IType[] types, bool[] copy, object[] target, ISessionImplementor session) - { - for (int i = 0; i < types.Length; i++) - { - if (copy[i]) - { - if (values[i] == LazyPropertyInitializer.UnfetchedProperty || values[i] == BackrefPropertyAccessor.Unknown) - { - target[i] = values[i]; - } - else - { - target[i] = types[i].DeepCopy(values[i], session.EntityMode, session.Factory); - } - } - } - } - - /// <summary> Apply the <see cref="ICacheAssembler.BeforeAssemble"/> operation across a series of values. </summary> - /// <param name="row">The values </param> - /// <param name="types">The value types </param> - /// <param name="session">The originating session </param> - public static void BeforeAssemble(object[] row, ICacheAssembler[] types, ISessionImplementor session) - { - for (int i = 0; i < types.Length; i++) - { - if (row[i] != LazyPropertyInitializer.UnfetchedProperty && row[i] != BackrefPropertyAccessor.Unknown) - { - types[i].BeforeAssemble(row[i], session); - } - } - } - /// <summary> - /// Determine if any of the given field values are dirty, - /// returning an array containing indexes of - /// the dirty fields or null if no fields are dirty. - /// </summary> - public static int[] FindDirty( - StandardProperty[] properties, - object[] x, - object[] y, - bool[][] includeColumns, - bool anyUninitializedProperties, - ISessionImplementor session) - { - int[] results = null; - int count = 0; - int span = properties.Length; - - for (int i = 0; i < span; i++) - { - bool dirty = - // TODO H3: x[ i ] != LazyPropertyInitializer.UnfetchedProperty && //x is the "current" state - properties[i].IsDirtyCheckable(anyUninitializedProperties) - && properties[i].Type.IsDirty(y[i], x[i], includeColumns[i], session); - - if (dirty) - { - if (results == null) - { - results = new int[span]; - } - results[count++] = i; - } - } - if (count == 0) - { - return null; - } - else - { - int[] trimmed = new int[count]; - System.Array.Copy(results, 0, trimmed, 0, count); - return trimmed; - } - } - - /// <summary> - /// Determine if any of the given field values are modified, - /// returning an array containing indexes of - /// the dirty fields or null if no fields are modified. - /// </summary> - public static int[] FindModified( - StandardProperty[] properties, - object[] x, - object[] y, - bool[][] includeColumns, - bool anyUninitializedProperties, - ISessionImplementor session) - { - int[] results = null; - int count = 0; - int span = properties.Length; - - for (int i = 0; i < span; i++) - { - bool dirty = - // TODO H3: x[ i ] != LazyPropertyInitializer.UnfetchedProperty && //x is the "current" state - properties[i].IsDirtyCheckable(anyUninitializedProperties) - && properties[i].Type.IsModified(y[i], x[i], includeColumns[i], session); - - if (dirty) - { - if (results == null) - { - results = new int[span]; - } - results[count++] = i; - } - } - if (count == 0) - { - return null; - } - else - { - int[] trimmed = new int[count]; - System.Array.Copy(results, 0, trimmed, 0, count); - return trimmed; - } - } - - /// <summary> - /// - /// </summary> - /// <param name="row"></param> - /// <param name="types"></param> - /// <param name="session"></param> - /// <param name="owner"></param> - /// <returns></returns> - public static object[] Assemble(object[] row, ICacheAssembler[] types, ISessionImplementor session, object owner) - { - object[] assembled = new object[row.Length]; - for (int i = 0; i < row.Length; i++) - { - assembled[i] = types[i].Assemble(row[i], session, owner); - } - return assembled; - } - - /// <summary> Apply the {@link Type#disassemble} operation across a series of values. </summary> - /// <param name="row">The values </param> - /// <param name="types">The value types </param> - /// <param name="nonCacheable">An array indicating which values to include in the disassembled state </param> - /// <param name="session">The originating session </param> - /// <param name="owner">The entity "owning" the values </param> - /// <returns> The disassembled state </returns> - public static object[] Disassemble(object[] row, ICacheAssembler[] types, bool[] nonCacheable, ISessionImplementor session, object owner) - { - object[] disassembled = new object[row.Length]; - for (int i = 0; i < row.Length; i++) - { - if (nonCacheable != null && nonCacheable[i]) - { - disassembled[i] = LazyPropertyInitializer.UnfetchedProperty; - } - else if (row[i] == LazyPropertyInitializer.UnfetchedProperty || row[i] == BackrefPropertyAccessor.Unknown) - { - disassembled[i] = row[i]; - } - else - { - disassembled[i] = types[i].Disassemble(row[i], session, owner); - } - } - return disassembled; - } - - - /// <summary> - /// Apply the <see cref="IType.Replace(object, object, ISessionImplementor, object, IDictionary)"/> operation across a series of values. - /// </summary> - /// <param name="original">The source of the state </param> - /// <param name="target">The target into which to replace the source values. </param> - /// <param name="types">The value types </param> - /// <param name="session">The originating session </param> - /// <param name="owner">The entity "owning" the values </param> - /// <param name="copiedAlready">Represent a cache of already replaced state </param> - /// <returns> The replaced state </returns> - public static object[] Replace(object[] original, object[] target, IType[] types, ISessionImplementor session, - object owner, IDictionary copiedAlready) - { - object[] copied = new object[original.Length]; - for (int i = 0; i < original.Length; i++) - { - copied[i] = types[i].Replace(original[i], target[i], session, owner, copiedAlready); - } - return copied; - } - - /// <summary> - /// Apply the <see cref="IType.Replace(object, object, ISessionImplementor, object, IDictionary, ForeignKeyDirection)"/> - /// operation across a series of values. - /// </summary> - /// <param name="original">The source of the state </param> - /// <param name="target">The target into which to replace the source values. </param> - /// <param name="types">The value types </param> - /// <param name="session">The originating session </param> - /// <param name="owner">The entity "owning" the values </param> - /// <param name="copyCache">A map representing a cache of already replaced state </param> - /// <param name="foreignKeyDirection">FK directionality to be applied to the replacement </param> - /// <returns> The replaced state </returns> - public static object[] Replace(object[] original, object[] target, IType[] types, - ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection) - { - object[] copied = new object[original.Length]; - for (int i = 0; i < types.Length; i++) - { - if (original[i] == LazyPropertyInitializer.UnfetchedProperty || original[i] == BackrefPropertyAccessor.Unknown) - { - copied[i] = target[i]; - } - else - copied[i] = types[i].Replace(original[i], target[i], session, owner, copyCache, foreignKeyDirection); - } - return copied; - } - - /// <summary> - /// Apply the <see cref="IType.Replace(object, object, ISessionImplementor, object, IDictionary, ForeignKeyDirection)"/> - /// operation across a series of values, as - /// long as the corresponding <see cref="IType"/> is an association. - /// </summary> - /// <param name="original">The source of the state </param> - /// <param name="target">The target into which to replace the source values. </param> - /// <param name="types">The value types </param> - /// <param name="session">The originating session </param> - /// <param name="owner">The entity "owning" the values </param> - /// <param name="copyCache">A map representing a cache of already replaced state </param> - /// <param name="foreignKeyDirection">FK directionality to be applied to the replacement </param> - /// <returns> The replaced state </returns> - /// <remarks> - /// If the corresponding type is a component type, then apply <see cref="ReplaceAssociations"/> - /// across the component subtypes but do not replace the component value itself. - /// </remarks> - public static object[] ReplaceAssociations(object[] original, object[] target, IType[] types, - ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection) - { - object[] copied = new object[original.Length]; - for (int i = 0; i < types.Length; i++) - { - if (original[i] == LazyPropertyInitializer.UnfetchedProperty || original[i] == BackrefPropertyAccessor.Unknown) - { - copied[i] = target[i]; - } - else if (types[i].IsComponentType) - { - // need to extract the component values and check for subtype replacements... - IAbstractComponentType componentType = (IAbstractComponentType)types[i]; - IType[] subtypes = componentType.Subtypes; - object[] origComponentValues = original[i] == null ? new object[subtypes.Length] : componentType.GetPropertyValues(original[i], session); - object[] targetComponentValues = target[i] == null ? new object[subtypes.Length] : componentType.GetPropertyValues(target[i], session); - - object[] componentCopy = ReplaceAssociations(origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection); - - if (!componentType.IsAnyType && target[i] != null) - componentType.SetPropertyValues(target[i], componentCopy, session.EntityMode); - - copied[i] = target[i]; - } - else if (!types[i].IsAssociationType) - { - copied[i] = target[i]; - } - else - { - copied[i] = types[i].Replace(original[i], target[i], session, owner, copyCache, foreignKeyDirection); - } - } - return copied; - } - public static CollectionType CustomCollection(string typeName, IDictionary<string, string> typeParameters, string role, string propertyRef, bool embedded) { Added: trunk/nhibernate/src/NHibernate/Type/TypeHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeHelper.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Type/TypeHelper.cs 2010-11-07 15:52:07 UTC (rev 5262) @@ -0,0 +1,304 @@ +using System; +using System.Collections; +using NHibernate.Engine; +using NHibernate.Intercept; +using NHibernate.Properties; +using NHibernate.Tuple; + +namespace NHibernate.Type +{ + /// <summary> + /// Collection of convenience methods relating to operations across arrays of types... + /// </summary> + public static class TypeHelper + { + /// <summary>Deep copy a series of values from one array to another</summary> + /// <param name="values">The values to copy (the source)</param> + /// <param name="types">The value types</param> + /// <param name="copy">An array indicating which values to include in the copy</param> + /// <param name="target">The array into which to copy the values</param> + /// <param name="session">The originating session</param> + public static void DeepCopy(object[] values, IType[] types, bool[] copy, object[] target, ISessionImplementor session) + { + for (int i = 0; i < types.Length; i++) + { + if (copy[i]) + { + if (values[i] == LazyPropertyInitializer.UnfetchedProperty || values[i] == BackrefPropertyAccessor.Unknown) + { + target[i] = values[i]; + } + else + { + target[i] = types[i].DeepCopy(values[i], session.EntityMode, session.Factory); + } + } + } + } + + /// <summary>Apply the <see cref="ICacheAssembler.BeforeAssemble" /> operation across a series of values.</summary> + /// <param name="row">The values</param> + /// <param name="types">The value types</param> + /// <param name="session">The originating session</param> + public static void BeforeAssemble(object[] row, ICacheAssembler[] types, ISessionImplementor session) + { + for (int i = 0; i < types.Length; i++) + { + if (row[i] != LazyPropertyInitializer.UnfetchedProperty && row[i] != BackrefPropertyAccessor.Unknown) + { + types[i].BeforeAssemble(row[i], session); + } + } + } + + /// <summary> + /// Apply the <see cref="ICacheAssembler.Assemble" /> operation across a series of values. + /// </summary> + /// <param name="row">The values</param> + /// <param name="types">The value types</param> + /// <param name="session">The originating session</param> + /// <param name="owner">The entity "owning" the values</param> + /// <returns></returns> + public static object[] Assemble(object[] row, ICacheAssembler[] types, ISessionImplementor session, object owner) + { + object[] assembled = new object[row.Length]; + for (int i = 0; i < row.Length; i++) + { + assembled[i] = types[i].Assemble(row[i], session, owner); + } + return assembled; + } + + /// <summary>Apply the <see cref="ICacheAssembler.Disassemble" /> operation across a series of values.</summary> + /// <param name="row">The values</param> + /// <param name="types">The value types</param> + /// <param name="nonCacheable">An array indicating which values to include in the disassembled state</param> + /// <param name="session">The originating session</param> + /// <param name="owner">The entity "owning" the values</param> + /// <returns> The disassembled state</returns> + public static object[] Disassemble(object[] row, ICacheAssembler[] types, bool[] nonCacheable, ISessionImplementor session, object owner) + { + object[] disassembled = new object[row.Length]; + for (int i = 0; i < row.Length; i++) + { + if (nonCacheable != null && nonCacheable[i]) + { + disassembled[i] = LazyPropertyInitializer.UnfetchedProperty; + } + else if (row[i] == LazyPropertyInitializer.UnfetchedProperty || row[i] == BackrefPropertyAccessor.Unknown) + { + disassembled[i] = row[i]; + } + else + { + disassembled[i] = types[i].Disassemble(row[i], session, owner); + } + } + return disassembled; + } + + /// <summary> + /// Apply the <see cref="IType.Replace(object, object, ISessionImplementor, object, IDictionary)" /> operation across a series of values. + /// </summary> + /// <param name="original">The source of the state</param> + /// <param name="target">The target into which to replace the source values.</param> + /// <param name="types">The value types</param> + /// <param name="session">The originating session</param> + /// <param name="owner">The entity "owning" the values</param> + /// <param name="copiedAlready">Represent a cache of already replaced state</param> + /// <returns> The replaced state</returns> + public static object[] Replace(object[] original, object[] target, IType[] types, ISessionImplementor session, + object owner, IDictionary copiedAlready) + { + object[] copied = new object[original.Length]; + for (int i = 0; i < original.Length; i++) + { + copied[i] = types[i].Replace(original[i], target[i], session, owner, copiedAlready); + } + return copied; + } + + /// <summary> + /// Apply the <see cref="IType.Replace(object, object, ISessionImplementor, object, IDictionary, ForeignKeyDirection)" /> + /// operation across a series of values. + /// </summary> + /// <param name="original">The source of the state</param> + /// <param name="target">The target into which to replace the source values.</param> + /// <param name="types">The value types</param> + /// <param name="session">The originating session</param> + /// <param name="owner">The entity "owning" the values</param> + /// <param name="copyCache">A map representing a cache of already replaced state</param> + /// <param name="foreignKeyDirection">FK directionality to be applied to the replacement</param> + /// <returns> The replaced state</returns> + public static object[] Replace(object[] original, object[] target, IType[] types, + ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection) + { + object[] copied = new object[original.Length]; + for (int i = 0; i < types.Length; i++) + { + if (original[i] == LazyPropertyInitializer.UnfetchedProperty || original[i] == BackrefPropertyAccessor.Unknown) + { + copied[i] = target[i]; + } + else + copied[i] = types[i].Replace(original[i], target[i], session, owner, copyCache, foreignKeyDirection); + } + return copied; + } + + /// <summary> + /// Apply the <see cref="IType.Replace(object, object, ISessionImplementor, object, IDictionary, ForeignKeyDirection)" /> + /// operation across a series of values, as long as the corresponding <see cref="IType"/> is an association. + /// </summary> + /// <param name="original">The source of the state</param> + /// <param name="target">The target into which to replace the source values.</param> + /// <param name="types">The value types</param> + /// <param name="session">The originating session</param> + /// <param name="owner">The entity "owning" the values</param> + /// <param name="copyCache">A map representing a cache of already replaced state</param> + /// <param name="foreignKeyDirection">FK directionality to be applied to the replacement</param> + /// <returns> The replaced state</returns> + /// <remarks> + /// If the corresponding type is a component type, then apply <see cref="ReplaceAssociations" /> + /// across the component subtypes but do not replace the component value itself. + /// </remarks> + public static object[] ReplaceAssociations(object[] original, object[] target, IType[] types, + ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection) + { + object[] copied = new object[original.Length]; + for (int i = 0; i < types.Length; i++) + { + if (original[i] == LazyPropertyInitializer.UnfetchedProperty || original[i] == BackrefPropertyAccessor.Unknown) + { + copied[i] = target[i]; + } + else if (types[i].IsComponentType) + { + // need to extract the component values and check for subtype replacements... + IAbstractComponentType componentType = (IAbstractComponentType)types[i]; + IType[] subtypes = componentType.Subtypes; + object[] origComponentValues = original[i] == null ? new object[subtypes.Length] : componentType.GetPropertyValues(original[i], session); + object[] targetComponentValues = target[i] == null ? new object[subtypes.Length] : componentType.GetPropertyValues(target[i], session); + + object[] componentCopy = ReplaceAssociations(origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection); + + if (!componentType.IsAnyType && target[i] != null) + componentType.SetPropertyValues(target[i], componentCopy, session.EntityMode); + + copied[i] = target[i]; + } + else if (!types[i].IsAssociationType) + { + copied[i] = target[i]; + } + else + { + copied[i] = types[i].Replace(original[i], target[i], session, owner, copyCache, foreignKeyDirection); + } + } + return copied; + } + + /// <summary> + /// <para>Determine if any of the given field values are dirty, returning an array containing + /// indices of the dirty fields.</para> + /// <para>If it is determined that no fields are dirty, null is returned.</para> + /// </summary> + /// <param name="properties">The property definitions</param> + /// <param name="x">The current state of the entity</param> + /// <param name="y">The baseline state of the entity</param> + /// <param name="includeColumns">Columns to be included in the dirty checking, per property</param> + /// <param name="anyUninitializedProperties">Does the entity currently hold any uninitialized property values?</param> + /// <param name="session">The session from which the dirty check request originated.</param> + /// <returns>Array containing indices of the dirty properties, or null if no properties considered dirty.</returns> + public static int[] FindDirty(StandardProperty[] properties, + object[] currentState, + object[] previousState, + bool[][] includeColumns, + bool anyUninitializedProperties, + ISessionImplementor session) + { + int[] results = null; + int count = 0; + int span = properties.Length; + + for (int i = 0; i < span; i++) + { + bool dirty = + // TODO H3: x[ i ] != LazyPropertyInitializer.UnfetchedProperty && //x is the "current" state + properties[i].IsDirtyCheckable(anyUninitializedProperties) + && properties[i].Type.IsDirty(previousState[i], currentState[i], includeColumns[i], session); + + if (dirty) + { + if (results == null) + { + results = new int[span]; + } + results[count++] = i; + } + } + if (count == 0) + { + return null; + } + else + { + int[] trimmed = new int[count]; + System.Array.Copy(results, 0, trimmed, 0, count); + return trimmed; + } + } + + /// <summary> + /// <para>Determine if any of the given field values are modified, returning an array containing + /// indices of the modified fields.</para> + /// <para>If it is determined that no fields are dirty, null is returned.</para> + /// </summary> + /// <param name="properties">The property definitions</param> + /// <param name="x">The current state of the entity</param> + /// <param name="y">The baseline state of the entity</param> + /// <param name="includeColumns">Columns to be included in the mod checking, per property</param> + /// <param name="anyUninitializedProperties">Does the entity currently hold any uninitialized property values?</param> + /// <param name="session">The session from which the dirty check request originated.</param> + /// <returns>Array containing indices of the modified properties, or null if no properties considered modified.</returns> + public static int[] FindModified(StandardProperty[] properties, + object[] currentState, + object[] previousState, + bool[][] includeColumns, + bool anyUninitializedProperties, + ISessionImplementor session) + { + int[] results = null; + int count = 0; + int span = properties.Length; + + for (int i = 0; i < span; i++) + { + bool dirty = + // TODO H3: x[ i ] != LazyPropertyInitializer.UnfetchedProperty && //x is the "current" state + properties[i].IsDirtyCheckable(anyUninitializedProperties) + && properties[i].Type.IsModified(previousState[i], currentState[i], includeColumns[i], session); + + if (dirty) + { + if (results == null) + { + results = new int[span]; + } + results[count++] = i; + } + } + if (count == 0) + { + return null; + } + else + { + int[] trimmed = new int[count]; + System.Array.Copy(results, 0, trimmed, 0, count); + return trimmed; + } + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2010-11-07 16:26:10
|
Revision: 5263 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5263&view=rev Author: julian-maughan Date: 2010-11-07 16:26:04 +0000 (Sun, 07 Nov 2010) Log Message: ----------- Changed projects to suppress CLS-compliance compiler warnings: CS3001-3005 (Debug and Release configurations). Improves visibility of more relevant warnings. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.ByteCode.Castle/NHibernate.ByteCode.Castle.csproj trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/NHibernate.ByteCode.Castle.Tests.csproj trunk/nhibernate/src/NHibernate.ByteCode.LinFu/NHibernate.ByteCode.LinFu.csproj trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/NHibernate.ByteCode.LinFu.Tests.csproj trunk/nhibernate/src/NHibernate.ByteCode.Spring/NHibernate.ByteCode.Spring.csproj trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/NHibernate.ByteCode.Spring.Tests.csproj trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-11-07 15:52:07 UTC (rev 5262) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-11-07 16:26:04 UTC (rev 5263) @@ -30,7 +30,7 @@ <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <DocumentationFile>bin\Debug-2.0\NHibernate.XML</DocumentationFile> - <NoWarn>1591</NoWarn> + <NoWarn>1591%3b3001%3b3002%3b3003%3b3004%3b3005</NoWarn> <WarningsAsErrors>1717;1574</WarningsAsErrors> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> @@ -42,6 +42,7 @@ <DefineConstants>TRACE;NET_2_0</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <ItemGroup> <Reference Include="System" /> Modified: trunk/nhibernate/src/NHibernate.ByteCode.Castle/NHibernate.ByteCode.Castle.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle/NHibernate.ByteCode.Castle.csproj 2010-11-07 15:52:07 UTC (rev 5262) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle/NHibernate.ByteCode.Castle.csproj 2010-11-07 16:26:04 UTC (rev 5263) @@ -23,6 +23,7 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -31,6 +32,7 @@ <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <ItemGroup> <Reference Include="Castle.Core, Version=1.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL"> Modified: trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/NHibernate.ByteCode.Castle.Tests.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/NHibernate.ByteCode.Castle.Tests.csproj 2010-11-07 15:52:07 UTC (rev 5262) +++ trunk/nhibernate/src/NHibernate.ByteCode.Castle.Tests/NHibernate.ByteCode.Castle.Tests.csproj 2010-11-07 16:26:04 UTC (rev 5263) @@ -23,6 +23,7 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -31,6 +32,7 @@ <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <ItemGroup> <Reference Include="Castle.Core, Version=1.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL"> Modified: trunk/nhibernate/src/NHibernate.ByteCode.LinFu/NHibernate.ByteCode.LinFu.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.LinFu/NHibernate.ByteCode.LinFu.csproj 2010-11-07 15:52:07 UTC (rev 5262) +++ trunk/nhibernate/src/NHibernate.ByteCode.LinFu/NHibernate.ByteCode.LinFu.csproj 2010-11-07 16:26:04 UTC (rev 5263) @@ -23,6 +23,7 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -31,6 +32,7 @@ <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <ItemGroup> <Reference Include="System" /> Modified: trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/NHibernate.ByteCode.LinFu.Tests.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/NHibernate.ByteCode.LinFu.Tests.csproj 2010-11-07 15:52:07 UTC (rev 5262) +++ trunk/nhibernate/src/NHibernate.ByteCode.LinFu.Tests/NHibernate.ByteCode.LinFu.Tests.csproj 2010-11-07 16:26:04 UTC (rev 5263) @@ -23,6 +23,7 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -31,6 +32,7 @@ <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <ItemGroup> <Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL"> Modified: trunk/nhibernate/src/NHibernate.ByteCode.Spring/NHibernate.ByteCode.Spring.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Spring/NHibernate.ByteCode.Spring.csproj 2010-11-07 15:52:07 UTC (rev 5262) +++ trunk/nhibernate/src/NHibernate.ByteCode.Spring/NHibernate.ByteCode.Spring.csproj 2010-11-07 16:26:04 UTC (rev 5263) @@ -23,6 +23,7 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -31,6 +32,7 @@ <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <ItemGroup> <Reference Include="antlr.runtime, Version=2.7.6.2, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL"> Modified: trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/NHibernate.ByteCode.Spring.Tests.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/NHibernate.ByteCode.Spring.Tests.csproj 2010-11-07 15:52:07 UTC (rev 5262) +++ trunk/nhibernate/src/NHibernate.ByteCode.Spring.Tests/NHibernate.ByteCode.Spring.Tests.csproj 2010-11-07 16:26:04 UTC (rev 5263) @@ -23,6 +23,7 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -31,6 +32,7 @@ <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <ItemGroup> <Reference Include="antlr.runtime, Version=2.7.6.2, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL"> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-11-07 15:52:07 UTC (rev 5262) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-11-07 16:26:04 UTC (rev 5263) @@ -30,6 +30,7 @@ <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <UseVSHostingProcess>false</UseVSHostingProcess> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -41,6 +42,7 @@ <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <UseVSHostingProcess>false</UseVSHostingProcess> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <ItemGroup> <Reference Include="Antlr3.Runtime, Version=3.1.0.39271, Culture=neutral, PublicKeyToken=3a9cab8f8d22bfb7, processorArchitecture=MSIL"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2010-11-10 06:54:19
|
Revision: 5264 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5264&view=rev Author: ricbrown Date: 2010-11-10 06:54:12 +0000 (Wed, 10 Nov 2010) Log Message: ----------- QueryOver - pushed Skip/Take up to base class so that paging can be applied to IQueryOver<T> as well as IQueryOver<T,U> Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/IQueryOver.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-11-07 16:26:04 UTC (rev 5263) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2010-11-10 06:54:12 UTC (rev 5264) @@ -116,12 +116,12 @@ /// <returns></returns> public QueryOver<TRoot,TRoot> ToRowCountQuery() { - return + return (QueryOver<TRoot,TRoot>) Clone() + .Select(Projections.RowCount()) .ClearOrders() .Skip(0) - .Take(RowSelection.NoValue) - .Select(Projections.RowCount()); + .Take(RowSelection.NoValue); } /// <summary> @@ -130,12 +130,12 @@ /// <returns></returns> public QueryOver<TRoot,TRoot> ToRowCountInt64Query() { - return + return (QueryOver<TRoot,TRoot>) Clone() + .Select(Projections.RowCountInt64()) .ClearOrders() .Skip(0) - .Take(RowSelection.NoValue) - .Select(Projections.RowCountInt64()); + .Take(RowSelection.NoValue); } /// <summary> @@ -146,6 +146,42 @@ return new QueryOver<TRoot,TRoot>((CriteriaImpl)criteria.Clone()); } + public QueryOver<TRoot> ClearOrders() + { + criteria.ClearOrders(); + return this; + } + + public QueryOver<TRoot> Skip(int firstResult) + { + criteria.SetFirstResult(firstResult); + return this; + } + + public QueryOver<TRoot> Take(int maxResults) + { + criteria.SetMaxResults(maxResults); + return this; + } + + public QueryOver<TRoot> Cacheable() + { + criteria.SetCacheable(true); + return this; + } + + public QueryOver<TRoot> CacheMode(CacheMode cacheMode) + { + criteria.SetCacheMode(cacheMode); + return this; + } + + public QueryOver<TRoot> CacheRegion(string cacheRegion) + { + criteria.SetCacheRegion(cacheRegion); + return this; + } + /// <summary> /// Method to allow comparison of detached query in Lambda expression /// e.g., p => p.Name == myQuery.As<string> @@ -197,6 +233,24 @@ IQueryOver<TRoot,TRoot> IQueryOver<TRoot>.Clone() { return Clone(); } + IQueryOver<TRoot> IQueryOver<TRoot>.ClearOrders() + { return ClearOrders(); } + + IQueryOver<TRoot> IQueryOver<TRoot>.Skip(int firstResult) + { return Skip(firstResult); } + + IQueryOver<TRoot> IQueryOver<TRoot>.Take(int maxResults) + { return Take(maxResults); } + + IQueryOver<TRoot> IQueryOver<TRoot>.Cacheable() + { return Cacheable(); } + + IQueryOver<TRoot> IQueryOver<TRoot>.CacheMode(CacheMode cacheMode) + { return CacheMode(cacheMode); } + + IQueryOver<TRoot> IQueryOver<TRoot>.CacheRegion(string cacheRegion) + { return CacheRegion(cacheRegion); } + } /// <summary> @@ -364,48 +418,12 @@ return new QueryOverOrderBuilder<TRoot,TSubType>(this, path, true); } - public QueryOver<TRoot,TSubType> ClearOrders() - { - criteria.ClearOrders(); - return this; - } - public QueryOver<TRoot,TSubType> TransformUsing(IResultTransformer resultTransformer) { criteria.SetResultTransformer(resultTransformer); return this; } - public QueryOver<TRoot,TSubType> Skip(int firstResult) - { - criteria.SetFirstResult(firstResult); - return this; - } - - public QueryOver<TRoot,TSubType> Take(int maxResults) - { - criteria.SetMaxResults(maxResults); - return this; - } - - public QueryOver<TRoot,TSubType> Cacheable() - { - criteria.SetCacheable(true); - return this; - } - - public QueryOver<TRoot,TSubType> CacheMode(CacheMode cacheMode) - { - criteria.SetCacheMode(cacheMode); - return this; - } - - public QueryOver<TRoot,TSubType> CacheRegion(string cacheRegion) - { - criteria.SetCacheRegion(cacheRegion); - return this; - } - public QueryOverSubqueryBuilder<TRoot,TSubType> WithSubquery { get { return new QueryOverSubqueryBuilder<TRoot,TSubType>(this); } @@ -718,27 +736,9 @@ IQueryOverOrderBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.ThenByAlias(Expression<Func<object>> path) { return new IQueryOverOrderBuilder<TRoot,TSubType>(this, path, true); } - IQueryOver<TRoot,TSubType> IQueryOver<TRoot, TSubType>.ClearOrders() - { return ClearOrders(); } - IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.TransformUsing(IResultTransformer resultTransformer) { return TransformUsing(resultTransformer); } - IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.Skip(int firstResult) - { return Skip(firstResult); } - - IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.Take(int maxResults) - { return Take(maxResults); } - - IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.Cacheable() - { return Cacheable(); } - - IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.CacheMode(CacheMode cacheMode) - { return CacheMode(cacheMode); } - - IQueryOver<TRoot,TSubType> IQueryOver<TRoot,TSubType>.CacheRegion(string cacheRegion) - { return CacheRegion(cacheRegion); } - IQueryOverSubqueryBuilder<TRoot,TSubType> IQueryOver<TRoot,TSubType>.WithSubquery { get { return new IQueryOverSubqueryBuilder<TRoot,TSubType>(this); } } Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-11-07 16:26:04 UTC (rev 5263) +++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2010-11-10 06:54:12 UTC (rev 5264) @@ -120,6 +120,40 @@ /// </summary> IQueryOver<TRoot,TRoot> Clone(); + /// <summary> + /// Clear all orders from the query. + /// </summary> + IQueryOver<TRoot> ClearOrders(); + + /// <summary> + /// Set the first result to be retrieved + /// </summary> + /// <param name="firstResult"></param> + IQueryOver<TRoot> Skip(int firstResult); + + /// <summary> + /// Set a limit upon the number of objects to be retrieved + /// </summary> + /// <param name="maxResults"></param> + IQueryOver<TRoot> Take(int maxResults); + + /// <summary> + /// Enable caching of this query result set + /// </summary> + IQueryOver<TRoot> Cacheable(); + + /// <summary> Override the cache mode for this particular query. </summary> + /// <param name="cacheMode">The cache mode to use. </param> + /// <returns> this (for method chaining) </returns> + IQueryOver<TRoot> CacheMode(CacheMode cacheMode); + + /// <summary> + /// Set the name of the cache region. + /// </summary> + /// <param name="cacheRegion">the name of a query cache region, or <see langword="null" /> + /// for the default query cache</param> + IQueryOver<TRoot> CacheRegion(string cacheRegion); + } /// <summary> @@ -301,45 +335,11 @@ IQueryOverOrderBuilder<TRoot,TSubType> ThenByAlias(Expression<Func<object>> path); /// <summary> - /// Clear all orders from the query. - /// </summary> - IQueryOver<TRoot, TSubType> ClearOrders(); - - /// <summary> /// Transform the results using the supplied IResultTransformer /// </summary> IQueryOver<TRoot,TSubType> TransformUsing(IResultTransformer resultTransformer); /// <summary> - /// Set the first result to be retrieved - /// </summary> - /// <param name="firstResult"></param> - IQueryOver<TRoot,TSubType> Skip(int firstResult); - - /// <summary> - /// Set a limit upon the number of objects to be retrieved - /// </summary> - /// <param name="maxResults"></param> - IQueryOver<TRoot,TSubType> Take(int maxResults); - - /// <summary> - /// Enable caching of this query result set - /// </summary> - IQueryOver<TRoot,TSubType> Cacheable(); - - /// <summary> Override the cache mode for this particular query. </summary> - /// <param name="cacheMode">The cache mode to use. </param> - /// <returns> this (for method chaining) </returns> - IQueryOver<TRoot,TSubType> CacheMode(CacheMode cacheMode); - - /// <summary> - /// Set the name of the cache region. - /// </summary> - /// <param name="cacheRegion">the name of a query cache region, or <see langword="null" /> - /// for the default query cache</param> - IQueryOver<TRoot,TSubType> CacheRegion(string cacheRegion); - - /// <summary> /// Add a subquery expression /// </summary> IQueryOverSubqueryBuilder<TRoot,TSubType> WithSubquery { get; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2010-11-21 17:14:56
|
Revision: 5267 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5267&view=rev Author: julian-maughan Date: 2010-11-21 17:14:48 +0000 (Sun, 21 Nov 2010) Log Message: ----------- In the Criteria API, fix the way in which query parameters are generated, so that they are in the same order as the parameters in the SQL statement (ref. NH-2409). Reverses a design change introduced in r3458 (see NH-1280). Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/AggregateProjection.cs trunk/nhibernate/src/NHibernate/Criterion/BetweenExpression.cs trunk/nhibernate/src/NHibernate/Criterion/ConstantProjection.cs trunk/nhibernate/src/NHibernate/Criterion/ICriteriaQuery.cs trunk/nhibernate/src/NHibernate/Criterion/IdentifierEqExpression.cs trunk/nhibernate/src/NHibernate/Criterion/InExpression.cs trunk/nhibernate/src/NHibernate/Criterion/InsensitiveLikeExpression.cs trunk/nhibernate/src/NHibernate/Criterion/LikeExpression.cs trunk/nhibernate/src/NHibernate/Criterion/Order.cs trunk/nhibernate/src/NHibernate/Criterion/SQLCriterion.cs trunk/nhibernate/src/NHibernate/Criterion/SimpleExpression.cs trunk/nhibernate/src/NHibernate/Criterion/SimpleSubqueryExpression.cs trunk/nhibernate/src/NHibernate/Criterion/SubqueryExpression.cs trunk/nhibernate/src/NHibernate/Criterion/SubqueryProjection.cs trunk/nhibernate/src/NHibernate/Loader/AbstractEntityJoinWalker.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs trunk/nhibernate/src/NHibernate.Test/Criteria/AddNumberProjection.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Contest.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Message.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/MessageReading.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/User.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/AggregateProjection.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/AggregateProjection.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/AggregateProjection.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using NHibernate.SqlCommand; +using NHibernate.Engine; using NHibernate.Type; using NHibernate.Util; @@ -47,25 +48,24 @@ return new IType[] {criteriaQuery.GetType(criteria, propertyName)}; } - public override SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery, - IDictionary<string, IFilter> enabledFilters) + public override SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { if (projection != null) { return new SqlString(new object[] - { - aggregate, "(", - StringHelper.RemoveAsAliasesFromSql(projection.ToSqlString(criteria, loc, criteriaQuery, - enabledFilters)), ") as y", - loc.ToString(), "_" - }); + { + aggregate, "(", + StringHelper.RemoveAsAliasesFromSql(projection.ToSqlString(criteria, loc, criteriaQuery, + enabledFilters)), ") as y", + loc.ToString(), "_" + }); } else { return new SqlString(new object[] - {aggregate, "(", criteriaQuery.GetColumn(criteria, propertyName), ") as y", loc.ToString(), "_"}); + {aggregate, "(", criteriaQuery.GetColumn(criteria, propertyName), ") as y", loc.ToString(), "_"}); } } @@ -74,10 +74,17 @@ get { return false; } } - public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, - IDictionary<string, IFilter> enabledFilters) + public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { throw new InvalidOperationException("not a grouping projection"); } + + public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) + { + if (projection != null) + return projection.GetTypedValues(criteria, criteriaQuery); + + return base.GetTypedValues(criteria, criteriaQuery); + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Criterion/BetweenExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/BetweenExpression.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/BetweenExpression.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -1,10 +1,10 @@ +using System; +using System.Collections.Generic; +using NHibernate.Engine; +using NHibernate.SqlCommand; + namespace NHibernate.Criterion { - using System; - using System.Collections.Generic; - using Engine; - using SqlCommand; - /// <summary> /// An <see cref="ICriterion"/> that represents a "between" constraint. /// </summary> @@ -23,11 +23,11 @@ /// <param name="_projection">The _projection.</param> /// <param name="_lo">The _lo.</param> /// <param name="_hi">The _hi.</param> - public BetweenExpression(IProjection _projection, object _lo, object _hi) + public BetweenExpression(IProjection projection, object lo, object hi) { - this._projection = _projection; - this._lo = _lo; - this._hi = _hi; + this._projection = projection; + this._lo = lo; + this._hi = hi; } /// <summary> @@ -44,8 +44,7 @@ _hi = hi; } - public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, - IDictionary<string, IFilter> enabledFilters) + public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { //TODO: add a default capacity SqlStringBuilder sqlBuilder = new SqlStringBuilder(); @@ -54,7 +53,6 @@ SqlString[] columnNames = CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters); - criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery)); if (columnNames.Length == 1) { sqlBuilder @@ -107,7 +105,6 @@ return null; } - /// <summary></summary> public override string ToString() { return _propertyName + " between " + _lo + " and " + _hi; Modified: trunk/nhibernate/src/NHibernate/Criterion/ConstantProjection.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/ConstantProjection.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/ConstantProjection.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -1,11 +1,11 @@ +using System; +using System.Collections.Generic; +using NHibernate.Engine; +using NHibernate.SqlCommand; +using NHibernate.Type; + namespace NHibernate.Criterion { - using System; - using System.Collections.Generic; - using Engine; - using SqlCommand; - using Type; - /// <summary> /// This is useful if we want to send a value to the database /// </summary> @@ -14,17 +14,17 @@ { private readonly object value; private readonly IType type; - public ConstantProjection(object value):this(value,NHibernateUtil.GuessType(value.GetType())) + + public ConstantProjection(object value) : this(value, NHibernateUtil.GuessType(value.GetType())) { - } - public ConstantProjection(object value,IType type) + + public ConstantProjection(object value, IType type) { this.value = value; this.type = type; } - public override bool IsAggregate { get { return false; } @@ -42,7 +42,6 @@ public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { - criteriaQuery.AddUsedTypedValues(new TypedValue[] { new TypedValue(type, value, EntityMode.Poco) }); return new SqlStringBuilder() .AddParameter() .Add(" as ") Modified: trunk/nhibernate/src/NHibernate/Criterion/ICriteriaQuery.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/ICriteriaQuery.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/ICriteriaQuery.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -13,27 +13,27 @@ { ISessionFactoryImplementor Factory { get; } - /// <summary> Get the name of the column mapped by a property path, ignoring projection alias</summary> + /// <summary>Get the name of the column mapped by a property path, ignoring projection alias</summary> string GetColumn(ICriteria criteria, string propertyPath); - /// <summary> Get the names of the columns mapped by a property path, ignoring projection aliases</summary> + /// <summary>Get the names of the columns mapped by a property path, ignoring projection aliases</summary> string[] GetColumns(ICriteria criteria, string propertyPath); - /// <summary> Get the type of a property path, ignoring projection aliases</summary> + /// <summary>Get the type of a property path, ignoring projection aliases</summary> IType GetType(ICriteria criteria, string propertyPath); string[] GetColumnAliasesUsingProjection(ICriteria criteria, string propertyPath); - /// <summary> Get the names of the columns mapped by a property path</summary> + /// <summary>Get the names of the columns mapped by a property path</summary> string[] GetColumnsUsingProjection(ICriteria criteria, string propertyPath); - /// <summary> Get the type of a property path</summary> + /// <summary>Get the type of a property path</summary> IType GetTypeUsingProjection(ICriteria criteria, string propertyPath); - /// <summary> Get the a typed value for the given property value.</summary> + /// <summary>Get the a typed value for the given property value.</summary> TypedValue GetTypedValue(ICriteria criteria, string propertyPath, object value); - /// <summary> Get the entity name of an entity</summary> + /// <summary>Get the entity name of an entity</summary> string GetEntityName(ICriteria criteria); /// <summary> @@ -42,7 +42,7 @@ /// </summary> string GetEntityName(ICriteria criteria, string propertyPath); - /// <summary> Get the root table alias of an entity</summary> + /// <summary>Get the root table alias of an entity</summary> string GetSQLAlias(ICriteria subcriteria); /// <summary> @@ -51,13 +51,13 @@ /// </summary> string GetSQLAlias(ICriteria criteria, string propertyPath); - /// <summary> Get the property name, given a possibly qualified property name</summary> + /// <summary>Get the property name, given a possibly qualified property name</summary> string GetPropertyName(string propertyName); - /// <summary> Get the identifier column names of this entity</summary> + /// <summary>Get the identifier column names of this entity</summary> string[] GetIdentifierColumns(ICriteria subcriteria); - /// <summary> Get the identifier type of this entity</summary> + /// <summary>Get the identifier type of this entity</summary> IType GetIdentifierType(ICriteria subcriteria); TypedValue GetTypedIdentifierValue(ICriteria subcriteria, object value); @@ -67,12 +67,6 @@ int GetIndexForAlias(); /// <summary> - /// When adding values to the query string it is imperative that they are reported via this function back to the query builder. - /// Do not report the same item multiple times as it will be assumed to be a separate parameter. - /// </summary> - void AddUsedTypedValues(TypedValue [] values); - - /// <summary> /// Creates a dummy parameter index for the supplied paged value. /// Returns null if the Dialect does not support limit parameters /// </summary> Modified: trunk/nhibernate/src/NHibernate/Criterion/IdentifierEqExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/IdentifierEqExpression.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/IdentifierEqExpression.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -62,7 +62,6 @@ { if (_projection == null) { - criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria,criteriaQuery)); result.AddParameter(); } else @@ -74,6 +73,9 @@ public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) { + if (_projection != null) + return _projection.GetTypedValues(criteria, criteriaQuery); + return new TypedValue[] {criteriaQuery.GetTypedIdentifierValue(criteria, value)}; } Modified: trunk/nhibernate/src/NHibernate/Criterion/InExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/InExpression.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/InExpression.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -1,15 +1,15 @@ using System; using System.Collections; +using System.Collections.Generic; using NHibernate.Engine; using NHibernate.SqlCommand; using NHibernate.Type; using NHibernate.Util; -using System.Collections.Generic; namespace NHibernate.Criterion { /// <summary> - /// An <see cref="ICriterion"/> that constrains the property + /// An <see cref="ICriterion"/> that constrains the property /// to a specified list of values. /// </summary> /// <remarks> @@ -27,17 +27,12 @@ /// </summary> /// <param name="projection">The projection.</param> /// <param name="_values">The _values.</param> - public InExpression(IProjection projection, object[] _values) + public InExpression(IProjection projection, object[] values) { _projection = projection; - this._values = _values; + _values = values; } - /// <summary> - /// - /// </summary> - /// <param name="propertyName"></param> - /// <param name="values"></param> public InExpression(string propertyName, object[] values) { _propertyName = propertyName; @@ -46,15 +41,14 @@ public override IProjection[] GetProjections() { - if(_projection != null) + if (_projection != null) { return new IProjection[] { _projection }; } return null; } - public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, - IDictionary<string, IFilter> enabledFilters) + public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { if (_projection == null) { @@ -75,7 +69,6 @@ // Generate SqlString of the form: // columnName1 in (values) and columnName2 in (values) and ... - criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery)); for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++) { SqlString columnName = columnNames[columnIndex]; @@ -124,7 +117,7 @@ else { IType[] types = _projection.GetTypes(criteria, criteriaQuery); - if(types.Length!=1) + if (types.Length != 1) { throw new QueryException("Cannot use projections that return more than a single column with InExpression"); } @@ -142,10 +135,8 @@ for (int j = 0; j < _values.Length; j++) { object subval = _values[j] == null - ? - null - : - actype.GetPropertyValues(_values[j], EntityMode.Poco)[i]; + ? null + : actype.GetPropertyValues(_values[j], EntityMode.Poco)[i]; list.Add(new TypedValue(types[i], subval, EntityMode.Poco)); } } @@ -167,7 +158,6 @@ protected set { _values = value; } } - /// <summary></summary> public override string ToString() { return (_projection ?? (object)_propertyName) + " in (" + StringHelper.ToString(_values) + ')'; Modified: trunk/nhibernate/src/NHibernate/Criterion/InsensitiveLikeExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/InsensitiveLikeExpression.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/InsensitiveLikeExpression.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -1,11 +1,11 @@ +using System; +using System.Collections.Generic; +using NHibernate.Dialect; +using NHibernate.Engine; +using NHibernate.SqlCommand; + namespace NHibernate.Criterion { - using System; - using System.Collections.Generic; - using Dialect; - using Engine; - using SqlCommand; - /// <summary> /// An <see cref="ICriterion"/> that represents an "like" constraint /// that is <b>not</b> case sensitive. @@ -58,15 +58,13 @@ { } - public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, - IDictionary<string, IFilter> enabledFilters) + public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { //TODO: add default capacity SqlStringBuilder sqlBuilder = new SqlStringBuilder(); SqlString[] columnNames = CriterionUtil.GetColumnNames(propertyName, projection, criteriaQuery, criteria, enabledFilters); - criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria,criteriaQuery)); if (columnNames.Length != 1) { throw new HibernateException("insensitive like may only be used with single-column properties"); @@ -93,23 +91,31 @@ public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) { - return CriterionUtil.GetTypedValues(criteriaQuery, criteria, projection, propertyName, value.ToString().ToLower()); + List<TypedValue> typedValues = new List<TypedValue>(); + + if (projection != null) + { + typedValues.AddRange(projection.GetTypedValues(criteria, criteriaQuery)); + typedValues.AddRange(CriterionUtil.GetTypedValues(criteriaQuery, criteria, projection, null, value.ToString().ToLower())); + } + else + typedValues.Add(criteriaQuery.GetTypedValue(criteria, propertyName, value.ToString().ToLower())); + + return typedValues.ToArray(); } public override IProjection[] GetProjections() { - if(projection != null) + if (projection != null) { return new IProjection[] { projection }; } return null; } - /// <summary></summary> public override string ToString() { return (projection ?? (object)propertyName) + " ilike " + value; } - } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Criterion/LikeExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/LikeExpression.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/LikeExpression.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -1,7 +1,7 @@ using System; +using System.Collections.Generic; using NHibernate.Engine; using NHibernate.SqlCommand; -using System.Collections.Generic; using NHibernate.Util; namespace NHibernate.Criterion @@ -10,7 +10,7 @@ /// An <see cref="ICriterion"/> that represents an "like" constraint. /// </summary> /// <remarks> - /// The case sensitivity depends on the database settings for string + /// The case sensitivity depends on the database settings for string /// comparisons. Use <see cref="InsensitiveLikeExpression"/> if the /// string comparison should not be case sensitive. /// </remarks> @@ -73,8 +73,6 @@ else lhs.Add(columns[0]); - criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery)); - if (ignoreCase) { Dialect.Dialect dialect = criteriaQuery.Factory.Dialect; @@ -89,14 +87,13 @@ if (escapeChar.HasValue) lhs.Add(" escape '" + escapeChar + "'"); + return lhs.ToSqlString(); } public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) { - return new TypedValue[] { - new TypedValue(NHibernateUtil.String, value, EntityMode.Poco), - }; + return new TypedValue[] { new TypedValue(NHibernateUtil.String, value, EntityMode.Poco) }; } public override IProjection[] GetProjections() Modified: trunk/nhibernate/src/NHibernate/Criterion/Order.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/Order.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/Order.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using System.Text; +using NHibernate.Criterion; using NHibernate.Engine; -using NHibernate.Criterion; using NHibernate.SqlCommand; namespace NHibernate.Criterion @@ -11,43 +11,36 @@ /// Represents an order imposed upon a <see cref="ICriteria"/> /// result set. /// </summary> + /// <remarks> + /// Should Order implement ICriteriaQuery? + /// </remarks> [Serializable] public class Order { protected bool ascending; protected string propertyName; protected IProjection projection; - /// <summary> - /// Constructor for Order. - /// </summary> - /// <param name="projection"></param> - /// <param name="ascending"></param> + public Order(IProjection projection, bool ascending) { this.projection = projection; this.ascending = ascending; } - /// <summary> - /// Constructor for Order. - /// </summary> - /// <param name="propertyName"></param> - /// <param name="ascending"></param> public Order(string propertyName, bool ascending) { this.propertyName = propertyName; this.ascending = ascending; } - /// <summary> /// Render the SQL fragment /// </summary> public virtual SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { - if(projection!=null) + if (projection!=null) { - SqlString sb=new SqlString(); + SqlString sb = new SqlString(); SqlString produced = this.projection.ToSqlString(criteria, 0, criteriaQuery, new Dictionary<string, IFilter>()); SqlString truncated = NHibernate.Util.StringHelper.RemoveAsAliasesFromSql(produced); sb = sb.Append(truncated); @@ -131,5 +124,13 @@ { return new Order(propertyName, false); } + + public TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) + { + if (projection != null) + return projection.GetTypedValues(criteria, criteriaQuery); + + return new TypedValue[0]; // not using parameters for ORDER BY columns + } } } Modified: trunk/nhibernate/src/NHibernate/Criterion/SQLCriterion.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/SQLCriterion.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/SQLCriterion.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -32,7 +32,6 @@ public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { - criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery)); return _sql.Replace("{alias}", criteriaQuery.GetSQLAlias(criteria)); } @@ -46,7 +45,6 @@ return null; } - /// <summary></summary> public override string ToString() { return _sql.ToString(); Modified: trunk/nhibernate/src/NHibernate/Criterion/SimpleExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/SimpleExpression.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/SimpleExpression.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -77,10 +77,15 @@ public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { SqlString[] columnNames = - CriterionUtil.GetColumnNamesForSimpleExpression(propertyName, _projection, criteriaQuery, criteria, enabledFilters, - this, value); + CriterionUtil.GetColumnNamesForSimpleExpression( + propertyName, + _projection, + criteriaQuery, + criteria, + enabledFilters, + this, + value); - criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery)); if (ignoreCase) { if (columnNames.Length != 1) @@ -120,20 +125,29 @@ public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) { + List<TypedValue> typedValues = new List<TypedValue>(); object icvalue = ignoreCase ? value.ToString().ToLower() : value; - return CriterionUtil.GetTypedValues(criteriaQuery, criteria, _projection,propertyName, icvalue); + + if (_projection != null) + { + typedValues.AddRange(_projection.GetTypedValues(criteria, criteriaQuery)); + typedValues.AddRange(CriterionUtil.GetTypedValues(criteriaQuery, criteria, _projection, null, icvalue)); + } + else + typedValues.Add(criteriaQuery.GetTypedValue(criteria, propertyName, icvalue)); + + return typedValues.ToArray(); } public override IProjection[] GetProjections() { - if(_projection != null) + if (_projection != null) { return new IProjection[] { _projection }; } return null; } - /// <summary></summary> public override string ToString() { return (_projection ?? (object)propertyName) + Op + value; Modified: trunk/nhibernate/src/NHibernate/Criterion/SimpleSubqueryExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/SimpleSubqueryExpression.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/SimpleSubqueryExpression.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -14,12 +14,10 @@ internal SimpleSubqueryExpression(Object value, String op, String quantifier, DetachedCriteria dc) : base(op, quantifier, dc) - { this.value = value; } - public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) { TypedValue[] superTv = base.GetTypedValues(criteria, criteriaQuery); @@ -31,7 +29,6 @@ protected override SqlString ToLeftSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { - criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery)); return SqlString.Parameter; } } Modified: trunk/nhibernate/src/NHibernate/Criterion/SubqueryExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/SubqueryExpression.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/SubqueryExpression.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -14,25 +14,24 @@ { private readonly CriteriaImpl criteriaImpl; private readonly String quantifier; - private readonly bool prefixOp; - private readonly String op; + private readonly bool prefixOp; + private readonly String op; private QueryParameters parameters; private IType[] types; [NonSerialized] private CriteriaQueryTranslator innerQuery; - protected SubqueryExpression(String op, String quantifier, DetachedCriteria dc) - :this(op, quantifier, dc, true) - { - - } + protected SubqueryExpression(String op, String quantifier, DetachedCriteria dc) + :this(op, quantifier, dc, true) + { + } protected SubqueryExpression(String op, String quantifier, DetachedCriteria dc, bool prefixOp) { criteriaImpl = dc.GetCriteriaImpl(); this.quantifier = quantifier; - this.prefixOp = prefixOp; - this.op = op; + this.prefixOp = prefixOp; + this.op = op; } public IType[] GetTypes() @@ -42,8 +41,7 @@ protected abstract SqlString ToLeftSqlString(ICriteria criteria, ICriteriaQuery outerQuery); - public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, - IDictionary<string, IFilter> enabledFilters) + public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { InitializeInnerQueryAndParameters(criteriaQuery); @@ -80,27 +78,27 @@ buf.Add(" ").Add(op).Add(" "); } - if (quantifier != null && prefixOp) + if (quantifier != null && prefixOp) { buf.Add(quantifier).Add(" "); } - - buf.Add("(").Add(sql).Add(")"); + + buf.Add("(").Add(sql).Add(")"); - if(quantifier!=null && prefixOp==false) - { - buf.Add(" ").Add(quantifier); - } + if (quantifier != null && prefixOp == false) + { + buf.Add(" ").Add(quantifier); + } - return buf.ToSqlString(); + return buf.ToSqlString(); } public override string ToString() { - if(prefixOp) - return string.Format("{0} {1} ({2})", op, quantifier, criteriaImpl); - return string.Format("{0} ({1}) {2}", op, criteriaImpl, quantifier); - + if(prefixOp) + return string.Format("{0} {1} ({2})", op, quantifier, criteriaImpl); + + return string.Format("{0} ({1}) {2}", op, criteriaImpl, quantifier); } public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) @@ -123,19 +121,28 @@ public void InitializeInnerQueryAndParameters(ICriteriaQuery criteriaQuery) { - ISessionFactoryImplementor factory = criteriaQuery.Factory; - innerQuery = - new CriteriaQueryTranslator(factory, criteriaImpl, //implicit polymorphism not supported (would need a union) - criteriaImpl.EntityOrClassName, criteriaQuery.GenerateSQLAlias(), criteriaQuery); - if (innerQuery.HasProjection) + if (innerQuery == null) { - parameters = innerQuery.GetQueryParameters(); - types = innerQuery.ProjectedTypes; + ISessionFactoryImplementor factory = criteriaQuery.Factory; + + innerQuery = + new CriteriaQueryTranslator( + factory, + criteriaImpl, //implicit polymorphism not supported (would need a union) + criteriaImpl.EntityOrClassName, + criteriaQuery.GenerateSQLAlias(), + criteriaQuery); + + if (innerQuery.HasProjection) + { + parameters = innerQuery.GetQueryParameters(); + types = innerQuery.ProjectedTypes; + } + else + { + types = null; + } } - else - { - types = null; - } } public ICriteria Criteria @@ -144,4 +151,4 @@ get { return criteriaImpl; } } } -} +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Criterion/SubqueryProjection.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/SubqueryProjection.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Criterion/SubqueryProjection.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -1,12 +1,12 @@ using System; +using System.Collections.Generic; +using NHibernate.Engine; using NHibernate.Impl; using NHibernate.SqlCommand; using NHibernate.Type; namespace NHibernate.Criterion { - using System.Collections.Generic; - /// <summary> /// A property value, or grouped property value /// </summary> @@ -19,6 +19,7 @@ { _subQuery = subquery; } + public override string ToString() { return _subQuery.ToString(); @@ -43,17 +44,17 @@ public override SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { SqlString sqlStringSubquery = _subQuery.ToSqlString(criteria, criteriaQuery, enabledFilters); - return sqlStringSubquery.Append(new SqlString(new object[] - { - " as y", - loc.ToString(), - "_" - })); + return sqlStringSubquery.Append(new SqlString(new object[] { " as y", loc.ToString(), "_" } )); } public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { throw new InvalidOperationException("not a grouping projection"); } + + public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) + { + return _subQuery.GetTypedValues(criteria, criteriaQuery); + } } } Modified: trunk/nhibernate/src/NHibernate/Loader/AbstractEntityJoinWalker.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/AbstractEntityJoinWalker.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Loader/AbstractEntityJoinWalker.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -1,10 +1,10 @@ using System.Collections.Generic; using NHibernate.Engine; +using NHibernate.Loader.Criteria; using NHibernate.Persister.Entity; using NHibernate.SqlCommand; using NHibernate.Type; using NHibernate.Util; -using NHibernate.Loader.Criteria; namespace NHibernate.Loader { @@ -13,16 +13,14 @@ private readonly IOuterJoinLoadable persister; private readonly string alias; - public AbstractEntityJoinWalker(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, - IDictionary<string, IFilter> enabledFilters) + public AbstractEntityJoinWalker(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters) : base(factory, enabledFilters) { this.persister = persister; alias = GenerateRootAlias(persister.EntityName); } - public AbstractEntityJoinWalker(string rootSqlAlias, IOuterJoinLoadable persister, ISessionFactoryImplementor factory, - IDictionary<string, IFilter> enabledFilters) + public AbstractEntityJoinWalker(string rootSqlAlias, IOuterJoinLoadable persister, ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters) : base(factory, enabledFilters) { this.persister = persister; @@ -35,26 +33,17 @@ IList<OuterJoinableAssociation> allAssociations = new List<OuterJoinableAssociation>(associations); allAssociations.Add( new OuterJoinableAssociation(persister.EntityType, null, null, alias, JoinType.LeftOuterJoin, null, Factory, - new CollectionHelper.EmptyMapClass<string, IFilter>())); + new CollectionHelper.EmptyMapClass<string, IFilter>())); InitPersisters(allAssociations, lockMode); InitStatementString(whereString, orderByString, lockMode); } - protected void InitProjection(CriteriaQueryTranslator translator, - IDictionary<string, IFilter> enabledFilters, LockMode lockMode) + protected void InitProjection(SqlString projectionString, SqlString whereString, SqlString orderByString, SqlString groupByString, SqlString havingString, IDictionary<string, IFilter> enabledFilters, LockMode lockMode) { - // the order of the calls here is important, as the join clauses can contain parameter bindings - SqlString projectionString = translator.GetSelect(enabledFilters); WalkEntityTree(persister, Alias); - SqlString whereString = translator.GetWhereCondition(enabledFilters); - SqlString orderByString = translator.GetOrderBy(); - SqlString groupByString = translator.GetGroupBy(); - SqlString havingString = translator.GetHavingCondition(enabledFilters); - Persisters = new ILoadable[0]; - InitStatementString(projectionString, whereString, orderByString, groupByString.ToString(), - havingString, lockMode); + InitStatementString(projectionString, whereString, orderByString, groupByString.ToString(), havingString, lockMode); } private void InitStatementString(SqlString condition, SqlString orderBy, LockMode lockMode) @@ -62,16 +51,14 @@ InitStatementString(null, condition, orderBy, string.Empty, null, lockMode); } - private void InitStatementString(SqlString projection,SqlString condition, - SqlString orderBy,string groupBy, SqlString having, LockMode lockMode) + private void InitStatementString(SqlString projection,SqlString condition, SqlString orderBy, string groupBy, SqlString having, LockMode lockMode) { int joins = CountEntityPersisters(associations); Suffixes = BasicLoader.GenerateSuffixes(joins + 1); JoinFragment ojf = MergeOuterJoins(associations); - SqlString selectClause = projection - ?? - new SqlString(persister.SelectFragment(alias, Suffixes[joins]) + SelectString(associations)); + SqlString selectClause = + projection ?? new SqlString(persister.SelectFragment(alias, Suffixes[joins]) + SelectString(associations)); SqlSelectBuilder select = new SqlSelectBuilder(Factory) .SetLockMode(lockMode) @@ -92,8 +79,7 @@ /// <summary> /// The superclass deliberately excludes collections /// </summary> - protected override bool IsJoinedFetchEnabled(IAssociationType type, FetchMode config, - CascadeStyle cascadeStyle) + protected override bool IsJoinedFetchEnabled(IAssociationType type, FetchMode config, CascadeStyle cascadeStyle) { return IsJoinedFetchEnabledInMapping(config, type); } Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -42,7 +42,14 @@ { resultTypes = translator.ProjectedTypes; - InitProjection(translator, enabledFilters, LockMode.None); + InitProjection( + translator.GetSelect(enabledFilters), + translator.GetWhereCondition(enabledFilters), + translator.GetOrderBy(), + translator.GetGroupBy(), + translator.GetHavingCondition(enabledFilters), + enabledFilters, + LockMode.None); } else { Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Text; using Iesi.Collections.Generic; using NHibernate.Criterion; @@ -8,7 +9,7 @@ using NHibernate.Hql.Util; using NHibernate.Impl; using NHibernate.Persister.Collection; -using NHibernate.Persister.Entity; +using NHibernate_Persister_Entity = NHibernate.Persister.Entity; using NHibernate.SqlCommand; using NHibernate.Type; using NHibernate.Util; @@ -106,18 +107,6 @@ public QueryParameters GetQueryParameters() { - ArrayList values = new ArrayList(usedTypedValues.Count); - List<IType> types = new List<IType>(usedTypedValues.Count); - - foreach (TypedValue value in usedTypedValues) - { - values.Add(value.Value); - types.Add(value.Type); - } - - object[] valueArray = values.ToArray(); - IType[] typeArray = types.ToArray(); - RowSelection selection = new RowSelection(); selection.FirstRow = rootCriteria.FirstResult; selection.MaxRows = rootCriteria.MaxResults; @@ -130,6 +119,14 @@ ICriteria subcriteria = GetAliasedCriteria(me.Key); lockModes[GetSQLAlias(subcriteria)] = me.Value; } + + List<TypedValue> typedValues = new List<TypedValue>(); + + // NH-specific: Get parameters for projections first + if (this.HasProjection) + { + typedValues.AddRange(rootCriteria.Projection.GetTypedValues(rootCriteria, this)); + } foreach (CriteriaImpl.Subcriteria subcriteria in rootCriteria.IterateSubcriteria()) { @@ -138,13 +135,69 @@ { lockModes[GetSQLAlias(subcriteria)] = lm; } + // Get parameters that may be used in JOINs + if (subcriteria.WithClause != null) + { + typedValues.AddRange(subcriteria.WithClause.GetTypedValues(subcriteria, this)); + } } + + List<TypedValue> groupedTypedValues = new List<TypedValue>(); + + // Type and value gathering for the WHERE clause needs to come AFTER lock mode gathering, + // because the lock mode gathering loop now contains join clauses which can contain + // parameter bindings (as in the HQL WITH clause). + foreach(CriteriaImpl.CriterionEntry ce in rootCriteria.IterateExpressionEntries()) + { + bool criteriaContainsGroupedProjections = false; + IProjection[] projections = ce.Criterion.GetProjections(); + if (projections != null) + { + foreach (IProjection projection in projections) + { + if (projection.IsGrouped) + { + criteriaContainsGroupedProjections = true; + break; + } + } + } + + if (criteriaContainsGroupedProjections) + // GROUP BY/HAVING parameters need to be added after WHERE parameters - so don't add them + // to typedValues yet + groupedTypedValues.AddRange(ce.Criterion.GetTypedValues(ce.Criteria, this)); + else + typedValues.AddRange(ce.Criterion.GetTypedValues(ce.Criteria, this)); + } + + // NH-specific: GROUP BY/HAVING parameters need to appear after WHERE parameters + if (groupedTypedValues.Count > 0) + { + typedValues.AddRange(groupedTypedValues); + } + + // NH-specific: To support expressions/projections used in ORDER BY + foreach(CriteriaImpl.OrderEntry oe in rootCriteria.IterateOrderings()) + { + typedValues.AddRange(oe.Order.GetTypedValues(oe.Criteria, this)); + } + return - new QueryParameters(typeArray, valueArray, lockModes, selection, rootCriteria.Cacheable, rootCriteria.CacheRegion, - rootCriteria.Comment, rootCriteria.LookupByNaturalKey, rootCriteria.ResultTransformer, _tempPagingParameterIndexes); + new QueryParameters( + typedValues.Select(tv => tv.Type).ToArray(), + typedValues.Select(tv => tv.Value).ToArray(), + lockModes, + selection, + rootCriteria.Cacheable, + rootCriteria.CacheRegion, + rootCriteria.Comment, + rootCriteria.LookupByNaturalKey, + rootCriteria.ResultTransformer, + _tempPagingParameterIndexes); } - + public SqlString GetGroupBy() { if (rootCriteria.Projection.IsGrouped) @@ -366,7 +419,7 @@ private void CreateCriteriaEntityNameMap() { // initialize the rootProvider first - ICriteriaInfoProvider rootProvider = new EntityCriteriaInfoProvider((IQueryable)sessionFactory.GetEntityPersister(rootEntityName)); + ICriteriaInfoProvider rootProvider = new EntityCriteriaInfoProvider((NHibernate_Persister_Entity.IQueryable)sessionFactory.GetEntityPersister(rootEntityName)); criteriaInfoMap.Add(rootCriteria, rootProvider); nameCriteriaInfoMap.Add(rootProvider.Name, rootProvider); @@ -384,7 +437,7 @@ { foreach (KeyValuePair<string, ICriteria> me in associationPathCriteriaMap) { - IJoinable joinable = GetPathJoinable(me.Key); + NHibernate_Persister_Entity.IJoinable joinable = GetPathJoinable(me.Key); if (joinable != null && joinable.IsCollection) { criteriaCollectionPersisters.Add((ICollectionPersister)joinable); @@ -392,10 +445,10 @@ } } - private IJoinable GetPathJoinable(string path) + private Persister.Entity.IJoinable GetPathJoinable(string path) { - IJoinable last = (IJoinable)Factory.GetEntityPersister(rootEntityName); - IPropertyMapping lastEntity = (IPropertyMapping)last; + NHibernate_Persister_Entity.IJoinable last = (NHibernate_Persister_Entity.IJoinable)Factory.GetEntityPersister(rootEntityName); + NHibernate_Persister_Entity.IPropertyMapping lastEntity = (NHibernate_Persister_Entity.IPropertyMapping)last; string componentPath = ""; @@ -417,7 +470,7 @@ IAssociationType atype = (IAssociationType)type; last = atype.GetAssociatedJoinable(Factory); - lastEntity = (IPropertyMapping)Factory.GetEntityPersister(atype.GetAssociatedEntityName(Factory)); + lastEntity = (NHibernate_Persister_Entity.IPropertyMapping)Factory.GetEntityPersister(atype.GetAssociatedEntityName(Factory)); componentPath = ""; } else if (type.IsComponentType) @@ -466,7 +519,7 @@ } else { - provider = new EntityCriteriaInfoProvider((IQueryable)sessionFactory.GetEntityPersister( + provider = new EntityCriteriaInfoProvider((NHibernate_Persister_Entity.IQueryable)sessionFactory.GetEntityPersister( atype.GetAssociatedEntityName( sessionFactory) )); @@ -564,18 +617,18 @@ public string[] GetIdentifierColumns(ICriteria subcriteria) { - string[] idcols = ((ILoadable)GetPropertyMapping(GetEntityName(subcriteria))).IdentifierColumnNames; + string[] idcols = ((NHibernate_Persister_Entity.ILoadable)GetPropertyMapping(GetEntityName(subcriteria))).IdentifierColumnNames; return StringHelper.Qualify(GetSQLAlias(subcriteria), idcols); } public IType GetIdentifierType(ICriteria subcriteria) { - return ((ILoadable)GetPropertyMapping(GetEntityName(subcriteria))).IdentifierType; + return ((NHibernate_Persister_Entity.ILoadable)GetPropertyMapping(GetEntityName(subcriteria))).IdentifierType; } public TypedValue GetTypedIdentifierValue(ICriteria subcriteria, object value) { - ILoadable loadable = (ILoadable)GetPropertyMapping(GetEntityName(subcriteria)); + NHibernate_Persister_Entity.ILoadable loadable = (NHibernate_Persister_Entity.ILoadable)GetPropertyMapping(GetEntityName(subcriteria)); return new TypedValue(loadable.IdentifierType, value, EntityMode.Poco); } @@ -641,7 +694,7 @@ var entityClass = value as System.Type; if (entityClass != null) { - IQueryable q = helper.FindQueryableUsingImports(entityClass.FullName); + NHibernate_Persister_Entity.IQueryable q = helper.FindQueryableUsingImports(entityClass.FullName); if (q != null && q.DiscriminatorValue != null) { @@ -653,7 +706,7 @@ return new TypedValue(GetTypeUsingProjection(subcriteria, propertyName), value, EntityMode.Poco); } - private IPropertyMapping GetPropertyMapping(string entityName) + private Persister.Entity.IPropertyMapping GetPropertyMapping(string entityName) { ICriteriaInfoProvider info ; if (nameCriteriaInfoMap.TryGetValue(entityName, out info)==false) @@ -720,21 +773,6 @@ return indexForAlias++; } - public void AddUsedTypedValues(TypedValue[] values) - { - if (values != null) - { - if (outerQueryTranslator != null) - { - outerQueryTranslator.AddUsedTypedValues(values); - } - else - { - usedTypedValues.AddRange(values); - } - } - } - public int? CreatePagingParameter(int value) { if (!Factory.Dialect.SupportsVariableLimit) Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/AddNumberProjection.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/AddNumberProjection.cs 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/AddNumberProjection.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -1,13 +1,12 @@ using System; +using System.Collections.Generic; +using NHibernate.Engine; +using NHibernate.Criterion; +using NHibernate.SqlCommand; +using NHibernate.Type; namespace NHibernate.Test.Criteria { - using System.Collections.Generic; - using Engine; - using Criterion; - using SqlCommand; - using Type; - public class AddNumberProjection : SimpleProjection { private readonly string propertyName; @@ -27,7 +26,7 @@ public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { string[] projection = criteriaQuery.GetColumnsUsingProjection(criteria, propertyName); - criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery)); + return new SqlStringBuilder() .Add("(") .Add(projection[0]) @@ -54,8 +53,7 @@ get { return false; } } - public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, - IDictionary<string, IFilter> enabledFilters) + public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { throw new InvalidOperationException("not a grouping projection"); } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Contest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Contest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Contest.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -0,0 +1,7 @@ +namespace NHibernate.Test.NHSpecificTest.NH2409 +{ + public class Contest + { + public virtual int Id { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Fixture.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -0,0 +1,60 @@ +using System; +using System.Linq; +using NHibernate.Criterion; +using NHibernate.SqlCommand; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2409 +{ + [TestFixture] + public class Fixture : BugTestCase + { + [Test] + public void Bug() + { + using (var session = OpenSession()) + using (var tx = session.BeginTransaction()) + { + var contest1 = new Contest {Id = 1}; + var contest2 = new Contest {Id = 2}; + var user = new User(); + + var message = new Message {Contest = contest2 }; + + session.Save(contest1); + session.Save(contest2); + session.Save(user); + + session.Save(message); + tx.Commit(); + } + + using (var session = OpenSession()) + { + var contest2 = session.CreateCriteria<Contest>().Add(Restrictions.IdEq(2)).UniqueResult<Contest>(); + var user = session.CreateCriteria<User>().List<User>().Single(); + + var msgs = session.CreateCriteria<Message>() + .Add(Restrictions.Eq("Contest", contest2)) + .CreateAlias("Readings", "mr", JoinType.LeftOuterJoin, Restrictions.Eq("mr.User", user)) + .List<Message>(); + + Assert.AreEqual(1, msgs.Count, "We should be able to find our message despite any left outer joins"); + } + } + + protected override void OnTearDown() + { + using (var session = OpenSession()) + using (var tx = session.BeginTransaction()) + { + session.Delete("from Contest"); + session.Delete("from User"); + session.Delete("from Message"); + session.Delete("from MessageReading"); + tx.Commit(); + } + base.OnTearDown(); + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Mappings.hbm.xml 2010-11-21 17:14:48 UTC (rev 5267) @@ -0,0 +1,38 @@ +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.NH2409" + assembly="NHibernate.Test"> + <class name="Contest" lazy="true"> + <id name="Id"> + <generator class="assigned" /> + </id> + </class> + + <class name="Message" lazy="true"> + <id name="Id"> + <generator class="native" /> + </id> + + <many-to-one name="Contest" class="Contest" column="ContestId"/> + + <bag name="Readings" cascade="all" inverse="true"> + <key column="MessageReadingId"/> + <one-to-many class="MessageReading"/> + </bag> + </class> + + <class name="MessageReading" lazy="true"> + <id name="Id"> + <generator class="native" /> + </id> + + <many-to-one name="User" + class="User" column="UserId"/> + </class> + + <class name="User" lazy="true" table="`User`"> + <id name="Id"> + <generator class="native" /> + </id> + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Message.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Message.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/Message.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH2409 +{ + public class Message + { + public virtual int Id { get; set; } + + public virtual Contest Contest { get; set; } + + public virtual IList<MessageReading> Readings { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/MessageReading.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/MessageReading.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/MessageReading.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -0,0 +1,9 @@ +namespace NHibernate.Test.NHSpecificTest.NH2409 +{ + public class MessageReading + { + public virtual int Id { get; set; } + + public virtual User User { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/User.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/User.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2409/User.cs 2010-11-21 17:14:48 UTC (rev 5267) @@ -0,0 +1,7 @@ +namespace NHibernate.Test.NHSpecificTest.NH2409 +{ + public class User + { + public virtual int Id { get; set; } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-11-20 13:12:25 UTC (rev 5266) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-11-21 17:14:48 UTC (rev 5267) @@ -30,7 +30,7 @@ <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <UseVSHostingProcess>false</UseVSHostingProcess> - <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -42,7 +42,7 @@ <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <UseVSHostingProcess>false</UseVSHostingProcess> - <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> + <NoWarn>3001%3b3002%3b3003%3b3004%3b3005</NoWarn> </PropertyGroup> <ItemGroup> <Reference Include="Antlr3.Runtime, Version=3.1.0.39271, Culture=neutral, PublicKeyToken=3a9cab8f8d22bfb7, processorArchitecture=MSIL"> @@ -542,6 +542,11 @@ <Compile Include="NHSpecificTest\NH2392\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2392\PhoneNumber.cs" /> <Compile Include="NHSpecificTest\NH2392\PhoneNumberUserType.cs" /> + <Compile Include="NHSpecificTest\NH2409\Contest.cs" /> + <Compile Include="NHSpecificTest\NH2409\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2409\Message.cs" /> + <Compile Include="NHSpecificTest\NH2409\MessageReading.cs" /> + <Compile Include="NHSpecificTest\NH2409\User.cs" /> <Compile Include="PolymorphicGetAndLoad\Domain.cs" /> <Compile Include="PolymorphicGetAndLoad\PolymorphicGetAndLoadTest.cs" /> <Compile Include="TypesTest\CharClass.cs" /> @@ -1834,6 +1839,7 @@ <EmbeddedResource Include="NHSpecificTest\NH2202\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1869\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2392\Mappings.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\NH2409\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\NHibernate.ByteCode.Castle\NHibernate.ByteCode.Castle.csproj"> @@ -2699,6 +2705,7 @@ </ItemGroup> <ItemGroup> <Folder Include="NHSpecificTest\NH2392" /> + <Folder Include="NHSpecificTest\NH2409" /> <Folder Include="Properties\" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2010-11-25 03:34:12
|
Revision: 5269 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5269&view=rev Author: patearl Date: 2010-11-25 03:34:05 +0000 (Thu, 25 Nov 2010) Log Message: ----------- Utilize simple SQL equality in expressions that may involve null values. (NH-2402) Fixed missing cases in Linq null (in)equality handling. Fixed Linq query caching when the same variable alternates between null and non-null values. (part of NH-2397) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionKeyVisitor.cs trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs trunk/nhibernate/src/NHibernate.Test/DbScripts/MsSql2008DialectLinqReadonlyCreateScript.sql trunk/nhibernate/src/NHibernate.Test/Linq/Entities/AnotherEntity.cs trunk/nhibernate/src/NHibernate.Test/Linq/Mappings/AnotherEntity.hbm.xml trunk/nhibernate/src/NHibernate.Test/Linq/NorthwindDbCreator.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionKeyVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionKeyVisitor.cs 2010-11-21 17:36:14 UTC (rev 5268) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionKeyVisitor.cs 2010-11-25 03:34:05 UTC (rev 5269) @@ -77,7 +77,11 @@ if (_constantToParameterMap.TryGetValue(expression, out param)) { - _string.Append(param.Name); + // Nulls generate different query plans. X = variable generates a different query depending on if variable is null or not. + if (param.Value == null) + _string.Append("NULL"); + else + _string.Append(param.Name); } else { Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2010-11-21 17:36:14 UTC (rev 5268) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2010-11-25 03:34:05 UTC (rev 5269) @@ -226,34 +226,22 @@ return _hqlTreeBuilder.Equality(lhs, rhs); } - // Also check for nullability - if (expression.Left.Type.IsNullableOrReference() || expression.Right.Type.IsNullableOrReference()) + // Check for nulls on left or right. + if (expression.Right is ConstantExpression + && expression.Right.Type.IsNullableOrReference() + && ((ConstantExpression)expression.Right).Value == null) { - // TODO - yuck. This clone is needed because the AST tree nodes are not immutable, - // and sharing nodes between multiple branches will cause issues in the hqlSqlWalker phase - - // a node, x, gets visited during the walk and updated to refer to a real property. Later in - // the walk, x get revisited (since we copied it here), but now the type doesn't match what - // the parser expects. So we can't share. Implementing Clone() on HqlTreeNode would be better - // that doing a full visit of the Expression tree. Allowing shared nodes in the AST would be better - // still, but might be more work - var lhs2 = VisitExpression(expression.Left).AsExpression(); - var rhs2 = VisitExpression(expression.Right).AsExpression(); - - if (expression.Right is ConstantExpression - && expression.Right.Type.IsNullableOrReference() - && ((ConstantExpression)expression.Right).Value == null) - { - return _hqlTreeBuilder.IsNull(lhs2); - } - - return _hqlTreeBuilder.BooleanOr( - _hqlTreeBuilder.BooleanAnd( - _hqlTreeBuilder.IsNull(lhs), - _hqlTreeBuilder.IsNull(rhs)), - _hqlTreeBuilder.Equality(lhs2, rhs2) - ); + return _hqlTreeBuilder.IsNull(lhs); } + if (expression.Left is ConstantExpression + && expression.Left.Type.IsNullableOrReference() + && ((ConstantExpression)expression.Left).Value == null) + { + return _hqlTreeBuilder.IsNull(rhs); + } + + // Nothing was null, use standard equality. return _hqlTreeBuilder.Equality(lhs, rhs); case ExpressionType.NotEqual: @@ -274,36 +262,24 @@ } - // Also check for nullability - if (expression.Left.Type.IsNullableOrReference() || expression.Right.Type.IsNullableOrReference()) + // Check for nulls on left or right. + if (expression.Right is ConstantExpression + && expression.Right.Type.IsNullableOrReference() + && ((ConstantExpression)expression.Right).Value == null) { - var lhs2 = VisitExpression(expression.Left).AsExpression(); - var rhs2 = VisitExpression(expression.Right).AsExpression(); - var lhs3 = VisitExpression(expression.Left).AsExpression(); - var rhs3 = VisitExpression(expression.Right).AsExpression(); - - if (expression.Right is ConstantExpression - && expression.Right.Type.IsNullableOrReference() - && ((ConstantExpression)expression.Right).Value == null) - { - return _hqlTreeBuilder.IsNotNull(lhs2); - } - - return - _hqlTreeBuilder.BooleanOr( - _hqlTreeBuilder.BooleanOr( - _hqlTreeBuilder.BooleanAnd( - _hqlTreeBuilder.IsNull(lhs), - _hqlTreeBuilder.IsNotNull(rhs)), - _hqlTreeBuilder.BooleanAnd( - _hqlTreeBuilder.IsNotNull(lhs2), - _hqlTreeBuilder.IsNull(rhs2)) - ), - _hqlTreeBuilder.Inequality(lhs3, rhs3)); + return _hqlTreeBuilder.IsNotNull(lhs); } - return _hqlTreeBuilder.Inequality(lhs, rhs); + if (expression.Left is ConstantExpression + && expression.Left.Type.IsNullableOrReference() + && ((ConstantExpression)expression.Left).Value == null) + { + return _hqlTreeBuilder.IsNotNull(rhs); + } + // Nothing was null, use standard inequality. + return _hqlTreeBuilder.Inequality(lhs, rhs); + case ExpressionType.And: return _hqlTreeBuilder.BitwiseAnd(lhs, rhs); Modified: trunk/nhibernate/src/NHibernate.Test/DbScripts/MsSql2008DialectLinqReadonlyCreateScript.sql =================================================================== (Binary files differ) Modified: trunk/nhibernate/src/NHibernate.Test/Linq/Entities/AnotherEntity.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/Entities/AnotherEntity.cs 2010-11-21 17:36:14 UTC (rev 5268) +++ trunk/nhibernate/src/NHibernate.Test/Linq/Entities/AnotherEntity.cs 2010-11-25 03:34:05 UTC (rev 5269) @@ -4,5 +4,6 @@ { public virtual int Id { get; set; } public virtual string Output { get; set; } + public virtual string Input { get; set; } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/Linq/Mappings/AnotherEntity.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/Mappings/AnotherEntity.hbm.xml 2010-11-21 17:36:14 UTC (rev 5268) +++ trunk/nhibernate/src/NHibernate.Test/Linq/Mappings/AnotherEntity.hbm.xml 2010-11-25 03:34:05 UTC (rev 5269) @@ -5,5 +5,6 @@ <generator class="native" /> </id> <property name="Output" /> + <property name="Input" /> </class> </hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/Linq/NorthwindDbCreator.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/NorthwindDbCreator.cs 2010-11-21 17:36:14 UTC (rev 5268) +++ trunk/nhibernate/src/NHibernate.Test/Linq/NorthwindDbCreator.cs 2010-11-25 03:34:05 UTC (rev 5269) @@ -20,7 +20,7 @@ IsActive = true, Entity = new AnotherEntity() { - Output = "this is output..." + Output = "output" } }, new Role() @@ -143,6 +143,16 @@ animals[1].Children = new[] { animals[5] }.ToList(); + List<AnotherEntity> otherEntities = new List<AnotherEntity>(); + // AnotherEntity with only Output set is created above. + otherEntities.Add(new AnotherEntity { Input = "input" }); + otherEntities.Add(new AnotherEntity { Input = "i/o", Output = "i/o" }); + otherEntities.Add(new AnotherEntity()); // Input and Output both null. + otherEntities.Add(new AnotherEntity { Input = "input", Output = "output" }); + + foreach (AnotherEntity otherEntity in otherEntities) + session.Save(otherEntity); + foreach (Role role in roles) session.Save(role); Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-11-21 17:36:14 UTC (rev 5268) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-11-25 03:34:05 UTC (rev 5269) @@ -448,6 +448,7 @@ <Compile Include="Linq\MethodCallTests.cs" /> <Compile Include="Linq\MiscellaneousTextFixture.cs" /> <Compile Include="Linq\NorthwindDbCreator.cs" /> + <Compile Include="Linq\NullComparisonTests.cs" /> <Compile Include="Linq\ObjectDumper.cs" /> <Compile Include="Linq\OrderByTests.cs" /> <Compile Include="Linq\PagingTests.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2010-11-28 03:37:37
|
Revision: 5276 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5276&view=rev Author: patearl Date: 2010-11-28 03:37:31 +0000 (Sun, 28 Nov 2010) Log Message: ----------- Linq: Added an expression visitor that provides access to parent nodes while visiting. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/NHibernate.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Linq/Visitors/ContextualNhExpressionTreeVisitor.cs trunk/nhibernate/src/NHibernate/Linq/Visitors/VisitorContext.cs Added: trunk/nhibernate/src/NHibernate/Linq/Visitors/ContextualNhExpressionTreeVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/ContextualNhExpressionTreeVisitor.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ContextualNhExpressionTreeVisitor.cs 2010-11-28 03:37:31 UTC (rev 5276) @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using NHibernate.Linq.Visitors; + +namespace NHibernate.Linq +{ + public class ContextualNhExpressionTreeVisitor : NhExpressionTreeVisitor + { + private Stack<VisitorContext> _contextStack; + + public ContextualNhExpressionTreeVisitor() + { + _contextStack = new Stack<VisitorContext>(); + _contextStack.Push(null); + } + + public override Expression VisitExpression(Expression expression) + { + if (expression == null) + return null; + + VisitorContext context = new VisitorContext(_contextStack.Peek(), expression); + _contextStack.Push(context); + + Expression result = base.VisitExpression(expression); + + _contextStack.Pop(); + + return result; + } + + protected VisitorContext Context + { + get { return _contextStack.Peek(); } + } + } +} Added: trunk/nhibernate/src/NHibernate/Linq/Visitors/VisitorContext.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/VisitorContext.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/VisitorContext.cs 2010-11-28 03:37:31 UTC (rev 5276) @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; + +namespace NHibernate.Linq.Visitors +{ + public class VisitorContext + { + public VisitorContext(VisitorContext parent, Expression expression) + { + Parent = parent; + Expression = expression; + } + + public VisitorContext Parent { get; private set; } + public Expression Expression { get; private set; } + } +} Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-11-26 04:02:34 UTC (rev 5275) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-11-28 03:37:31 UTC (rev 5276) @@ -241,6 +241,8 @@ <Compile Include="ISessionFactory.cs" /> <Compile Include="ITransaction.cs" /> <Compile Include="LazyInitializationException.cs" /> + <Compile Include="Linq\Visitors\ContextualNhExpressionTreeVisitor.cs" /> + <Compile Include="Linq\Visitors\VisitorContext.cs" /> <Compile Include="Loader\Loader.cs" /> <Compile Include="Loader\OuterJoinLoader.cs" /> <Compile Include="LockMode.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2010-11-28 19:12:19
|
Revision: 5278 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5278&view=rev Author: patearl Date: 2010-11-28 19:12:13 +0000 (Sun, 28 Nov 2010) Log Message: ----------- Fixed incorrect usages of StringHelper.Split. This is a partial fix for using composite types as HQL parameter values. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/AbstractNullnessCheckNode.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/BinaryLogicOperatorNode.cs trunk/nhibernate/src/NHibernate/Id/IncrementGenerator.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/AbstractNullnessCheckNode.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/AbstractNullnessCheckNode.cs 2010-11-28 04:35:11 UTC (rev 5277) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/AbstractNullnessCheckNode.cs 2010-11-28 19:12:13 UTC (rev 5278) @@ -142,7 +142,7 @@ nodeText = nodeText.Substring( 0, nodeText.Length - 1 ); } - string[] splits = StringHelper.Split( ", ", nodeText ); + string[] splits = nodeText.Split(new[] { ", " }, StringSplitOptions.None); if ( count != splits.Length ) { Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/BinaryLogicOperatorNode.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/BinaryLogicOperatorNode.cs 2010-11-28 04:35:11 UTC (rev 5277) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/BinaryLogicOperatorNode.cs 2010-11-28 19:12:13 UTC (rev 5278) @@ -221,7 +221,7 @@ { nodeText = nodeText.Substring( 0, nodeText.Length - 1 ); } - String[] splits = StringHelper.Split( ", ", nodeText ); + string[] splits = nodeText.Split(new[] { ", " }, StringSplitOptions.None); if ( count != splits.Length ) { Modified: trunk/nhibernate/src/NHibernate/Id/IncrementGenerator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Id/IncrementGenerator.cs 2010-11-28 04:35:11 UTC (rev 5277) +++ trunk/nhibernate/src/NHibernate/Id/IncrementGenerator.cs 2010-11-28 19:12:13 UTC (rev 5278) @@ -48,7 +48,7 @@ if (!parms.TryGetValue("tables", out tableList)) parms.TryGetValue(PersistentIdGeneratorParmsNames.Tables, out tableList); - string[] tables = StringHelper.Split(", ", tableList); + string[] tables = tableList.Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (!parms.TryGetValue("column", out column)) parms.TryGetValue(PersistentIdGeneratorParmsNames.PK, out column); returnClass = type.ReturnedClass; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2010-11-28 20:14:08
|
Revision: 5280 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5280&view=rev Author: patearl Date: 2010-11-28 20:14:01 +0000 (Sun, 28 Nov 2010) Log Message: ----------- Linq: Let HQL figure out the type of non-null parameters. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionParameterVisitor.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/A.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/EnumStringUserType.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/PhoneNumber.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/PhoneNumberUserType.cs Modified: trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs 2010-11-28 19:18:45 UTC (rev 5279) +++ trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs 2010-11-28 20:14:01 UTC (rev 5280) @@ -137,9 +137,13 @@ { query.SetParameterList(parameterName, (ICollection) param.First); } + else if (param.Second != null) + { + query.SetParameter(parameterName, param.First, param.Second); + } else { - query.SetParameter(parameterName, param.First); + query.SetParameter(parameterName, param.First); } } } Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionParameterVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionParameterVisitor.cs 2010-11-28 19:18:45 UTC (rev 5279) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionParameterVisitor.cs 2010-11-28 20:14:01 UTC (rev 5280) @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using NHibernate.Type; namespace NHibernate.Linq.Visitors { @@ -25,7 +26,20 @@ { if (!typeof(IQueryable).IsAssignableFrom(expression.Type) && !IsNullObject(expression)) { - _parameters.Add(expression, new NamedParameter("p" + (_parameters.Count + 1), expression.Value, NHibernateUtil.GuessType(expression.Type))); + // We use null for the type to indicate that the caller should let HQL figure it out. + IType type = null; + + // We have a bit more information about the null parameter value. + // Figure out a type so that HQL doesn't break on the null. (Related to NH-2430) + if (expression.Value == null) + type = NHibernateUtil.GuessType(expression.Type); + + // There is more information available in the Linq expression than to HQL directly. + // In some cases it might be advantageous to use the extra info. Assuming this + // comes up, it would be nice to combine the HQL parameter type determination code + // and the Expression information. + + _parameters.Add(expression, new NamedParameter("p" + (_parameters.Count + 1), expression.Value, type)); } return base.VisitConstantExpression(expression); Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394 ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/A.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/A.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/A.cs 2010-11-28 20:14:01 UTC (rev 5280) @@ -0,0 +1,30 @@ +using System; +using System.Collections; + +namespace NHibernate.Test.NHSpecificTest.NH2394 +{ + public interface IA + { + int? Id { get; set; } + TypeOfA Type { get; set; } + TypeOfA? NullableType { get; set; } + PhoneNumber Phone { get; set; } + bool IsNice { get; set; } + } + + public class A : IA + { + public int? Id { get; set; } + public TypeOfA Type { get; set; } + public TypeOfA? NullableType { get; set; } + public PhoneNumber Phone { get; set; } + public bool IsNice { get; set; } + } + + public enum TypeOfA + { + Awesome, + Boring, + Cool + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/EnumStringUserType.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/EnumStringUserType.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/EnumStringUserType.cs 2010-11-28 20:14:01 UTC (rev 5280) @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using NHibernate.SqlTypes; +using NHibernate.Type; +using NHibernate.UserTypes; + +namespace NHibernate.Test.NHSpecificTest.NH2394 +{ + public class EnumStringUserType : EnumStringType<TypeOfA> + { + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/Fixture.cs 2010-11-28 20:14:01 UTC (rev 5280) @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using NHibernate.Criterion; +using NUnit.Framework; +using NHibernate.Linq; +using System.Linq; +using NHibernate.Linq.Functions; + +namespace NHibernate.Test.NHSpecificTest.NH2394 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override void OnTearDown() + { + using (ISession s = sessions.OpenSession()) + { + s.Delete("from A"); + s.Flush(); + } + } + + [Test] + public void LinqUserTypeEquality() + { + ISession s = OpenSession(); + try + { + s.Save(new A { Type = TypeOfA.Awesome, Phone = new PhoneNumber(1, "555-1111") }); + s.Save(new A { Type = TypeOfA.Boring, NullableType = TypeOfA.Awesome, Phone = new PhoneNumber(1, "555-2222") }); + s.Save(new A { Type = TypeOfA.Cool, Phone = new PhoneNumber(1, "555-3333") }); + s.Flush(); + } + finally + { + s.Close(); + } + + s = OpenSession(); + try + { + A item; + + Assert.AreEqual(3, s.CreateQuery("from A a where a.IsNice = ?").SetParameter(0, false).List().Count); + Assert.AreEqual(3, s.Query<A>().Count(a => a.IsNice == false)); + + item = s.CreateQuery("from A a where a.Type = ?").SetParameter(0, TypeOfA.Awesome).UniqueResult<A>(); + Assert.AreEqual(TypeOfA.Awesome, item.Type); + Assert.AreEqual("555-1111", item.Phone.Number); + + item = s.Query<A>().Where(a => a.Type == TypeOfA.Awesome).Single(); + Assert.AreEqual(TypeOfA.Awesome, item.Type); + Assert.AreEqual("555-1111", item.Phone.Number); + + item = s.Query<A>().Where(a => TypeOfA.Awesome == a.Type).Single(); + Assert.AreEqual(TypeOfA.Awesome, item.Type); + Assert.AreEqual("555-1111", item.Phone.Number); + + IA interfaceItem = s.Query<IA>().Where(a => a.Type == TypeOfA.Awesome).Single(); + Assert.AreEqual(TypeOfA.Awesome, interfaceItem.Type); + Assert.AreEqual("555-1111", interfaceItem.Phone.Number); + + item = s.CreateQuery("from A a where a.NullableType = ?").SetParameter(0, TypeOfA.Awesome).UniqueResult<A>(); + Assert.AreEqual(TypeOfA.Boring, item.Type); + Assert.AreEqual("555-2222", item.Phone.Number); + Assert.AreEqual(TypeOfA.Awesome, item.NullableType); + + item = s.Query<A>().Where(a => a.NullableType == TypeOfA.Awesome).Single(); + Assert.AreEqual(TypeOfA.Boring, item.Type); + Assert.AreEqual("555-2222", item.Phone.Number); + Assert.AreEqual(TypeOfA.Awesome, item.NullableType); + + Assert.AreEqual(2, s.Query<A>().Count(a => a.NullableType == null)); + + item = s.CreateQuery("from A a where a.Phone = ?").SetParameter(0, new PhoneNumber(1, "555-2222")).UniqueResult<A>(); + Assert.AreEqual(TypeOfA.Boring, item.Type); + Assert.AreEqual("555-2222", item.Phone.Number); + + item = s.Query<A>().Where(a => a.Phone == new PhoneNumber(1, "555-2222")).Single(); + Assert.AreEqual(TypeOfA.Boring, item.Type); + Assert.AreEqual("555-2222", item.Phone.Number); + } + finally + { + s.Close(); + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/Mappings.hbm.xml 2010-11-28 20:14:01 UTC (rev 5280) @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH2394"> + <class name="A" table="a" lazy="false" optimistic-lock="dirty" dynamic-update="true"> + <id name="Id" column="id" unsaved-value="null"> + <generator class="native" /> + </id> + <property name="Phone" type="NHibernate.Test.NHSpecificTest.NH2394.PhoneNumberUserType, NHibernate.Test"> + <column name="PhoneCountryCode"/> + <column name="PhoneNumber"/> + </property> + <property name="Type" type="NHibernate.Test.NHSpecificTest.NH2394.EnumStringUserType, NHibernate.Test"/> + <property name="NullableType" type="NHibernate.Test.NHSpecificTest.NH2394.EnumStringUserType, NHibernate.Test"/> + <property name="IsNice" type="TrueFalse"/> + </class> +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/PhoneNumber.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/PhoneNumber.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/PhoneNumber.cs 2010-11-28 20:14:01 UTC (rev 5280) @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NHibernate.Test.NHSpecificTest.NH2394 +{ + public class PhoneNumber + { + public PhoneNumber(int countryCode, string number) + { + CountryCode = countryCode; + Number = number; + } + + public int CountryCode { get; private set; } + public string Number { get; private set; } + + public override bool Equals(object obj) + { + if (obj == null) + return false; + + if (obj.GetType() != GetType()) + return false; + + PhoneNumber that = (PhoneNumber) obj; + + return + CountryCode == that.CountryCode && + Number == that.Number; + } + + public override int GetHashCode() + { + return CountryCode.GetHashCode() ^ (Number ?? "").GetHashCode(); + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/PhoneNumberUserType.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/PhoneNumberUserType.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2394/PhoneNumberUserType.cs 2010-11-28 20:14:01 UTC (rev 5280) @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using NHibernate.Engine; +using NHibernate.Type; +using NHibernate.UserTypes; + +namespace NHibernate.Test.NHSpecificTest.NH2394 +{ + class PhoneNumberUserType : ICompositeUserType + { + public string[] PropertyNames + { + get { return new[] { "CountryCode", "Number" }; } + } + + public IType[] PropertyTypes + { + get { return new[] { NHibernateUtil.Int32, NHibernateUtil.String }; } + } + + public object GetPropertyValue(object component, int property) + { + PhoneNumber phone = (PhoneNumber)component; + + switch (property) + { + case 0: return phone.CountryCode; + case 1: return phone.Number; + default: throw new NotImplementedException(); + } + } + + public void SetPropertyValue(object component, int property, object value) + { + throw new NotImplementedException(); + } + + public System.Type ReturnedClass + { + get { return typeof(PhoneNumber); } + } + + bool ICompositeUserType.Equals(object x, object y) + { + if (ReferenceEquals(x, null) && ReferenceEquals(y, null)) + return true; + + if (ReferenceEquals(x, null) || ReferenceEquals(y, null)) + return false; + + return x.Equals(y); + } + + public int GetHashCode(object x) + { + return x.GetHashCode(); + } + + public object NullSafeGet(IDataReader dr, string[] names, ISessionImplementor session, object owner) + { + if (dr.IsDBNull(dr.GetOrdinal(names[0]))) + return null; + + return new PhoneNumber( + (int)NHibernateUtil.Int32.NullSafeGet(dr, names[0], session, owner), + (string)NHibernateUtil.String.NullSafeGet(dr, names[1], session, owner)); + } + + public void NullSafeSet(IDbCommand cmd, object value, int index, bool[] settable, ISessionImplementor session) + { + object countryCode = value == null ? null : (int?)((PhoneNumber)value).CountryCode; + object number = value == null ? null : ((PhoneNumber)value).Number; + + if (settable[0]) NHibernateUtil.Int32.NullSafeSet(cmd, countryCode, index++, session); + if (settable[1]) NHibernateUtil.String.NullSafeSet(cmd, number, index, session); + } + + public object DeepCopy(object value) + { + return value; + } + + public bool IsMutable + { + get { return false; } + } + + public object Disassemble(object value, ISessionImplementor session) + { + return value; + } + + public object Assemble(object cached, ISessionImplementor session, object owner) + { + return cached; + } + + public object Replace(object original, object target, ISessionImplementor session, object owner) + { + return original; + } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-11-28 19:18:45 UTC (rev 5279) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-11-28 20:14:01 UTC (rev 5280) @@ -543,6 +543,11 @@ <Compile Include="NHSpecificTest\NH2392\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2392\PhoneNumber.cs" /> <Compile Include="NHSpecificTest\NH2392\PhoneNumberUserType.cs" /> + <Compile Include="NHSpecificTest\NH2394\A.cs" /> + <Compile Include="NHSpecificTest\NH2394\EnumStringUserType.cs" /> + <Compile Include="NHSpecificTest\NH2394\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2394\PhoneNumber.cs" /> + <Compile Include="NHSpecificTest\NH2394\PhoneNumberUserType.cs" /> <Compile Include="NHSpecificTest\NH2409\Contest.cs" /> <Compile Include="NHSpecificTest\NH2409\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2409\Message.cs" /> @@ -2329,6 +2334,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH2394\Mappings.hbm.xml" /> <EmbeddedResource Include="DynamicEntity\Interceptor\Customer.hbm.xml" /> <EmbeddedResource Include="Any\Person.hbm.xml" /> <EmbeddedResource Include="Any\Properties.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2010-11-28 20:41:04
|
Revision: 5281 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5281&view=rev Author: patearl Date: 2010-11-28 20:40:57 +0000 (Sun, 28 Nov 2010) Log Message: ----------- Backed out the ContextualNhExpressionTreeVisitor from revision 5276. I discovered a simpler implementation strategy and didn't need the context anymore. Revision Links: -------------- http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5276&view=rev Modified Paths: -------------- trunk/nhibernate/src/NHibernate/NHibernate.csproj Removed Paths: ------------- trunk/nhibernate/src/NHibernate/Linq/Visitors/ContextualNhExpressionTreeVisitor.cs trunk/nhibernate/src/NHibernate/Linq/Visitors/VisitorContext.cs Deleted: trunk/nhibernate/src/NHibernate/Linq/Visitors/ContextualNhExpressionTreeVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/ContextualNhExpressionTreeVisitor.cs 2010-11-28 20:14:01 UTC (rev 5280) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/ContextualNhExpressionTreeVisitor.cs 2010-11-28 20:40:57 UTC (rev 5281) @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; -using NHibernate.Linq.Visitors; - -namespace NHibernate.Linq -{ - public class ContextualNhExpressionTreeVisitor : NhExpressionTreeVisitor - { - private Stack<VisitorContext> _contextStack; - - public ContextualNhExpressionTreeVisitor() - { - _contextStack = new Stack<VisitorContext>(); - _contextStack.Push(null); - } - - public override Expression VisitExpression(Expression expression) - { - if (expression == null) - return null; - - VisitorContext context = new VisitorContext(_contextStack.Peek(), expression); - _contextStack.Push(context); - - Expression result = base.VisitExpression(expression); - - _contextStack.Pop(); - - return result; - } - - protected VisitorContext Context - { - get { return _contextStack.Peek(); } - } - } -} Deleted: trunk/nhibernate/src/NHibernate/Linq/Visitors/VisitorContext.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Visitors/VisitorContext.cs 2010-11-28 20:14:01 UTC (rev 5280) +++ trunk/nhibernate/src/NHibernate/Linq/Visitors/VisitorContext.cs 2010-11-28 20:40:57 UTC (rev 5281) @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; - -namespace NHibernate.Linq.Visitors -{ - public class VisitorContext - { - public VisitorContext(VisitorContext parent, Expression expression) - { - Parent = parent; - Expression = expression; - } - - public VisitorContext Parent { get; private set; } - public Expression Expression { get; private set; } - } -} Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-11-28 20:14:01 UTC (rev 5280) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-11-28 20:40:57 UTC (rev 5281) @@ -241,8 +241,6 @@ <Compile Include="ISessionFactory.cs" /> <Compile Include="ITransaction.cs" /> <Compile Include="LazyInitializationException.cs" /> - <Compile Include="Linq\Visitors\ContextualNhExpressionTreeVisitor.cs" /> - <Compile Include="Linq\Visitors\VisitorContext.cs" /> <Compile Include="Loader\Loader.cs" /> <Compile Include="Loader\OuterJoinLoader.cs" /> <Compile Include="LockMode.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2010-12-01 16:03:38
|
Revision: 5285 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5285&view=rev Author: julian-maughan Date: 2010-12-01 16:03:31 +0000 (Wed, 01 Dec 2010) Log Message: ----------- Fix to correctly set the IsInActiveTransaction property of a Session's TransactionContext, on TransactionCompletion. This prevent an exception from being thrown by ConnectionManager.Disconnect. Occurs when a database connection enlisted in a distributed transaction is passed to the NHibernate Session (ref. NH-2420) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Transaction/AdoNetWithDistributedTransactionFactory.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/DummyEnlistment.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/MyTable.cs Modified: trunk/nhibernate/src/NHibernate/Transaction/AdoNetWithDistributedTransactionFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Transaction/AdoNetWithDistributedTransactionFactory.cs 2010-11-29 12:59:16 UTC (rev 5284) +++ trunk/nhibernate/src/NHibernate/Transaction/AdoNetWithDistributedTransactionFactory.cs 2010-12-01 16:03:31 UTC (rev 5285) @@ -42,6 +42,8 @@ { using (new SessionIdLoggingContext(session.SessionId)) { + ((DistributedTransactionContext)session.TransactionContext).IsInActiveTransaction = false; + bool wasSuccessful = false; try { @@ -134,7 +136,7 @@ using (new SessionIdLoggingContext(sessionImplementor.SessionId)) { logger.Debug("committing DTC transaction"); - // we have nothing to do here, since it is the actual + // we have nothing to do here, since it is the actual // DB connection that will commit the transaction enlistment.Done(); IsInActiveTransaction = false; Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/DummyEnlistment.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/DummyEnlistment.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/DummyEnlistment.cs 2010-12-01 16:03:31 UTC (rev 5285) @@ -0,0 +1,30 @@ +using System; +using System.Transactions; + +namespace NHibernate.Test.NHSpecificTest.NH2420 +{ + public class DummyEnlistment : IEnlistmentNotification + { + public static readonly Guid Id = new Guid("E2D35055-4187-4ff5-82A1-F1F161A008D0"); + + public void Prepare(PreparingEnlistment preparingEnlistment) + { + preparingEnlistment.Prepared(); + } + + public void Commit(Enlistment enlistment) + { + enlistment.Done(); + } + + public void Rollback(Enlistment enlistment) + { + enlistment.Done(); + } + + public void InDoubt(Enlistment enlistment) + { + enlistment.Done(); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/Fixture.cs 2010-12-01 16:03:31 UTC (rev 5285) @@ -0,0 +1,69 @@ +using System.Data; +using System.Data.SqlClient; +using System.Transactions; + +using NHibernate.Criterion; +using NHibernate.Dialect; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2420 +{ + [TestFixture] + public class Fixture : BugTestCase + { + public override string BugNumber + { + get { return "NH2420"; } + } + + protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect) + { + return (dialect is NHibernate.Dialect.MsSql2008Dialect || dialect is NHibernate.Dialect.MsSql2005Dialect); + } + + [Test] + [Explicit("Requires the Microsoft DTC service. Also, the exception thrown by this test when it fails is on a ThreadPool thread which is not visible to NUnit. So although the test accurately reproduces the issue, it passes anyway.")] + public void Bug() + { + string connectionString = cfg.GetProperty("connection.connection_string"); + int id = -1; + + using (TransactionScope ts = new TransactionScope()) + { + // Enlisting DummyEnlistment as a durable resource manager will start + // a DTC transaction + System.Transactions.Transaction.Current.EnlistDurable( + DummyEnlistment.Id, + new DummyEnlistment(), + EnlistmentOptions.None); + + using (IDbConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + using (ISession s = Sfi.OpenSession(connection)) + { + id = (int)s.Save(new MyTable() { String = "hello!" }); + } + connection.Close(); + } + + // Prior to the patch, an InvalidOperationException exception would occur in the + // TransactionCompleted delegate at this point with the message, "Disconnect cannot + // be called while a transaction is in progress". Although the exception can be + // seen reported in the IDE, NUnit fails to see it, and the test passes. The + // TransactionCompleted event fires *after* the transaction is committed and so + // it doesn't affect the success of the transaction + ts.Complete(); + } + } + + protected override void OnTearDown() + { + using (ISession s = OpenSession()) + { + s.Delete("from MyTable"); + s.Flush(); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/Mappings.hbm.xml 2010-12-01 16:03:31 UTC (rev 5285) @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping + xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2420"> + + <class name="MyTable" table="MyTable"> + <id name="Id"> + <generator class="native" /> + </id> + <property name="String"/> + </class> + +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/MyTable.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/MyTable.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2420/MyTable.cs 2010-12-01 16:03:31 UTC (rev 5285) @@ -0,0 +1,10 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH2420 +{ + public class MyTable + { + public virtual int Id { get; private set; } + public virtual string String { get; set; } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-11-29 12:59:16 UTC (rev 5284) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-01 16:03:31 UTC (rev 5285) @@ -556,6 +556,9 @@ <Compile Include="NHSpecificTest\NH2409\Message.cs" /> <Compile Include="NHSpecificTest\NH2409\MessageReading.cs" /> <Compile Include="NHSpecificTest\NH2409\User.cs" /> + <Compile Include="NHSpecificTest\NH2420\DummyEnlistment.cs" /> + <Compile Include="NHSpecificTest\NH2420\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2420\MyTable.cs" /> <Compile Include="PolymorphicGetAndLoad\Domain.cs" /> <Compile Include="PolymorphicGetAndLoad\PolymorphicGetAndLoadTest.cs" /> <Compile Include="TypesTest\CharClass.cs" /> @@ -1849,6 +1852,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1869\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2392\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2409\Mappings.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\NH2420\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\NHibernate.ByteCode.Castle\NHibernate.ByteCode.Castle.csproj"> @@ -2715,6 +2719,7 @@ <EmbeddedResource Include="DynamicEntity\Tuplizer\Customer.hbm.xml" /> </ItemGroup> <ItemGroup> + <Folder Include="NHSpecificTest\NH2420" /> <Folder Include="Properties\" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2010-12-02 11:46:25
|
Revision: 5286 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5286&view=rev Author: julian-maughan Date: 2010-12-02 11:46:19 +0000 (Thu, 02 Dec 2010) Log Message: ----------- Minor tidy-ups following on from r5267. No functional changes. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/BetweenExpression.cs trunk/nhibernate/src/NHibernate/Criterion/InExpression.cs trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs trunk/nhibernate/src/NHibernate/Type/TypeHelper.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/BetweenExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/BetweenExpression.cs 2010-12-01 16:03:31 UTC (rev 5285) +++ trunk/nhibernate/src/NHibernate/Criterion/BetweenExpression.cs 2010-12-02 11:46:19 UTC (rev 5286) @@ -20,9 +20,9 @@ /// <summary> /// Initializes a new instance of the <see cref="BetweenExpression"/> class. /// </summary> - /// <param name="_projection">The _projection.</param> - /// <param name="_lo">The _lo.</param> - /// <param name="_hi">The _hi.</param> + /// <param name="projection">The _projection.</param> + /// <param name="lo">The _lo.</param> + /// <param name="hi">The _hi.</param> public BetweenExpression(IProjection projection, object lo, object hi) { this._projection = projection; Modified: trunk/nhibernate/src/NHibernate/Criterion/InExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/InExpression.cs 2010-12-01 16:03:31 UTC (rev 5285) +++ trunk/nhibernate/src/NHibernate/Criterion/InExpression.cs 2010-12-02 11:46:19 UTC (rev 5286) @@ -26,7 +26,7 @@ /// Initializes a new instance of the <see cref="InExpression"/> class. /// </summary> /// <param name="projection">The projection.</param> - /// <param name="_values">The _values.</param> + /// <param name="values">The _values.</param> public InExpression(IProjection projection, object[] values) { _projection = projection; Modified: trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2010-12-01 16:03:31 UTC (rev 5285) +++ trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2010-12-02 11:46:19 UTC (rev 5286) @@ -43,7 +43,6 @@ private bool _readOnly; private int? limitParameterIndex = null; private int? offsetParameterIndex = null; - private int wildcardSubqueryLimitParameterIndex = -1; private IDictionary<int, int> _adjustedParameterLocations; private IDictionary<int, int> _tempPagingParameterIndexes; private IDictionary<int, int> _pagingParameterIndexMap; Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs 2010-12-01 16:03:31 UTC (rev 5285) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs 2010-12-02 11:46:19 UTC (rev 5286) @@ -20,12 +20,15 @@ { public static readonly string RootSqlAlias = CriteriaSpecification.RootAlias + '_'; + private static readonly IInternalLogger logger = LoggerProvider.LoggerFor(typeof(CriteriaQueryTranslator)); + + private const int AliasCount = 0; + private readonly ICriteriaQuery outerQueryTranslator; - private readonly CriteriaImpl rootCriteria; private readonly string rootEntityName; private readonly string rootSQLAlias; - private const int aliasCount = 0; + private int indexForAlias = 0; private int _tempPagingParameterIndex = -1; private IDictionary<int, int> _tempPagingParameterIndexes = new Dictionary<int, int>(); @@ -36,18 +39,12 @@ new Dictionary<string, ICriteriaInfoProvider>(); private readonly ISet<ICollectionPersister> criteriaCollectionPersisters = new HashedSet<ICollectionPersister>(); - private readonly IDictionary<ICriteria, string> criteriaSQLAliasMap = new Dictionary<ICriteria, string>(); private readonly IDictionary<string, ICriteria> aliasCriteriaMap = new Dictionary<string, ICriteria>(); private readonly IDictionary<string, ICriteria> associationPathCriteriaMap = new LinkedHashMap<string, ICriteria>(); private readonly IDictionary<string, JoinType> associationPathJoinTypesMap = new LinkedHashMap<string, JoinType>(); private readonly IDictionary<string, ICriterion> withClauseMap = new Dictionary<string, ICriterion>(); - private readonly ISessionFactoryImplementor sessionFactory; - private int indexForAlias = 0; - private static readonly IInternalLogger logger = LoggerProvider.LoggerFor(typeof(CriteriaQueryTranslator)); - - private readonly List<TypedValue> usedTypedValues = new List<TypedValue>(); private SessionFactoryHelper helper; public CriteriaQueryTranslator(ISessionFactoryImplementor factory, CriteriaImpl criteria, string rootEntityName, @@ -282,7 +279,7 @@ public string GenerateSQLAlias() { - return StringHelper.GenerateAlias(rootSQLAlias, aliasCount); + return StringHelper.GenerateAlias(rootSQLAlias, AliasCount); } private ICriteria GetAliasedCriteria(string alias) Modified: trunk/nhibernate/src/NHibernate/Type/TypeHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeHelper.cs 2010-12-01 16:03:31 UTC (rev 5285) +++ trunk/nhibernate/src/NHibernate/Type/TypeHelper.cs 2010-12-02 11:46:19 UTC (rev 5286) @@ -205,8 +205,8 @@ /// <para>If it is determined that no fields are dirty, null is returned.</para> /// </summary> /// <param name="properties">The property definitions</param> - /// <param name="x">The current state of the entity</param> - /// <param name="y">The baseline state of the entity</param> + /// <param name="currentState">The current state of the entity</param> + /// <param name="previousState">The baseline state of the entity</param> /// <param name="includeColumns">Columns to be included in the dirty checking, per property</param> /// <param name="anyUninitializedProperties">Does the entity currently hold any uninitialized property values?</param> /// <param name="session">The session from which the dirty check request originated.</param> @@ -256,8 +256,8 @@ /// <para>If it is determined that no fields are dirty, null is returned.</para> /// </summary> /// <param name="properties">The property definitions</param> - /// <param name="x">The current state of the entity</param> - /// <param name="y">The baseline state of the entity</param> + /// <param name="currentState">The current state of the entity</param> + /// <param name="previousState">The baseline state of the entity</param> /// <param name="includeColumns">Columns to be included in the mod checking, per property</param> /// <param name="anyUninitializedProperties">Does the entity currently hold any uninitialized property values?</param> /// <param name="session">The session from which the dirty check request originated.</param> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2010-12-04 02:27:10
|
Revision: 5288 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5288&view=rev Author: julian-maughan Date: 2010-12-04 02:27:02 +0000 (Sat, 04 Dec 2010) Log Message: ----------- Added some Linq support for Dictionary collections (ref. NH-2416, NH-2423). Based on a patch from Diego Mijelshon. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.DomainModel/NHSpecific/BasicClass.cs trunk/nhibernate/src/NHibernate.DomainModel/NHSpecific/BasicClass.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/BasicClassFixture.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate/Linq/Functions/DictionaryGenerator.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs 2010-12-03 09:20:26 UTC (rev 5287) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs 2010-12-04 02:27:02 UTC (rev 5288) @@ -5,430 +5,440 @@ namespace NHibernate.Hql.Ast { - public class HqlTreeBuilder - { - private readonly IASTFactory _factory; + public class HqlTreeBuilder + { + private readonly IASTFactory _factory; - public HqlTreeBuilder() - { - _factory = new ASTFactory(new ASTTreeAdaptor()); - } + public HqlTreeBuilder() + { + _factory = new ASTFactory(new ASTTreeAdaptor()); + } - public HqlQuery Query() - { - return new HqlQuery(_factory); - } + public HqlQuery Query() + { + return new HqlQuery(_factory); + } - public HqlQuery Query(HqlSelectFrom selectFrom) - { - return new HqlQuery(_factory, selectFrom); - } + public HqlQuery Query(HqlSelectFrom selectFrom) + { + return new HqlQuery(_factory, selectFrom); + } - public HqlQuery Query(HqlSelectFrom selectFrom, HqlWhere where) - { - return new HqlQuery(_factory, selectFrom, where); - } + public HqlQuery Query(HqlSelectFrom selectFrom, HqlWhere where) + { + return new HqlQuery(_factory, selectFrom, where); + } - public HqlTreeNode Query(HqlSelectFrom selectFrom, HqlWhere where, HqlOrderBy orderBy) - { - return new HqlQuery(_factory, selectFrom, where, orderBy); - } + public HqlTreeNode Query(HqlSelectFrom selectFrom, HqlWhere where, HqlOrderBy orderBy) + { + return new HqlQuery(_factory, selectFrom, where, orderBy); + } - public HqlSelectFrom SelectFrom() - { - return new HqlSelectFrom(_factory); - } + public HqlSelectFrom SelectFrom() + { + return new HqlSelectFrom(_factory); + } - public HqlSelectFrom SelectFrom(HqlSelect select) - { - return new HqlSelectFrom(_factory, select); - } + public HqlSelectFrom SelectFrom(HqlSelect select) + { + return new HqlSelectFrom(_factory, select); + } - public HqlSelectFrom SelectFrom(HqlFrom @from, HqlSelect select) - { - return new HqlSelectFrom(_factory, @from, select); - } + public HqlSelectFrom SelectFrom(HqlFrom @from, HqlSelect select) + { + return new HqlSelectFrom(_factory, @from, select); + } - public HqlSelectFrom SelectFrom(HqlFrom @from) - { - return new HqlSelectFrom(_factory, @from); - } + public HqlSelectFrom SelectFrom(HqlFrom @from) + { + return new HqlSelectFrom(_factory, @from); + } - public HqlFrom From(HqlRange range) - { - return new HqlFrom(_factory, range); - } + public HqlFrom From(HqlRange range) + { + return new HqlFrom(_factory, range); + } - public HqlFrom From() - { - return new HqlFrom(_factory); - } + public HqlFrom From() + { + return new HqlFrom(_factory); + } - public HqlRange Range(HqlIdent ident) - { - return new HqlRange(_factory, ident); - } + public HqlRange Range(HqlIdent ident) + { + return new HqlRange(_factory, ident); + } - public HqlRange Range(HqlTreeNode ident, HqlAlias alias) - { - return new HqlRange(_factory, ident, alias); - } + public HqlRange Range(HqlTreeNode ident, HqlAlias alias) + { + return new HqlRange(_factory, ident, alias); + } - public HqlIdent Ident(string ident) - { - return new HqlIdent(_factory, ident); - } + public HqlIdent Ident(string ident) + { + return new HqlIdent(_factory, ident); + } - public HqlIdent Ident(System.Type type) - { - return new HqlIdent(_factory, type); - } + public HqlIdent Ident(System.Type type) + { + return new HqlIdent(_factory, type); + } - public HqlAlias Alias(string alias) - { - return new HqlAlias(_factory, alias); - } + public HqlAlias Alias(string alias) + { + return new HqlAlias(_factory, alias); + } - public HqlEquality Equality(HqlExpression lhs, HqlExpression rhs) - { - return new HqlEquality(_factory, lhs, rhs); - } + public HqlEquality Equality(HqlExpression lhs, HqlExpression rhs) + { + return new HqlEquality(_factory, lhs, rhs); + } - public HqlBooleanAnd BooleanAnd(HqlBooleanExpression lhs, HqlBooleanExpression rhs) - { - return new HqlBooleanAnd(_factory, lhs, rhs); - } + public HqlBooleanAnd BooleanAnd(HqlBooleanExpression lhs, HqlBooleanExpression rhs) + { + return new HqlBooleanAnd(_factory, lhs, rhs); + } - public HqlBooleanOr BooleanOr(HqlBooleanExpression lhs, HqlBooleanExpression rhs) - { - return new HqlBooleanOr(_factory, lhs, rhs); - } + public HqlBooleanOr BooleanOr(HqlBooleanExpression lhs, HqlBooleanExpression rhs) + { + return new HqlBooleanOr(_factory, lhs, rhs); + } - public HqlAdd Add(HqlExpression lhs, HqlExpression rhs) - { - return new HqlAdd(_factory, lhs, rhs); - } + public HqlAdd Add(HqlExpression lhs, HqlExpression rhs) + { + return new HqlAdd(_factory, lhs, rhs); + } - public HqlSubtract Subtract(HqlExpression lhs, HqlExpression rhs) - { - return new HqlSubtract(_factory, lhs, rhs); - } + public HqlSubtract Subtract(HqlExpression lhs, HqlExpression rhs) + { + return new HqlSubtract(_factory, lhs, rhs); + } - public HqlMultiplty Multiply(HqlExpression lhs, HqlExpression rhs) - { - return new HqlMultiplty(_factory, lhs, rhs); - } + public HqlMultiplty Multiply(HqlExpression lhs, HqlExpression rhs) + { + return new HqlMultiplty(_factory, lhs, rhs); + } - public HqlDivide Divide(HqlExpression lhs, HqlExpression rhs) - { - return new HqlDivide(_factory, lhs, rhs); - } + public HqlDivide Divide(HqlExpression lhs, HqlExpression rhs) + { + return new HqlDivide(_factory, lhs, rhs); + } - public HqlDot Dot(HqlExpression lhs, HqlExpression rhs) - { - return new HqlDot(_factory, lhs, rhs); - } + public HqlDot Dot(HqlExpression lhs, HqlExpression rhs) + { + return new HqlDot(_factory, lhs, rhs); + } - public HqlParameter Parameter(string name) - { - return new HqlParameter(_factory, name); - } + public HqlParameter Parameter(string name) + { + return new HqlParameter(_factory, name); + } - public HqlWhere Where(HqlExpression expression) - { - return new HqlWhere(_factory, expression); - } + public HqlWhere Where(HqlExpression expression) + { + return new HqlWhere(_factory, expression); + } - // TODO - constant will be removed when we have parameter handling done properly. Particularly bad datetime handling here, so it'll be good to delete it :) - public HqlConstant Constant(object value) - { - if (value == null) - { - return new HqlNull(_factory); - } + // TODO - constant will be removed when we have parameter handling done properly. Particularly bad datetime handling here, so it'll be good to delete it :) + public HqlConstant Constant(object value) + { + if (value == null) + { + return new HqlNull(_factory); + } - switch (System.Type.GetTypeCode(value.GetType())) - { - case TypeCode.Int16: - case TypeCode.Int32: - case TypeCode.Int64: - return new HqlIntegerConstant(_factory, value.ToString()); - case TypeCode.Single: - return new HqlFloatConstant(_factory, value.ToString()); - case TypeCode.Double: - return new HqlDoubleConstant(_factory, value.ToString()); - case TypeCode.Decimal: - return new HqlDecimalConstant(_factory, value.ToString()); - case TypeCode.String: - case TypeCode.Char: - return new HqlStringConstant(_factory, "\'" + value + "\'"); - case TypeCode.DateTime: - return new HqlStringConstant(_factory, "\'" + (DateTime)value + "\'"); - case TypeCode.Boolean: - return new HqlStringConstant(_factory, "\'" + ((bool)value ? "true" : "false") + "\'"); - default: - throw new NotSupportedException(string.Format("The constant for '{0}' is not supported", value)); - } - } + switch (System.Type.GetTypeCode(value.GetType())) + { + case TypeCode.Int16: + case TypeCode.Int32: + case TypeCode.Int64: + return new HqlIntegerConstant(_factory, value.ToString()); + case TypeCode.Single: + return new HqlFloatConstant(_factory, value.ToString()); + case TypeCode.Double: + return new HqlDoubleConstant(_factory, value.ToString()); + case TypeCode.Decimal: + return new HqlDecimalConstant(_factory, value.ToString()); + case TypeCode.String: + case TypeCode.Char: + return new HqlStringConstant(_factory, "\'" + value + "\'"); + case TypeCode.DateTime: + return new HqlStringConstant(_factory, "\'" + (DateTime)value + "\'"); + case TypeCode.Boolean: + return new HqlStringConstant(_factory, "\'" + ((bool)value ? "true" : "false") + "\'"); + default: + throw new NotSupportedException(string.Format("The constant for '{0}' is not supported", value)); + } + } - public HqlOrderBy OrderBy() - { - return new HqlOrderBy(_factory); - } + public HqlOrderBy OrderBy() + { + return new HqlOrderBy(_factory); + } - public HqlSelect Select(HqlExpression expression) - { - return new HqlSelect(_factory, expression); - } + public HqlSelect Select(HqlExpression expression) + { + return new HqlSelect(_factory, expression); + } - public HqlSelect Select(params HqlExpression[] expression) - { - return new HqlSelect(_factory, expression); - } + public HqlSelect Select(params HqlExpression[] expression) + { + return new HqlSelect(_factory, expression); + } - public HqlSelect Select(IEnumerable<HqlExpression> expressions) - { - return new HqlSelect(_factory, expressions.ToArray()); - } + public HqlSelect Select(IEnumerable<HqlExpression> expressions) + { + return new HqlSelect(_factory, expressions.ToArray()); + } - public HqlCase Case(HqlWhen[] whenClauses) - { - return new HqlCase(_factory, whenClauses, null); - } + public HqlCase Case(HqlWhen[] whenClauses) + { + return new HqlCase(_factory, whenClauses, null); + } - public HqlCase Case(HqlWhen[] whenClauses, HqlExpression ifFalse) - { - return new HqlCase(_factory, whenClauses, ifFalse); - } + public HqlCase Case(HqlWhen[] whenClauses, HqlExpression ifFalse) + { + return new HqlCase(_factory, whenClauses, ifFalse); + } - public HqlWhen When(HqlExpression predicate, HqlExpression ifTrue) - { - return new HqlWhen(_factory, predicate, ifTrue); - } + public HqlWhen When(HqlExpression predicate, HqlExpression ifTrue) + { + return new HqlWhen(_factory, predicate, ifTrue); + } - public HqlElse Else(HqlExpression ifFalse) - { - return new HqlElse(_factory, ifFalse); - } + public HqlElse Else(HqlExpression ifFalse) + { + return new HqlElse(_factory, ifFalse); + } - public HqlInequality Inequality(HqlExpression lhs, HqlExpression rhs) - { - return new HqlInequality(_factory, lhs, rhs); - } + public HqlInequality Inequality(HqlExpression lhs, HqlExpression rhs) + { + return new HqlInequality(_factory, lhs, rhs); + } - public HqlLessThan LessThan(HqlExpression lhs, HqlExpression rhs) - { - return new HqlLessThan(_factory, lhs, rhs); - } + public HqlLessThan LessThan(HqlExpression lhs, HqlExpression rhs) + { + return new HqlLessThan(_factory, lhs, rhs); + } - public HqlLessThanOrEqual LessThanOrEqual(HqlExpression lhs, HqlExpression rhs) - { - return new HqlLessThanOrEqual(_factory, lhs, rhs); - } + public HqlLessThanOrEqual LessThanOrEqual(HqlExpression lhs, HqlExpression rhs) + { + return new HqlLessThanOrEqual(_factory, lhs, rhs); + } - public HqlGreaterThan GreaterThan(HqlExpression lhs, HqlExpression rhs) - { - return new HqlGreaterThan(_factory, lhs, rhs); - } + public HqlGreaterThan GreaterThan(HqlExpression lhs, HqlExpression rhs) + { + return new HqlGreaterThan(_factory, lhs, rhs); + } - public HqlGreaterThanOrEqual GreaterThanOrEqual(HqlExpression lhs, HqlExpression rhs) - { - return new HqlGreaterThanOrEqual(_factory, lhs, rhs); - } + public HqlGreaterThanOrEqual GreaterThanOrEqual(HqlExpression lhs, HqlExpression rhs) + { + return new HqlGreaterThanOrEqual(_factory, lhs, rhs); + } - public HqlCount Count() - { - return new HqlCount(_factory); - } + public HqlCount Count() + { + return new HqlCount(_factory); + } - public HqlCount Count(HqlExpression child) - { - return new HqlCount(_factory, child); - } + public HqlCount Count(HqlExpression child) + { + return new HqlCount(_factory, child); + } - public HqlRowStar RowStar() - { - return new HqlRowStar(_factory); - } + public HqlRowStar RowStar() + { + return new HqlRowStar(_factory); + } - public HqlCast Cast(HqlExpression expression, System.Type type) - { - return new HqlCast(_factory, expression, type); - } + public HqlCast Cast(HqlExpression expression, System.Type type) + { + return new HqlCast(_factory, expression, type); + } - public HqlBitwiseNot BitwiseNot() - { - return new HqlBitwiseNot(_factory); - } + public HqlBitwiseNot BitwiseNot() + { + return new HqlBitwiseNot(_factory); + } - public HqlBooleanNot BooleanNot(HqlBooleanExpression operand) - { - return new HqlBooleanNot(_factory, operand); - } + public HqlBooleanNot BooleanNot(HqlBooleanExpression operand) + { + return new HqlBooleanNot(_factory, operand); + } - public HqlAverage Average(HqlExpression expression) - { - return new HqlAverage(_factory, expression); - } + public HqlAverage Average(HqlExpression expression) + { + return new HqlAverage(_factory, expression); + } - public HqlSum Sum(HqlExpression expression) - { - return new HqlSum(_factory, expression); - } + public HqlSum Sum(HqlExpression expression) + { + return new HqlSum(_factory, expression); + } - public HqlMin Min(HqlExpression expression) - { - return new HqlMin(_factory, expression); - } + public HqlMin Min(HqlExpression expression) + { + return new HqlMin(_factory, expression); + } - public HqlMax Max(HqlExpression expression) - { - return new HqlMax(_factory, expression); - } + public HqlMax Max(HqlExpression expression) + { + return new HqlMax(_factory, expression); + } - public HqlJoin Join(HqlExpression expression, HqlAlias @alias) - { - return new HqlJoin(_factory, expression, @alias); - } + public HqlJoin Join(HqlExpression expression, HqlAlias @alias) + { + return new HqlJoin(_factory, expression, @alias); + } - public HqlAny Any() - { - return new HqlAny(_factory); - } + public HqlAny Any() + { + return new HqlAny(_factory); + } - public HqlExists Exists(HqlQuery query) - { - return new HqlExists(_factory, query); - } + public HqlExists Exists(HqlQuery query) + { + return new HqlExists(_factory, query); + } - public HqlElements Elements() - { - return new HqlElements(_factory); - } + public HqlElements Elements() + { + return new HqlElements(_factory); + } - public HqlDistinct Distinct() - { - return new HqlDistinct(_factory); - } + public HqlDistinct Distinct() + { + return new HqlDistinct(_factory); + } - public HqlDirectionAscending Ascending() - { - return new HqlDirectionAscending(_factory); - } + public HqlDirectionAscending Ascending() + { + return new HqlDirectionAscending(_factory); + } - public HqlDirectionDescending Descending() - { - return new HqlDirectionDescending(_factory); - } + public HqlDirectionDescending Descending() + { + return new HqlDirectionDescending(_factory); + } - public HqlGroupBy GroupBy(HqlExpression expression) - { - return new HqlGroupBy(_factory, expression); - } + public HqlGroupBy GroupBy(HqlExpression expression) + { + return new HqlGroupBy(_factory, expression); + } public HqlAll All() - { - return new HqlAll(_factory); - } + { + return new HqlAll(_factory); + } - public HqlLike Like(HqlExpression lhs, HqlExpression rhs) - { - return new HqlLike(_factory, lhs, rhs); - } + public HqlLike Like(HqlExpression lhs, HqlExpression rhs) + { + return new HqlLike(_factory, lhs, rhs); + } - public HqlConcat Concat(params HqlExpression[] args) - { - return new HqlConcat(_factory, args); - } + public HqlConcat Concat(params HqlExpression[] args) + { + return new HqlConcat(_factory, args); + } - public HqlMethodCall MethodCall(string methodName, IEnumerable<HqlExpression> parameters) - { - return new HqlMethodCall(_factory, methodName, parameters); - } + public HqlMethodCall MethodCall(string methodName, IEnumerable<HqlExpression> parameters) + { + return new HqlMethodCall(_factory, methodName, parameters); + } - public HqlMethodCall MethodCall(string methodName, params HqlExpression[] parameters) - { - return new HqlMethodCall(_factory, methodName, parameters); - } + public HqlMethodCall MethodCall(string methodName, params HqlExpression[] parameters) + { + return new HqlMethodCall(_factory, methodName, parameters); + } - public HqlBooleanMethodCall BooleanMethodCall(string methodName, IEnumerable<HqlExpression> parameters) - { - return new HqlBooleanMethodCall(_factory, methodName, parameters); - } + public HqlBooleanMethodCall BooleanMethodCall(string methodName, IEnumerable<HqlExpression> parameters) + { + return new HqlBooleanMethodCall(_factory, methodName, parameters); + } - public HqlDistinctHolder DistinctHolder(params HqlTreeNode[] children) - { - return new HqlDistinctHolder(_factory, children); - } + public HqlDistinctHolder DistinctHolder(params HqlTreeNode[] children) + { + return new HqlDistinctHolder(_factory, children); + } - public HqlIsNull IsNull(HqlExpression lhs) - { - return new HqlIsNull(_factory, lhs); - } + public HqlIsNull IsNull(HqlExpression lhs) + { + return new HqlIsNull(_factory, lhs); + } - public HqlIsNotNull IsNotNull(HqlExpression lhs) - { - return new HqlIsNotNull(_factory, lhs); - } + public HqlIsNotNull IsNotNull(HqlExpression lhs) + { + return new HqlIsNotNull(_factory, lhs); + } - public HqlTreeNode ExpressionList(IEnumerable<HqlExpression> expressions) - { - return new HqlExpressionList(_factory, expressions); - } + public HqlTreeNode ExpressionList(IEnumerable<HqlExpression> expressions) + { + return new HqlExpressionList(_factory, expressions); + } - public HqlStar Star() - { - return new HqlStar(_factory); - } + public HqlStar Star() + { + return new HqlStar(_factory); + } - public HqlTrue True() - { - return new HqlTrue(_factory); - } + public HqlTrue True() + { + return new HqlTrue(_factory); + } - public HqlFalse False() - { - return new HqlFalse(_factory); - } + public HqlFalse False() + { + return new HqlFalse(_factory); + } - public HqlIn In(HqlExpression itemExpression, HqlTreeNode source) - { - return new HqlIn(_factory, itemExpression, source); - } + public HqlIn In(HqlExpression itemExpression, HqlTreeNode source) + { + return new HqlIn(_factory, itemExpression, source); + } - public HqlLeftJoin LeftJoin(HqlExpression expression, HqlAlias @alias) - { - return new HqlLeftJoin(_factory, expression, @alias); - } + public HqlLeftJoin LeftJoin(HqlExpression expression, HqlAlias @alias) + { + return new HqlLeftJoin(_factory, expression, @alias); + } - public HqlFetchJoin FetchJoin(HqlExpression expression, HqlAlias @alias) - { - return new HqlFetchJoin(_factory, expression, @alias); - } + public HqlFetchJoin FetchJoin(HqlExpression expression, HqlAlias @alias) + { + return new HqlFetchJoin(_factory, expression, @alias); + } - public HqlLeftFetchJoin LeftFetchJoin(HqlExpression expression, HqlAlias @alias) - { - return new HqlLeftFetchJoin(_factory, expression, @alias); - } + public HqlLeftFetchJoin LeftFetchJoin(HqlExpression expression, HqlAlias @alias) + { + return new HqlLeftFetchJoin(_factory, expression, @alias); + } - public HqlClass Class() - { - return new HqlClass(_factory); - } + public HqlClass Class() + { + return new HqlClass(_factory); + } - public HqlBitwiseAnd BitwiseAnd(HqlExpression lhs, HqlExpression rhs) - { - return new HqlBitwiseAnd(_factory, lhs, rhs); - } + public HqlBitwiseAnd BitwiseAnd(HqlExpression lhs, HqlExpression rhs) + { + return new HqlBitwiseAnd(_factory, lhs, rhs); + } - public HqlBitwiseOr BitwiseOr(HqlExpression lhs, HqlExpression rhs) - { - return new HqlBitwiseOr(_factory, lhs, rhs); - } + public HqlBitwiseOr BitwiseOr(HqlExpression lhs, HqlExpression rhs) + { + return new HqlBitwiseOr(_factory, lhs, rhs); + } - public HqlTreeNode Coalesce(HqlExpression lhs, HqlExpression rhs) - { - return new HqlCoalesce(_factory, lhs, rhs); - } - } + public HqlTreeNode Coalesce(HqlExpression lhs, HqlExpression rhs) + { + return new HqlCoalesce(_factory, lhs, rhs); + } + + public HqlTreeNode DictionaryItem(HqlExpression dictionary, HqlExpression index) + { + return new HqlDictionaryIndex(_factory, dictionary, index); + } + + public HqlTreeNode Indices(HqlExpression dictionary) + { + return new HqlIndices(_factory, dictionary); + } + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs 2010-12-03 09:20:26 UTC (rev 5287) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs 2010-12-04 02:27:02 UTC (rev 5288) @@ -6,598 +6,596 @@ namespace NHibernate.Hql.Ast { - public class HqlTreeNode - { - public IASTFactory Factory { get; private set; } - private readonly IASTNode _node; - private readonly List<HqlTreeNode> _children; + public class HqlTreeNode + { + public IASTFactory Factory { get; private set; } + private readonly IASTNode _node; + private readonly List<HqlTreeNode> _children; - protected HqlTreeNode(int type, string text, IASTFactory factory, IEnumerable<HqlTreeNode> children) - { - Factory = factory; - _node = factory.CreateNode(type, text); - _children = new List<HqlTreeNode>(); + protected HqlTreeNode(int type, string text, IASTFactory factory, IEnumerable<HqlTreeNode> children) + { + Factory = factory; + _node = factory.CreateNode(type, text); + _children = new List<HqlTreeNode>(); - AddChildren(children); - } + AddChildren(children); + } - protected HqlTreeNode(int type, string text, IASTFactory factory, params HqlTreeNode[] children) : this(type, text, factory, (IEnumerable<HqlTreeNode>) children) - { - } + protected HqlTreeNode(int type, string text, IASTFactory factory, params HqlTreeNode[] children) : this(type, text, factory, (IEnumerable<HqlTreeNode>) children) + { + } - private void AddChildren(IEnumerable<HqlTreeNode> children) - { - foreach (var child in children) - { - if (child != null) - { - if (child is HqlDistinctHolder) - { - AddChildren(child.Children); - } - else - { - _children.Add(child); - _node.AddChild(child.AstNode); - } - } - } - } + private void AddChildren(IEnumerable<HqlTreeNode> children) + { + foreach (var child in children) + { + if (child != null) + { + if (child is HqlDistinctHolder) + { + AddChildren(child.Children); + } + else + { + _children.Add(child); + _node.AddChild(child.AstNode); + } + } + } + } - public IEnumerable<HqlTreeNode> NodesPreOrder - { - get - { - yield return this; + public IEnumerable<HqlTreeNode> NodesPreOrder + { + get + { + yield return this; - foreach (var child in _children) - { - foreach (var node in child.NodesPreOrder) - { - yield return node; - } - } - } - } + foreach (var child in _children) + { + foreach (var node in child.NodesPreOrder) + { + yield return node; + } + } + } + } - public IEnumerable<HqlTreeNode> NodesPostOrder - { - get - { - foreach (var child in _children) - { - foreach (var node in child.NodesPostOrder) - { - yield return node; - } - } + public IEnumerable<HqlTreeNode> NodesPostOrder + { + get + { + foreach (var child in _children) + { + foreach (var node in child.NodesPostOrder) + { + yield return node; + } + } - yield return this; - } - } + yield return this; + } + } - public IEnumerable<HqlTreeNode> Children - { - get { return _children; } - } + public IEnumerable<HqlTreeNode> Children + { + get { return _children; } + } - public void ClearChildren() - { - _children.Clear(); - _node.ClearChildren(); - } + public void ClearChildren() + { + _children.Clear(); + _node.ClearChildren(); + } - protected void SetText(string text) - { - _node.Text = text; - } + protected void SetText(string text) + { + _node.Text = text; + } - internal IASTNode AstNode - { - get { return _node; } - } + internal IASTNode AstNode + { + get { return _node; } + } - internal void AddChild(HqlTreeNode child) - { - if (child is HqlDistinctHolder) - { - AddChildren(child.Children); - } - else - { - _children.Add(child); - _node.AddChild(child.AstNode); - } - } - } + internal void AddChild(HqlTreeNode child) + { + if (child is HqlDistinctHolder) + { + AddChildren(child.Children); + } + else + { + _children.Add(child); + _node.AddChild(child.AstNode); + } + } + } - public static class HqlTreeNodeExtensions - { - public static HqlExpression AsExpression(this HqlTreeNode node) - { - // TODO - nice error handling if cast fails - return (HqlExpression)node; - } + public static class HqlTreeNodeExtensions + { + public static HqlExpression AsExpression(this HqlTreeNode node) + { + // TODO - nice error handling if cast fails + return (HqlExpression)node; + } - public static HqlBooleanExpression AsBooleanExpression(this HqlTreeNode node) - { - if (node is HqlDot) - { - return new HqlBooleanDot(node.Factory, (HqlDot) node); - } + public static HqlBooleanExpression AsBooleanExpression(this HqlTreeNode node) + { + if (node is HqlDot) + { + return new HqlBooleanDot(node.Factory, (HqlDot) node); + } - // TODO - nice error handling if cast fails - return (HqlBooleanExpression)node; - } - - } + // TODO - nice error handling if cast fails + return (HqlBooleanExpression)node; + } + + } - public abstract class HqlStatement : HqlTreeNode - { - protected HqlStatement(int type, string text, IASTFactory factory, params HqlTreeNode[] children) - : base(type, text, factory, children) - { - } + public abstract class HqlStatement : HqlTreeNode + { + protected HqlStatement(int type, string text, IASTFactory factory, params HqlTreeNode[] children) + : base(type, text, factory, children) + { + } - protected HqlStatement(int type, string text, IASTFactory factory, IEnumerable<HqlTreeNode> children) - : base(type, text, factory, children) - { - } - } + protected HqlStatement(int type, string text, IASTFactory factory, IEnumerable<HqlTreeNode> children) + : base(type, text, factory, children) + { + } + } - public abstract class HqlExpression : HqlTreeNode - { - protected HqlExpression(int type, string text, IASTFactory factory, IEnumerable<HqlTreeNode> children) - : base(type, text, factory, children) - { - } + public abstract class HqlExpression : HqlTreeNode + { + protected HqlExpression(int type, string text, IASTFactory factory, IEnumerable<HqlTreeNode> children) + : base(type, text, factory, children) + { + } - protected HqlExpression(int type, string text, IASTFactory factory, params HqlTreeNode[] children) - : base(type, text, factory, children) - { - } - } + protected HqlExpression(int type, string text, IASTFactory factory, params HqlTreeNode[] children) + : base(type, text, factory, children) + { + } + } - public abstract class HqlBooleanExpression : HqlExpression - { - protected HqlBooleanExpression(int type, string text, IASTFactory factory, IEnumerable<HqlTreeNode> children) - : base(type, text, factory, children) - { - } + public abstract class HqlBooleanExpression : HqlExpression + { + protected HqlBooleanExpression(int type, string text, IASTFactory factory, IEnumerable<HqlTreeNode> children) + : base(type, text, factory, children) + { + } - protected HqlBooleanExpression(int type, string text, IASTFactory factory, params HqlTreeNode[] children) - : base(type, text, factory, children) - { - } - } + protected HqlBooleanExpression(int type, string text, IASTFactory factory, params HqlTreeNode[] children) + : base(type, text, factory, children) + { + } + } - public class HqlQuery : HqlExpression - { - internal HqlQuery(IASTFactory factory, params HqlStatement[] children) - : base(HqlSqlWalker.QUERY, "query", factory, children) - { - } - } + public class HqlQuery : HqlExpression + { + internal HqlQuery(IASTFactory factory, params HqlStatement[] children) + : base(HqlSqlWalker.QUERY, "query", factory, children) + { + } + } - public class HqlIdent : HqlExpression - { - internal HqlIdent(IASTFactory factory, string ident) - : base(HqlSqlWalker.IDENT, ident, factory) - { - } + public class HqlIdent : HqlExpression + { + internal HqlIdent(IASTFactory factory, string ident) + : base(HqlSqlWalker.IDENT, ident, factory) + { + } - internal HqlIdent(IASTFactory factory, System.Type type) - : base(HqlSqlWalker.IDENT, "", factory) - { - if (IsNullableType(type)) - { - type = ExtractUnderlyingTypeFromNullable(type); - } + internal HqlIdent(IASTFactory factory, System.Type type) + : base(HqlSqlWalker.IDENT, "", factory) + { + if (IsNullableType(type)) + { + type = ExtractUnderlyingTypeFromNullable(type); + } - switch (System.Type.GetTypeCode(type)) - { + switch (System.Type.GetTypeCode(type)) + { case TypeCode.Boolean: - SetText("bool"); - break; + SetText("bool"); + break; case TypeCode.Int16: - SetText("short"); - break; + SetText("short"); + break; case TypeCode.Int32: - SetText("integer"); - break; - case TypeCode.Int64: - SetText("long"); - break; - case TypeCode.Decimal: - SetText("decimal"); - break; - case TypeCode.DateTime: - SetText("datetime"); - break; + SetText("integer"); + break; + case TypeCode.Int64: + SetText("long"); + break; + case TypeCode.Decimal: + SetText("decimal"); + break; + case TypeCode.DateTime: + SetText("datetime"); + break; case TypeCode.String: - SetText("string"); - break; - case TypeCode.Double: - SetText("double"); - break; - default: + SetText("string"); + break; + case TypeCode.Double: + SetText("double"); + break; + default: if (type == typeof(Guid)) { SetText("guid"); break; } - throw new NotSupportedException(string.Format("Don't currently support idents of type {0}", type.Name)); - } - } + throw new NotSupportedException(string.Format("Don't currently support idents of type {0}", type.Name)); + } + } - private static System.Type ExtractUnderlyingTypeFromNullable(System.Type type) - { - return type.GetGenericArguments()[0]; - } + private static System.Type ExtractUnderlyingTypeFromNullable(System.Type type) + { + return type.GetGenericArguments()[0]; + } - // TODO - code duplicated in LinqExtensionMethods - private static bool IsNullableType(System.Type type) - { - return (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)); - } + // TODO - code duplicated in LinqExtensionMethods + private static bool IsNullableType(System.Type type) + { + return (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)); + } + } - } + public class HqlRange : HqlStatement + { + internal HqlRange(IASTFactory factory, params HqlTreeNode[] children) + : base(HqlSqlWalker.RANGE, "range", factory, children) + { + } + } - public class HqlRange : HqlStatement - { - internal HqlRange(IASTFactory factory, params HqlTreeNode[] children) - : base(HqlSqlWalker.RANGE, "range", factory, children) - { - } - } + public class HqlFrom : HqlStatement + { + internal HqlFrom(IASTFactory factory, params HqlTreeNode[] children) + : base(HqlSqlWalker.FROM, "from", factory, children) + { + } + } - public class HqlFrom : HqlStatement - { - internal HqlFrom(IASTFactory factory, params HqlTreeNode[] children) - : base(HqlSqlWalker.FROM, "from", factory, children) - { - } - } + public class HqlSelectFrom : HqlStatement + { + internal HqlSelectFrom(IASTFactory factory, params HqlTreeNode[] children) + : base(HqlSqlWalker.SELECT_FROM, "select_from", factory, children) + { + } + } - public class HqlSelectFrom : HqlStatement - { - internal HqlSelectFrom(IASTFactory factory, params HqlTreeNode[] children) - : base(HqlSqlWalker.SELECT_FROM, "select_from", factory, children) - { - } - } + public class HqlAlias : HqlExpression + { + public HqlAlias(IASTFactory factory, string @alias) + : base(HqlSqlWalker.ALIAS, alias, factory) + { + } + } - public class HqlAlias : HqlExpression - { - public HqlAlias(IASTFactory factory, string @alias) - : base(HqlSqlWalker.ALIAS, alias, factory) - { - } - } + public class HqlDivide : HqlExpression + { + public HqlDivide(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) + : base(HqlSqlWalker.DIV, "/", factory, lhs, rhs) + { + } + } - public class HqlDivide : HqlExpression - { - public HqlDivide(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) - : base(HqlSqlWalker.DIV, "/", factory, lhs, rhs) - { - } - } + public class HqlMultiplty : HqlExpression + { + public HqlMultiplty(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) + : base(HqlSqlWalker.STAR, "*", factory, lhs, rhs) + { + } + } - public class HqlMultiplty : HqlExpression - { - public HqlMultiplty(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) - : base(HqlSqlWalker.STAR, "*", factory, lhs, rhs) - { - } - } + public class HqlSubtract : HqlExpression + { + public HqlSubtract(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) + : base(HqlSqlWalker.MINUS, "-", factory, lhs, rhs) + { + } + } - public class HqlSubtract : HqlExpression - { - public HqlSubtract(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) - : base(HqlSqlWalker.MINUS, "-", factory, lhs, rhs) - { - } - } + public class HqlAdd : HqlExpression + { + public HqlAdd(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) + : base(HqlSqlWalker.PLUS, "+", factory, lhs, rhs) + { + } + } - public class HqlAdd : HqlExpression - { - public HqlAdd(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) - : base(HqlSqlWalker.PLUS, "+", factory, lhs, rhs) - { - } - } + public class HqlBooleanOr : HqlBooleanExpression + { + public HqlBooleanOr(IASTFactory factory, HqlBooleanExpression lhs, HqlBooleanExpression rhs) + : base(HqlSqlWalker.OR, "or", factory, lhs, rhs) + { + } + } - public class HqlBooleanOr : HqlBooleanExpression - { - public HqlBooleanOr(IASTFactory factory, HqlBooleanExpression lhs, HqlBooleanExpression rhs) - : base(HqlSqlWalker.OR, "or", factory, lhs, rhs) - { - } - } + public class HqlBooleanAnd : HqlBooleanExpression + { + public HqlBooleanAnd(IASTFactory factory, HqlBooleanExpression lhs, HqlBooleanExpression rhs) + : base(HqlSqlWalker.AND, "and", factory, lhs, rhs) + { + } + } - public class HqlBooleanAnd : HqlBooleanExpression - { - public HqlBooleanAnd(IASTFactory factory, HqlBooleanExpression lhs, HqlBooleanExpression rhs) - : base(HqlSqlWalker.AND, "and", factory, lhs, rhs) - { - } - } + public class HqlEquality : HqlBooleanExpression + { + public HqlEquality(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) + : base(HqlSqlWalker.EQ, "==", factory, lhs, rhs) + { + } + } - public class HqlEquality : HqlBooleanExpression - { - public HqlEquality(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) - : base(HqlSqlWalker.EQ, "==", factory, lhs, rhs) - { - } - } - - public class HqlParameter : HqlExpression - { - public HqlParameter(IASTFactory factory, string name) - : base(HqlSqlWalker.COLON, ":", factory) - { + public class HqlParameter : HqlExpression + { + public HqlParameter(IASTFactory factory, string name) + : base(HqlSqlWalker.COLON, ":", factory) + { AddChild(new HqlIdent(factory, name)); - } - } + } + } - public class HqlDot : HqlExpression - { - public HqlDot(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) - : base(HqlSqlWalker.DOT, ".", factory, lhs, rhs) - { - } - } + public class HqlDot : HqlExpression + { + public HqlDot(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) + : base(HqlSqlWalker.DOT, ".", factory, lhs, rhs) + { + } + } - public class HqlBooleanDot : HqlBooleanExpression - { - public HqlBooleanDot(IASTFactory factory, HqlDot dot) : base(dot.AstNode.Type, dot.AstNode.Text, factory, dot.Children) - { - } - } + public class HqlBooleanDot : HqlBooleanExpression + { + public HqlBooleanDot(IASTFactory factory, HqlDot dot) : base(dot.AstNode.Type, dot.AstNode.Text, factory, dot.Children) + { + } + } - public class HqlWhere : HqlStatement - { - public HqlWhere(IASTFactory factory, HqlExpression expression) - : base(HqlSqlWalker.WHERE, "where", factory, expression) - { - } - } + public class HqlWhere : HqlStatement + { + public HqlWhere(IASTFactory factory, HqlExpression expression) + : base(HqlSqlWalker.WHERE, "where", factory, expression) + { + } + } - public class HqlConstant : HqlExpression - { - public HqlConstant(IASTFactory factory, int type, string value) - : base(type, value, factory) - { - } - } + public class HqlConstant : HqlExpression + { + public HqlConstant(IASTFactory factory, int type, string value) + : base(type, value, factory) + { + } + } - public class HqlStringConstant : HqlConstant - { - public HqlStringConstant(IASTFactory factory, string s) - : base(factory, HqlSqlWalker.QUOTED_String, s) - { - } - } + public class HqlStringConstant : HqlConstant + { + public HqlStringConstant(IASTFactory factory, string s) + : base(factory, HqlSqlWalker.QUOTED_String, s) + { + } + } - public class HqlDoubleConstant : HqlConstant - { - public HqlDoubleConstant(IASTFactory factory, string s) - : base(factory, HqlSqlWalker.NUM_DOUBLE, s) - { - } - } + public class HqlDoubleConstant : HqlConstant + { + public HqlDoubleConstant(IASTFactory factory, string s) + : base(factory, HqlSqlWalker.NUM_DOUBLE, s) + { + } + } - public class HqlFloatConstant : HqlConstant - { - public HqlFloatConstant(IASTFactory factory, string s) - : base(factory, HqlSqlWalker.NUM_FLOAT, s) - { - } - } + public class HqlFloatConstant : HqlConstant + { + public HqlFloatConstant(IASTFactory factory, string s) + : base(factory, HqlSqlWalker.NUM_FLOAT, s) + { + } + } - public class HqlIntegerConstant : HqlConstant - { - public HqlIntegerConstant(IASTFactory factory, string s) - : base(factory, HqlSqlWalker.NUM_INT, s) - { - } - } + public class HqlIntegerConstant : HqlConstant + { + public HqlIntegerConstant(IASTFactory factory, string s) + : base(factory, HqlSqlWalker.NUM_INT, s) + { + } + } - public class HqlDecimalConstant : HqlConstant - { - public HqlDecimalConstant(IASTFactory factory, string s) - : base(factory, HqlSqlWalker.NUM_DECIMAL, s) - { - } - } + public class HqlDecimalConstant : HqlConstant + { + public HqlDecimalConstant(IASTFactory factory, string s) + : base(factory, HqlSqlWalker.NUM_DECIMAL, s) + { + } + } - public class HqlFalse : HqlConstant - { - public HqlFalse(IASTFactory factory) - : base(factory, HqlSqlWalker.FALSE, "false") - { - } - } + public class HqlFalse : HqlConstant + { + public HqlFalse(IASTFactory factory) + : base(factory, HqlSqlWalker.FALSE, "false") + { + } + } - public class HqlTrue : HqlConstant - { - public HqlTrue(IASTFactory factory) - : base(factory, HqlSqlWalker.TRUE, "true") - { - } - } + public class HqlTrue : HqlConstant + { + public HqlTrue(IASTFactory factory) + : base(factory, HqlSqlWalker.TRUE, "true") + { + } + } + public class HqlNull : HqlConstant + { + public HqlNull(IASTFactory factory) + : base(factory, HqlSqlWalker.NULL, "null") + { + } + } - public class HqlNull : HqlConstant - { - public HqlNull(IASTFactory factory) - : base(factory, HqlSqlWalker.NULL, "null") - { - } - } + public class HqlOrderBy : HqlStatement + { + public HqlOrderBy(IASTFactory factory) + : base(HqlSqlWalker.ORDER, "order by", factory) + { + } + } - public class HqlOrderBy : HqlStatement - { - public HqlOrderBy(IASTFactory factory) - : base(HqlSqlWalker.ORDER, "order by", factory) - { - } - } + public enum HqlDirection + { + Ascending, + Descending + } - public enum HqlDirection - { - Ascending, - Descending - } + public class HqlDirectionStatement : HqlStatement + { + public HqlDirectionStatement(int type, string text, IASTFactory factory) + : base(type, text, factory) + { + } + } - public class HqlDirectionStatement : HqlStatement - { - public HqlDirectionStatement(int type, string text, IASTFactory factory) - : base(type, text, factory) - { - } - } + public class HqlDirectionAscending : HqlDirectionStatement + { + public HqlDirectionAscending(IASTFactory factory) + : base(HqlSqlWalker.ASCENDING, "asc", factory) + { + } + } - public class HqlDirectionAscending : HqlDirectionStatement - { - public HqlDirectionAscending(IASTFactory factory) - : base(HqlSqlWalker.ASCENDING, "asc", factory) - { - } - } + public class HqlDirectionDescending : HqlDirectionStatement + { + public HqlDirectionDescending(IASTFactory factory) + : base(HqlSqlWalker.DESCENDING, "desc", factory) + { + } + } - public class HqlDirectionDescending : HqlDirectionStatement - { - public HqlDirectionDescending(IASTFactory factory) - : base(HqlSqlWalker.DESCENDING, "desc", factory) - { - } - } + public class HqlSelect : HqlStatement + { + public HqlSelect(IASTFactory factory, params HqlExpression[] expression) + : base(HqlSqlWalker.SELECT, "select", factory, expression) + { + } + } - public class HqlSelect : HqlStatement - { - public HqlSelect(IASTFactory factory, params HqlExpression[] expression) - : base(HqlSqlWalker.SELECT, "select", factory, expression) - { - } - } + public class HqlElse : HqlStatement + { + public HqlElse(IASTFactory factory, HqlExpression ifFalse) + : base(HqlSqlWalker.ELSE, "else", factory, ifFalse) + { + } + } - public class HqlElse : HqlStatement - { - public HqlElse(IASTFactory factory, HqlExpression ifFalse) - : base(HqlSqlWalker.ELSE, "else", factory, ifFalse) - { - } - } + public class HqlWhen : HqlStatement + { + public HqlWhen(IASTFactory factory, HqlExpression predicate, HqlExpression ifTrue) + : base(HqlSqlWalker.WHEN, "when", factory, predicate, ifTrue) + { + } + } - public class HqlWhen : HqlStatement - { - public HqlWhen(IASTFactory factory, HqlExpression predicate, HqlExpression ifTrue) - : base(HqlSqlWalker.WHEN, "when", factory, predicate, ifTrue) - { - } - } + public class HqlCase : HqlExpression + { + public HqlCase(IASTFactory factory, HqlWhen[] whenClauses, HqlExpression ifFalse) + : base(HqlSqlWalker.CASE, "case", factory, whenClauses) + { + if (ifFalse != null) + { + AddChild(new HqlElse(factory, ifFalse)); + } + } + } - public class HqlCase : HqlExpression - { - public HqlCase(IASTFactory factory, HqlWhen[] whenClauses, HqlExpression ifFalse) - : base(HqlSqlWalker.CASE, "case", factory, whenClauses) - { - if (ifFalse != null) - { - AddChild(new HqlElse(factory, ifFalse)); - } - } - } + public class HqlGreaterThanOrEqual : HqlBooleanExpression + { + public HqlGreaterThanOrEqual(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) + : base(HqlSqlWalker.GE, "ge", factory, lhs, rhs) + { + } + } - public class HqlGreaterThanOrEqual : HqlBooleanExpression - { - public HqlGreaterThanOrEqual(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) - : base(HqlSqlWalker.GE, "ge", factory, lhs, rhs) - { - } - } + public class HqlGreaterThan : HqlBooleanExpression + { + public HqlGreaterThan(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) + : base(HqlSqlWalker.GT, "gt", factory, lhs, rhs) + { + } + } - public class HqlGreaterThan : HqlBooleanExpression - { - public HqlGreaterThan(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) - : base(HqlSqlWalker.GT, "gt", factory, lhs, rhs) - { - } - } + public class HqlLessThanOrEqual : HqlBooleanExpression + { + public HqlLessThanOrEqual(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) + : base(HqlSqlWalker.LE, "le", factory, lhs, rhs) + { + } + } - public class HqlLessThanOrEqual : HqlBooleanExpression - { - public HqlLessThanOrEqual(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) - : base(HqlSqlWalker.LE, "le", factory, lhs, rhs) - { - } - } + public class HqlLessThan : HqlBooleanExpression + { + public HqlLessThan(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) + : base(HqlSqlWalker.LT, "lt", factory, lhs, rhs) + { + } + } - public class HqlLessThan : HqlBooleanExpression - { - public HqlLessThan(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) - : base(HqlSqlWalker.LT, "lt", factory, lhs, rhs) - { - } - } + public class HqlInequality : HqlBooleanExpression + { + public HqlInequality(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) + : base(HqlSqlWalker.NE, "ne", factory, lhs, rhs) + { + } + } - public class HqlInequality : HqlBooleanExpression - { - public HqlInequality(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) - : base(HqlSqlWalker.NE, "ne", factory, lhs, rhs) - { - } - } + public class HqlRowStar : HqlStatement + { + public HqlRowStar(IASTFactory factory) + : base(HqlSqlWalker.ROW_STAR, "*", factory) + { + } + } - public class HqlRowStar : HqlStatement - { - public HqlRowStar(IASTFactory factory) - : base(HqlSqlWalker.ROW_STAR, "*", factory) - { - } - } + public class HqlCount : HqlExpression + { + public HqlCount(IASTFactory factory) + : base(HqlSqlWalker.COUNT, "count", factory) + { + } - public class HqlCount : HqlExpression - { - public HqlCount(IASTFactory factory) - : base(HqlSqlWalker.COUNT, "count", factory) - { - } + public HqlCount(IASTFactory factory, HqlExpression child) + : base(HqlSqlWalker.COUNT, "count", factory, child) + { + } + } - public HqlCount(IASTFactory factory, HqlExpression child) - : base(HqlSqlWalker.COUNT, "count", factory, child) - { - } - } + public class HqlAs : HqlExpression + { + public HqlAs(IASTFactory factory, HqlExpression expression, System.Type type) + : base(HqlSqlWalker.AS, "as", factory, expression) + { + switch (System.Type.GetTypeCode(type)) + { + case TypeCode.Int32: + AddChild(new HqlIdent(factory, "integer")); + break; + default: + throw new InvalidOperationException(); + } + } + } - public class HqlAs : HqlExpression - { - public HqlAs(IASTFactory factory, HqlExpression expression, System.Type type) - : base(HqlSqlWalker.AS, "as", factory, expression) - { - switch (System.Type.GetTypeCode(type)) - { - case TypeCode.Int32: - AddChild(new HqlIdent(factory, "integer")); - break; - default: - throw new InvalidOperationException(); - } - } - } + public class HqlCast : HqlExpression + { + public HqlCast(IASTFactory factory, HqlExpression expression, System.Type type) + : base(HqlSqlWalker.METHOD_CALL, "method", factory) + { + AddChild(new HqlIdent(factory, "cast")); + AddChild(new HqlExpressionList(factory, expression, new HqlIdent(factory, type))); + } + } - public class HqlCast : HqlExpression - { - public HqlCast(IASTFactory factory, HqlExpression expression, System.Type type) - : base(HqlSqlWalker.METHOD_CALL, "method", factory) - { - AddChild(new HqlIdent(factory, "cast")); - AddChild(new HqlExpressionList(factory, expression, new HqlIdent(factory, type))); - } - } - public class HqlCoalesce : HqlExpression { public HqlCoalesce(IASTFactory factory, HqlExpression lhs, HqlExpression rhs) @@ -608,264 +606,280 @@ } } - public class HqlExpressionList : HqlStatement - { - public HqlExpressionList(IASTFactory factory, params HqlExpression[] expressions) - : base(HqlSqlWalker.EXPR_LIST, "expr_list", factory, expressions) - { - } + public class HqlDictionaryIndex : HqlExpression + { + public HqlDictionaryIndex(IASTFactory factory, HqlExpression dictionary, HqlExpression index) + : base(HqlSqlWalker.INDEX_OP, "[", factory, dictionary, index) + { + } + } - public HqlExpressionList(IASTFactory factory, IEnumerable<HqlExpression> expressions) - : base(HqlSqlWalker.EXPR_LIST, "expr_list", factory, expressions.Cast<HqlTreeNode>()) - { - } - } + public class HqlIndices : HqlExpression + { + public HqlIndices(IASTFactory factory, HqlExpression dictionary) + : base(HqlSqlWalker.INDICES, "indices", factory, dictionary) + { + } + } - public class HqlBooleanNot : HqlBooleanExpression - { - public HqlBooleanNot(IASTFactory factory, HqlBooleanExpression operand) - : base(HqlSqlWalker.NOT, "not", factory, operand) - { - } - } + public class HqlExpressionList : HqlStatement + { + public HqlExpressionList(IASTFactory factory, params HqlExpression[] expressions) + : base(HqlSqlWalker.EXPR_LIST, "expr_list", factory, expressions) + { + } - public class HqlAverage : HqlExpression - { - public HqlAverage(IASTFactory factory, HqlExpression expression) - : base(HqlSqlWalker.AGGREGATE, "avg", factory, expression) - { - } - } + public HqlExpressionList(IASTFactory factory, IEnumerable<HqlExpression> expressions) + : base(HqlSqlWalker.EXPR_LIST, "expr_list", factory, expressions.Cast<HqlTreeNode>()) + { + } + } - public class HqlBitwiseNot : HqlExpression - { - public HqlBitwiseNot(IASTFactory factory) : base(HqlSqlWalker.BNOT, "not", factory) - { - } - } + public class HqlBooleanNot : HqlBooleanExpression + { + public HqlBooleanNot(IASTFactory factory, HqlBooleanExpression operand) + : base(HqlSqlWalker.NOT, "not", factory, operand) + { + } + } - public class HqlSum : HqlExpression - { - public HqlSum(IASTFactory factory) - : base(HqlSqlWalker.AGGREGATE, "sum", factory) - { - } + public class HqlAverage : HqlExpression + { + public HqlAverage(IASTFactory factory, HqlExpression expression) + : base(HqlSqlWalker.AGGREGATE, "avg", factory, expression) + { + } + } - public HqlSum(IASTFactory factory, HqlExpression expression) - : base(HqlSqlWalker.AGGREGATE, "sum", factory, expression) - { - } - } + public class HqlBitwiseNot : HqlExpression + { + public HqlBitwiseNot(IASTFactory factory) : base(HqlSqlWalker.BNOT, "not", factory) + { + } + } - public class HqlMax : HqlExpression - { - public HqlMax(IASTFactory factory, HqlExpression expression) - : base(HqlSqlWalker.AGGREGATE, "max", factory, expression) - { - } + public class HqlSum : HqlExpression + { + public HqlSum(IASTFactory factory) + : base(HqlSqlWalker.AGGREGATE, "sum", factory) + { + } + + public HqlSum(IASTFactory factory, HqlExpression expression) + : base(HqlSqlWalker.AGGREGATE, "sum", factory, expression) + { + } + } + + public class HqlMax : HqlExpression + { + public HqlMax(IASTFactory factory, HqlExpression expression) + : base(HqlSqlWalker.AGGREGATE, "max", factory, expression) + { + } } - public class HqlMin : HqlExpression - { - public HqlMin(IASTFactory factory, HqlExpression expression) - : base(HqlSqlWalker.AGGREGATE, "min", factory, expression) - { - } - } + public class HqlMin : HqlExpression + { + public HqlMin(IASTFactory factory, HqlExpression expression) + : base(HqlSqlWalker.AGGREGATE, "min", factory, expression) + { + } + } - public class HqlJoin : HqlStatement - { - public HqlJoin(IASTFactory factory, HqlExpression expression, HqlAlias @alias) : base(HqlSqlWalker.JOIN, "join", factory, expression, @alias) - { - } - } + public class HqlJoin : HqlStatement + { + public HqlJoin(IASTFactory factory, HqlExpression expression, HqlAlias @alias) : base(HqlSqlWalker.JOIN, "join", factory, expression, @alias) + { + } + } - public class HqlLeftJoin : HqlTreeNode - { - public HqlLeftJoin(IASTFactory factory, HqlExpression expression, HqlAlias @alias) : base(HqlSqlWalker.JOIN, "join", factory, new HqlLeft(factory), expression, @alias) - { - } - } + public class HqlLeftJoin : HqlTreeNode + { + public HqlLeftJoin(IASTFactory factory, HqlExpression expression, HqlAlias @alias) : base(HqlSqlWalker.JOIN, "join", factory, new HqlLeft(factory), expression, @alias) + { + } + } - public class HqlFetchJoin : HqlTreeNode - { - public HqlFetchJoin(IASTFactory factory, HqlExpression expression, HqlAlias @alias) - : base(HqlSqlWalker.JOIN, "join", factory, new HqlFetch(factory), expression, @alias) - { - } - } + public class HqlFetchJoin : HqlTreeNode + { + public HqlFetchJoin(IASTFactory factory, HqlExpression expression, HqlAlias @alias) + : base(HqlSqlWalker.JOIN, "join", factory, new HqlFetch(factory), expression, @alias) + { + } + } - public class HqlLeftFetchJoin : HqlTreeNode - { - public HqlLeftFetchJoin(IASTFactory factory, HqlExpression ... [truncated message content] |
From: <jul...@us...> - 2010-12-09 16:15:44
|
Revision: 5300 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5300&view=rev Author: julian-maughan Date: 2010-12-09 16:15:38 +0000 (Thu, 09 Dec 2010) Log Message: ----------- Fixed typing of boolean parameter values (issue reported on SQLite) [ref. NH-2441] Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/Model.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs 2010-12-06 16:56:40 UTC (rev 5299) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs 2010-12-09 16:15:38 UTC (rev 5300) @@ -165,7 +165,7 @@ case TypeCode.DateTime: return new HqlStringConstant(_factory, "\'" + (DateTime)value + "\'"); case TypeCode.Boolean: - return new HqlStringConstant(_factory, "\'" + ((bool)value ? "true" : "false") + "\'"); + return (bool)value ? (HqlConstant)True() : (HqlConstant)False(); default: throw new NotSupportedException(string.Format("The constant for '{0}' is not supported", value)); } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/Fixture.cs 2010-12-09 16:15:38 UTC (rev 5300) @@ -0,0 +1,57 @@ +using System.Linq; +using NHibernate.Dialect; +using NHibernate.Linq; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2441 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect) + { + return ((dialect is Dialect.SQLiteDialect) || (dialect is Dialect.MsSql2008Dialect)); + } + + protected override void OnSetUp() + { + base.OnSetUp(); + + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + Person e1 = new Person("Tuna Toksoz", "Born in Istanbul :Turkey"); + Person e2 = new Person("Tuna Toksoz", "Born in Istanbul :Turkiye"); + s.Save(e1); + s.Save(e2); + tx.Commit(); + } + } + + protected override void OnTearDown() + { + using (ISession session = OpenSession()) + using (ITransaction tx = session.BeginTransaction()) + { + session.Delete("from Person"); + tx.Commit(); + } + + base.OnTearDown(); + } + + [Test] + public void LinqQueryBooleanSQLite() + { + using (ISession session = OpenSession()) + { + var query1 = session.Query<Person>().Where(p => true); + var query2 = session.Query<Person>().Where(p => p.Id != null); + var query3 = session.Query<Person>(); + + Assert.That(query1.Count(), Is.EqualTo(query2.Count())); + Assert.That(query3.Count(), Is.EqualTo(query1.Count())); + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/Mappings.hbm.xml 2010-12-09 16:15:38 UTC (rev 5300) @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping + xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2441"> + + <class name="Person" lazy="false"> + <id name="Id"> + <generator class="native" /> + </id> + <property name="Name"/> + <property name="Biography"/> + </class> + +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2441/Model.cs 2010-12-09 16:15:38 UTC (rev 5300) @@ -0,0 +1,19 @@ +namespace NHibernate.Test.NHSpecificTest.NH2441 +{ + public class Person + { + public virtual int Id { get; set; } + public virtual string Name { get; set; } + public virtual string Biography { get; set; } + + public Person() + { + } + + public Person(string name, string bio) + { + this.Name = name; + this.Biography = bio; + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-06 16:56:40 UTC (rev 5299) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-09 16:15:38 UTC (rev 5300) @@ -538,6 +538,8 @@ <Compile Include="NHSpecificTest\NH2420\DummyEnlistment.cs" /> <Compile Include="NHSpecificTest\NH2420\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2420\MyTable.cs" /> + <Compile Include="NHSpecificTest\NH2441\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2441\Model.cs" /> <Compile Include="PolymorphicGetAndLoad\Domain.cs" /> <Compile Include="PolymorphicGetAndLoad\PolymorphicGetAndLoadTest.cs" /> <Compile Include="TypesTest\CharClass.cs" /> @@ -1832,6 +1834,7 @@ <EmbeddedResource Include="NHSpecificTest\NH2392\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2409\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2420\Mappings.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\NH2441\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\NHibernate.ByteCode.Castle\NHibernate.ByteCode.Castle.csproj"> @@ -2683,6 +2686,7 @@ </ItemGroup> <ItemGroup> <Folder Include="NHSpecificTest\NH2420" /> + <Folder Include="NHSpecificTest\NH2441" /> <Folder Include="Properties\" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2010-12-10 14:23:55
|
Revision: 5301 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5301&view=rev Author: julian-maughan Date: 2010-12-10 14:23:49 +0000 (Fri, 10 Dec 2010) Log Message: ----------- Added BeginTransaction method overload - with IsolationLevel parameter - for stateless sessions (ref. NH-2449) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/IStatelessSession.cs trunk/nhibernate/src/NHibernate/Impl/StatelessSessionImpl.cs Modified: trunk/nhibernate/src/NHibernate/IStatelessSession.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IStatelessSession.cs 2010-12-09 16:15:38 UTC (rev 5300) +++ trunk/nhibernate/src/NHibernate/IStatelessSession.cs 2010-12-10 14:23:49 UTC (rev 5301) @@ -3,8 +3,8 @@ namespace NHibernate { - /// <summary> - /// A command-oriented API for performing bulk operations against a database. + /// <summary> + /// A command-oriented API for performing bulk operations against a database. /// </summary> /// <remarks> /// A stateless session does not implement a first-level cache nor @@ -17,7 +17,7 @@ /// aliasing effects, due to the lack of a first-level cache. /// <para/> /// For certain kinds of transactions, a stateless session may - /// perform slightly faster than a stateful session. + /// perform slightly faster than a stateful session. /// </remarks> public interface IStatelessSession : IDisposable { @@ -61,46 +61,46 @@ object Get(string entityName, object id); /// <summary> Retrieve a entity. - /// + /// /// </summary> /// <returns> a detached entity instance /// </returns> T Get<T>(object id); - /// <summary> - /// Retrieve a entity, obtaining the specified lock mode. + /// <summary> + /// Retrieve a entity, obtaining the specified lock mode. /// </summary> /// <returns> a detached entity instance </returns> object Get(string entityName, object id, LockMode lockMode); - /// <summary> - /// Retrieve a entity, obtaining the specified lock mode. + /// <summary> + /// Retrieve a entity, obtaining the specified lock mode. /// </summary> /// <returns> a detached entity instance </returns> T Get<T>(object id, LockMode lockMode); - /// <summary> - /// Refresh the entity instance state from the database. + /// <summary> + /// Refresh the entity instance state from the database. /// </summary> /// <param name="entity">The entity to be refreshed. </param> void Refresh(object entity); - /// <summary> - /// Refresh the entity instance state from the database. + /// <summary> + /// Refresh the entity instance state from the database. /// </summary> /// <param name="entityName">The entityName for the entity to be refreshed. </param> /// <param name="entity">The entity to be refreshed.</param> void Refresh(string entityName, object entity); - /// <summary> - /// Refresh the entity instance state from the database. + /// <summary> + /// Refresh the entity instance state from the database. /// </summary> /// <param name="entity">The entity to be refreshed. </param> /// <param name="lockMode">The LockMode to be applied.</param> void Refresh(object entity, LockMode lockMode); - /// <summary> - /// Refresh the entity instance state from the database. + /// <summary> + /// Refresh the entity instance state from the database. /// </summary> /// <param name="entityName">The entityName for the entity to be refreshed. </param> /// <param name="entity">The entity to be refreshed. </param> @@ -113,7 +113,7 @@ /// <remarks>Entities returned by the query are detached.</remarks> IQuery CreateQuery(string queryString); - /// <summary> + /// <summary> /// Obtain an instance of <see cref="IQuery"/> for a named query string defined in /// the mapping file. /// </summary> @@ -125,7 +125,7 @@ /// <summary> /// Create a new <see cref="ICriteria"/> instance, for the given entity class, - /// or a superclass of an entity class. + /// or a superclass of an entity class. /// </summary> /// <typeparam name="T">A class, which is persistent, or has persistent subclasses</typeparam> /// <returns> The <see cref="ICriteria"/>. </returns> @@ -134,7 +134,7 @@ /// <summary> /// Create a new <see cref="ICriteria"/> instance, for the given entity class, - /// or a superclass of an entity class, with the given alias. + /// or a superclass of an entity class, with the given alias. /// </summary> /// <typeparam name="T">A class, which is persistent, or has persistent subclasses</typeparam> /// <param name="alias">The alias of the entity</param> @@ -144,7 +144,7 @@ /// <summary> /// Create a new <see cref="ICriteria"/> instance, for the given entity class, - /// or a superclass of an entity class. + /// or a superclass of an entity class. /// </summary> /// <param name="entityType">A class, which is persistent, or has persistent subclasses</param> /// <returns> The <see cref="ICriteria"/>. </returns> @@ -153,7 +153,7 @@ /// <summary> /// Create a new <see cref="ICriteria"/> instance, for the given entity class, - /// or a superclass of an entity class, with the given alias. + /// or a superclass of an entity class, with the given alias. /// </summary> /// <param name="entityType">A class, which is persistent, or has persistent subclasses</param> /// <param name="alias">The alias of the entity</param> @@ -161,7 +161,7 @@ /// <remarks>Entities returned by the query are detached.</remarks> ICriteria CreateCriteria(System.Type entityType, string alias); - /// <summary> + /// <summary> /// Create a new <see cref="ICriteria"/> instance, for the given entity name. /// </summary> /// <param name="entityName">The entity name. </param> @@ -169,9 +169,9 @@ /// <remarks>Entities returned by the query are detached.</remarks> ICriteria CreateCriteria(string entityName); - /// <summary> + /// <summary> /// Create a new <see cref="ICriteria"/> instance, for the given entity name, - /// with the given alias. + /// with the given alias. /// </summary> /// <param name="entityName">The entity name. </param> /// <param name="alias">The alias of the entity</param> @@ -179,7 +179,7 @@ /// <remarks>Entities returned by the query are detached.</remarks> ICriteria CreateCriteria(string entityName, string alias); - /// <summary> + /// <summary> /// Create a new instance of <see cref="ISQLQuery"/> for the given SQL query string. /// Entities returned by the query are detached. /// </summary> @@ -187,10 +187,20 @@ /// <returns> The <see cref="ISQLQuery"/> </returns> ISQLQuery CreateSQLQuery(string queryString); - /// <summary> Begin a NHibernate transaction.</summary> + /// <summary> + /// Begin a NHibernate transaction + /// </summary> + /// <returns>A NHibernate transaction</returns> ITransaction BeginTransaction(); - /// <summary> + /// <summary> + /// Begin a NHibernate transaction with the specified isolation level + /// </summary> + /// <param name="isolationLevel">The isolation level</param> + /// <returns>A NHibernate transaction</returns> + ITransaction BeginTransaction(IsolationLevel isolationLevel); + + /// <summary> /// Returns the current ADO.NET connection associated with this instance. /// </summary> /// <remarks> Modified: trunk/nhibernate/src/NHibernate/Impl/StatelessSessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/StatelessSessionImpl.cs 2010-12-09 16:15:38 UTC (rev 5300) +++ trunk/nhibernate/src/NHibernate/Impl/StatelessSessionImpl.cs 2010-12-10 14:23:49 UTC (rev 5301) @@ -140,15 +140,15 @@ } } - public override IList List(IQueryExpression queryExpression, QueryParameters parameters) - { - throw new System.NotImplementedException(); - } + public override IList List(IQueryExpression queryExpression, QueryParameters parameters) + { + throw new System.NotImplementedException(); + } - public override void List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) - { - throw new System.NotImplementedException(); - } + public override void List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) + { + throw new System.NotImplementedException(); + } public override IList<T> List<T>(string query, QueryParameters queryParameters) { @@ -660,7 +660,7 @@ } /// <summary> Retrieve a entity. - /// + /// /// </summary> /// <returns> a detached entity instance /// </returns> @@ -680,8 +680,8 @@ } } - /// <summary> - /// Retrieve a entity, obtaining the specified lock mode. + /// <summary> + /// Retrieve a entity, obtaining the specified lock mode. /// </summary> /// <returns> a detached entity instance </returns> public object Get(string entityName, object id, LockMode lockMode) @@ -695,8 +695,8 @@ } } - /// <summary> - /// Retrieve a entity, obtaining the specified lock mode. + /// <summary> + /// Retrieve a entity, obtaining the specified lock mode. /// </summary> /// <returns> a detached entity instance </returns> public T Get<T>(object id, LockMode lockMode) @@ -707,8 +707,8 @@ } } - /// <summary> - /// Refresh the entity instance state from the database. + /// <summary> + /// Refresh the entity instance state from the database. /// </summary> /// <param name="entity">The entity to be refreshed. </param> public void Refresh(object entity) @@ -719,8 +719,8 @@ } } - /// <summary> - /// Refresh the entity instance state from the database. + /// <summary> + /// Refresh the entity instance state from the database. /// </summary> /// <param name="entityName">The entityName for the entity to be refreshed. </param> /// <param name="entity">The entity to be refreshed.</param> @@ -732,8 +732,8 @@ } } - /// <summary> - /// Refresh the entity instance state from the database. + /// <summary> + /// Refresh the entity instance state from the database. /// </summary> /// <param name="entity">The entity to be refreshed. </param> /// <param name="lockMode">The LockMode to be applied.</param> @@ -745,8 +745,8 @@ } } - /// <summary> - /// Refresh the entity instance state from the database. + /// <summary> + /// Refresh the entity instance state from the database. /// </summary> /// <param name="entityName">The entityName for the entity to be refreshed. </param> /// <param name="entity">The entity to be refreshed. </param> @@ -794,7 +794,7 @@ /// <summary> /// Create a new <see cref="ICriteria"/> instance, for the given entity class, - /// or a superclass of an entity class. + /// or a superclass of an entity class. /// </summary> /// <typeparam name="T">A class, which is persistent, or has persistent subclasses</typeparam> /// <returns> The <see cref="ICriteria"/>. </returns> @@ -809,7 +809,7 @@ /// <summary> /// Create a new <see cref="ICriteria"/> instance, for the given entity class, - /// or a superclass of an entity class, with the given alias. + /// or a superclass of an entity class, with the given alias. /// </summary> /// <typeparam name="T">A class, which is persistent, or has persistent subclasses</typeparam> /// <param name="alias">The alias of the entity</param> @@ -841,7 +841,7 @@ } } - /// <summary> + /// <summary> /// Create a new <see cref="ICriteria"/> instance, for the given entity name. /// </summary> /// <param name="entityName">The entity name. </param> @@ -856,9 +856,9 @@ } } - /// <summary> + /// <summary> /// Create a new <see cref="ICriteria"/> instance, for the given entity name, - /// with the given alias. + /// with the given alias. /// </summary> /// <param name="entityName">The entity name. </param> /// <param name="alias">The alias of the entity</param> @@ -873,13 +873,26 @@ } } - /// <summary> Begin a NHibernate transaction.</summary> + /// <summary> + /// Begin a NHibernate transaction + /// </summary> + /// <returns>A NHibernate transaction</returns> public ITransaction BeginTransaction() { + return BeginTransaction(IsolationLevel.Unspecified); + } + + /// <summary> + /// Begin a NHibernate transaction with the specified isolation level + /// </summary> + /// <param name="isolationLevel">The isolation level</param> + /// <returns>A NHibernate transaction</returns> + public ITransaction BeginTransaction(IsolationLevel isolationLevel) + { using (new SessionIdLoggingContext(SessionId)) { CheckAndUpdateSessionStatus(); - return connectionManager.BeginTransaction(); + return connectionManager.BeginTransaction(isolationLevel); } } @@ -1011,8 +1024,7 @@ } else { - return Factory.GetEntityPersister(entityName).GetSubclassEntityPersister(obj, Factory, - EntityMode.Poco); + return Factory.GetEntityPersister(entityName).GetSubclassEntityPersister(obj, Factory, EntityMode.Poco); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-12-10 16:47:17
|
Revision: 5302 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5302&view=rev Author: fabiomaulo Date: 2010-12-10 16:47:11 +0000 (Fri, 10 Dec 2010) Log Message: ----------- Fix NH-2410 (Port <properties> from Hibernate) thanks to Roger Kratz Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs trunk/nhibernate/src/NHibernate/Mapping/PersistentClass.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmProperties.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/CompositePropertyRefTest.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/DynamicEntityTest.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/Model.cs Added: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmProperties.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmProperties.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmProperties.cs 2010-12-10 16:47:11 UTC (rev 5302) @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Serialization; + +namespace NHibernate.Cfg.MappingSchema +{ + public partial class HbmProperties : AbstractDecoratable, IEntityPropertyMapping, IComponentMapping + { + #region Implementation of IEntityPropertyMapping + + public bool IsLazyProperty + { + get { return false; } + } + + public string Class + { + get { return null; } + } + + public HbmParent Parent + { + get { return null; } + } + + public string EmbeddedNode + { + get { return node; } + } + + public string Name + { + get { return name; } + } + + public string Access + { + get { return "embedded"; } + } + + public bool OptimisticLock + { + get { return optimisticlock; } + } + + #endregion + + #region Implementation of IPropertiesContainerMapping + + [XmlIgnore] + public IEnumerable<IEntityPropertyMapping> Properties + { + get { return Items != null ? Items.Cast<IEntityPropertyMapping>() : new IEntityPropertyMapping[0]; } + } + + #endregion + + #region Overrides of AbstractDecoratable + + protected override HbmMeta[] Metadatas + { + get { return new HbmMeta[0]; } + } + + #endregion + } +} Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2010-12-10 14:23:49 UTC (rev 5301) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2010-12-10 16:47:11 UTC (rev 5302) @@ -286,6 +286,7 @@ model.IsEmbedded = false; model.IsDynamic = true; } + else if (reflectedClass != null) { model.ComponentClass = reflectedClass; @@ -294,8 +295,15 @@ else { // an "embedded" component (ids only) - model.ComponentClass = model.Owner.MappedClass; model.IsEmbedded = true; + if (model.Owner.HasPocoRepresentation) + { + model.ComponentClass = model.Owner.MappedClass; + } + else + { + model.IsDynamic = true; + } } string nodeName = !string.IsNullOrEmpty(componentMapping.EmbeddedNode) Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs 2010-12-10 14:23:49 UTC (rev 5301) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/PropertiesBinder.cs 2010-12-10 16:47:11 UTC (rev 5302) @@ -83,6 +83,7 @@ HbmNestedCompositeElement nestedCompositeElementMapping; HbmKeyProperty keyPropertyMapping; HbmKeyManyToOne keyManyToOneMapping; + HbmProperties propertiesMapping; if ((propertyMapping = entityPropertyMapping as HbmProperty) != null) { @@ -104,6 +105,14 @@ property = CreateProperty(collectionMapping, className, collection, inheritedMetas); BindCollectionProperty(collectionMapping, property); } + else if ((propertiesMapping = entityPropertyMapping as HbmProperties) != null) + { + var subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName); + var value = CreateNewComponent(table); + BindComponent(propertiesMapping, value, null, entityName, subpath, componetDefaultNullable, inheritedMetas); + property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas); + BindComponentProperty(propertiesMapping, property, value); + } else if ((manyToOneMapping = entityPropertyMapping as HbmManyToOne) != null) { var value = new ManyToOne(table); @@ -326,6 +335,16 @@ } } + private void BindComponentProperty(HbmProperties propertiesMapping, Property property, Component model) + { + property.IsUpdateable = propertiesMapping.update; + property.IsInsertable = propertiesMapping.insert; + if (propertiesMapping.unique) + { + model.Owner.Table.CreateUniqueKey(model.ColumnIterator.OfType<Column>().ToList()); + } + } + private void BindComponentProperty(HbmComponent componentMapping, Property property, Component model) { property.IsUpdateable = componentMapping.update; Modified: trunk/nhibernate/src/NHibernate/Mapping/PersistentClass.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/PersistentClass.cs 2010-12-10 14:23:49 UTC (rev 5301) +++ trunk/nhibernate/src/NHibernate/Mapping/PersistentClass.cs 2010-12-10 16:47:11 UTC (rev 5302) @@ -910,9 +910,10 @@ private Property GetProperty(string propertyName, IEnumerable<Property> iter) { - foreach (Property prop in iter) + var propName = StringHelper.Root(propertyName); + foreach (var prop in iter) { - if (prop.Name.Equals(StringHelper.Root(propertyName))) + if (prop.Name.Equals(propName)) { return prop; } Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-12-10 14:23:49 UTC (rev 5301) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-12-10 16:47:11 UTC (rev 5302) @@ -530,6 +530,7 @@ <Compile Include="Cfg\MappingSchema\HbmOneToMany.cs" /> <Compile Include="Cfg\MappingSchema\HbmOneToOne.cs" /> <Compile Include="Cfg\MappingSchema\HbmPrimitiveArray.cs" /> + <Compile Include="Cfg\MappingSchema\HbmProperties.cs" /> <Compile Include="Cfg\MappingSchema\HbmProperty.cs" /> <Compile Include="Cfg\MappingSchema\HbmSet.cs" /> <Compile Include="Cfg\MappingSchema\HbmSubclass.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/CompositePropertyRefTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/CompositePropertyRefTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/CompositePropertyRefTest.cs 2010-12-10 16:47:11 UTC (rev 5302) @@ -0,0 +1,142 @@ +using System; +using System.Linq; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.Properties +{ + [TestFixture] + public class CompositePropertyRefTest : BugTestCase + { + private long p_id; + private long p2_id; + + protected override void OnSetUp() + { + using (var s = OpenSession()) + { + using (var tx = s.BeginTransaction()) + { + var p = new Person { Name = "Steve", UserId = "steve" }; + var a = new Address { Addr = "Texas", Country = "USA", Person = p }; + var p2 = new Person { Name = "Max", UserId = "max" }; + var act = new Account { Type = Convert.ToChar("c"), User = p2 }; + p2.Accounts.Add(act); + p_id = (long)s.Save(p); + s.Save(a); + p2_id = (long)s.Save(p2); + s.Save(act); + tx.Commit(); + } + } + } + + protected override void OnTearDown() + { + using (var s = OpenSession()) + { + using (var tx = s.BeginTransaction()) + { + s.Delete("from Account"); + s.Delete("from Address"); + s.Delete("from Person"); + tx.Commit(); + } + } + } + + [Test] + public void MappingOuterJoin() + { + using(var s = OpenSession()) + { + using (s.BeginTransaction()) + { + var p = s.Get<Person>(p_id); //get address reference by outer join + var p2 = s.Get<Person>(p2_id); //get null address reference by outer join + Assert.IsNull(p2.Address); + Assert.IsNotNull(p.Address); + var l = s.CreateQuery("from Person").List(); //pull address references for cache + Assert.AreEqual(l.Count, 2); + Assert.IsTrue(l.Contains(p) && l.Contains(p2)); + } + } + } + + [Test] + public void AddressBySequentialSelect() + { + using (var s = OpenSession()) + { + using (s.BeginTransaction()) + { + var l = s.CreateQuery("from Person p order by p.Name").List<Person>(); + Assert.AreEqual(l.Count, 2); + Assert.IsNull(l[0].Address); + Assert.IsNotNull(l[1].Address); + } + } + } + + [Test] + public void AddressOuterJoin() + { + using (var s = OpenSession()) + { + using (s.BeginTransaction()) + { + var l = s.CreateQuery("from Person p left join fetch p.Address a order by a.Country").List<Person>(); + Assert.AreEqual(l.Count, 2); + if (l[0].Name.Equals("Max")) + { + Assert.IsNull(l[0].Address); + Assert.IsNotNull(l[1].Address); + } + else + { + Assert.IsNull(l[1].Address); + Assert.IsNotNull(l[0].Address); + } + } + } + } + + [Test] + public void AccountsOuterJoin() + { + using (var s = OpenSession()) + { + using (s.BeginTransaction()) + { + var l = s.CreateQuery("from Person p left join p.Accounts").List(); + for (var i = 0; i < 2; i++) + { + var row = (object[])l[i]; + var px = (Person)row[0]; + var accounts = px.Accounts; + Assert.IsFalse(NHibernateUtil.IsInitialized(accounts)); + Assert.IsTrue(px.Accounts.Count > 0 || row[1] == null); + } + } + } + } + + [Test] + public void AccountsOuterJoinVerifyInitialization() + { + using (var s = OpenSession()) + { + using (s.BeginTransaction()) + { + var l = s.CreateQuery("from Person p left join fetch p.Accounts a order by p.Name").List<Person>(); + var p0 = l[0]; + Assert.IsTrue(NHibernateUtil.IsInitialized(p0.Accounts)); + Assert.AreEqual(p0.Accounts.Count, 1); + Assert.AreSame(p0.Accounts.First().User, p0); + var p1 = l[1]; + Assert.IsTrue(NHibernateUtil.IsInitialized(p1.Accounts)); + Assert.AreEqual(p1.Accounts.Count, 0); + } + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/DynamicEntityTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/DynamicEntityTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/DynamicEntityTest.cs 2010-12-10 16:47:11 UTC (rev 5302) @@ -0,0 +1,56 @@ +using System.Collections; +using System.Collections.Generic; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.Properties +{ + [TestFixture] + public class DynamicEntityTest : BugTestCase + { + protected override void OnSetUp() + { + using (var s = OpenSession()) + { + using (var tx = s.BeginTransaction()) + { + var props = new Dictionary<string, object>(); + props["Foo"] = "Sweden"; + props["Bar"] = "IsCold"; + s.Save("DynamicEntity", new Dictionary<string, object> + { + {"SomeProps", props}, + }); + tx.Commit(); + } + } + } + + protected override void OnTearDown() + { + using (var s = OpenSession()) + { + using (var tx = s.BeginTransaction()) + { + s.Delete("from DynamicEntity"); + tx.Commit(); + } + } + } + + [Test] + public void CanFetchByProperty() + { + using (var s = OpenSession()) + { + using (s.BeginTransaction()) + { + var l = s.CreateQuery("from DynamicEntity de where de.SomeProps.Foo=:fooParam") + .SetString("fooParam", "Sweden").List(); + Assert.AreEqual(1, l.Count); + var props = ((IDictionary)l[0])["SomeProps"]; + Assert.AreEqual("IsCold", ((IDictionary)props)["Bar"]); + } + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/Mappings.hbm.xml 2010-12-10 16:47:11 UTC (rev 5302) @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.Properties" + assembly="NHibernate.Test"> + + <class entity-name="DynamicEntity"> + <id name="Id" type="Int32"> + <generator class="hilo"/> + + </id> + <properties name="SomeProps"> + <property name="Foo" type="string"/> + <property name="Bar" type="string"/> + </properties> + </class> + + <class name="Person"> + <id name="Id"> + <generator class="hilo"/> + </id> + <property name="Name" length="100"/> + <one-to-one name="Address" property-ref="Person" cascade="all" fetch="join"/> + <set name="Accounts" inverse="true"> + <key property-ref="UserIdAndDeleted"> + <column name="userId"/> + <column name="userDeleted"/> + </key> + <one-to-many class="Account"/> + </set> + <properties name="UserIdAndDeleted" update="false" unique="true"> + <property name="UserId" length="8"/> + <property name="Deleted"/> + </properties> + </class> + + <class name="Address"> + <id name="Id"> + <generator class="hilo"/> + + </id> + <property name="Addr" length="300"/> + <property name="Zip" length="5"/> + <property name="Country" length="25"/> + <many-to-one name="Person" unique="true" not-null="true"/> + </class> + + <class name="Account" table="`Account`"> + <id name="AccountId" length="32"> + <generator class="uuid.hex"/> + </id> + <many-to-one name="User" property-ref="UserIdAndDeleted"> + <column name="userId"/> + <column name="userDeleted"/> + </many-to-one> + <property name="Type" column="`type`" not-null="true"/> + </class> + +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Properties/Model.cs 2010-12-10 16:47:11 UTC (rev 5302) @@ -0,0 +1,42 @@ +using Iesi.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.Properties +{ + public class Person + { + public virtual long Id { get; set; } + public virtual string Name { get; set; } + public virtual Address Address { get; set; } + public virtual string UserId { get; set; } + public virtual bool Deleted { get; set; } + public virtual ISet<Account> Accounts { get; set; } + + public Person() + { + Accounts = new HashedSet<Account>(); + } + } + + public class Address + { + public virtual long Id { get; set; } + public virtual string Addr { get; set; } + public virtual string Zip { get; set; } + public virtual string Country { get; set; } + public virtual Person Person { get; set; } + } + + public class Account + { + public virtual string AccountId { get; set; } + public virtual Person User { get; set; } + public virtual char Type { get; set; } + } + + public class DynamicEntity + { + public virtual long Id { get; set; } + public virtual string Foo { get; set; } + public virtual string Bar { get; set; } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-10 14:23:49 UTC (rev 5301) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-10 16:47:11 UTC (rev 5302) @@ -540,6 +540,9 @@ <Compile Include="NHSpecificTest\NH2420\MyTable.cs" /> <Compile Include="NHSpecificTest\NH2441\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2441\Model.cs" /> + <Compile Include="NHSpecificTest\Properties\CompositePropertyRefTest.cs" /> + <Compile Include="NHSpecificTest\Properties\DynamicEntityTest.cs" /> + <Compile Include="NHSpecificTest\Properties\Model.cs" /> <Compile Include="PolymorphicGetAndLoad\Domain.cs" /> <Compile Include="PolymorphicGetAndLoad\PolymorphicGetAndLoadTest.cs" /> <Compile Include="TypesTest\CharClass.cs" /> @@ -2348,6 +2351,7 @@ <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <EmbeddedResource Include="DriverTest\EntityForMs2008.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\Properties\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2378\Mappings.hbm.xml" /> <EmbeddedResource Include="TypesTest\XDocClass.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2374\Mappings.hbm.xml" /> @@ -2685,8 +2689,6 @@ <EmbeddedResource Include="DynamicEntity\Tuplizer\Customer.hbm.xml" /> </ItemGroup> <ItemGroup> - <Folder Include="NHSpecificTest\NH2420" /> - <Folder Include="NHSpecificTest\NH2441" /> <Folder Include="Properties\" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-12-11 18:39:54
|
Revision: 5307 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5307&view=rev Author: fabiomaulo Date: 2010-12-11 18:39:48 +0000 (Sat, 11 Dec 2010) Log Message: ----------- Fix NH-2386 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/Organisation.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/ResponsibleLegalPerson.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/Test.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/TradingName.cs Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-12-11 15:44:12 UTC (rev 5306) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-12-11 18:39:48 UTC (rev 5307) @@ -1128,9 +1128,14 @@ } if (IsVersioned) { - tableUpdateNeeded[0] = tableUpdateNeeded[0] || - Versioning.IsVersionIncrementRequired(dirtyProperties, hasDirtyCollection, - PropertyVersionability); + // NH-2386 when there isn't dirty-properties and the version is generated even in UPDATE + // we can't execute an UPDATE because there isn't something to UPDATE + if(!entityMetamodel.VersionProperty.IsUpdateGenerated) + { + tableUpdateNeeded[0] = tableUpdateNeeded[0] || + Versioning.IsVersionIncrementRequired(dirtyProperties, hasDirtyCollection, + PropertyVersionability); + } } return tableUpdateNeeded; } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/Mappings.hbm.xml 2010-12-11 18:39:48 UTC (rev 5307) @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH2386"> + <class name="Organisation" abstract ="false" table="tblTrnOrganisation"> + <id name="OrganisationId"> + <generator class="guid"></generator> + </id> + + <version name="RowVersion" type="BinaryBlob" generated="always" unsaved-value="null"> + <column name="RVersion" sql-type="timestamp"/> + </version> + + <set name="ResponsibleLegalPersons" table="tblTrnRtoResponsibleLegalPerson" cascade="all-delete-orphan" fetch="join" lazy="false"> + <key column="OrganisationId"></key> + <one-to-many class="ResponsibleLegalPerson"/> + </set> + + <set name="TradingNames" table="tblTrnOrganisationTradingName" cascade="all-delete-orphan" lazy="true" batch-size="10" inverse="true"> + <key column="OrganisationId"></key> + <one-to-many class="TradingName"/> + </set> + + + </class> + + <class name="TradingName" abstract="false" table="tblTrnOrganisationTradingName" dynamic-insert="true" dynamic-update="true"> + <id name="TradingNameId" type="guid" column="TradingNameId"> + <generator class="guid"></generator> + </id> + <many-to-one name="Organisation" column="OrganisationId" class="Organisation" not-null="true"/> + <property name="Name" column="TradingName" length="300" not-null="true"/> + <property name="StartDate" column="TradingNameStartDate"/> + <property name="EndDate" column="TradingNameEndDate"/> + </class> + + <class name="ResponsibleLegalPerson" table="tblTrnRtoResponsibleLegalPerson" dynamic-insert="true" dynamic-update="true" > + <id name="ResponsibleLegalPersonId" column="ResponsibleLegalPersonId"> + <generator class="guid"></generator> + </id> + + <many-to-one name="Organisation" column="OrganisationId" class="Organisation" not-null="true"/> + <property name="StartDate" column="ResponsibleLegalPersonStartDate" not-null="true"/> + <property name="EndDate" column="ResponsibleLegalPersonEndDate"/> + <property name="Name" column="ResponsibleLegalPersonName" not-null="true"/> + <property name="Abn" length="11"/> + <property name="Acn" length="9"/> + </class> + + +</hibernate-mapping> + Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/Organisation.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/Organisation.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/Organisation.cs 2010-12-11 18:39:48 UTC (rev 5307) @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Iesi.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH2386 +{ + public class Organisation + { + //internal to TGA + //private int organisationId; + public virtual Guid OrganisationId { get; set; } + private ISet<TradingName> tradingNames; + private ISet<ResponsibleLegalPerson> responsibleLegalPersons; + + /// <summary> + /// + /// </summary> + + + public virtual ISet<ResponsibleLegalPerson> ResponsibleLegalPersons { + get { + if (responsibleLegalPersons == null) { + responsibleLegalPersons = new HashedSet<ResponsibleLegalPerson>(); + } + return responsibleLegalPersons; + } + protected set { + responsibleLegalPersons = value; + + } + } + + public virtual ISet<TradingName> TradingNames { + get { + if (tradingNames == null) { + tradingNames = new HashedSet<TradingName>(); + } + return tradingNames; + } + protected set { + tradingNames = value; + + } + } + + protected internal virtual byte[] RowVersion { get; protected set; } + + } + +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/ResponsibleLegalPerson.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/ResponsibleLegalPerson.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/ResponsibleLegalPerson.cs 2010-12-11 18:39:48 UTC (rev 5307) @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; + +namespace NHibernate.Test.NHSpecificTest.NH2386 +{ + [Serializable] + public class ResponsibleLegalPerson { + private Guid responsibleLegalPersonId; + private Organisation organisation; + //private DateTime startDate; + + protected ResponsibleLegalPerson() {} + + public ResponsibleLegalPerson(Organisation organisation) { + if (organisation == null) { + throw new ArgumentNullException("organisation"); + } + + this.organisation = organisation; + } + + public virtual Guid ResponsibleLegalPersonId { + get { return responsibleLegalPersonId; } + protected set { responsibleLegalPersonId = value; } + } + + + public virtual Organisation Organisation { + get { return organisation; } + protected set { organisation = value; } + } + + public virtual DateTime StartDate { get; set; } + public virtual DateTime? EndDate { get; set; } + public virtual string Abn { get; set; } + public virtual string Acn { get; set; } + + public virtual string Name { get; set; } + + public override int GetHashCode() { + return responsibleLegalPersonId.GetHashCode(); + } + + public override bool Equals(object obj) { + ResponsibleLegalPerson other = obj as ResponsibleLegalPerson; + if (other == null) { + return false; + } + + if (responsibleLegalPersonId == Guid.Empty) { + return object.ReferenceEquals(this, other); + } + return this.responsibleLegalPersonId == other.responsibleLegalPersonId; + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/Test.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/Test.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/Test.cs 2010-12-11 18:39:48 UTC (rev 5307) @@ -0,0 +1,44 @@ +using System; +using log4net; +using log4net.Appender; +using log4net.Repository.Hierarchy; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2386 { + [TestFixture] + public class Test : BugTestCase { + private MemoryAppender memoryAppender; + + + protected override void OnTearDown() { + if (memoryAppender != null) { + var repository = (Hierarchy) LogManager.GetRepository(); + repository.Root.RemoveAppender(memoryAppender); + memoryAppender = null; + } + base.OnTearDown(); + } + + [Test] + public void TheTest() { + using (ISession session = OpenSession()) { + var organisation = new Organisation(); + session.SaveOrUpdate(organisation); + session.Flush(); + + organisation.TradingNames.Add(new TradingName(organisation) + {Name = "Trading Name", StartDate = DateTime.Today}); + + session.SaveOrUpdate(organisation); + + //this line below fails + //AbstractBatcher:0 - Could not execute command: UPDATE tblTrnOrganisation SET WHERE OrganisationId = @p0 AND RVersion = @p1 + //System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'WHERE'. + session.Flush(); + + session.Delete(organisation); + session.Flush(); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/TradingName.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/TradingName.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2386/TradingName.cs 2010-12-11 18:39:48 UTC (rev 5307) @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NHibernate.Test.NHSpecificTest.NH2386 +{ + /// <summary> + /// represents a trading name for an organisation + /// </summary> + public class TradingName { + private Organisation organisation; + + public virtual Guid TradingNameId { get; protected set;} + + + public TradingName(Organisation organisation) { + if (organisation == null) { + throw new ArgumentNullException("organisation"); + } + this.organisation = organisation; + } + + protected TradingName() {} + + public virtual string Name { get; set; } + + public virtual Organisation Organisation { + get { return organisation; } + protected set { organisation = value; } + } + + public virtual DateTime StartDate { get; set; } + + public virtual DateTime? EndDate { get; set; } + + private bool ShouldSerializeEndDate() { + return EndDate.HasValue; + } + + public override string ToString() { + return Name; + } + + } + + +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-11 15:44:12 UTC (rev 5306) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-11 18:39:48 UTC (rev 5307) @@ -521,6 +521,10 @@ <Compile Include="NHSpecificTest\NH2378\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2378\TestEntity.cs" /> <Compile Include="NHSpecificTest\NH2378\TestEntityDto.cs" /> + <Compile Include="NHSpecificTest\NH2386\Organisation.cs" /> + <Compile Include="NHSpecificTest\NH2386\ResponsibleLegalPerson.cs" /> + <Compile Include="NHSpecificTest\NH2386\Test.cs" /> + <Compile Include="NHSpecificTest\NH2386\TradingName.cs" /> <Compile Include="NHSpecificTest\NH2392\A.cs" /> <Compile Include="NHSpecificTest\NH2392\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2392\PhoneNumber.cs" /> @@ -2351,6 +2355,7 @@ <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <EmbeddedResource Include="DriverTest\EntityForMs2008.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2386\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\Properties\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2378\Mappings.hbm.xml" /> <EmbeddedResource Include="TypesTest\XDocClass.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-12-12 12:47:06
|
Revision: 5308 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5308&view=rev Author: fabiomaulo Date: 2010-12-12 12:47:00 +0000 (Sun, 12 Dec 2010) Log Message: ----------- First step to fix NH-2211 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/ISessionImplementor.cs trunk/nhibernate/src/NHibernate/ISession.cs trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs Modified: trunk/nhibernate/src/NHibernate/Engine/ISessionImplementor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/ISessionImplementor.cs 2010-12-11 18:39:48 UTC (rev 5307) +++ trunk/nhibernate/src/NHibernate/Engine/ISessionImplementor.cs 2010-12-12 12:47:00 UTC (rev 5308) @@ -89,6 +89,13 @@ /// <returns></returns> IList List(IQueryExpression queryExpression, QueryParameters parameters); + /// <summary> + /// Create a new instance of <c>Query</c> for the given query expression + /// <param name="queryExpression">A hibernate query expression</param> + /// <returns>The query</returns> + /// </summary> + IQuery CreateQuery(IQueryExpression queryExpression); + void List(string query, QueryParameters parameters, IList results); /// <summary> Modified: trunk/nhibernate/src/NHibernate/ISession.cs =================================================================== --- trunk/nhibernate/src/NHibernate/ISession.cs 2010-12-11 18:39:48 UTC (rev 5307) +++ trunk/nhibernate/src/NHibernate/ISession.cs 2010-12-12 12:47:00 UTC (rev 5308) @@ -663,13 +663,6 @@ /// <param name="queryString">A hibernate query string</param> /// <returns>The query</returns> IQuery CreateQuery(string queryString); - - /// <summary> - /// Create a new instance of <c>Query</c> for the given query expression - /// <param name="queryExpression">A hibernate query expression</param> - /// <returns>The query</returns> - /// </summary> - IQuery CreateQuery(IQueryExpression queryExpression); /// <summary> /// Create a new instance of <c>Query</c> for the given collection and filter string Modified: trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs 2010-12-11 18:39:48 UTC (rev 5307) +++ trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs 2010-12-12 12:47:00 UTC (rev 5308) @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using NHibernate.Engine; using NHibernate.Impl; namespace NHibernate.Linq @@ -10,7 +11,7 @@ { public static IQueryable<T> Query<T>(this ISession session) { - return new NhQueryable<T>(session); + return new NhQueryable<T>(session as ISessionImplementor); } public static IQueryable<T> Cacheable<T>(this IQueryable<T> query) Modified: trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs 2010-12-11 18:39:48 UTC (rev 5307) +++ trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs 2010-12-12 12:47:00 UTC (rev 5308) @@ -4,6 +4,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using NHibernate.Engine; using NHibernate.Impl; using NHibernate.Type; @@ -11,9 +12,9 @@ { public class NhQueryProvider : IQueryProvider { - private readonly ISession _session; + private readonly ISessionImplementor _session; - public NhQueryProvider(ISession session) + public NhQueryProvider(ISessionImplementor session) { _session = session; } Modified: trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs 2010-12-11 18:39:48 UTC (rev 5307) +++ trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs 2010-12-12 12:47:00 UTC (rev 5308) @@ -1,5 +1,6 @@ using System.Linq; using System.Linq.Expressions; +using NHibernate.Engine; using Remotion.Data.Linq; namespace NHibernate.Linq @@ -10,7 +11,7 @@ public class NhQueryable<T> : QueryableBase<T> { // This constructor is called by our users, create a new IQueryExecutor. - public NhQueryable(ISession session) + public NhQueryable(ISessionImplementor session) : base(new NhQueryProvider(session)) { } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-12-12 13:18:32
|
Revision: 5309 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5309&view=rev Author: fabiomaulo Date: 2010-12-12 13:18:26 +0000 (Sun, 12 Dec 2010) Log Message: ----------- Fix NH-2211 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs trunk/nhibernate/src/NHibernate/Impl/StatelessSessionImpl.cs trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/Linq/StatelessSessionQueringTest.cs Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2010-12-12 12:47:00 UTC (rev 5308) +++ trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2010-12-12 13:18:26 UTC (rev 5309) @@ -82,8 +82,18 @@ public abstract void CloseSessionFromDistributedTransaction(); public abstract IList List(string query, QueryParameters parameters); public abstract void List(string query, QueryParameters parameters, IList results); - public abstract IList List(IQueryExpression queryExpression, QueryParameters parameters); - public abstract void List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results); + + public virtual IList List(IQueryExpression queryExpression, QueryParameters parameters) + { + IList results = (IList)typeof(List<>).MakeGenericType(queryExpression.Type) + .GetConstructor(System.Type.EmptyTypes) + .Invoke(null); + + List(queryExpression, parameters, results); + return results; + } + + public abstract void List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results); public abstract IList<T> List<T>(string query, QueryParameters queryParameters); public abstract IList<T> List<T>(CriteriaImpl criteria); public abstract void List(CriteriaImpl criteria, IList results); Modified: trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2010-12-12 12:47:00 UTC (rev 5308) +++ trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2010-12-12 13:18:26 UTC (rev 5309) @@ -625,17 +625,6 @@ } } - public override IList List(IQueryExpression queryExpression, QueryParameters parameters) - { - IList results = (IList) typeof(List<>).MakeGenericType(queryExpression.Type) - .GetConstructor(System.Type.EmptyTypes) - .Invoke(null); - - List(queryExpression, parameters, results); - - return results; - } - public override void List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) { using (new SessionIdLoggingContext(SessionId)) Modified: trunk/nhibernate/src/NHibernate/Impl/StatelessSessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/StatelessSessionImpl.cs 2010-12-12 12:47:00 UTC (rev 5308) +++ trunk/nhibernate/src/NHibernate/Impl/StatelessSessionImpl.cs 2010-12-12 13:18:26 UTC (rev 5309) @@ -140,14 +140,35 @@ } } - public override IList List(IQueryExpression queryExpression, QueryParameters parameters) + public override void List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) { - throw new System.NotImplementedException(); - } + using (new SessionIdLoggingContext(SessionId)) + { + CheckAndUpdateSessionStatus(); + queryParameters.ValidateParameters(); + var plan = GetHQLQueryPlan(queryExpression, false); - public override void List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) - { - throw new System.NotImplementedException(); + bool success = false; + try + { + plan.PerformList(queryParameters, this, results); + success = true; + } + catch (HibernateException) + { + // Do not call Convert on HibernateExceptions + throw; + } + catch (Exception e) + { + throw Convert(e, "Could not execute query"); + } + finally + { + AfterOperation(success); + } + temporaryPersistenceContext.Clear(); + } } public override IList<T> List<T>(string query, QueryParameters queryParameters) Modified: trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs 2010-12-12 12:47:00 UTC (rev 5308) +++ trunk/nhibernate/src/NHibernate/Linq/LinqExtensionMethods.cs 2010-12-12 13:18:26 UTC (rev 5309) @@ -14,6 +14,11 @@ return new NhQueryable<T>(session as ISessionImplementor); } + public static IQueryable<T> Query<T>(this IStatelessSession session) + { + return new NhQueryable<T>(session as ISessionImplementor); + } + public static IQueryable<T> Cacheable<T>(this IQueryable<T> query) { var method = ReflectionHelper.GetMethodDefinition(() => Cacheable<object>(null)).MakeGenericMethod(typeof(T)); Added: trunk/nhibernate/src/NHibernate.Test/Linq/StatelessSessionQueringTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/StatelessSessionQueringTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Linq/StatelessSessionQueringTest.cs 2010-12-12 13:18:26 UTC (rev 5309) @@ -0,0 +1,33 @@ +using System.Linq; +using System.Text; +using NHibernate.DomainModel.Northwind.Entities; +using NUnit.Framework; +using NHibernate.Linq; +using SharpTestsEx; + +namespace NHibernate.Test.Linq +{ + public class StatelessSessionQueringTest : LinqTestCase + { + [Test] + public void WhenQueryThroughStatelessSessionThenDoesNotThrows() + { + using (var statelessSession = Sfi.OpenStatelessSession()) + { + var query = statelessSession.Query<Customer>(); + query.Executing(q => q.ToList()).NotThrows(); + } + } + + [Test] + public void AggregateWithStartsWith() + { + using (IStatelessSession statelessSession = Sfi.OpenStatelessSession()) + { + StringBuilder query = (from c in statelessSession.Query<Customer>() where c.CustomerId.StartsWith("A") select c.CustomerId) + .Aggregate(new StringBuilder(), (sb, id) => sb.Append(id).Append(",")); + query.ToString().Should().Be("ALFKI,ANATR,ANTON,AROUT,"); + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-12 12:47:00 UTC (rev 5308) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-12 13:18:26 UTC (rev 5309) @@ -438,6 +438,7 @@ <Compile Include="Linq\QueryCacheableTests.cs" /> <Compile Include="Linq\QueryReuseTests.cs" /> <Compile Include="Linq\ReadonlyTestCase.cs" /> + <Compile Include="Linq\StatelessSessionQueringTest.cs" /> <Compile Include="Logging\Log4NetLoggerTest.cs" /> <Compile Include="Logging\LoggerProviderTest.cs" /> <Compile Include="NHSpecificTest\EntityNameAndCompositeId\Fixture.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-12-12 16:22:57
|
Revision: 5310 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5310&view=rev Author: fabiomaulo Date: 2010-12-12 15:31:41 +0000 (Sun, 12 Dec 2010) Log Message: ----------- Fix NH-2228 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Domain.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-12-12 13:18:26 UTC (rev 5309) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-12-12 15:31:41 UTC (rev 5310) @@ -2772,6 +2772,15 @@ return Check(session.Batcher.ExecuteNonQuery(statement), id, j, expectation, statement); } } + catch (StaleStateException e) + { + if (useBatch) + { + session.Batcher.AbortBatch(e); + } + + throw new StaleObjectStateException(EntityName, id); + } catch (Exception e) { if (useBatch) Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Domain.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Domain.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Domain.cs 2010-12-12 15:31:41 UTC (rev 5310) @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH2228 +{ + public class Parent + { + public Parent() + { + Children = new List<Child>(); + } + public virtual int Id { get; set; } + public virtual IList<Child> Children { get; set; } + } + public class Child + { + public virtual int Id { get; set; } + public virtual Parent Parent { get; set; } + public virtual string Description { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Fixture.cs 2010-12-12 15:31:41 UTC (rev 5310) @@ -0,0 +1,81 @@ +using System; +using NUnit.Framework; +using NHibernate.Cfg.Loquacious; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2228 +{ + public class Fixture : BugTestCase + { + public class ParentWithTwoChildrenScenario : IDisposable + { + private readonly ISessionFactory factory; + private readonly int parentId; + + public ParentWithTwoChildrenScenario(ISessionFactory factory) + { + this.factory = factory; + var parent = new Parent(); + parent.Children.Add(new Child {Description = "Child1", Parent = parent}); + parent.Children.Add(new Child { Description = "Child2", Parent = parent }); + using (var s = factory.OpenSession()) + { + parentId = (int)s.Save(parent); + s.Flush(); + } + } + + public int ParentId + { + get { return parentId; } + } + + public void Dispose() + { + using (var s = factory.OpenSession()) + { + s.Delete("from Parent"); + s.Flush(); + } + } + } + + protected override void Configure(NHibernate.Cfg.Configuration configuration) + { + // needed to be sure of StaleStateException that the user has reported in the issue + configuration.DataBaseIntegration(x => x.BatchSize = 1); + } + + [Test] + public void WhenStaleObjectStateThenMessageContainsEntity() + { + using (var scenario = new ParentWithTwoChildrenScenario(Sfi)) + { + using (var client1 = OpenSession()) + using (var tx1 = client1.BeginTransaction()) + { + var parentFromClient1 = client1.Get<Parent>(scenario.ParentId); + NHibernateUtil.Initialize(parentFromClient1.Children); + var firstChildId = parentFromClient1.Children[0].Id; + + DeleteChildUsingAnotherSession(firstChildId); + + parentFromClient1.Children[0].Description = "Modified info"; + var expectedException = tx1.Executing(x => x.Commit()).Throws<StaleObjectStateException>().Exception; + expectedException.EntityName.Should().Be(typeof(Child).FullName); + expectedException.Identifier.Should().Be(firstChildId); + } + } + } + + private void DeleteChildUsingAnotherSession(int childIdToDelete) + { + using (var client2 = Sfi.OpenStatelessSession()) + using (var tx2 = client2.BeginTransaction()) + { + client2.CreateQuery("delete from Child c where c.Id = :pChildId").SetInt32("pChildId", childIdToDelete).ExecuteUpdate(); + tx2.Commit(); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2228/Mappings.hbm.xml 2010-12-12 15:31:41 UTC (rev 5310) @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2228"> + + <class name="Parent" > + <id name="Id"> + <generator class="hilo" /> + </id> + <bag name="Children" inverse="true" cascade="all,delete-orphan"> + <key column="ParentId" /> + <one-to-many class="Child"/> + </bag> + </class> + <class name="Child" > + <id name="Id"> + <generator class="hilo" /> + </id> + <many-to-one name="Parent" column="ParentId"/> + <property name="Description"/> + </class> + +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-12 13:18:26 UTC (rev 5309) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-12 15:31:41 UTC (rev 5310) @@ -474,6 +474,8 @@ <Compile Include="NHSpecificTest\NH2202\Model.cs" /> <Compile Include="NHSpecificTest\NH2224\Domain.cs" /> <Compile Include="NHSpecificTest\NH2224\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2228\Domain.cs" /> + <Compile Include="NHSpecificTest\NH2228\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2244\A.cs" /> <Compile Include="NHSpecificTest\NH2244\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2244\PhoneNumber.cs" /> @@ -2356,6 +2358,7 @@ <EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" /> <EmbeddedResource Include="DriverTest\EntityForMs2008.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH2228\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2386\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\Properties\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2378\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-12-15 21:36:31
|
Revision: 5316 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5316&view=rev Author: fabiomaulo Date: 2010-12-15 21:36:23 +0000 (Wed, 15 Dec 2010) Log Message: ----------- EnumerableExtensions (perhaps the place to replace some old stuff) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Util/EnumerableExtensions.cs trunk/nhibernate/src/NHibernate.Test/UtilityTest/EnumerableExtensionsTests/ trunk/nhibernate/src/NHibernate.Test/UtilityTest/EnumerableExtensionsTests/AnyExtensionTests.cs Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-12-15 18:29:52 UTC (rev 5315) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-12-15 21:36:23 UTC (rev 5316) @@ -440,6 +440,7 @@ <Compile Include="Util\ADOExceptionReporter.cs" /> <Compile Include="Util\ArrayHelper.cs" /> <Compile Include="Util\CollectionPrinter.cs" /> + <Compile Include="Util\EnumerableExtensions.cs" /> <Compile Include="Util\IdentityMap.cs" /> <Compile Include="Util\JoinedEnumerable.cs" /> <Compile Include="Util\ObjectUtils.cs" /> Added: trunk/nhibernate/src/NHibernate/Util/EnumerableExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Util/EnumerableExtensions.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Util/EnumerableExtensions.cs 2010-12-15 21:36:23 UTC (rev 5316) @@ -0,0 +1,75 @@ +using System; +using System.Collections; + +namespace NHibernate.Util +{ + public static class EnumerableExtensions + { + public static bool Any(this IEnumerable source) + { + if (source == null) + { + throw new ArgumentNullException("source"); + } + using (DisposableEnumerator enumerator = source.GetDisposableEnumerator()) + { + if (enumerator.MoveNext()) + { + return true; + } + } + return false; + } + + private static DisposableEnumerator GetDisposableEnumerator(this IEnumerable source) + { + return new DisposableEnumerator(source); + } + + #region Nested type: DisposableEnumerator + + internal class DisposableEnumerator : IDisposable, IEnumerator + { + private readonly IEnumerator wrapped; + + public DisposableEnumerator(IEnumerable source) + { + wrapped = source.GetEnumerator(); + } + + #region IDisposable Members + + public void Dispose() + { + var disposable = wrapped as IDisposable; + if (disposable != null) + { + disposable.Dispose(); + } + } + + #endregion + + #region IEnumerator Members + + public bool MoveNext() + { + return wrapped.MoveNext(); + } + + public void Reset() + { + wrapped.Reset(); + } + + public object Current + { + get { return wrapped.Current; } + } + + #endregion + } + + #endregion + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-15 18:29:52 UTC (rev 5315) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-15 21:36:23 UTC (rev 5316) @@ -580,6 +580,7 @@ <Compile Include="TypesTest\XDocTypeFixture.cs" /> <Compile Include="TypesTest\XmlDocClass.cs" /> <Compile Include="TypesTest\XmlDocTypeFixture.cs" /> + <Compile Include="UtilityTest\EnumerableExtensionsTests\AnyExtensionTests.cs" /> <Compile Include="UtilityTest\ReflectionHelperIsMethodOfTests.cs" /> <Compile Include="UtilityTest\ReflectionHelperTest.cs" /> <Compile Include="Linq\RegresstionTests.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/UtilityTest/EnumerableExtensionsTests/AnyExtensionTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/UtilityTest/EnumerableExtensionsTests/AnyExtensionTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/UtilityTest/EnumerableExtensionsTests/AnyExtensionTests.cs 2010-12-15 21:36:23 UTC (rev 5316) @@ -0,0 +1,75 @@ +using System; +using System.Collections; +using NUnit.Framework; +using NHibernate.Util; +using SharpTestsEx; + +namespace NHibernate.Test.UtilityTest.EnumerableExtensionsTests +{ + public class AnyExtensionTests + { + [Test] + public void WhenEmptyListThenReturnFalse() + { + (new object[0]).Any().Should().Be.False(); + } + + [Test] + public void WhenNoEmptyListThenReturnTrue() + { + (new object[1]).Any().Should().Be.True(); + } + + private class MyDisposableList: IEnumerable + { + private readonly System.Action enumeratorDisposeCallback; + + public MyDisposableList(System.Action enumeratorDisposeCallback) + { + this.enumeratorDisposeCallback = enumeratorDisposeCallback; + } + + public IEnumerator GetEnumerator() + { + return new EmptyEnumerator(enumeratorDisposeCallback); + } + } + + private class EmptyEnumerator : IEnumerator, IDisposable + { + private readonly System.Action disposeCallback; + + public EmptyEnumerator(System.Action disposeCallback) + { + this.disposeCallback = disposeCallback; + } + + public void Reset() + { + } + + public object Current + { + get { throw new InvalidOperationException("EmptyEnumerator"); } + } + + public bool MoveNext() + { + return false; + } + + public void Dispose() + { + disposeCallback(); + } + } + + [Test] + public void WhenDisposableListThenCallDispose() + { + var disposeCalled = false; + (new MyDisposableList(()=> disposeCalled = true)).Any(); + disposeCalled.Should().Be.True(); + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-12-15 21:57:32
|
Revision: 5317 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5317&view=rev Author: fabiomaulo Date: 2010-12-15 21:57:25 +0000 (Wed, 15 Dec 2010) Log Message: ----------- First as enumerable extensions Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Util/EnumerableExtensions.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/UtilityTest/EnumerableExtensionsTests/FirstExtensionTests.cs Modified: trunk/nhibernate/src/NHibernate/Util/EnumerableExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Util/EnumerableExtensions.cs 2010-12-15 21:36:23 UTC (rev 5316) +++ trunk/nhibernate/src/NHibernate/Util/EnumerableExtensions.cs 2010-12-15 21:57:25 UTC (rev 5317) @@ -21,6 +21,33 @@ return false; } + public static object First(this IEnumerable source) + { + if (source == null) + { + throw new ArgumentNullException("source"); + } + IList collection = source as IList; + if (collection != null) + { + if (collection.Count > 0) + { + return collection[0]; + } + } + else + { + using (DisposableEnumerator enumerator = source.GetDisposableEnumerator()) + { + if (enumerator.MoveNext()) + { + return enumerator.Current; + } + } + } + throw new InvalidOperationException("Sequence contains no elements"); + } + private static DisposableEnumerator GetDisposableEnumerator(this IEnumerable source) { return new DisposableEnumerator(source); Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-15 21:36:23 UTC (rev 5316) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-12-15 21:57:25 UTC (rev 5317) @@ -581,6 +581,7 @@ <Compile Include="TypesTest\XmlDocClass.cs" /> <Compile Include="TypesTest\XmlDocTypeFixture.cs" /> <Compile Include="UtilityTest\EnumerableExtensionsTests\AnyExtensionTests.cs" /> + <Compile Include="UtilityTest\EnumerableExtensionsTests\FirstExtensionTests.cs" /> <Compile Include="UtilityTest\ReflectionHelperIsMethodOfTests.cs" /> <Compile Include="UtilityTest\ReflectionHelperTest.cs" /> <Compile Include="Linq\RegresstionTests.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/UtilityTest/EnumerableExtensionsTests/FirstExtensionTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/UtilityTest/EnumerableExtensionsTests/FirstExtensionTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/UtilityTest/EnumerableExtensionsTests/FirstExtensionTests.cs 2010-12-15 21:57:25 UTC (rev 5317) @@ -0,0 +1,29 @@ +using System; +using System.Collections; +using NHibernate.Util; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.UtilityTest.EnumerableExtensionsTests +{ + public class FirstExtensionTests + { + [Test] + public void WhenNullThenThenThrows() + { + Executing.This(() => ((IEnumerable)null).First()).Should().Throw<ArgumentNullException>(); + } + + [Test] + public void WhenHasElementsThenReturnFirst() + { + (new[] { 2, 1 }).First().Should().Be(2); + } + + [Test] + public void WhenEmptyThenThrowsInvalidOperation() + { + Executing.This(() => (new object[0]).First()).Should().Throw<InvalidOperationException>(); + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |