|
From: <fab...@us...> - 2009-07-05 18:50:48
|
Revision: 4585
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4585&view=rev
Author: fabiomaulo
Date: 2009-07-05 18:50:45 +0000 (Sun, 05 Jul 2009)
Log Message:
-----------
Merge r4584 (fix NH-1868)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/Model.cs
Modified: trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs 2009-07-05 18:48:06 UTC (rev 4584)
+++ trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs 2009-07-05 18:50:45 UTC (rev 4585)
@@ -71,7 +71,7 @@
{
// NH Different behaviour NH-1776
// Analyze all named parameters declared after filters
- //in general all named parameters but depend on the complexity of the query
+ // in general all named parameters but depend on the complexity of the query (see sub query)
foreach (ParameterInfo entry in _namedParameters.Values)
{
int amountOfPush = 0;
@@ -79,7 +79,7 @@
{
// a parameter span, at least, one value; where span more than one all values are cosecutive
// the first position determines the position of the others values
- if (entry.SqlLocations[0] >= existingParameterLocation)
+ if (entry.SqlLocations[0]+amountOfPush >= existingParameterLocation)
{
amountOfPush++;
}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/Fixture.cs 2009-07-05 18:50:45 UTC (rev 4585)
@@ -0,0 +1,103 @@
+using System;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1868
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ protected override void OnSetUp()
+ {
+ base.OnSetUp();
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ cat = new Category {ValidUntil = DateTime.Now};
+ session.Save(cat);
+
+ package = new Package {ValidUntil = DateTime.Now};
+ session.Save(package);
+
+ tx.Commit();
+ }
+ }
+ }
+
+ private Category cat;
+ private Package package;
+
+ protected override void OnTearDown()
+ {
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ session.Delete("from Category");
+ session.Delete("from Package");
+ tx.Commit();
+ }
+ }
+ base.OnTearDown();
+ }
+
+ public void ExecuteQuery(Action<ISession> sessionModifier)
+ {
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ sessionModifier(session);
+ session.Refresh(cat);
+ session.Refresh(package);
+
+ session.CreateQuery(
+ @"
+ select
+ inv
+ from
+ Invoice inv
+ , Package p
+ where
+ p = :package
+ and inv.Category = :cat
+ and inv.ValidUntil > :now
+ and inv.Package = :package
+ ")
+ .SetEntity("cat", cat).SetEntity("package", package).SetDateTime("now", DateTime.Now).UniqueResult<Invoice>();
+
+ tx.Commit();
+ }
+ }
+ }
+
+ [Test]
+ public void Bug()
+ {
+ Assert.DoesNotThrow(() => ExecuteQuery(s => s.EnableFilter("validity").SetParameter("date", DateTime.Now)));
+ }
+
+ [Test]
+ public void FilterOnOffOn()
+ {
+ Assert.DoesNotThrow(() => ExecuteQuery(s => s.EnableFilter("validity").SetParameter("date", DateTime.Now)));
+ Assert.DoesNotThrow(() => ExecuteQuery(s => { }));
+ Assert.DoesNotThrow(() => ExecuteQuery(s => s.EnableFilter("validity").SetParameter("date", DateTime.Now)));
+ }
+
+ [Test]
+ public void FilterQueryTwice()
+ {
+ Assert.DoesNotThrow(() => ExecuteQuery(s => s.EnableFilter("validity").SetParameter("date", DateTime.Now)));
+ Assert.DoesNotThrow(() => ExecuteQuery(s => s.EnableFilter("validity").SetParameter("date", DateTime.Now)));
+ }
+
+ [Test]
+ public void FilterQuery3()
+ {
+ Assert.DoesNotThrow(() => ExecuteQuery(s => s.EnableFilter("validity").SetParameter("date", DateTime.Now)));
+ Assert.DoesNotThrow(() => ExecuteQuery(s => s.EnableFilter("validity").SetParameter("date", DateTime.Now)));
+ Assert.DoesNotThrow(() => ExecuteQuery(s => s.EnableFilter("validity").SetParameter("date", DateTime.Now)));
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/Mappings.hbm.xml 2009-07-05 18:50:45 UTC (rev 4585)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH1868">
+
+ <class name="Category">
+ <id name="ID" type="Int32">
+ <generator class="hilo" />
+ </id>
+ <property name="ValidUntil" type="DateTime" />
+ <filter name="validity" condition="ValidUntil > :date" />
+ </class>
+
+ <class name="Package">
+ <id name="ID" type="Int32">
+ <generator class="hilo" />
+ </id>
+ <property name="ValidUntil" type="DateTime" />
+ <filter name="validity" condition="ValidUntil > :date" />
+ </class>
+
+ <class name="Invoice">
+ <id name="ID" type="Int32">
+ <generator class="hilo" />
+ </id>
+
+ <many-to-one name="Category" column="CategoryId" class="Category" />
+ <many-to-one name="Package" column="PacakgeId" class="Package" />
+ <property name="ValidUntil" type="DateTime" />
+ <filter name="validity" condition="ValidUntil > :date" />
+ </class>
+
+ <filter-def name="validity">
+ <filter-param name="date" type="DateTime"/>
+ </filter-def>
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/Model.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1868/Model.cs 2009-07-05 18:50:45 UTC (rev 4585)
@@ -0,0 +1,24 @@
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH1868
+{
+ public class Category
+ {
+ public virtual int ID { get; private set; }
+ public virtual DateTime ValidUntil { get; set; }
+ }
+
+ public class Package
+ {
+ public virtual int ID { get; private set; }
+ public virtual DateTime ValidUntil { get; set; }
+ }
+
+ public class Invoice
+ {
+ public virtual int ID { get; private set; }
+ public virtual DateTime ValidUntil { get; set; }
+ public virtual Category Category { get; set; }
+ public virtual Package Package { get; set; }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-05 18:48:06 UTC (rev 4584)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-05 18:50:45 UTC (rev 4585)
@@ -539,6 +539,8 @@
<Compile Include="NHSpecificTest\NH1859\SampleTest.cs" />
<Compile Include="NHSpecificTest\NH1864\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1864\Model.cs" />
+ <Compile Include="NHSpecificTest\NH1868\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1868\Model.cs" />
<Compile Include="NHSpecificTest\NH473\Child.cs" />
<Compile Include="NHSpecificTest\NH473\Fixture.cs" />
<Compile Include="NHSpecificTest\NH473\Parent.cs" />
@@ -1950,6 +1952,7 @@
<EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" />
<EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1868\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1857\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1859\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1864\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2009-07-05 22:42:33
|
Revision: 4588
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4588&view=rev
Author: fabiomaulo
Date: 2009-07-05 22:42:32 +0000 (Sun, 05 Jul 2009)
Log Message:
-----------
Merge r4587 (fix NH-1867)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Util/StringHelper.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1867/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1867/AddMappingTest.cs
Modified: trunk/nhibernate/src/NHibernate/Util/StringHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Util/StringHelper.cs 2009-07-05 22:37:05 UTC (rev 4587)
+++ trunk/nhibernate/src/NHibernate/Util/StringHelper.cs 2009-07-05 22:42:32 UTC (rev 4588)
@@ -213,6 +213,14 @@
/// <returns></returns>
public static string Unqualify(string qualifiedName)
{
+ if(qualifiedName.IndexOf('`') > 0)
+ {
+ // less performance but correctly manage generics classes
+ // where the entity-name was not specified
+ // Note: the enitty-name is mandatory when the user want work with different type-args
+ // for the same generic-entity implementation
+ return GetClassname(qualifiedName);
+ }
return Unqualify(qualifiedName, ".");
}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1867/AddMappingTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1867/AddMappingTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1867/AddMappingTest.cs 2009-07-05 22:42:32 UTC (rev 4588)
@@ -0,0 +1,56 @@
+using NHibernate.Cfg;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1867
+{
+ [TestFixture]
+ public class AddMappingTest
+ {
+ private const string mappingTemplate =
+@"<?xml version='1.0' encoding='utf-8' ?>
+<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2' auto-import='true'>
+ <class name='{0},NHibernate.Test'>
+ <id name='Id' column='Id' type='string'>
+ <generator class='assigned' />
+ </id>
+ </class>
+ <class name='{1},NHibernate.Test'>
+ <id name='OwnerId' column='Id' type='string'>
+ <generator class='assigned' />
+ </id>
+ </class>
+</hibernate-mapping>";
+
+ private class A
+ {
+ private string Id { get; set; }
+ public class B
+ {
+ private string OwnerId { get; set; }
+ }
+ }
+
+ private class A<T>
+ {
+ private string Id { get; set; }
+ public class B
+ {
+ private string OwnerId { get; set; }
+ }
+ }
+
+ [Test]
+ public void NestedWithinNonGeneric()
+ {
+ var configuration = new Configuration().Configure();
+ configuration.AddXml(string.Format(mappingTemplate, typeof(A).FullName, typeof(A.B).FullName));
+ }
+
+ [Test]
+ public void NestedWithinGeneric()
+ {
+ var configuration = new Configuration().Configure();
+ configuration.AddXml(string.Format(mappingTemplate, typeof(A<int>).FullName, typeof(A<int>.B).FullName));
+ }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-05 22:37:05 UTC (rev 4587)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-05 22:42:32 UTC (rev 4588)
@@ -539,6 +539,7 @@
<Compile Include="NHSpecificTest\NH1859\SampleTest.cs" />
<Compile Include="NHSpecificTest\NH1864\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1864\Model.cs" />
+ <Compile Include="NHSpecificTest\NH1867\AddMappingTest.cs" />
<Compile Include="NHSpecificTest\NH1868\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1868\Model.cs" />
<Compile Include="NHSpecificTest\NH473\Child.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ric...@us...> - 2009-07-08 09:44:29
|
Revision: 4590
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4590&view=rev
Author: ricbrown
Date: 2009-07-08 09:44:23 +0000 (Wed, 08 Jul 2009)
Log Message:
-----------
Added place-holder for QueryOver join syntax.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
trunk/nhibernate/src/NHibernate/IQueryOver.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Criterion/QueryOverJoinBuilder.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-06 08:48:13 UTC (rev 4589)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-08 09:44:23 UTC (rev 4590)
@@ -104,6 +104,19 @@
JoinType.InnerJoin);
}
+ public QueryOver<T> Join(Expression<Func<T, object>> path, Expression<Func<object>> alias, JoinType joinType)
+ {
+ return AddAlias(
+ ExpressionProcessor.FindMemberExpression(path.Body),
+ ExpressionProcessor.FindMemberExpression(alias.Body),
+ joinType);
+ }
+
+ public QueryOverJoinBuilder<T> Inner
+ {
+ get { return new QueryOverJoinBuilder<T>(this, JoinType.InnerJoin); }
+ }
+
public IList<T> List()
{
return _criteria.List<T>();
@@ -182,6 +195,12 @@
IQueryOver<T> IQueryOver<T>.Join(Expression<Func<T, object>> path, Expression<Func<object>> alias)
{ return Join(path, alias); }
+ IQueryOver<T> IQueryOver<T>.Join(Expression<Func<T, object>> path, Expression<Func<object>> alias, JoinType joinType)
+ { return Join(path, alias, joinType); }
+
+ IQueryOverJoinBuilder<T> IQueryOver<T>.Left
+ { get { return new IQueryOverJoinBuilder<T>(this, JoinType.LeftOuterJoin); } }
+
}
}
Added: trunk/nhibernate/src/NHibernate/Criterion/QueryOverJoinBuilder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOverJoinBuilder.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOverJoinBuilder.cs 2009-07-08 09:44:23 UTC (rev 4590)
@@ -0,0 +1,41 @@
+
+using System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+
+using NHibernate.Impl;
+using NHibernate.SqlCommand;
+
+namespace NHibernate.Criterion
+{
+
+ public class QueryOverJoinBuilder<T> : QueryOverJoinBuilderBase<QueryOver<T>, T>
+ {
+ public QueryOverJoinBuilder(QueryOver<T> root, JoinType joinType) : base(root, joinType) { }
+ }
+
+ public class IQueryOverJoinBuilder<T> : QueryOverJoinBuilderBase<IQueryOver<T>, T>
+ {
+ public IQueryOverJoinBuilder(IQueryOver<T> root, JoinType joinType) : base(root, joinType) { }
+ }
+
+ public class QueryOverJoinBuilderBase<R, T> where R : IQueryOver<T>
+ {
+
+ private R _root;
+ private JoinType _joinType;
+
+ public QueryOverJoinBuilderBase(R root, JoinType joinType)
+ {
+ _root = root;
+ _joinType = joinType;
+ }
+
+ public R Join(Expression<Func<T, object>> path, Expression<Func<object>> alias)
+ {
+ return (R)_root.Join(path, alias, _joinType);
+ }
+
+ }
+
+}
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-06 08:48:13 UTC (rev 4589)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-08 09:44:23 UTC (rev 4590)
@@ -4,6 +4,7 @@
using System.Linq.Expressions;
using NHibernate.Criterion;
+using NHibernate.SqlCommand;
namespace NHibernate
{
@@ -113,6 +114,16 @@
IQueryOver<T> Join(Expression<Func<T, object>> path, Expression<Func<object>> alias);
/// <summary>
+ /// Join an association, assigning an alias to the joined entity
+ /// </summary>
+ /// <param name="path">Lambda expression returning association path</param>
+ /// <param name="alias">Lambda expression returning alias reference</param>
+ /// <returns>criteria instance</returns>
+ IQueryOver<T> Join(Expression<Func<T, object>> path, Expression<Func<object>> alias, JoinType joinType);
+
+ IQueryOverJoinBuilder<T> Left { get; }
+
+ /// <summary>
/// Get the results of the root type and fill the <see cref="IList<T>"/>
/// </summary>
/// <returns>The list filled with the results.</returns>
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-06 08:48:13 UTC (rev 4589)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-08 09:44:23 UTC (rev 4590)
@@ -486,6 +486,7 @@
<Compile Include="Cfg\MappingSchema\HbmVersion.cs" />
<Compile Include="Cfg\MappingSchema\IDecoratable.cs" />
<Compile Include="Criterion\IPropertyProjection.cs" />
+ <Compile Include="Criterion\QueryOverJoinBuilder.cs" />
<Compile Include="Dialect\MsSql2008Dialect.cs" />
<Compile Include="Dialect\InformixDialect0940.cs" />
<Compile Include="Dialect\InformixDialect1000.cs" />
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-06 08:48:13 UTC (rev 4589)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-08 09:44:23 UTC (rev 4590)
@@ -4,6 +4,7 @@
using NUnit.Framework;
using NHibernate.Criterion;
+using NHibernate.SqlCommand;
using NHibernate.Transform;
using NHibernate.Type;
using NHibernate.Util;
@@ -128,7 +129,7 @@
}
[Test]
- public void SubCriteria_JoinWalk_ToOne()
+ public void SubCriteria_JoinQueryOver_ToOne()
{
ICriteria expected =
CreateTestCriteria(typeof(Person))
@@ -144,7 +145,7 @@
}
[Test]
- public void SubCriteria_JoinWalk_ToMany()
+ public void SubCriteria_JoinQueryOver_ToMany()
{
ICriteria expected =
CreateTestCriteria(typeof(Person))
@@ -178,6 +179,24 @@
}
[Test]
+ public void Alias_LeftJoin()
+ {
+ ICriteria expected =
+ CreateTestCriteria(typeof(Person))
+ .CreateAlias("Father", "fatherAlias", JoinType.LeftOuterJoin)
+ .CreateAlias("Children", "childAlias", JoinType.LeftOuterJoin);
+
+ Person fatherAlias = null;
+ Child childAlias = null;
+ IQueryOver<Person> actual =
+ CreateTestQueryOver<Person>()
+ .Left.Join(p => p.Father, () => fatherAlias)
+ .Left.Join(p => p.Children, () => childAlias);
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
+ [Test]
public void OrderBy()
{
ICriteria expected =
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ric...@us...> - 2009-07-08 15:34:58
|
Revision: 4591
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4591&view=rev
Author: ricbrown
Date: 2009-07-08 15:34:48 +0000 (Wed, 08 Jul 2009)
Log Message:
-----------
Added QueryOver syntax for join-types.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
trunk/nhibernate/src/NHibernate/IQueryOver.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-08 09:44:23 UTC (rev 4590)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-08 15:34:48 UTC (rev 4591)
@@ -117,6 +117,21 @@
get { return new QueryOverJoinBuilder<T>(this, JoinType.InnerJoin); }
}
+ public QueryOverJoinBuilder<T> Left
+ {
+ get { return new QueryOverJoinBuilder<T>(this, JoinType.LeftOuterJoin); }
+ }
+
+ public QueryOverJoinBuilder<T> Right
+ {
+ get { return new QueryOverJoinBuilder<T>(this, JoinType.RightOuterJoin); }
+ }
+
+ public QueryOverJoinBuilder<T> Full
+ {
+ get { return new QueryOverJoinBuilder<T>(this, JoinType.FullJoin); }
+ }
+
public IList<T> List()
{
return _criteria.List<T>();
@@ -198,9 +213,18 @@
IQueryOver<T> IQueryOver<T>.Join(Expression<Func<T, object>> path, Expression<Func<object>> alias, JoinType joinType)
{ return Join(path, alias, joinType); }
+ IQueryOverJoinBuilder<T> IQueryOver<T>.Inner
+ { get { return new IQueryOverJoinBuilder<T>(this, JoinType.InnerJoin); } }
+
IQueryOverJoinBuilder<T> IQueryOver<T>.Left
{ get { return new IQueryOverJoinBuilder<T>(this, JoinType.LeftOuterJoin); } }
+ IQueryOverJoinBuilder<T> IQueryOver<T>.Right
+ { get { return new IQueryOverJoinBuilder<T>(this, JoinType.RightOuterJoin); } }
+
+ IQueryOverJoinBuilder<T> IQueryOver<T>.Full
+ { get { return new IQueryOverJoinBuilder<T>(this, JoinType.FullJoin); } }
+
}
}
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-08 09:44:23 UTC (rev 4590)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-08 15:34:48 UTC (rev 4591)
@@ -121,7 +121,10 @@
/// <returns>criteria instance</returns>
IQueryOver<T> Join(Expression<Func<T, object>> path, Expression<Func<object>> alias, JoinType joinType);
- IQueryOverJoinBuilder<T> Left { get; }
+ IQueryOverJoinBuilder<T> Inner { get; }
+ IQueryOverJoinBuilder<T> Left { get; }
+ IQueryOverJoinBuilder<T> Right { get; }
+ IQueryOverJoinBuilder<T> Full { get; }
/// <summary>
/// Get the results of the root type and fill the <see cref="IList<T>"/>
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-07-08 09:44:23 UTC (rev 4590)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-07-08 15:34:48 UTC (rev 4591)
@@ -23,5 +23,20 @@
public virtual string Nickname { get; set; }
}
+ public class Relation
+ {
+
+ public virtual Relation Related1 { get; set; }
+ public virtual Relation Related2 { get; set; }
+ public virtual Relation Related3 { get; set; }
+ public virtual Relation Related4 { get; set; }
+
+ public virtual IEnumerable<Relation> Collection1 { get; set; }
+ public virtual IEnumerable<Relation> Collection2 { get; set; }
+ public virtual IEnumerable<Relation> Collection3 { get; set; }
+ public virtual IEnumerable<Relation> Collection4 { get; set; }
+
+ }
+
}
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-08 09:44:23 UTC (rev 4590)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-08 15:34:48 UTC (rev 4591)
@@ -179,19 +179,31 @@
}
[Test]
- public void Alias_LeftJoin()
+ public void Alias_JoinCombinations()
{
ICriteria expected =
- CreateTestCriteria(typeof(Person))
- .CreateAlias("Father", "fatherAlias", JoinType.LeftOuterJoin)
- .CreateAlias("Children", "childAlias", JoinType.LeftOuterJoin);
+ CreateTestCriteria(typeof(Relation))
+ .CreateAlias("Related1", "related1Alias")
+ .CreateAlias("Collection1", "collection1Alias")
+ .CreateAlias("Related2", "related2Alias", JoinType.LeftOuterJoin)
+ .CreateAlias("Collection2", "collection2Alias", JoinType.LeftOuterJoin)
+ .CreateAlias("Related3", "related3Alias", JoinType.RightOuterJoin)
+ .CreateAlias("Collection3", "collection3Alias", JoinType.RightOuterJoin)
+ .CreateAlias("Related4", "related4Alias", JoinType.FullJoin)
+ .CreateAlias("Collection4", "collection4Alias", JoinType.FullJoin);
- Person fatherAlias = null;
- Child childAlias = null;
- IQueryOver<Person> actual =
- CreateTestQueryOver<Person>()
- .Left.Join(p => p.Father, () => fatherAlias)
- .Left.Join(p => p.Children, () => childAlias);
+ Relation related1Alias = null, related2Alias = null, related3Alias = null, related4Alias = null;
+ Relation collection1Alias = null, collection2Alias = null, collection3Alias = null, collection4Alias = null;
+ IQueryOver<Relation> actual =
+ CreateTestQueryOver<Relation>()
+ .Inner.Join(r => r.Related1, () => related1Alias)
+ .Inner.Join(r => r.Collection1, () => collection1Alias)
+ .Left.Join(r => r.Related2, () => related2Alias)
+ .Left.Join(r => r.Collection2, () => collection2Alias)
+ .Right.Join(r => r.Related3, () => related3Alias)
+ .Right.Join(r => r.Collection3, () => collection3Alias)
+ .Full.Join(r => r.Related4, () => related4Alias)
+ .Full.Join(r => r.Collection4, () => collection4Alias);
AssertCriteriaAreEqual(expected, actual);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ric...@us...> - 2009-07-08 17:07:08
|
Revision: 4592
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4592&view=rev
Author: ricbrown
Date: 2009-07-08 17:07:02 +0000 (Wed, 08 Jul 2009)
Log Message:
-----------
Added overloads for creating sub-criteria with alias and join types.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
trunk/nhibernate/src/NHibernate/Criterion/QueryOverJoinBuilder.cs
trunk/nhibernate/src/NHibernate/IQueryOver.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/LambdaFixtureBase.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-08 15:34:48 UTC (rev 4591)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-08 17:07:02 UTC (rev 4592)
@@ -89,6 +89,39 @@
ExpressionProcessor.FindMemberExpression(path.Body)));
}
+ public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path, Expression<Func<U>> alias)
+ {
+ return new QueryOver<U>(_impl,
+ _criteria.CreateCriteria(
+ ExpressionProcessor.FindMemberExpression(path.Body),
+ ExpressionProcessor.FindMemberExpression(alias.Body)));
+ }
+
+ public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path, JoinType joinType)
+ {
+ return new QueryOver<U>(_impl,
+ _criteria.CreateCriteria(
+ ExpressionProcessor.FindMemberExpression(path.Body),
+ joinType));
+ }
+
+ public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path, Expression<Func<U>> alias, JoinType joinType)
+ {
+ return new QueryOver<U>(_impl,
+ _criteria.CreateCriteria(
+ ExpressionProcessor.FindMemberExpression(path.Body),
+ ExpressionProcessor.FindMemberExpression(alias.Body),
+ joinType));
+ }
+
+ public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path, Expression<Func<U>> alias)
+ {
+ return new QueryOver<U>(_impl,
+ _criteria.CreateCriteria(
+ ExpressionProcessor.FindMemberExpression(path.Body),
+ ExpressionProcessor.FindMemberExpression(alias.Body)));
+ }
+
public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path)
{
return new QueryOver<U>(_impl,
@@ -96,6 +129,23 @@
ExpressionProcessor.FindMemberExpression(path.Body)));
}
+ public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType)
+ {
+ return new QueryOver<U>(_impl,
+ _criteria.CreateCriteria(
+ ExpressionProcessor.FindMemberExpression(path.Body),
+ ExpressionProcessor.FindMemberExpression(alias.Body),
+ joinType));
+ }
+
+ public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path, JoinType joinType)
+ {
+ return new QueryOver<U>(_impl,
+ _criteria.CreateCriteria(
+ ExpressionProcessor.FindMemberExpression(path.Body),
+ joinType));
+ }
+
public QueryOver<T> Join(Expression<Func<T, object>> path, Expression<Func<object>> alias)
{
return AddAlias(
@@ -204,9 +254,27 @@
IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, U>> path)
{ return JoinQueryOver(path); }
+ IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, U>> path, Expression<Func<U>> alias)
+ { return JoinQueryOver(path, alias); }
+
+ IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, U>> path, JoinType joinType)
+ { return JoinQueryOver(path, joinType); }
+
+ IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, U>> path, Expression<Func<U>> alias, JoinType joinType)
+ { return JoinQueryOver(path, alias, joinType); }
+
IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path)
{ return JoinQueryOver(path); }
+ IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path, Expression<Func<U>> alias)
+ { return JoinQueryOver(path, alias); }
+
+ IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path, JoinType joinType)
+ { return JoinQueryOver(path, joinType); }
+
+ IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType)
+ { return JoinQueryOver(path, alias, joinType); }
+
IQueryOver<T> IQueryOver<T>.Join(Expression<Func<T, object>> path, Expression<Func<object>> alias)
{ return Join(path, alias); }
Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOverJoinBuilder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOverJoinBuilder.cs 2009-07-08 15:34:48 UTC (rev 4591)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOverJoinBuilder.cs 2009-07-08 17:07:02 UTC (rev 4592)
@@ -12,28 +12,70 @@
public class QueryOverJoinBuilder<T> : QueryOverJoinBuilderBase<QueryOver<T>, T>
{
public QueryOverJoinBuilder(QueryOver<T> root, JoinType joinType) : base(root, joinType) { }
+
+ public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path)
+ {
+ return root.JoinQueryOver<U>(path, joinType);
+ }
+
+ public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path, Expression<Func<U>> alias)
+ {
+ return root.JoinQueryOver<U>(path, alias, joinType);
+ }
+
+ public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path)
+ {
+ return root.JoinQueryOver<U>(path, joinType);
+ }
+
+ public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path, Expression<Func<U>> alias)
+ {
+ return root.JoinQueryOver<U>(path, alias, joinType);
+ }
+
}
public class IQueryOverJoinBuilder<T> : QueryOverJoinBuilderBase<IQueryOver<T>, T>
{
public IQueryOverJoinBuilder(IQueryOver<T> root, JoinType joinType) : base(root, joinType) { }
+
+ public IQueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path)
+ {
+ return root.JoinQueryOver<U>(path, joinType);
+ }
+
+ public IQueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path, Expression<Func<U>> alias)
+ {
+ return root.JoinQueryOver<U>(path, alias, joinType);
+ }
+
+ public IQueryOver<U> JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path)
+ {
+ return root.JoinQueryOver<U>(path, joinType);
+ }
+
+ public IQueryOver<U> JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path, Expression<Func<U>> alias)
+ {
+ return root.JoinQueryOver<U>(path, alias, joinType);
+ }
+
}
public class QueryOverJoinBuilderBase<R, T> where R : IQueryOver<T>
{
- private R _root;
- private JoinType _joinType;
+ protected R root;
+ protected JoinType joinType;
public QueryOverJoinBuilderBase(R root, JoinType joinType)
{
- _root = root;
- _joinType = joinType;
+ this.root = root;
+ this.joinType = joinType;
}
public R Join(Expression<Func<T, object>> path, Expression<Func<object>> alias)
{
- return (R)_root.Join(path, alias, _joinType);
+ return (R)root.Join(path, alias, joinType);
}
}
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-08 15:34:48 UTC (rev 4591)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-08 17:07:02 UTC (rev 4592)
@@ -98,6 +98,32 @@
/// <summary>
/// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
+ /// </summary>
+ /// <typeparam name="U">Type of sub-criteria</typeparam>
+ /// <param name="path">Lambda expression returning association path</param>
+ /// <param name="alias">Lambda expression returning alias reference</param>
+ /// <returns>The created "sub criteria"</returns>
+ IQueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path, Expression<Func<U>> alias);
+
+ /// <summary>
+ /// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
+ /// </summary>
+ /// <typeparam name="U">Type of sub-criteria</typeparam>
+ /// <param name="path">Lambda expression returning association path</param>
+ /// <returns>The created "sub criteria"</returns>
+ IQueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path, JoinType joinType);
+
+ /// <summary>
+ /// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
+ /// </summary>
+ /// <typeparam name="U">Type of sub-criteria</typeparam>
+ /// <param name="path">Lambda expression returning association path</param>
+ /// <param name="alias">Lambda expression returning alias reference</param>
+ /// <returns>The created "sub criteria"</returns>
+ IQueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path, Expression<Func<U>> alias, JoinType joinType);
+
+ /// <summary>
+ /// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
/// specifying a collection for the join.
/// </summary>
/// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
@@ -106,6 +132,35 @@
IQueryOver<U> JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path);
/// <summary>
+ /// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
+ /// specifying a collection for the join.
+ /// </summary>
+ /// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
+ /// <param name="path">Lambda expression returning association path</param>
+ /// <param name="alias">Lambda expression returning alias reference</param>
+ /// <returns>The created "sub criteria"</returns>
+ IQueryOver<U> JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path, Expression<Func<U>> alias);
+
+ /// <summary>
+ /// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
+ /// specifying a collection for the join.
+ /// </summary>
+ /// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
+ /// <param name="path">Lambda expression returning association path</param>
+ /// <returns>The created "sub criteria"</returns>
+ IQueryOver<U> JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path, JoinType joinType);
+
+ /// <summary>
+ /// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
+ /// specifying a collection for the join.
+ /// </summary>
+ /// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
+ /// <param name="path">Lambda expression returning association path</param>
+ /// <param name="alias">Lambda expression returning alias reference</param>
+ /// <returns>The created "sub criteria"</returns>
+ IQueryOver<U> JoinQueryOver<U>(Expression<Func<T, IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType);
+
+ /// <summary>
/// Join an association, assigning an alias to the joined entity
/// </summary>
/// <param name="path">Lambda expression returning association path</param>
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/LambdaFixtureBase.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/LambdaFixtureBase.cs 2009-07-08 15:34:48 UTC (rev 4591)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/LambdaFixtureBase.cs 2009-07-08 17:07:02 UTC (rev 4592)
@@ -94,7 +94,7 @@
PushName(name);
string fieldPath = _fieldPath.Peek();
- if (expected == null)
+ if (expected == null || actual == null)
{
Assert.AreEqual(expected, actual, fieldPath);
_fieldPath.Pop();
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-07-08 15:34:48 UTC (rev 4591)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-07-08 17:07:02 UTC (rev 4592)
@@ -36,6 +36,8 @@
public virtual IEnumerable<Relation> Collection3 { get; set; }
public virtual IEnumerable<Relation> Collection4 { get; set; }
+ public virtual IEnumerable<Person> People { get; set; }
+
}
}
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-08 15:34:48 UTC (rev 4591)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-08 17:07:02 UTC (rev 4592)
@@ -154,13 +154,43 @@
IQueryOver<Child> actual =
CreateTestQueryOver<Person>()
- .JoinQueryOver<Child>(p => p.Children) // sub-criteria
+ .JoinQueryOver(p => p.Children) // sub-criteria
.Where(c => c.Nickname == "test name");
AssertCriteriaAreEqual(expected, actual);
}
[Test]
+ public void SubCriteria_JoinQueryOverCombinations()
+ {
+ ICriteria expected =
+ CreateTestCriteria(typeof(Relation))
+ .CreateCriteria("Related1")
+ .CreateCriteria("Related2", JoinType.LeftOuterJoin)
+ .CreateCriteria("Related3", JoinType.RightOuterJoin)
+ .CreateCriteria("Related4", JoinType.FullJoin)
+ .CreateCriteria("Collection1", "collection1Alias")
+ .CreateCriteria("Collection2", "collection2Alias", JoinType.LeftOuterJoin)
+ .CreateCriteria("Collection3", JoinType.RightOuterJoin)
+ .CreateCriteria("People", "personAlias", JoinType.FullJoin);
+
+ Relation collection1Alias = null, collection2Alias = null;
+ Person personAlias = null;
+ IQueryOver<Person> actual =
+ CreateTestQueryOver<Relation>()
+ .Inner.JoinQueryOver(r => r.Related1)
+ .Left.JoinQueryOver(r => r.Related2)
+ .Right.JoinQueryOver(r => r.Related3)
+ .Full.JoinQueryOver(r => r.Related4)
+ .JoinQueryOver(r => r.Collection1, () => collection1Alias)
+ .Left.JoinQueryOver(r => r.Collection2, () => collection2Alias)
+ .Right.JoinQueryOver(r => r.Collection3)
+ .Full.JoinQueryOver(r => r.People, () => personAlias);
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
+ [Test]
public void Alias_Join()
{
ICriteria expected =
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <te...@us...> - 2009-07-09 11:32:27
|
Revision: 4595
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4595&view=rev
Author: tehlike
Date: 2009-07-09 11:32:22 +0000 (Thu, 09 Jul 2009)
Log Message:
-----------
Merging the fix for NH-1877
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/Projections.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Criterion/GroupedProjection.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Person.cs
Removed Paths:
-------------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Person.cs
Property Changed:
----------------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Customer.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests/
Copied: trunk/nhibernate/src/NHibernate/Criterion/GroupedProjection.cs (from rev 4594, branches/2.1.x/nhibernate/src/NHibernate/Criterion/GroupedProjection.cs)
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/GroupedProjection.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Criterion/GroupedProjection.cs 2009-07-09 11:32:22 UTC (rev 4595)
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NHibernate.Engine;
+using NHibernate.SqlCommand;
+using NHibernate.Type;
+using NHibernate.Util;
+
+namespace NHibernate.Criterion
+{
+ [Serializable]
+ public class GroupedProjection:IProjection
+ {
+ private readonly IProjection projection;
+
+ public GroupedProjection(IProjection projection)
+ {
+ this.projection = projection;
+ }
+
+ public virtual SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
+ {
+ return projection.ToSqlString(criteria, position, criteriaQuery, enabledFilters);
+ }
+
+ public virtual SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
+ {
+ return StringHelper.RemoveAsAliasesFromSql(this.projection.ToSqlString(criteria, 0, criteriaQuery, enabledFilters));
+ }
+
+ public virtual IType[] GetTypes(ICriteria criteria, ICriteriaQuery criteriaQuery)
+ {
+ return projection.GetTypes(criteria, criteriaQuery);
+ }
+
+ public virtual IType[] GetTypes(String alias, ICriteria criteria, ICriteriaQuery criteriaQuery)
+ {
+ return this.projection.GetTypes(alias,criteria,criteriaQuery);
+ }
+
+ public virtual string[] GetColumnAliases(int loc)
+ {
+ return projection.GetColumnAliases(loc);
+ }
+
+ public virtual string[] GetColumnAliases(string alias, int loc)
+ {
+ return null;
+ }
+
+ public virtual string[] Aliases
+ {
+ get { return new string[] { }; }
+ }
+
+ public virtual bool IsGrouped
+ {
+ get { return true; }
+ }
+
+ public bool IsAggregate
+ {
+ get { return projection.IsAggregate; }
+ }
+
+ /// <summary>
+ /// Gets the typed values for parameters in this projection
+ /// </summary>
+ /// <param name="criteria">The criteria.</param>
+ /// <param name="criteriaQuery">The criteria query.</param>
+ /// <returns></returns>
+ public TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
+ {
+ return projection.GetTypedValues(criteria, criteriaQuery);
+ }
+
+ public override string ToString()
+ {
+ return projection.ToString();
+ }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate/Criterion/Projections.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/Projections.cs 2009-07-09 10:46:19 UTC (rev 4594)
+++ trunk/nhibernate/src/NHibernate/Criterion/Projections.cs 2009-07-09 11:32:22 UTC (rev 4595)
@@ -202,6 +202,16 @@
}
/// <summary>
+ /// A grouping projection value
+ /// </summary>
+ /// <param name="projection"></param>
+ /// <returns></returns>
+ public static GroupedProjection GroupProperty(IProjection projection)
+ {
+ return new GroupedProjection(projection);
+ }
+
+ /// <summary>
/// A projected property value
/// </summary>
/// <param name="propertyName"></param>
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-09 10:46:19 UTC (rev 4594)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-09 11:32:22 UTC (rev 4595)
@@ -485,6 +485,7 @@
<Compile Include="Cfg\MappingSchema\HbmTimestamp.cs" />
<Compile Include="Cfg\MappingSchema\HbmVersion.cs" />
<Compile Include="Cfg\MappingSchema\IDecoratable.cs" />
+ <Compile Include="Criterion\GroupedProjection.cs" />
<Compile Include="Criterion\IPropertyProjection.cs" />
<Compile Include="Criterion\QueryOverJoinBuilder.cs" />
<Compile Include="Dialect\MsSql2008Dialect.cs" />
Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Customer.cs
___________________________________________________________________
Modified: svn:mergeinfo
-
+ /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Customer.cs:4593-4594
Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Fixture.cs
___________________________________________________________________
Modified: svn:mergeinfo
-
+ /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Fixture.cs:4593-4594
Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Mappings.hbm.xml
___________________________________________________________________
Modified: svn:mergeinfo
-
+ /branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Mappings.hbm.xml:4593-4594
Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Fixture.cs
===================================================================
--- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Fixture.cs 2009-07-09 10:46:19 UTC (rev 4594)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Fixture.cs 2009-07-09 11:32:22 UTC (rev 4595)
@@ -1,63 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using NHibernate.Criterion;
-using NUnit.Framework;
-
-namespace NHibernate.Test.NHSpecificTest.NH1877
-{
- [TestFixture]
- public class Fixture : BugTestCase
- {
- protected override void OnSetUp()
- {
- using(var session=OpenSession())
- using(var tran=session.BeginTransaction())
- {
- session.Save(new Person {BirthDate = new DateTime(1988, 7, 21)});
- session.Save(new Person { BirthDate = new DateTime(1987, 7, 22) });
- session.Save(new Person { BirthDate = new DateTime(1986, 7, 23) });
- session.Save(new Person { BirthDate = new DateTime(1987, 7, 24) });
- session.Save(new Person { BirthDate = new DateTime(1988, 7, 25) });
- tran.Commit();
- }
- }
-
- protected override void OnTearDown()
- {
- using (var session = OpenSession())
- using (var tran = session.BeginTransaction())
- {
- session.CreateQuery("delete from Person").ExecuteUpdate();
- tran.Commit();
- }
- }
-
- [Test]
- public void CanGroupByWithPropertyName()
- {
- using(var session=OpenSession())
- {
- var crit = session.CreateCriteria(typeof (Person))
- .SetProjection(Projections.GroupProperty("BirthDate"),
- Projections.Count("Id"));
- var result = crit.List();
- Assert.That(result,Has.Count.EqualTo(5));
- }
- }
-
- [Test]
- public void CanGroupByWithSqlFunctionProjection()
- {
- using (var session = OpenSession())
- {
- var crit = session.CreateCriteria(typeof (Person))
- .SetProjection(
- Projections.GroupProperty(Projections.SqlFunction("month", NHibernateUtil.Int32, Projections.Property("BirthDate"))));
-
- var result = crit.UniqueResult();
- Assert.That(result,Is.EqualTo(7));
- }
- }
- }
-}
\ No newline at end of file
Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Fixture.cs (from rev 4594, branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Fixture.cs)
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Fixture.cs 2009-07-09 11:32:22 UTC (rev 4595)
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NHibernate.Criterion;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1877
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ protected override void OnSetUp()
+ {
+ using(var session=OpenSession())
+ using(var tran=session.BeginTransaction())
+ {
+ session.Save(new Person {BirthDate = new DateTime(1988, 7, 21)});
+ session.Save(new Person { BirthDate = new DateTime(1987, 7, 22) });
+ session.Save(new Person { BirthDate = new DateTime(1986, 7, 23) });
+ session.Save(new Person { BirthDate = new DateTime(1987, 7, 24) });
+ session.Save(new Person { BirthDate = new DateTime(1988, 7, 25) });
+ tran.Commit();
+ }
+ }
+
+ protected override void OnTearDown()
+ {
+ using (var session = OpenSession())
+ using (var tran = session.BeginTransaction())
+ {
+ session.CreateQuery("delete from Person").ExecuteUpdate();
+ tran.Commit();
+ }
+ }
+
+ [Test]
+ public void CanGroupByWithPropertyName()
+ {
+ using(var session=OpenSession())
+ {
+ var crit = session.CreateCriteria(typeof (Person))
+ .SetProjection(Projections.GroupProperty("BirthDate"),
+ Projections.Count("Id"));
+ var result = crit.List();
+ Assert.That(result,Has.Count.EqualTo(5));
+ }
+ }
+
+ [Test]
+ public void CanGroupByWithSqlFunctionProjection()
+ {
+ using (var session = OpenSession())
+ {
+ var crit = session.CreateCriteria(typeof (Person))
+ .SetProjection(
+ Projections.GroupProperty(Projections.SqlFunction("month", NHibernateUtil.Int32, Projections.Property("BirthDate"))));
+
+ var result = crit.UniqueResult();
+ Assert.That(result,Is.EqualTo(7));
+ }
+ }
+ }
+}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Mappings.hbm.xml
===================================================================
--- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Mappings.hbm.xml 2009-07-09 10:46:19 UTC (rev 4594)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Mappings.hbm.xml 2009-07-09 11:32:22 UTC (rev 4595)
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
- namespace="NHibernate.Test.NHSpecificTest.NH1877"
- default-lazy="false">
-
- <class name="Person">
- <id name="Id">
- <generator class="hilo"/>
- </id>
- <property name="BirthDate"/>
-
- </class>
-</hibernate-mapping>
\ No newline at end of file
Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Mappings.hbm.xml (from rev 4594, branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Mappings.hbm.xml)
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Mappings.hbm.xml 2009-07-09 11:32:22 UTC (rev 4595)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH1877"
+ default-lazy="false">
+
+ <class name="Person">
+ <id name="Id">
+ <generator class="hilo"/>
+ </id>
+ <property name="BirthDate"/>
+
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Person.cs
===================================================================
--- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Person.cs 2009-07-09 10:46:19 UTC (rev 4594)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Person.cs 2009-07-09 11:32:22 UTC (rev 4595)
@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace NHibernate.Test.NHSpecificTest.NH1877
-{
- public class Person
- {
- public virtual long Id { get; set; }
- public virtual DateTime BirthDate { get; set; }
- }
-}
Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Person.cs (from rev 4594, branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Person.cs)
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Person.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1877/Person.cs 2009-07-09 11:32:22 UTC (rev 4595)
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace NHibernate.Test.NHSpecificTest.NH1877
+{
+ public class Person
+ {
+ public virtual long Id { get; set; }
+ public virtual DateTime BirthDate { get; set; }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-09 10:46:19 UTC (rev 4594)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-09 11:32:22 UTC (rev 4595)
@@ -542,6 +542,8 @@
<Compile Include="NHSpecificTest\NH1867\AddMappingTest.cs" />
<Compile Include="NHSpecificTest\NH1868\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1868\Model.cs" />
+ <Compile Include="NHSpecificTest\NH1877\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1877\Person.cs" />
<Compile Include="NHSpecificTest\NH473\Child.cs" />
<Compile Include="NHSpecificTest\NH473\Fixture.cs" />
<Compile Include="NHSpecificTest\NH473\Parent.cs" />
@@ -1953,6 +1955,7 @@
<EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" />
<EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1877\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1868\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1857\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1859\Mappings.hbm.xml" />
Property changes on: trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/2.1.x/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests:4507-4508,4510-4513,4537-4538
+ /branches/2.1.x/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests:4507-4508,4510-4513,4537-4538,4593-4594
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2009-07-09 17:05:28
|
Revision: 4600
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4600&view=rev
Author: fabiomaulo
Date: 2009-07-09 17:05:23 +0000 (Thu, 09 Jul 2009)
Log Message:
-----------
Merge r4598 and r4599 (fix NH-1876)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Id/TableGenerator.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/IdTest/TableGeneratorFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Id/TableGenerator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Id/TableGenerator.cs 2009-07-09 16:45:16 UTC (rev 4599)
+++ trunk/nhibernate/src/NHibernate/Id/TableGenerator.cs 2009-07-09 17:05:23 UTC (rev 4600)
@@ -4,9 +4,9 @@
using System.Data;
using System.Runtime.CompilerServices;
using log4net;
+using NHibernate.AdoNet.Util;
using NHibernate.Dialect;
using NHibernate.Engine;
-using NHibernate.Engine.Transaction;
using NHibernate.SqlCommand;
using NHibernate.SqlTypes;
using NHibernate.Type;
@@ -14,9 +14,6 @@
namespace NHibernate.Id
{
- using System.Transactions;
- using NHibernate.AdoNet.Util;
-
/// <summary>
/// An <see cref="IIdentifierGenerator" /> that uses a database table to store the last
/// generated value.
@@ -38,7 +35,8 @@
/// </remarks>
public class TableGenerator : TransactionHelper, IPersistentIdentifierGenerator, IConfigurable
{
- private static readonly ILog log = LogManager.GetLogger(typeof(TableGenerator));
+ private static readonly ILog log = LogManager.GetLogger(typeof (TableGenerator));
+
/// <summary>
/// An additional where clause that is added to
/// the queries against the table.
@@ -83,7 +81,6 @@
/// <param name="dialect">The <see cref="Dialect"/> to help with Configuration.</param>
public virtual void Configure(IType type, IDictionary<string, string> parms, Dialect.Dialect dialect)
{
-
tableName = PropertiesHelper.GetString(TableParamName, parms, DefaultTableName);
columnName = PropertiesHelper.GetString(ColumnParamName, parms, DefaultColumnName);
whereClause = PropertiesHelper.GetString(Where, parms, "");
@@ -95,9 +92,17 @@
tableName = dialect.Qualify(catalogName, schemaName, tableName);
}
- query = "select " + columnName + " from " + dialect.AppendLockHint(LockMode.Upgrade, tableName)
- + dialect.ForUpdateString;
+ var selectBuilder = new SqlStringBuilder(100);
+ selectBuilder.Add("select " + columnName)
+ .Add(" from " + dialect.AppendLockHint(LockMode.Upgrade, tableName));
+ if (string.IsNullOrEmpty(whereClause) == false)
+ {
+ selectBuilder.Add(" where ").Add(whereClause);
+ }
+ selectBuilder.Add(dialect.ForUpdateString);
+ query = selectBuilder.ToString();
+
columnType = type as PrimitiveType;
if (columnType == null)
{
@@ -119,21 +124,16 @@
columnSqlType = SqlTypeFactory.Int32;
}
- parameterTypes = new SqlType[2] {columnSqlType, columnSqlType};
+ parameterTypes = new[] {columnSqlType, columnSqlType};
- SqlStringBuilder builder = new SqlStringBuilder();
+ var builder = new SqlStringBuilder(100);
builder.Add("update " + tableName + " set ")
- .Add(columnName)
- .Add(" = ")
- .Add(Parameter.Placeholder)
+ .Add(columnName).Add(" = ").Add(Parameter.Placeholder)
.Add(" where ")
- .Add(columnName)
- .Add(" = ")
- .Add(Parameter.Placeholder);
+ .Add(columnName).Add(" = ").Add(Parameter.Placeholder);
if (string.IsNullOrEmpty(whereClause) == false)
{
- builder.Add(" and ")
- .Add(whereClause);
+ builder.Add(" and ").Add(whereClause);
}
updateSql = builder.ToSqlString();
@@ -172,16 +172,16 @@
/// create the necessary database objects and to create the first value as <c>1</c>
/// for the TableGenerator.
/// </returns>
- public string[] SqlCreateStrings(Dialect.Dialect dialect)
+ public virtual string[] SqlCreateStrings(Dialect.Dialect dialect)
{
// changed the first value to be "1" by default since an uninitialized Int32 is 0 - leaving
// it at 0 would cause problems with an unsaved-value="0" which is what most people are
// defaulting <id>'s with Int32 types at.
- return new string[]
- {
- "create table " + tableName + " ( " + columnName + " " + dialect.GetTypeName(columnSqlType) + " )",
- "insert into " + tableName + " values ( 1 )"
- };
+ return new[]
+ {
+ "create table " + tableName + " ( " + columnName + " " + dialect.GetTypeName(columnSqlType) + " )",
+ "insert into " + tableName + " values ( 1 )"
+ };
}
/// <summary>
@@ -191,9 +191,9 @@
/// <returns>
/// A <see cref="string"/> that will drop the database objects for the TableGenerator.
/// </returns>
- public string[] SqlDropString(Dialect.Dialect dialect)
+ public virtual string[] SqlDropString(Dialect.Dialect dialect)
{
- return new string[] { dialect.GetDropTableString(tableName) };
+ return new[] {dialect.GetDropTableString(tableName)};
}
/// <summary>
@@ -209,7 +209,8 @@
#endregion
- public override object DoWorkInCurrentTransaction(ISessionImplementor session, IDbConnection conn, IDbTransaction transaction)
+ public override object DoWorkInCurrentTransaction(ISessionImplementor session, IDbConnection conn,
+ IDbTransaction transaction)
{
long result;
int rows;
@@ -243,15 +244,18 @@
}
finally
{
- if (rs != null) rs.Close();
+ if (rs != null)
+ {
+ rs.Close();
+ }
qps.Dispose();
}
- IDbCommand ups =
- session.Factory.ConnectionProvider.Driver.GenerateCommand(CommandType.Text, updateSql, parameterTypes);
+ IDbCommand ups = session.Factory.ConnectionProvider.Driver.GenerateCommand(CommandType.Text, updateSql,
+ parameterTypes);
ups.Connection = conn;
ups.Transaction = transaction;
-
+
try
{
columnType.Set(ups, result + 1, 0);
@@ -270,9 +274,10 @@
{
ups.Dispose();
}
- } while (rows == 0);
+ }
+ while (rows == 0);
return result;
}
}
-}
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/IdTest/TableGeneratorFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/IdTest/TableGeneratorFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/IdTest/TableGeneratorFixture.cs 2009-07-09 17:05:23 UTC (rev 4600)
@@ -0,0 +1,29 @@
+using System.Collections.Generic;
+using System.Reflection;
+using NHibernate.Dialect;
+using NHibernate.Id;
+using NUnit.Framework;
+
+namespace NHibernate.Test.IdTest
+{
+ [TestFixture]
+ public class TableGeneratorFixture
+ {
+ private const BindingFlags Flags =
+ BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
+
+ private readonly FieldInfo updateSql = typeof (TableGenerator).GetField("updateSql", Flags);
+ private readonly FieldInfo selectSql = typeof (TableGenerator).GetField("query", Flags);
+
+ [Test]
+ public void SelectAndUpdateStringContainCustomWhere()
+ {
+ const string customWhere = "table_name='second'";
+ var dialect = new MsSql2005Dialect();
+ var tg = new TableGenerator();
+ tg.Configure(NHibernateUtil.Int64, new Dictionary<string, string> {{"where", customWhere}}, dialect);
+ Assert.That(selectSql.GetValue(tg).ToString(), Text.Contains(customWhere));
+ Assert.That(updateSql.GetValue(tg).ToString(), Text.Contains(customWhere));
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2009-07-17 14:42:31
|
Revision: 4648
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4648&view=rev
Author: fabiomaulo
Date: 2009-07-17 14:42:29 +0000 (Fri, 17 Jul 2009)
Log Message:
-----------
Merge r4647
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/AbstractDecoratable.cs
trunk/nhibernate/src/NHibernate.Test/MappingTest/NonReflectiveBinderFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/AbstractDecoratable.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/AbstractDecoratable.cs 2009-07-17 14:24:31 UTC (rev 4647)
+++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/AbstractDecoratable.cs 2009-07-17 14:42:29 UTC (rev 4648)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Xml.Serialization;
using NHibernate.Mapping;
using NHibernate.Util;
@@ -10,7 +11,12 @@
{
private static readonly IDictionary<string, MetaAttribute> EmptyMetaData = new CollectionHelper.EmptyMapClass<string, MetaAttribute>();
+ [NonSerialized]
+ [XmlIgnore]
private IDictionary<string, MetaAttribute> mappedMetaData;
+
+ [NonSerialized]
+ [XmlIgnore]
private IDictionary<string, MetaAttribute> inheritableMetaData;
public virtual IDictionary<string, MetaAttribute> MappedMetaData
Modified: trunk/nhibernate/src/NHibernate.Test/MappingTest/NonReflectiveBinderFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingTest/NonReflectiveBinderFixture.cs 2009-07-17 14:24:31 UTC (rev 4647)
+++ trunk/nhibernate/src/NHibernate.Test/MappingTest/NonReflectiveBinderFixture.cs 2009-07-17 14:42:29 UTC (rev 4648)
@@ -1,4 +1,6 @@
+using System.IO;
using NHibernate.Cfg;
+using NHibernate.Cfg.MappingSchema;
using NHibernate.Mapping;
using NUnit.Framework;
@@ -180,5 +182,17 @@
metaAttribute = cm.GetMetaAttribute("Auditable");
Assert.That(metaAttribute, Is.Not.Null);
}
+
+ [Test]
+ public void XmlSerialization()
+ {
+ // NH-1865 (have a look to comments in JIRA)
+ var mdp = new MappingDocumentParser();
+ using (Stream stream = GetType().Assembly.GetManifestResourceStream("NHibernate.Test.MappingTest.Wicked.hbm.xml"))
+ {
+ HbmMapping mapping = mdp.Parse(stream);
+ Assert.That(mapping, Is.XmlSerializable);
+ }
+ }
}
}
\ 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...> - 2009-07-17 17:02:49
|
Revision: 4650
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4650&view=rev
Author: fabiomaulo
Date: 2009-07-17 17:02:38 +0000 (Fri, 17 Jul 2009)
Log Message:
-----------
Refactoring to allow class usage for fluent-conf.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CfgXmlHelper.cs
trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/ClassCacheConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CollectionCacheConfiguration.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Cfg/EntityCacheUsage.cs
trunk/nhibernate/src/NHibernate.Test/CfgTest/EntityCacheUsageParserFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -1434,7 +1434,7 @@
{
string region = string.IsNullOrEmpty(ccc.Region) ? ccc.Class : ccc.Region;
bool includeLazy = (ccc.Include != ClassCacheInclude.NonLazy);
- SetCacheConcurrencyStrategy(ccc.Class, CfgXmlHelper.ClassCacheUsageConvertToString(ccc.Usage), region, includeLazy);
+ SetCacheConcurrencyStrategy(ccc.Class, EntityCacheUsageParser.ToString(ccc.Usage), region, includeLazy);
}
// Load collection-cache
@@ -1449,7 +1449,7 @@
}
string region = string.IsNullOrEmpty(ccc.Region) ? role : ccc.Region;
- SetCollectionCacheConcurrencyStrategy(role, CfgXmlHelper.ClassCacheUsageConvertToString(ccc.Usage), region);
+ SetCollectionCacheConcurrencyStrategy(role, EntityCacheUsageParser.ToString(ccc.Usage), region);
}
// Events
Modified: trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CfgXmlHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CfgXmlHelper.cs 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CfgXmlHelper.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -102,51 +102,6 @@
}
/// <summary>
- /// Convert a string to <see cref="ClassCacheUsage"/>.
- /// </summary>
- /// <param name="usage">The string that represent <see cref="ClassCacheUsage"/>.</param>
- /// <returns>
- /// The <paramref name="usage"/> converted to <see cref="ClassCacheUsage"/>.
- /// </returns>
- /// <exception cref="HibernateConfigException">If the values is invalid.</exception>
- /// <remarks>
- /// See <see cref="ClassCacheUsage"/> for allowed values.
- /// </remarks>
- public static ClassCacheUsage ClassCacheUsageConvertFrom(string usage)
- {
- switch (usage)
- {
- case "read-only":
- return ClassCacheUsage.Readonly;
- case "read-write":
- return ClassCacheUsage.ReadWrite;
- case "nonstrict-read-write":
- return ClassCacheUsage.NonStrictReadWrite;
- case "transactional":
- return ClassCacheUsage.Transactional;
- default:
- throw new HibernateConfigException(string.Format("Invalid ClassCacheUsage value:{0}", usage));
- }
- }
-
- internal static string ClassCacheUsageConvertToString(ClassCacheUsage usage)
- {
- switch (usage)
- {
- case ClassCacheUsage.Readonly:
- return "read-only";
- case ClassCacheUsage.ReadWrite:
- return "read-write";
- case ClassCacheUsage.NonStrictReadWrite:
- return "nonstrict-read-write";
- case ClassCacheUsage.Transactional:
- return "transactional";
- default:
- return string.Empty;
- }
- }
-
- /// <summary>
/// Convert a string to <see cref="ClassCacheInclude"/>.
/// </summary>
/// <param name="include">The string that represent <see cref="ClassCacheInclude"/>.</param>
Modified: trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/ClassCacheConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/ClassCacheConfiguration.cs 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/ClassCacheConfiguration.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -4,21 +4,6 @@
namespace NHibernate.Cfg.ConfigurationSchema
{
/// <summary>
- /// Values for class-cache and collection-cache strategy.
- /// </summary>
- public enum ClassCacheUsage
- {
- /// <summary>Xml value: read-only</summary>
- Readonly,
- /// <summary>Xml value: read-write</summary>
- ReadWrite,
- /// <summary>Xml value: nonstrict-read-write</summary>
- NonStrictReadWrite,
- /// <summary>Xml value: transactional</summary>
- Transactional
- }
-
- /// <summary>
/// Values for class-cache include.
/// </summary>
/// <remarks>Not implemented in Cache.</remarks>
@@ -47,7 +32,7 @@
/// <param name="clazz">The class full name.</param>
/// <param name="usage">Cache strategy.</param>
/// <exception cref="ArgumentException">When <paramref name="clazz"/> is null or empty.</exception>
- public ClassCacheConfiguration(string clazz, ClassCacheUsage usage)
+ public ClassCacheConfiguration(string clazz, EntityCacheUsage usage)
{
if (string.IsNullOrEmpty(clazz))
throw new ArgumentException("clazz is null or empty.", "clazz");
@@ -62,7 +47,7 @@
/// <param name="usage">Cache strategy.</param>
/// <param name="include">Values for class-cache include.</param>
/// <exception cref="ArgumentException">When <paramref name="clazz"/> is null or empty.</exception>
- public ClassCacheConfiguration(string clazz, ClassCacheUsage usage, ClassCacheInclude include)
+ public ClassCacheConfiguration(string clazz, EntityCacheUsage usage, ClassCacheInclude include)
: this(clazz, usage)
{
this.include = include;
@@ -75,7 +60,7 @@
/// <param name="usage">Cache strategy.</param>
/// <param name="region">The cache region.</param>
/// <exception cref="ArgumentException">When <paramref name="clazz"/> is null or empty.</exception>
- public ClassCacheConfiguration(string clazz, ClassCacheUsage usage, string region)
+ public ClassCacheConfiguration(string clazz, EntityCacheUsage usage, string region)
: this(clazz, usage)
{
this.region = region;
@@ -89,7 +74,7 @@
/// <param name="include">Values for class-cache include.</param>
/// <param name="region">The cache region.</param>
/// <exception cref="ArgumentException">When <paramref name="clazz"/> is null or empty.</exception>
- public ClassCacheConfiguration(string clazz, ClassCacheUsage usage, ClassCacheInclude include, string region)
+ public ClassCacheConfiguration(string clazz, EntityCacheUsage usage, ClassCacheInclude include, string region)
: this(clazz, usage, include)
{
this.region = region;
@@ -109,7 +94,7 @@
clazz = classCacheElement.Value;
break;
case "usage":
- usage = CfgXmlHelper.ClassCacheUsageConvertFrom(classCacheElement.Value);
+ usage = EntityCacheUsageParser.Parse(classCacheElement.Value);
break;
case "region":
region = classCacheElement.Value;
@@ -143,11 +128,11 @@
}
- private ClassCacheUsage usage;
+ private EntityCacheUsage usage;
/// <summary>
/// Cache strategy.
/// </summary>
- public ClassCacheUsage Usage
+ public EntityCacheUsage Usage
{
get { return usage; }
}
Modified: trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CollectionCacheConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CollectionCacheConfiguration.cs 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CollectionCacheConfiguration.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -19,7 +19,7 @@
/// <param name="collection">The cache role.</param>
/// <param name="usage">Cache strategy.</param>
/// <exception cref="ArgumentException">When <paramref name="collection"/> is null or empty.</exception>
- public CollectionCacheConfiguration(string collection, ClassCacheUsage usage)
+ public CollectionCacheConfiguration(string collection, EntityCacheUsage usage)
{
if (String.IsNullOrEmpty(collection))
throw new ArgumentException("collection is null or empty.", "collection");
@@ -34,7 +34,7 @@
/// <param name="usage">Cache strategy.</param>
/// <param name="region">The cache region.</param>
/// <exception cref="ArgumentException">When <paramref name="collection"/> is null or empty.</exception>
- public CollectionCacheConfiguration(string collection, ClassCacheUsage usage, string region)
+ public CollectionCacheConfiguration(string collection, EntityCacheUsage usage, string region)
:this(collection,usage)
{
this.region = region;
@@ -54,7 +54,7 @@
collection = collectionCacheElement.Value;
break;
case "usage":
- usage = CfgXmlHelper.ClassCacheUsageConvertFrom(collectionCacheElement.Value);
+ usage = EntityCacheUsageParser.Parse(collectionCacheElement.Value);
break;
case "region":
region = collectionCacheElement.Value;
@@ -84,11 +84,11 @@
get { return region; }
}
- private ClassCacheUsage usage;
+ private EntityCacheUsage usage;
/// <summary>
/// Cache strategy.
/// </summary>
- public ClassCacheUsage Usage
+ public EntityCacheUsage Usage
{
get { return usage; }
}
Added: trunk/nhibernate/src/NHibernate/Cfg/EntityCacheUsage.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/EntityCacheUsage.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/EntityCacheUsage.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -0,0 +1,78 @@
+namespace NHibernate.Cfg
+{
+ /// <summary>
+ /// Values for class-cache and collection-cache strategy.
+ /// </summary>
+ public enum EntityCacheUsage
+ {
+ /// <summary>Xml value: read-only</summary>
+ Readonly,
+ /// <summary>Xml value: read-write</summary>
+ ReadWrite,
+ /// <summary>Xml value: nonstrict-read-write</summary>
+ NonStrictReadWrite,
+ /// <summary>Xml value: transactional</summary>
+ Transactional
+ }
+
+ /// <summary>
+ /// Helper to parse <see cref="EntityCacheUsage"/> to and from XML string value.
+ /// </summary>
+ public static class EntityCacheUsageParser
+ {
+ private const string ReadOnlyXmlValue = "read-only";
+ private const string ReadWriteXmlValue = "read-write";
+ private const string NonstrictReadWriteXmlValue = "nonstrict-read-write";
+ private const string TransactionalXmlValue = "transactional";
+
+ /// <summary>
+ /// Convert a <see cref="EntityCacheUsage"/> in its xml expected value.
+ /// </summary>
+ /// <param name="value">The <see cref="EntityCacheUsage"/> to convert.</param>
+ /// <returns>The <see cref="EntityCacheUsage"/>.</returns>
+ public static string ToString(EntityCacheUsage value)
+ {
+ switch (value)
+ {
+ case EntityCacheUsage.Readonly:
+ return ReadOnlyXmlValue;
+ case EntityCacheUsage.ReadWrite:
+ return ReadWriteXmlValue;
+ case EntityCacheUsage.NonStrictReadWrite:
+ return NonstrictReadWriteXmlValue;
+ case EntityCacheUsage.Transactional:
+ return TransactionalXmlValue;
+ default:
+ return string.Empty;
+ }
+ }
+
+ /// <summary>
+ /// Convert a string to <see cref="EntityCacheUsage"/>.
+ /// </summary>
+ /// <param name="value">The string that represent <see cref="EntityCacheUsage"/>.</param>
+ /// <returns>
+ /// The <paramref name="value"/> converted to <see cref="EntityCacheUsage"/>.
+ /// </returns>
+ /// <exception cref="HibernateConfigException">If the values is invalid.</exception>
+ /// <remarks>
+ /// See <see cref="EntityCacheUsage"/> for allowed values.
+ /// </remarks>
+ public static EntityCacheUsage Parse(string value)
+ {
+ switch (value)
+ {
+ case ReadOnlyXmlValue:
+ return EntityCacheUsage.Readonly;
+ case ReadWriteXmlValue:
+ return EntityCacheUsage.ReadWrite;
+ case NonstrictReadWriteXmlValue:
+ return EntityCacheUsage.NonStrictReadWrite;
+ case TransactionalXmlValue:
+ return EntityCacheUsage.Transactional;
+ default:
+ throw new HibernateConfigException(string.Format("Invalid EntityCacheUsage value:{0}", value));
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-17 17:02:38 UTC (rev 4650)
@@ -459,6 +459,7 @@
<Compile Include="Bytecode\ProxyFactoryFactoryNotConfiguredException.cs" />
<Compile Include="Bytecode\UnableToLoadProxyFactoryFactoryException.cs" />
<Compile Include="Cache\FakeCache.cs" />
+ <Compile Include="Cfg\EntityCacheUsage.cs" />
<Compile Include="Cfg\Hbm2ddlKeyWords.cs" />
<Compile Include="Cfg\Loquacious\CacheConfiguration.cs" />
<Compile Include="Cfg\Loquacious\ConfigurationExtensions.cs" />
Modified: trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -178,7 +178,7 @@
HibernateConfiguration hc = new HibernateConfiguration(xtr);
Assert.AreEqual(1, hc.SessionFactory.ClassesCache.Count);
Assert.AreEqual("Class1", hc.SessionFactory.ClassesCache[0].Class);
- Assert.AreEqual(ClassCacheUsage.Readonly, hc.SessionFactory.ClassesCache[0].Usage);
+ Assert.AreEqual(EntityCacheUsage.Readonly, hc.SessionFactory.ClassesCache[0].Usage);
Assert.AreEqual(ClassCacheInclude.NonLazy, hc.SessionFactory.ClassesCache[0].Include);
Assert.AreEqual("ARegion", hc.SessionFactory.ClassesCache[0].Region);
}
@@ -198,7 +198,7 @@
HibernateConfiguration hc = new HibernateConfiguration(xtr);
Assert.AreEqual(1, hc.SessionFactory.CollectionsCache.Count);
Assert.AreEqual("Collection1", hc.SessionFactory.CollectionsCache[0].Collection);
- Assert.AreEqual(ClassCacheUsage.NonStrictReadWrite, hc.SessionFactory.CollectionsCache[0].Usage);
+ Assert.AreEqual(EntityCacheUsage.NonStrictReadWrite, hc.SessionFactory.CollectionsCache[0].Usage);
Assert.AreEqual("ARegion", hc.SessionFactory.CollectionsCache[0].Region);
}
Added: trunk/nhibernate/src/NHibernate.Test/CfgTest/EntityCacheUsageParserFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/EntityCacheUsageParserFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/EntityCacheUsageParserFixture.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -0,0 +1,27 @@
+using NHibernate.Cfg;
+using NUnit.Framework;
+
+namespace NHibernate.Test.CfgTest
+{
+ [TestFixture]
+ public class EntityCacheUsageParserFixture
+ {
+ [Test]
+ public void CovertToString()
+ {
+ Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.Readonly), Is.EqualTo("read-only"));
+ Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.ReadWrite), Is.EqualTo("read-write"));
+ Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite), Is.EqualTo("nonstrict-read-write"));
+ Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.Transactional), Is.EqualTo("transactional"));
+ }
+
+ [Test]
+ public void Parse()
+ {
+ Assert.That(EntityCacheUsageParser.Parse("read-only"), Is.EqualTo(EntityCacheUsage.Readonly));
+ Assert.That(EntityCacheUsageParser.Parse("read-write"), Is.EqualTo(EntityCacheUsage.ReadWrite));
+ Assert.That(EntityCacheUsageParser.Parse("nonstrict-read-write"), Is.EqualTo(EntityCacheUsage.NonStrictReadWrite));
+ Assert.That(EntityCacheUsageParser.Parse("transactional"), Is.EqualTo(EntityCacheUsage.Transactional));
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-17 17:02:38 UTC (rev 4650)
@@ -104,6 +104,7 @@
<Compile Include="CfgTest\ConfigurationSchemaFixture.cs" />
<Compile Include="CfgTest\ConfigurationSerializationTests.cs" />
<Compile Include="CfgTest\DefaultNsAssmFixture.cs" />
+ <Compile Include="CfgTest\EntityCacheUsageParserFixture.cs" />
<Compile Include="CfgTest\HbmBinderFixture.cs" />
<Compile Include="CfgTest\HbmOrderingFixture.cs" />
<Compile Include="CfgTest\LocatedInTestAssembly.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2009-07-17 20:36:52
|
Revision: 4651
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4651&view=rev
Author: fabiomaulo
Date: 2009-07-17 20:36:48 +0000 (Fri, 17 Jul 2009)
Log Message:
-----------
Fix NH-1892 (cache configuration by code)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/EntityCacheConfigurationProperties.cs
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IEntityCacheConfigurationProperties.cs
trunk/nhibernate/src/NHibernate/Util/ExpressionsHelper.cs
trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/EntityCacheConfigurationFixture.cs
trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/EntityToCache.cs
trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/EntityToCache.hbm.xml
trunk/nhibernate/src/NHibernate.Test/UtilityTest/ExpressionsHelperFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs 2009-07-17 17:02:38 UTC (rev 4650)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs 2009-07-17 20:36:48 UTC (rev 4651)
@@ -1,5 +1,6 @@
using System;
using NHibernate.Hql;
+
namespace NHibernate.Cfg.Loquacious
{
public static class ConfigurationExtensions
@@ -51,5 +52,24 @@
dataBaseIntegration(new DbIntegrationConfigurationProperties(configuration));
return configuration;
}
+
+ public static Configuration EntityCache<TEntity>(this Configuration configuration, Action<IEntityCacheConfigurationProperties<TEntity>> entityCacheConfiguration)
+ where TEntity : class
+ {
+ var ecc = new EntityCacheConfigurationProperties<TEntity>();
+ entityCacheConfiguration(ecc);
+ if (ecc.Strategy.HasValue)
+ {
+ configuration.SetCacheConcurrencyStrategy(typeof (TEntity).FullName, EntityCacheUsageParser.ToString(ecc.Strategy.Value),
+ ecc.RegionName);
+ }
+ foreach (var collection in ecc.Collections)
+ {
+ configuration.SetCollectionCacheConcurrencyStrategy(collection.Key,
+ EntityCacheUsageParser.ToString(collection.Value.Strategy),
+ collection.Value.RegionName);
+ }
+ return configuration;
+ }
}
}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/EntityCacheConfigurationProperties.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/EntityCacheConfigurationProperties.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/EntityCacheConfigurationProperties.cs 2009-07-17 20:36:48 UTC (rev 4651)
@@ -0,0 +1,65 @@
+using System;
+using System.Collections;
+using System.Linq.Expressions;
+using System.Collections.Generic;
+using NHibernate.Util;
+
+namespace NHibernate.Cfg.Loquacious
+{
+ internal class EntityCacheConfigurationProperties<TEntity> : IEntityCacheConfigurationProperties<TEntity>
+ where TEntity : class
+ {
+ private readonly Dictionary<string, IEntityCollectionCacheConfigurationProperties> collections;
+
+ public EntityCacheConfigurationProperties()
+ {
+ collections = new Dictionary<string, IEntityCollectionCacheConfigurationProperties>(10);
+ Strategy = null;
+ }
+
+ #region Implementation of IEntityCacheConfigurationProperties
+
+ public EntityCacheUsage? Strategy { set; get; }
+ public string RegionName { set; get; }
+
+ public void Collection<TCollection>(Expression<Func<TEntity, TCollection>> collectionProperty,
+ Action<IEntityCollectionCacheConfigurationProperties> collectionCacheConfiguration)
+ where TCollection : IEnumerable
+ {
+ if (collectionProperty == null)
+ {
+ throw new ArgumentNullException("collectionProperty");
+ }
+ var mi = ExpressionsHelper.DecodeMemberAccessExpression(collectionProperty);
+ if(mi.DeclaringType != typeof(TEntity))
+ {
+ throw new ArgumentOutOfRangeException("collectionProperty", "Collection not owned by " + typeof (TEntity).FullName);
+ }
+ var ecc = new EntityCollectionCacheConfigurationProperties();
+ collectionCacheConfiguration(ecc);
+ collections.Add(typeof (TEntity).FullName + "." + mi.Name, ecc);
+ }
+
+ #endregion
+
+ public IDictionary<string, IEntityCollectionCacheConfigurationProperties> Collections
+ {
+ get { return collections; }
+ }
+ }
+
+ internal class EntityCollectionCacheConfigurationProperties : IEntityCollectionCacheConfigurationProperties
+ {
+ public EntityCollectionCacheConfigurationProperties()
+ {
+ Strategy = EntityCacheUsage.ReadWrite;
+ }
+
+ #region Implementation of IEntityCollectionCacheConfigurationProperties
+
+ public EntityCacheUsage Strategy { get; set; }
+ public string RegionName { get; set; }
+
+ #endregion
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IEntityCacheConfigurationProperties.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IEntityCacheConfigurationProperties.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/IEntityCacheConfigurationProperties.cs 2009-07-17 20:36:48 UTC (rev 4651)
@@ -0,0 +1,21 @@
+using System;
+using System.Linq.Expressions;
+using System.Collections;
+
+namespace NHibernate.Cfg.Loquacious
+{
+ public interface IEntityCollectionCacheConfigurationProperties
+ {
+ EntityCacheUsage Strategy { get; set; }
+ string RegionName { get; set; }
+ }
+
+ public interface IEntityCacheConfigurationProperties<TEntity> where TEntity: class
+ {
+ EntityCacheUsage? Strategy { get; set; }
+ string RegionName { get; set; }
+
+ void Collection<TCollection>(Expression<Func<TEntity, TCollection>> collectionProperty, Action<IEntityCollectionCacheConfigurationProperties> collectionCacheConfiguration)
+ where TCollection : IEnumerable;
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-17 17:02:38 UTC (rev 4650)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-17 20:36:48 UTC (rev 4651)
@@ -464,6 +464,7 @@
<Compile Include="Cfg\Loquacious\CacheConfiguration.cs" />
<Compile Include="Cfg\Loquacious\ConfigurationExtensions.cs" />
<Compile Include="Cfg\Loquacious\DbIntegrationConfiguration.cs" />
+ <Compile Include="Cfg\Loquacious\EntityCacheConfigurationProperties.cs" />
<Compile Include="Cfg\Loquacious\FluentSessionFactoryConfiguration.cs" />
<Compile Include="Cfg\Loquacious\IBatcherConfiguration.cs" />
<Compile Include="Cfg\Loquacious\ICacheConfiguration.cs" />
@@ -472,6 +473,7 @@
<Compile Include="Cfg\Loquacious\IConnectionConfiguration.cs" />
<Compile Include="Cfg\Loquacious\IDbIntegrationConfiguration.cs" />
<Compile Include="Cfg\Loquacious\IDbSchemaIntegrationConfiguration.cs" />
+ <Compile Include="Cfg\Loquacious\IEntityCacheConfigurationProperties.cs" />
<Compile Include="Cfg\Loquacious\IFluentSessionFactoryConfiguration.cs" />
<Compile Include="Cfg\Loquacious\IMappingsConfiguration.cs" />
<Compile Include="Cfg\Loquacious\IProxyConfiguration.cs" />
@@ -638,6 +640,7 @@
<Compile Include="Type\DbTimestampType.cs" />
<Compile Include="Type\DefaultCollectionTypeFactory.cs" />
<Compile Include="Bytecode\ICollectionTypeFactory.cs" />
+ <Compile Include="Util\ExpressionsHelper.cs" />
<Compile Include="Util\NullableDictionary.cs" />
<Compile Include="Hql\Ast\ANTLR\Util\PathHelper.cs" />
<Compile Include="Hql\Ast\ANTLR\Util\SyntheticAndFactory.cs" />
Added: trunk/nhibernate/src/NHibernate/Util/ExpressionsHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Util/ExpressionsHelper.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Util/ExpressionsHelper.cs 2009-07-17 20:36:48 UTC (rev 4651)
@@ -0,0 +1,19 @@
+using System.Linq.Expressions;
+using System.Reflection;
+using System;
+
+namespace NHibernate.Util
+{
+ public static class ExpressionsHelper
+ {
+ public static MemberInfo DecodeMemberAccessExpression<TEntity, TResult>(Expression<Func<TEntity, TResult>> expression)
+ {
+ if (expression.Body.NodeType != ExpressionType.MemberAccess)
+ {
+ throw new HibernateException(
+ string.Format("Invalid expression type: Expected ExpressionType.MemberAccess, Found {0}", expression.Body.NodeType));
+ }
+ return ((MemberExpression)expression.Body).Member;
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/EntityCacheConfigurationFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/EntityCacheConfigurationFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/EntityCacheConfigurationFixture.cs 2009-07-17 20:36:48 UTC (rev 4651)
@@ -0,0 +1,83 @@
+using System;
+using NHibernate.Cfg;
+using NHibernate.Cfg.Loquacious;
+using NHibernate.Mapping;
+using NUnit.Framework;
+
+namespace NHibernate.Test.CfgTest.Loquacious
+{
+ [TestFixture]
+ public class EntityCacheConfigurationFixture
+ {
+ [Test]
+ public void ConfigureCacheOfClass()
+ {
+ Configuration configure = new Configuration().Configure();
+ configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly);
+
+ configure.EntityCache<EntityToCache>(ce =>
+ {
+ ce.Strategy = EntityCacheUsage.NonStrictReadWrite;
+ ce.RegionName = "MyRegion";
+ });
+
+ var pc = (RootClass) configure.GetClassMapping(typeof (EntityToCache));
+ Assert.That(pc.CacheConcurrencyStrategy,
+ Is.EqualTo(EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite)));
+ Assert.That(pc.CacheRegionName, Is.EqualTo("MyRegion"));
+ }
+
+ [Test]
+ public void ConfigureCacheOfCollection()
+ {
+ Configuration configure = new Configuration().Configure();
+ configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly);
+
+ configure.EntityCache<EntityToCache>(ce =>
+ {
+ ce.Strategy = EntityCacheUsage.NonStrictReadWrite;
+ ce.RegionName = "MyRegion";
+ ce.Collection(e => e.Elements, cc =>
+ {
+ cc.RegionName = "MyCollectionRegion";
+ cc.Strategy =
+ EntityCacheUsage.NonStrictReadWrite;
+ });
+ });
+
+ Mapping.Collection pc = configure.GetCollectionMapping("NHibernate.Test.CfgTest.Loquacious.EntityToCache.Elements");
+ Assert.That(pc.CacheConcurrencyStrategy,
+ Is.EqualTo(EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite)));
+ Assert.That(pc.CacheRegionName, Is.EqualTo("MyCollectionRegion"));
+ }
+
+ [Test]
+ public void ConfigureCacheOfCollectionWithOutEntity()
+ {
+ Configuration configure = new Configuration().Configure();
+ configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly);
+
+ configure.EntityCache<EntityToCache>(ce => ce.Collection(e => e.Elements, cc =>
+ {
+ cc.RegionName = "MyCollectionRegion";
+ cc.Strategy =
+ EntityCacheUsage.NonStrictReadWrite;
+ }));
+
+ var pc = (RootClass) configure.GetClassMapping(typeof (EntityToCache));
+ Assert.That(pc.CacheConcurrencyStrategy, Is.Null);
+ }
+
+ [Test]
+ public void NotAllowRelatedCollections()
+ {
+ Configuration configure = new Configuration().Configure();
+ configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly);
+
+ var exception =
+ Assert.Throws<ArgumentOutOfRangeException>(
+ () => configure.EntityCache<EntityToCache>(ce => ce.Collection(e => e.Relation.Elements, cc => { })));
+ Assert.That(exception.Message, Text.Contains("Collection not owned by"));
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/EntityToCache.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/EntityToCache.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/EntityToCache.cs 2009-07-17 20:36:48 UTC (rev 4651)
@@ -0,0 +1,16 @@
+using System.Collections.Generic;
+
+namespace NHibernate.Test.CfgTest.Loquacious
+{
+ public class EntityToCache
+ {
+ public string Name { get; set; }
+ public IList<string> Elements { get; set; }
+ public AnotherEntity Relation { get; set; }
+ }
+
+ public class AnotherEntity
+ {
+ public IList<string> Elements { get; set; }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/EntityToCache.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/EntityToCache.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/EntityToCache.hbm.xml 2009-07-17 20:36:48 UTC (rev 4651)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.CfgTest.Loquacious"
+ assembly="NHibernate.Test">
+
+ <class name="EntityToCache">
+ <id name="Id" type="Int32">
+ <generator class="hilo" />
+ </id>
+
+ <property name="Name" />
+ <bag name="Elements">
+ <key column="parentId"/>
+ <element type="string"/>
+ </bag>
+ </class>
+</hibernate-mapping>
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-17 17:02:38 UTC (rev 4650)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-17 20:36:48 UTC (rev 4651)
@@ -109,6 +109,8 @@
<Compile Include="CfgTest\HbmOrderingFixture.cs" />
<Compile Include="CfgTest\LocatedInTestAssembly.cs" />
<Compile Include="CfgTest\Loquacious\ConfigurationFixture.cs" />
+ <Compile Include="CfgTest\Loquacious\EntityCacheConfigurationFixture.cs" />
+ <Compile Include="CfgTest\Loquacious\EntityToCache.cs" />
<Compile Include="CfgTest\Loquacious\LambdaConfigurationFixture.cs" />
<Compile Include="CfgTest\MappingDocumentAggregatorTests.cs" />
<Compile Include="CfgTest\MappingDocumentParserTests.cs" />
@@ -1368,6 +1370,7 @@
<Compile Include="UserCollection\User.cs" />
<Compile Include="UserCollection\UserCollectionTypeTest.cs" />
<Compile Include="UtilityTest\AssemblyQualifiedTypeNameFixture.cs" />
+ <Compile Include="UtilityTest\ExpressionsHelperFixture.cs" />
<Compile Include="UtilityTest\IdentityMapFixture.cs" />
<Compile Include="UtilityTest\IdentityMapSequencedFixture.cs" />
<Compile Include="UtilityTest\JoinedEnumerableFixture.cs" />
@@ -1957,6 +1960,7 @@
<EmbeddedResource Include="Bytecode\Lightweight\ProductLine.hbm.xml" />
<EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" />
<EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" />
+ <EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
<EmbeddedResource Include="NHSpecificTest\NH1877\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1868\Mappings.hbm.xml" />
Added: trunk/nhibernate/src/NHibernate.Test/UtilityTest/ExpressionsHelperFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/UtilityTest/ExpressionsHelperFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/UtilityTest/ExpressionsHelperFixture.cs 2009-07-17 20:36:48 UTC (rev 4651)
@@ -0,0 +1,39 @@
+using NHibernate.Util;
+using NUnit.Framework;
+using System.Collections.Generic;
+
+namespace NHibernate.Test.UtilityTest
+{
+ public class TestingClass
+ {
+ public int IntProp
+ {
+ get { return 0; }
+ }
+
+ public bool BoolProp
+ {
+ get { return false; }
+ }
+
+ public IEnumerable<string> CollectionProp
+ {
+ get { return new string[0]; }
+ }
+ }
+
+ [TestFixture]
+ public class ExpressionsHelperFixture
+ {
+ [Test]
+ public void DecodeMemberAccessExpression()
+ {
+ Assert.That(ExpressionsHelper.DecodeMemberAccessExpression<TestingClass, int>(x => x.IntProp),
+ Is.EqualTo(typeof(TestingClass).GetMember("IntProp")[0]));
+ Assert.That(ExpressionsHelper.DecodeMemberAccessExpression<TestingClass, bool>(x => x.BoolProp),
+ Is.EqualTo(typeof(TestingClass).GetMember("BoolProp")[0]));
+ Assert.That(ExpressionsHelper.DecodeMemberAccessExpression<TestingClass, IEnumerable<string>>(x => x.CollectionProp),
+ Is.EqualTo(typeof(TestingClass).GetMember("CollectionProp")[0]));
+ }
+ }
+}
\ 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...> - 2009-07-19 22:23:05
|
Revision: 4656
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4656&view=rev
Author: fabiomaulo
Date: 2009-07-19 22:22:59 +0000 (Sun, 19 Jul 2009)
Log Message:
-----------
TypeDefinition configuration by code
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ITypeDefConfiguration.cs
trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/TypeDefinitionFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs 2009-07-19 12:35:19 UTC (rev 4655)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs 2009-07-19 22:22:59 UTC (rev 4656)
@@ -1,5 +1,6 @@
using System;
using NHibernate.Hql;
+using NHibernate.Util;
namespace NHibernate.Cfg.Loquacious
{
@@ -60,16 +61,70 @@
entityCacheConfiguration(ecc);
if (ecc.Strategy.HasValue)
{
- configuration.SetCacheConcurrencyStrategy(typeof (TEntity).FullName, EntityCacheUsageParser.ToString(ecc.Strategy.Value),
- ecc.RegionName);
+ configuration.SetCacheConcurrencyStrategy(typeof(TEntity).FullName, EntityCacheUsageParser.ToString(ecc.Strategy.Value),
+ ecc.RegionName);
}
foreach (var collection in ecc.Collections)
{
configuration.SetCollectionCacheConcurrencyStrategy(collection.Key,
- EntityCacheUsageParser.ToString(collection.Value.Strategy),
- collection.Value.RegionName);
+ EntityCacheUsageParser.ToString(collection.Value.Strategy),
+ collection.Value.RegionName);
}
return configuration;
}
+
+ /// <summary>
+ /// Add a type-definition for mappings.
+ /// </summary>
+ /// <typeparam name="TDef">The peristent type.</typeparam>
+ /// <param name="configuration">The <see cref="Configuration"/> where add the type-definition.</param>
+ /// <param name="typeDefConfiguration">The custom configuration action.</param>
+ /// <returns>The <see cref="Configuration"/>.</returns>
+ /// <remarks>
+ /// <para>
+ /// <list type="bullet">
+ /// <listheader>
+ /// <description>Depending on where you will use the type-definition in the mapping the
+ /// <typeparamref name="TDef"/> can be :
+ /// </description>
+ ///</listheader>
+ ///<item>
+ /// <term><see cref="NHibernate.UserTypes.IUserType"/></term>
+ ///</item>
+ ///<item>
+ /// <term><see cref="NHibernate.UserTypes.IUserCollectionType"/></term>
+ ///</item>
+ ///<item>
+ /// <term><see cref="NHibernate.UserTypes.IUserVersionType"/></term>
+ ///</item>
+ ///<item>
+ /// <term><see cref="NHibernate.Id.IPersistentIdentifierGenerator"/> </term>
+ ///</item>
+ ///</list>
+ /// </para>
+ /// </remarks>
+ public static Configuration TypeDefinition<TDef>(this Configuration configuration, Action<ITypeDefConfigurationProperties> typeDefConfiguration)
+ where TDef : class
+ {
+ if (typeDefConfiguration == null)
+ {
+ return configuration;
+ }
+ var tdConfiguration = new TypeDefConfigurationProperties<TDef>();
+ typeDefConfiguration(tdConfiguration);
+ if(string.IsNullOrEmpty(tdConfiguration.Alias))
+ {
+ return configuration;
+ }
+ var mappings = GetMappings(configuration);
+ mappings.AddTypeDef(tdConfiguration.Alias, typeof(TDef).AssemblyQualifiedName, tdConfiguration.Properties.ToTypeParameters());
+ return configuration;
+ }
+
+ private static Mappings GetMappings(Configuration configuration)
+ {
+ Dialect.Dialect dialect = Dialect.Dialect.GetDialect(configuration.Properties);
+ return configuration.CreateMappings(dialect);
+ }
}
}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ITypeDefConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ITypeDefConfiguration.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/Loquacious/ITypeDefConfiguration.cs 2009-07-19 22:22:59 UTC (rev 4656)
@@ -0,0 +1,48 @@
+namespace NHibernate.Cfg.Loquacious
+{
+ /// <summary>
+ /// Properties of TypeDef configuration.
+ /// </summary>
+ /// <seealso cref="ConfigurationExtensions.TypeDefinition{TDef}<>"/>
+ public interface ITypeDefConfigurationProperties
+ {
+ /// <summary>
+ /// The key to use the type-definition inside not strongly typed mappings (XML mapping).
+ /// </summary>
+ string Alias { get; set; }
+
+ /// <summary>
+ /// An <see cref="object"/> which public properties are used as
+ /// type-definition pareneters or null where type-definition does not need parameters or you want use default values.
+ /// </summary>
+ /// <remarks>
+ /// <example>
+ /// As <paramref name="value"/> an anonimous object can be used:
+ /// <code>
+ /// configure.TypeDefinition<TableHiLoGenerator>(c=>
+ /// {
+ /// c.Alias = "HighLow";
+ /// c.Properties = new {max_lo = 99};
+ /// });
+ /// </code>
+ /// </example>
+ /// </remarks>
+ object Properties { get; set; }
+ }
+
+ internal class TypeDefConfigurationProperties<T> : ITypeDefConfigurationProperties
+ where T: class
+ {
+ public TypeDefConfigurationProperties()
+ {
+ Alias = typeof(T).Name;
+ }
+
+ #region Implementation of ITypeDefConfigurationProperties
+
+ public string Alias { get; set; }
+ public object Properties { get; set; }
+
+ #endregion
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-19 12:35:19 UTC (rev 4655)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-19 22:22:59 UTC (rev 4656)
@@ -479,6 +479,7 @@
<Compile Include="Cfg\Loquacious\IProxyConfiguration.cs" />
<Compile Include="Cfg\Loquacious\IQueryCacheConfiguration.cs" />
<Compile Include="Cfg\Loquacious\ITransactionConfiguration.cs" />
+ <Compile Include="Cfg\Loquacious\ITypeDefConfiguration.cs" />
<Compile Include="Cfg\Loquacious\MappingsConfiguration.cs" />
<Compile Include="Cfg\Loquacious\ProxyConfiguration.cs" />
<Compile Include="Cfg\SchemaAutoAction.cs" />
Modified: trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs 2009-07-19 12:35:19 UTC (rev 4655)
+++ trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs 2009-07-19 22:22:59 UTC (rev 4656)
@@ -594,5 +594,28 @@
}
return result;
}
+
+ public static IDictionary<string,string> ToTypeParameters(this object source)
+ {
+ if(source == null)
+ {
+ return new Dictionary<string, string>(1);
+ }
+ var props = source.GetType().GetProperties();
+ if(props.Length == 0)
+ {
+ return new Dictionary<string, string>(1);
+ }
+ var result = new Dictionary<string, string>(props.Length);
+ foreach (var prop in props)
+ {
+ var value = prop.GetValue(source, null);
+ if (!ReferenceEquals(null, value))
+ {
+ result[prop.Name] = value.ToString();
+ }
+ }
+ return result;
+ }
}
}
Added: trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/TypeDefinitionFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/TypeDefinitionFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/Loquacious/TypeDefinitionFixture.cs 2009-07-19 22:22:59 UTC (rev 4656)
@@ -0,0 +1,28 @@
+using NHibernate.Cfg;
+using NHibernate.Cfg.Loquacious;
+using NHibernate.Dialect;
+using NHibernate.Id;
+using NUnit.Framework;
+
+namespace NHibernate.Test.CfgTest.Loquacious
+{
+ [TestFixture]
+ public class TypeDefinitionFixture
+ {
+ [Test]
+ public void AddTypeDef()
+ {
+ var configure = new Configuration()
+ .DataBaseIntegration(db => db.Dialect<MsSql2005Dialect>());
+ configure.TypeDefinition<TableHiLoGenerator>(c=>
+ {
+ c.Alias = "HighLow";
+ c.Properties = new {max_lo = 99};
+ });
+ var mappings = configure.CreateMappings(Dialect.Dialect.GetDialect(configure.Properties));
+ var typeDef = mappings.GetTypeDef("HighLow");
+ Assert.That(typeDef, Is.Not.Null);
+ Assert.That(typeDef.Parameters["max_lo"], Is.EqualTo("99"));
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-19 12:35:19 UTC (rev 4655)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-19 22:22:59 UTC (rev 4656)
@@ -112,6 +112,7 @@
<Compile Include="CfgTest\Loquacious\EntityCacheConfigurationFixture.cs" />
<Compile Include="CfgTest\Loquacious\EntityToCache.cs" />
<Compile Include="CfgTest\Loquacious\LambdaConfigurationFixture.cs" />
+ <Compile Include="CfgTest\Loquacious\TypeDefinitionFixture.cs" />
<Compile Include="CfgTest\MappingDocumentAggregatorTests.cs" />
<Compile Include="CfgTest\MappingDocumentParserTests.cs" />
<Compile Include="CfgTest\SchemaAutoActionFixture.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dav...@us...> - 2009-07-26 15:07:47
|
Revision: 4657
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4657&view=rev
Author: davybrion
Date: 2009-07-26 15:07:33 +0000 (Sun, 26 Jul 2009)
Log Message:
-----------
applying patch from Armin Landscheidt to fix NH-1902
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/Example.cs
trunk/nhibernate/src/NHibernate.Test/ExpressionTest/QueryByExampleTest.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/Example.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/Example.cs 2009-07-19 22:22:59 UTC (rev 4656)
+++ trunk/nhibernate/src/NHibernate/Criterion/Example.cs 2009-07-26 15:07:33 UTC (rev 4657)
@@ -481,7 +481,7 @@
{
bool isString = propertyValue is String;
crit = (_isLikeEnabled && isString) ?
- (ICriterion) new LikeExpression(propertyName, propertyValue.ToString(), escapeCharacter, _isIgnoreCaseEnabled) :
+ (ICriterion) new LikeExpression(propertyName, propertyValue.ToString(), _matchMode, escapeCharacter, _isIgnoreCaseEnabled) :
new SimpleExpression(propertyName, propertyValue, " = ", _isIgnoreCaseEnabled && isString);
}
else
Modified: trunk/nhibernate/src/NHibernate.Test/ExpressionTest/QueryByExampleTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/ExpressionTest/QueryByExampleTest.cs 2009-07-19 22:22:59 UTC (rev 4656)
+++ trunk/nhibernate/src/NHibernate.Test/ExpressionTest/QueryByExampleTest.cs 2009-07-26 15:07:33 UTC (rev 4657)
@@ -42,6 +42,51 @@
}
[Test]
+ public void TestEnableLikeWithMatchmodeStart() {
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction()) {
+ Componentizable master = GetMaster("hib", null, "open source1");
+ ICriteria crit = s.CreateCriteria(typeof(Componentizable));
+ Example ex = Example.Create(master).EnableLike(MatchMode.Start);
+ crit.Add(ex);
+ IList result = crit.List();
+ Assert.IsNotNull(result);
+ Assert.AreEqual(1, result.Count);
+ t.Commit();
+ }
+ }
+
+ [Test]
+ public void TestEnableLikeWithMatchmodeEnd() {
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction()) {
+ Componentizable master = GetMaster("nate", null, "ORM tool1");
+ ICriteria crit = s.CreateCriteria(typeof(Componentizable));
+ Example ex = Example.Create(master).EnableLike(MatchMode.End);
+ crit.Add(ex);
+ IList result = crit.List();
+ Assert.IsNotNull(result);
+ Assert.AreEqual(1, result.Count);
+ t.Commit();
+ }
+ }
+
+ [Test]
+ public void TestEnableLikeWithMatchmodeAnywhere() {
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction()) {
+ Componentizable master = GetMaster("bern", null, null);
+ ICriteria crit = s.CreateCriteria(typeof(Componentizable));
+ Example ex = Example.Create(master).EnableLike(MatchMode.Anywhere);
+ crit.Add(ex);
+ IList result = crit.List();
+ Assert.IsNotNull(result);
+ Assert.AreEqual(3, result.Count);
+ t.Commit();
+ }
+ }
+
+ [Test]
public void TestJunctionNotExpressionQBE()
{
using (ISession s = OpenSession())
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ric...@us...> - 2009-07-27 09:42:23
|
Revision: 4661
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4661&view=rev
Author: ricbrown
Date: 2009-07-27 09:42:13 +0000 (Mon, 27 Jul 2009)
Log Message:
-----------
Added syntax for IQueryOver.Select(...)
Modified Paths:
--------------
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/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-26 17:02:35 UTC (rev 4660)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-27 09:42:13 UTC (rev 4661)
@@ -62,6 +62,22 @@
return Add(expression);
}
+ public QueryOver<T> Select(Expression<Func<object>>[] projections)
+ {
+ foreach (var projection in projections)
+ Select(projection);
+
+ return this;
+ }
+
+ public QueryOver<T> Select(Expression<Func<T, object>>[] projections)
+ {
+ foreach (var projection in projections)
+ Select(projection);
+
+ return this;
+ }
+
public QueryOver<T> OrderBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
{
return AddOrder(path, orderDelegate);
@@ -214,6 +230,16 @@
return this;
}
+ private void Select(Expression<Func<T, object>> projection)
+ {
+ _criteria.SetProjection(Projections.Property(ExpressionProcessor.FindMemberExpression(projection.Body)));
+ }
+
+ private void Select(Expression<Func<object>> projection)
+ {
+ _criteria.SetProjection(Projections.Property(ExpressionProcessor.FindMemberExpression(projection.Body)));
+ }
+
private QueryOver<T> AddOrder(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
{
_criteria.AddOrder(ExpressionProcessor.ProcessOrder<T>(path, orderDelegate));
@@ -239,6 +265,12 @@
IQueryOver<T> IQueryOver<T>.Where(Expression<Func<bool>> expression)
{ return Where(expression); }
+ IQueryOver<T> IQueryOver<T>.Select(params Expression<Func<T, object>>[] projections)
+ { return Select(projections); }
+
+ IQueryOver<T> IQueryOver<T>.Select(params Expression<Func<object>>[] projections)
+ { return Select(projections); }
+
IQueryOver<T> IQueryOver<T>.OrderBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
{ return OrderBy(path, orderDelegate); }
@@ -293,6 +325,9 @@
IQueryOverJoinBuilder<T> IQueryOver<T>.Full
{ get { return new IQueryOverJoinBuilder<T>(this, JoinType.FullJoin); } }
+ IList<T> IQueryOver<T>.List()
+ { return List(); }
+
}
}
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-26 17:02:35 UTC (rev 4660)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-27 09:42:13 UTC (rev 4661)
@@ -53,6 +53,20 @@
IQueryOver<T> Where(Expression<Func<bool>> expression);
/// <summary>
+ /// Add projection expressed as a lambda expression
+ /// </summary>
+ /// <param name="projections">Lambda expressions</param>
+ /// <returns>criteria instance</returns>
+ IQueryOver<T> Select(params Expression<Func<T, object>>[] projections);
+
+ /// <summary>
+ /// Add projection expressed as a lambda expression
+ /// </summary>
+ /// <param name="projections">Lambda expressions</param>
+ /// <returns>criteria instance</returns>
+ IQueryOver<T> Select(params Expression<Func<object>>[] projections);
+
+ /// <summary>
/// Add order 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 2009-07-26 17:02:35 UTC (rev 4660)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-27 09:42:13 UTC (rev 4661)
@@ -259,6 +259,27 @@
AssertCriteriaAreEqual(expected, actual);
}
+ [Test]
+ public void Project()
+ {
+ ICriteria expected =
+ CreateTestCriteria(typeof(Person), "personAlias")
+ .SetProjection(Projections.Property("Name"))
+ .SetProjection(Projections.Property("Age"))
+ .SetProjection(Projections.Property("personAlias.Gender"))
+ .SetProjection(Projections.Property("personAlias.HasCar"));
+
+ Person personAlias = null;
+ IQueryOver<Person> actual =
+ CreateTestQueryOver<Person>(() => personAlias)
+ .Select(p => p.Name,
+ p => p.Age)
+ .Select(() => personAlias.Gender,
+ () => personAlias.HasCar);
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
}
}
\ 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: <ric...@us...> - 2009-07-27 10:49:27
|
Revision: 4662
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4662&view=rev
Author: ricbrown
Date: 2009-07-27 10:49:18 +0000 (Mon, 27 Jul 2009)
Log Message:
-----------
Corrected syntax for IQueryOver.Select(...)
Modified Paths:
--------------
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/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-27 09:42:13 UTC (rev 4661)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-27 10:49:18 UTC (rev 4662)
@@ -62,19 +62,14 @@
return Add(expression);
}
- public QueryOver<T> Select(Expression<Func<object>>[] projections)
+ public QueryOver<T> Select(params Expression<Func<T, object>>[] projections)
{
- foreach (var projection in projections)
- Select(projection);
+ List<IProjection> projectionList = new List<IProjection>();
- return this;
- }
-
- public QueryOver<T> Select(Expression<Func<T, object>>[] projections)
- {
foreach (var projection in projections)
- Select(projection);
+ projectionList.Add(Projections.Property(ExpressionProcessor.FindMemberExpression(projection.Body)));
+ _criteria.SetProjection(projectionList.ToArray());
return this;
}
@@ -230,16 +225,6 @@
return this;
}
- private void Select(Expression<Func<T, object>> projection)
- {
- _criteria.SetProjection(Projections.Property(ExpressionProcessor.FindMemberExpression(projection.Body)));
- }
-
- private void Select(Expression<Func<object>> projection)
- {
- _criteria.SetProjection(Projections.Property(ExpressionProcessor.FindMemberExpression(projection.Body)));
- }
-
private QueryOver<T> AddOrder(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
{
_criteria.AddOrder(ExpressionProcessor.ProcessOrder<T>(path, orderDelegate));
@@ -268,9 +253,6 @@
IQueryOver<T> IQueryOver<T>.Select(params Expression<Func<T, object>>[] projections)
{ return Select(projections); }
- IQueryOver<T> IQueryOver<T>.Select(params Expression<Func<object>>[] projections)
- { return Select(projections); }
-
IQueryOver<T> IQueryOver<T>.OrderBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
{ return OrderBy(path, orderDelegate); }
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-27 09:42:13 UTC (rev 4661)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-27 10:49:18 UTC (rev 4662)
@@ -60,13 +60,6 @@
IQueryOver<T> Select(params Expression<Func<T, object>>[] projections);
/// <summary>
- /// Add projection expressed as a lambda expression
- /// </summary>
- /// <param name="projections">Lambda expressions</param>
- /// <returns>criteria instance</returns>
- IQueryOver<T> Select(params Expression<Func<object>>[] projections);
-
- /// <summary>
/// Add order 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 2009-07-27 09:42:13 UTC (rev 4661)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-27 10:49:18 UTC (rev 4662)
@@ -264,18 +264,19 @@
{
ICriteria expected =
CreateTestCriteria(typeof(Person), "personAlias")
- .SetProjection(Projections.Property("Name"))
- .SetProjection(Projections.Property("Age"))
- .SetProjection(Projections.Property("personAlias.Gender"))
- .SetProjection(Projections.Property("personAlias.HasCar"));
+ .SetProjection(
+ Projections.Property("Name"),
+ Projections.Property("Age"),
+ Projections.Property("personAlias.Gender"),
+ Projections.Property("personAlias.HasCar"));
Person personAlias = null;
IQueryOver<Person> actual =
CreateTestQueryOver<Person>(() => personAlias)
.Select(p => p.Name,
- p => p.Age)
- .Select(() => personAlias.Gender,
- () => personAlias.HasCar);
+ p => p.Age,
+ p => personAlias.Gender,
+ p => personAlias.HasCar);
AssertCriteriaAreEqual(expected, actual);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ric...@us...> - 2009-07-27 14:41:49
|
Revision: 4663
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4663&view=rev
Author: ricbrown
Date: 2009-07-27 14:41:38 +0000 (Mon, 27 Jul 2009)
Log Message:
-----------
Added integration test for IQueryOver projections.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
trunk/nhibernate/src/NHibernate/IQueryOver.cs
trunk/nhibernate/src/NHibernate/ISession.cs
trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-27 10:49:18 UTC (rev 4662)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-27 14:41:38 UTC (rev 4663)
@@ -198,6 +198,11 @@
return _criteria.List<T>();
}
+ public IList<U> List<U>()
+ {
+ return _criteria.List<U>();
+ }
+
/// <summary>
/// Get an executable instance of <c>IQueryOver<T></c>,
/// to actually run the query.</summary>
@@ -310,6 +315,9 @@
IList<T> IQueryOver<T>.List()
{ return List(); }
+ IList<U> IQueryOver<T>.List<U>()
+ { return List<U>(); }
+
}
}
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-27 10:49:18 UTC (rev 4662)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-27 14:41:38 UTC (rev 4663)
@@ -195,6 +195,12 @@
/// <returns>The list filled with the results.</returns>
IList<T> List();
+ /// <summary>
+ /// Get the results of the root type and fill the <see cref="IList<T>"/>
+ /// </summary>
+ /// <returns>The list filled with the results.</returns>
+ IList<U> List<U>();
+
}
}
Modified: trunk/nhibernate/src/NHibernate/ISession.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/ISession.cs 2009-07-27 10:49:18 UTC (rev 4662)
+++ trunk/nhibernate/src/NHibernate/ISession.cs 2009-07-27 14:41:38 UTC (rev 4663)
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Data;
+using System.Linq.Expressions;
using NHibernate.Engine;
using NHibernate.Stat;
using NHibernate.Type;
@@ -783,13 +784,20 @@
ICriteria CreateCriteria(string entityName, string alias);
/// <summary>
- /// Creates a new <c>ICriteria<T></c> for the entity class.
+ /// Creates a new <c>IQueryOver<T></c> for the entity class.
/// </summary>
/// <typeparam name="T">The entity class</typeparam>
/// <returns>An ICriteria<T> object</returns>
IQueryOver<T> QueryOver<T>() where T : class;
/// <summary>
+ /// Creates a new <c>IQueryOver<T></c> for the entity class.
+ /// </summary>
+ /// <typeparam name="T">The entity class</typeparam>
+ /// <returns>An ICriteria<T> object</returns>
+ IQueryOver<T> QueryOver<T>(Expression<Func<T>> alias) where T : class;
+
+ /// <summary>
/// Create a new instance of <c>Query</c> for the given query string
/// </summary>
/// <param name="queryString">A hibernate query string</param>
Modified: trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2009-07-27 10:49:18 UTC (rev 4662)
+++ trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2009-07-27 14:41:38 UTC (rev 4663)
@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Data;
+using System.Linq.Expressions;
using System.Runtime.Serialization;
using System.Security.Permissions;
using Iesi.Collections;
@@ -1881,6 +1882,16 @@
}
}
+ public IQueryOver<T> QueryOver<T>(Expression<Func<T>> alias) where T : class
+ {
+ using (new SessionIdLoggingContext(SessionId))
+ {
+ CheckAndUpdateSessionStatus();
+ string aliasPath = ExpressionProcessor.FindMemberExpression(alias.Body);
+ return new QueryOver<T>(new CriteriaImpl(typeof(T), aliasPath, this));
+ }
+ }
+
public override IList List(CriteriaImpl criteria)
{
using (new SessionIdLoggingContext(SessionId))
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2009-07-27 10:49:18 UTC (rev 4662)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2009-07-27 14:41:38 UTC (rev 4663)
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Linq;
using NUnit.Framework;
@@ -91,6 +92,59 @@
}
}
+ [Test]
+ public void Project_SingleProperty()
+ {
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ s.Save(new Person() { Name = "test person 1", Age = 20 });
+ s.Save(new Person() { Name = "test person 2", Age = 30 });
+ t.Commit();
+ }
+
+ using (ISession s = OpenSession())
+ {
+ var actual =
+ s.QueryOver<Person>()
+ .Select(p => p.Age)
+ .OrderBy(p => p.Age, Order.Asc)
+ .List<int>();
+
+ Assert.That(actual[0], Is.EqualTo(20));
+ }
+ }
+
+ [Test]
+ public void Project_MultipleProperties()
+ {
+ using (ISession s = OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ s.Save(new Person() { Name = "test person 1", Age = 20 });
+ s.Save(new Person() { Name = "test person 2", Age = 30 });
+ t.Commit();
+ }
+
+ using (ISession s = OpenSession())
+ {
+ Person personAlias = null;
+ var actual =
+ s.QueryOver<Person>(() => personAlias)
+ .Select(p => p.Name,
+ p => personAlias.Age)
+ .OrderBy(p => p.Age, Order.Asc)
+ .List<object[]>()
+ .Select(props => new {
+ TestName = (string)props[0],
+ TestAge = (int)props[1],
+ });
+
+ Assert.That(actual.ElementAt(0).TestName, Is.EqualTo("test person 1"));
+ Assert.That(actual.ElementAt(1).TestAge, Is.EqualTo(30));
+ }
+ }
+
}
}
\ 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: <ric...@us...> - 2009-07-27 22:29:02
|
Revision: 4665
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4665&view=rev
Author: ricbrown
Date: 2009-07-27 22:28:49 +0000 (Mon, 27 Jul 2009)
Log Message:
-----------
Added paging methods to IQueryOver.
Modified Paths:
--------------
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/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-27 21:24:37 UTC (rev 4664)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-27 22:28:49 UTC (rev 4665)
@@ -93,6 +93,18 @@
return AddOrder(path, orderDelegate);
}
+ public IQueryOver<T> Skip(int firstResult)
+ {
+ _criteria.SetFirstResult(firstResult);
+ return this;
+ }
+
+ public IQueryOver<T> Take(int maxResults)
+ {
+ _criteria.SetMaxResults(maxResults);
+ return this;
+ }
+
public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path)
{
return new QueryOver<U>(_impl,
@@ -243,6 +255,9 @@
}
+ ICriteria IQueryOver<T>.UnderlyingCriteria
+ { get { return UnderlyingCriteria; } }
+
IQueryOver<T> IQueryOver<T>.And(Expression<Func<T, bool>> expression)
{ return And(expression); }
@@ -270,6 +285,12 @@
IQueryOver<T> IQueryOver<T>.ThenBy(Expression<Func<object>> path, Func<string, Order> orderDelegate)
{ return ThenBy(path, orderDelegate); }
+ IQueryOver<T> IQueryOver<T>.Skip(int firstResult)
+ { return Skip(firstResult); }
+
+ IQueryOver<T> IQueryOver<T>.Take(int maxResults)
+ { return Take(maxResults); }
+
IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, U>> path)
{ return JoinQueryOver(path); }
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-27 21:24:37 UTC (rev 4664)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-27 22:28:49 UTC (rev 4665)
@@ -97,6 +97,18 @@
IQueryOver<T> ThenBy(Expression<Func<object>> path, Func<string, Order> orderDelegate);
/// <summary>
+ /// Set the first result to be retrieved
+ /// </summary>
+ /// <param name="firstResult"></param>
+ IQueryOver<T> Skip(int firstResult);
+
+ /// <summary>
+ /// Set a limit upon the number of objects to be retrieved
+ /// </summary>
+ /// <param name="maxResults"></param>
+ IQueryOver<T> Take(int maxResults);
+
+ /// <summary>
/// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-27 21:24:37 UTC (rev 4664)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-27 22:28:49 UTC (rev 4665)
@@ -281,6 +281,22 @@
AssertCriteriaAreEqual(expected, actual);
}
+ [Test]
+ public void Paging()
+ {
+ ICriteria expected =
+ CreateTestCriteria(typeof(Person))
+ .SetFirstResult(90)
+ .SetMaxResults(10);
+
+ IQueryOver<Person> actual =
+ CreateTestQueryOver<Person>()
+ .Skip(90)
+ .Take(10);
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
}
}
\ 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: <ric...@us...> - 2009-07-28 19:40:45
|
Revision: 4666
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4666&view=rev
Author: ricbrown
Date: 2009-07-28 19:40:32 +0000 (Tue, 28 Jul 2009)
Log Message:
-----------
Added Cachable() to IQueryOver.
Modified Paths:
--------------
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/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-27 22:28:49 UTC (rev 4665)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-28 19:40:32 UTC (rev 4666)
@@ -105,6 +105,12 @@
return this;
}
+ public IQueryOver<T> Cacheable()
+ {
+ _criteria.SetCacheable(true);
+ return this;
+ }
+
public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path)
{
return new QueryOver<U>(_impl,
@@ -291,6 +297,9 @@
IQueryOver<T> IQueryOver<T>.Take(int maxResults)
{ return Take(maxResults); }
+ IQueryOver<T> IQueryOver<T>.Cacheable()
+ { return Cacheable(); }
+
IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, U>> path)
{ return JoinQueryOver(path); }
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-27 22:28:49 UTC (rev 4665)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-28 19:40:32 UTC (rev 4666)
@@ -109,6 +109,11 @@
IQueryOver<T> Take(int maxResults);
/// <summary>
+ /// Enable caching of this query result set
+ /// </summary>
+ IQueryOver<T> Cacheable();
+
+ /// <summary>
/// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-27 22:28:49 UTC (rev 4665)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-28 19:40:32 UTC (rev 4666)
@@ -297,6 +297,20 @@
AssertCriteriaAreEqual(expected, actual);
}
+ [Test]
+ public void Cachable()
+ {
+ ICriteria expected =
+ CreateTestCriteria(typeof(Person))
+ .SetCacheable(true);
+
+ IQueryOver<Person> actual =
+ CreateTestQueryOver<Person>()
+ .Cacheable();
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
}
}
\ 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: <ric...@us...> - 2009-07-28 20:09:53
|
Revision: 4667
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4667&view=rev
Author: ricbrown
Date: 2009-07-28 20:09:38 +0000 (Tue, 28 Jul 2009)
Log Message:
-----------
Added CacheMode and CacheRegion to IQueryOver.
Modified Paths:
--------------
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/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-28 19:40:32 UTC (rev 4666)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-28 20:09:38 UTC (rev 4667)
@@ -111,6 +111,18 @@
return this;
}
+ public IQueryOver<T> CacheMode(CacheMode cacheMode)
+ {
+ _criteria.SetCacheMode(cacheMode);
+ return this;
+ }
+
+ public IQueryOver<T> CacheRegion(string cacheRegion)
+ {
+ _criteria.SetCacheRegion(cacheRegion);
+ return this;
+ }
+
public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path)
{
return new QueryOver<U>(_impl,
@@ -300,6 +312,12 @@
IQueryOver<T> IQueryOver<T>.Cacheable()
{ return Cacheable(); }
+ IQueryOver<T> IQueryOver<T>.CacheMode(CacheMode cacheMode)
+ { return CacheMode(cacheMode); }
+
+ IQueryOver<T> IQueryOver<T>.CacheRegion(string cacheRegion)
+ { return CacheRegion(cacheRegion); }
+
IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, U>> path)
{ return JoinQueryOver(path); }
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-28 19:40:32 UTC (rev 4666)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-28 20:09:38 UTC (rev 4667)
@@ -113,7 +113,19 @@
/// </summary>
IQueryOver<T> 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<T> 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<T> CacheRegion(string cacheRegion);
+
+ /// <summary>
/// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-28 19:40:32 UTC (rev 4666)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-28 20:09:38 UTC (rev 4667)
@@ -302,11 +302,15 @@
{
ICriteria expected =
CreateTestCriteria(typeof(Person))
- .SetCacheable(true);
+ .SetCacheable(true)
+ .SetCacheMode(CacheMode.Put)
+ .SetCacheRegion("my cache region");
IQueryOver<Person> actual =
CreateTestQueryOver<Person>()
- .Cacheable();
+ .Cacheable()
+ .CacheMode(CacheMode.Put)
+ .CacheRegion("my cache region");
AssertCriteriaAreEqual(expected, actual);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ric...@us...> - 2009-07-29 18:46:51
|
Revision: 4668
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4668&view=rev
Author: ricbrown
Date: 2009-07-29 18:46:44 +0000 (Wed, 29 Jul 2009)
Log Message:
-----------
Added handling for Lambda syntax allowing path including collections.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs
Modified: trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2009-07-28 20:09:38 UTC (rev 4667)
+++ trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2009-07-29 18:46:44 UTC (rev 4668)
@@ -121,10 +121,15 @@
{
MemberExpression memberExpression = (MemberExpression)expression;
- if (memberExpression.Expression.NodeType == ExpressionType.MemberAccess)
+ if (memberExpression.Expression.NodeType == ExpressionType.MemberAccess
+ || memberExpression.Expression.NodeType == ExpressionType.Call)
+ {
return FindMemberExpression(memberExpression.Expression) + "." + memberExpression.Member.Name;
+ }
else
+ {
return memberExpression.Member.Name;
+ }
}
if (expression is UnaryExpression)
@@ -149,6 +154,12 @@
return "class";
}
+ if (methodCallExpression.Method.Name == "get_Item")
+ return FindMemberExpression(methodCallExpression.Object);
+
+ if (methodCallExpression.Method.Name == "First")
+ return FindMemberExpression(methodCallExpression.Arguments[0]);
+
throw new Exception("Unrecognised method call in epression " + expression.ToString());
}
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs 2009-07-28 20:09:38 UTC (rev 4667)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs 2009-07-29 18:46:44 UTC (rev 4668)
@@ -1,5 +1,6 @@
using System;
+using System.Linq;
using System.Linq.Expressions;
using NHibernate.Criterion;
@@ -31,6 +32,22 @@
}
[Test]
+ public void TestFindMemberExpressionSubCollectionIndex()
+ {
+ Expression<Func<Person, object>> e = (Person p) => p.PersonList[0].Children;
+ string property = ExpressionProcessor.FindMemberExpression(e.Body);
+ Assert.AreEqual("PersonList.Children", property);
+ }
+
+ [Test]
+ public void TestFindMemberExpressionSubCollectionExtensionMethod()
+ {
+ Expression<Func<Person, object>> e = (Person p) => p.PersonList.First().Children;
+ string property = ExpressionProcessor.FindMemberExpression(e.Body);
+ Assert.AreEqual("PersonList.Children", property);
+ }
+
+ [Test]
public void TestEvaluatePropertyExpression()
{
string testName = "testName";
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-07-28 20:09:38 UTC (rev 4667)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-07-29 18:46:44 UTC (rev 4668)
@@ -25,6 +25,7 @@
public virtual bool IsParent { get; set; }
public virtual IEnumerable<Child> Children { get; set; }
+ public virtual IList<Person> PersonList { get; set; }
}
public class CustomPerson : Person { }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ric...@us...> - 2009-07-30 09:56:28
|
Revision: 4669
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4669&view=rev
Author: ricbrown
Date: 2009-07-30 09:56:14 +0000 (Thu, 30 Jul 2009)
Log Message:
-----------
Moved IQueryOver.OrderBy to more fluent syntax.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
trunk/nhibernate/src/NHibernate/IQueryOver.cs
trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Criterion/QueryOverOrderBuilder.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-29 18:46:44 UTC (rev 4668)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-30 09:56:14 UTC (rev 4669)
@@ -73,51 +73,51 @@
return this;
}
- public QueryOver<T> OrderBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
+ public QueryOverOrderBuilder<T> OrderBy(Expression<Func<T, object>> path)
{
- return AddOrder(path, orderDelegate);
+ return new QueryOverOrderBuilder<T>(this, path);
}
- public QueryOver<T> OrderBy(Expression<Func<object>> path, Func<string, Order> orderDelegate)
+ public QueryOverOrderBuilder<T> OrderBy(Expression<Func<object>> path)
{
- return AddOrder(path, orderDelegate);
+ return new QueryOverOrderBuilder<T>(this, path);
}
- public QueryOver<T> ThenBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
+ public QueryOverOrderBuilder<T> ThenBy(Expression<Func<T, object>> path)
{
- return AddOrder(path, orderDelegate);
+ return new QueryOverOrderBuilder<T>(this, path);
}
- public QueryOver<T> ThenBy(Expression<Func<object>> path, Func<string, Order> orderDelegate)
+ public QueryOverOrderBuilder<T> ThenBy(Expression<Func<object>> path)
{
- return AddOrder(path, orderDelegate);
+ return new QueryOverOrderBuilder<T>(this, path);
}
- public IQueryOver<T> Skip(int firstResult)
+ public QueryOver<T> Skip(int firstResult)
{
_criteria.SetFirstResult(firstResult);
return this;
}
- public IQueryOver<T> Take(int maxResults)
+ public QueryOver<T> Take(int maxResults)
{
_criteria.SetMaxResults(maxResults);
return this;
}
- public IQueryOver<T> Cacheable()
+ public QueryOver<T> Cacheable()
{
_criteria.SetCacheable(true);
return this;
}
- public IQueryOver<T> CacheMode(CacheMode cacheMode)
+ public QueryOver<T> CacheMode(CacheMode cacheMode)
{
_criteria.SetCacheMode(cacheMode);
return this;
}
- public IQueryOver<T> CacheRegion(string cacheRegion)
+ public QueryOver<T> CacheRegion(string cacheRegion)
{
_criteria.SetCacheRegion(cacheRegion);
return this;
@@ -260,19 +260,7 @@
return this;
}
- private QueryOver<T> AddOrder(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
- {
- _criteria.AddOrder(ExpressionProcessor.ProcessOrder<T>(path, orderDelegate));
- return this;
- }
- private QueryOver<T> AddOrder(Expression<Func<object>> path, Func<string, Order> orderDelegate)
- {
- _criteria.AddOrder(ExpressionProcessor.ProcessOrder(path, orderDelegate));
- return this;
- }
-
-
ICriteria IQueryOver<T>.UnderlyingCriteria
{ get { return UnderlyingCriteria; } }
@@ -291,17 +279,17 @@
IQueryOver<T> IQueryOver<T>.Select(params Expression<Func<T, object>>[] projections)
{ return Select(projections); }
- IQueryOver<T> IQueryOver<T>.OrderBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
- { return OrderBy(path, orderDelegate); }
+ IQueryOverOrderBuilder<T> IQueryOver<T>.OrderBy(Expression<Func<T, object>> path)
+ { return new IQueryOverOrderBuilder<T>(this, path); }
- IQueryOver<T> IQueryOver<T>.OrderBy(Expression<Func<object>> path, Func<string, Order> orderDelegate)
- { return OrderBy(path, orderDelegate); }
+ IQueryOverOrderBuilder<T> IQueryOver<T>.OrderBy(Expression<Func<object>> path)
+ { return new IQueryOverOrderBuilder<T>(this, path); }
- IQueryOver<T> IQueryOver<T>.ThenBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate)
- { return ThenBy(path, orderDelegate); }
+ IQueryOverOrderBuilder<T> IQueryOver<T>.ThenBy(Expression<Func<T, object>> path)
+ { return new IQueryOverOrderBuilder<T>(this, path); }
- IQueryOver<T> IQueryOver<T>.ThenBy(Expression<Func<object>> path, Func<string, Order> orderDelegate)
- { return ThenBy(path, orderDelegate); }
+ IQueryOverOrderBuilder<T> IQueryOver<T>.ThenBy(Expression<Func<object>> path)
+ { return new IQueryOverOrderBuilder<T>(this, path); }
IQueryOver<T> IQueryOver<T>.Skip(int firstResult)
{ return Skip(firstResult); }
Added: trunk/nhibernate/src/NHibernate/Criterion/QueryOverOrderBuilder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOverOrderBuilder.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOverOrderBuilder.cs 2009-07-30 09:56:14 UTC (rev 4669)
@@ -0,0 +1,72 @@
+
+using System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+
+using NHibernate.Impl;
+using NHibernate.SqlCommand;
+
+namespace NHibernate.Criterion
+{
+
+ public class QueryOverOrderBuilder<T> : QueryOverOrderBuilderBase<QueryOver<T>, T>
+ {
+
+ public QueryOverOrderBuilder(QueryOver<T> root, Expression<Func<T, object>> path) : base(root, path)
+ {}
+
+ public QueryOverOrderBuilder(QueryOver<T> root, Expression<Func<object>> path) : base(root, path)
+ {}
+
+ }
+
+ public class IQueryOverOrderBuilder<T> : QueryOverOrderBuilderBase<IQueryOver<T>, T>
+ {
+
+ public IQueryOverOrderBuilder(IQueryOver<T> root, Expression<Func<T, object>> path) : base(root, path)
+ {}
+
+ public IQueryOverOrderBuilder(IQueryOver<T> root, Expression<Func<object>> path) : base(root, path)
+ {}
+
+ }
+
+ public class QueryOverOrderBuilderBase<R, T> where R : IQueryOver<T>
+ {
+
+ protected R root;
+ protected LambdaExpression path;
+
+ protected QueryOverOrderBuilderBase(R root, Expression<Func<T, object>> path)
+ {
+ this.root = root;
+ this.path = path;
+ }
+
+ protected QueryOverOrderBuilderBase(R root, Expression<Func<object>> path)
+ {
+ this.root = root;
+ this.path = path;
+ }
+
+ public R Asc
+ {
+ get
+ {
+ this.root.UnderlyingCriteria.AddOrder(ExpressionProcessor.ProcessOrder(path, Order.Asc));
+ return this.root;
+ }
+ }
+
+ public R Desc
+ {
+ get
+ {
+ this.root.UnderlyingCriteria.AddOrder(ExpressionProcessor.ProcessOrder(path, Order.Desc));
+ return this.root;
+ }
+ }
+
+ }
+
+}
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-29 18:46:44 UTC (rev 4668)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-30 09:56:14 UTC (rev 4669)
@@ -68,33 +68,29 @@
/// Add order expressed as a lambda expression
/// </summary>
/// <param name="path">Lambda expression</param>
- /// <param name="orderDelegate">Order delegate (direction)</param>
/// <returns>criteria instance</returns>
- IQueryOver<T> OrderBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate);
+ IQueryOverOrderBuilder<T> OrderBy(Expression<Func<T, object>> path);
/// <summary>
/// Add order expressed as a lambda expression
/// </summary>
/// <param name="path">Lambda expression</param>
- /// <param name="orderDelegate">Order delegate (direction)</param>
/// <returns>criteria instance</returns>
- IQueryOver<T> OrderBy(Expression<Func<object>> path, Func<string, Order> orderDelegate);
+ IQueryOverOrderBuilder<T> OrderBy(Expression<Func<object>> path);
/// <summary>
/// Add order expressed as a lambda expression
/// </summary>
/// <param name="path">Lambda expression</param>
- /// <param name="orderDelegate">Order delegate (direction)</param>
/// <returns>criteria instance</returns>
- IQueryOver<T> ThenBy(Expression<Func<T, object>> path, Func<string, Order> orderDelegate);
+ IQueryOverOrderBuilder<T> ThenBy(Expression<Func<T, object>> path);
/// <summary>
/// Add order expressed as a lambda expression
/// </summary>
/// <param name="path">Lambda expression</param>
- /// <param name="orderDelegate">Order delegate (direction)</param>
/// <returns>criteria instance</returns>
- IQueryOver<T> ThenBy(Expression<Func<object>> path, Func<string, Order> orderDelegate);
+ IQueryOverOrderBuilder<T> ThenBy(Expression<Func<object>> path);
/// <summary>
/// Set the first result to be retrieved
Modified: trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2009-07-29 18:46:44 UTC (rev 4668)
+++ trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2009-07-30 09:56:14 UTC (rev 4669)
@@ -419,6 +419,20 @@
return order;
}
+ /// <summary>
+ /// Convert a lambda expression to NHibernate Order
+ /// </summary>
+ /// <param name="expression">The lambda expression to convert</param>
+ /// <param name="orderDelegate">The appropriate order delegate (order direction)</param>
+ /// <returns>NHibernate Order</returns>
+ public static Order ProcessOrder( LambdaExpression expression,
+ Func<string, Order> orderDelegate)
+ {
+ string property = FindMemberExpression(expression.Body);
+ Order order = orderDelegate(property);
+ return order;
+ }
+
private static AbstractCriterion ProcessSubqueryExpression(LambdaSubqueryType subqueryType,
BinaryExpression be)
{
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-29 18:46:44 UTC (rev 4668)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-30 09:56:14 UTC (rev 4669)
@@ -492,6 +492,7 @@
<Compile Include="Criterion\GroupedProjection.cs" />
<Compile Include="Criterion\IPropertyProjection.cs" />
<Compile Include="Criterion\QueryOverJoinBuilder.cs" />
+ <Compile Include="Criterion\QueryOverOrderBuilder.cs" />
<Compile Include="Dialect\MsSql2008Dialect.cs" />
<Compile Include="Dialect\InformixDialect0940.cs" />
<Compile Include="Dialect\InformixDialect1000.cs" />
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2009-07-29 18:46:44 UTC (rev 4668)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2009-07-30 09:56:14 UTC (rev 4669)
@@ -108,7 +108,7 @@
var actual =
s.QueryOver<Person>()
.Select(p => p.Age)
- .OrderBy(p => p.Age, Order.Asc)
+ .OrderBy(p => p.Age).Asc
.List<int>();
Assert.That(actual[0], Is.EqualTo(20));
@@ -133,7 +133,7 @@
s.QueryOver<Person>(() => personAlias)
.Select(p => p.Name,
p => personAlias.Age)
- .OrderBy(p => p.Age, Order.Asc)
+ .OrderBy(p => p.Age).Asc
.List<object[]>()
.Select(props => new {
TestName = (string)props[0],
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-29 18:46:44 UTC (rev 4668)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-30 09:56:14 UTC (rev 4669)
@@ -251,10 +251,10 @@
Person personAlias = null;
IQueryOver<Person> actual =
CreateTestQueryOver<Person>(() => personAlias)
- .OrderBy(p => p.Name, Order.Asc)
- .ThenBy(p => p.Age, Order.Desc)
- .ThenBy(() => personAlias.Name, Order.Desc)
- .ThenBy(() => personAlias.Age, Order.Asc);
+ .OrderBy(p => p.Name).Asc
+ .ThenBy(p => p.Age).Desc
+ .ThenBy(() => personAlias.Name).Desc
+ .ThenBy(() => personAlias.Age).Asc;
AssertCriteriaAreEqual(expected, actual);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ric...@us...> - 2009-07-30 16:10:20
|
Revision: 4670
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4670&view=rev
Author: ricbrown
Date: 2009-07-30 16:10:11 +0000 (Thu, 30 Jul 2009)
Log Message:
-----------
Added IQueryOver.Fetch(...)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
trunk/nhibernate/src/NHibernate/IQueryOver.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Criterion/QueryOverFetchBuilder.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-30 09:56:14 UTC (rev 4669)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-07-30 16:10:11 UTC (rev 4670)
@@ -123,6 +123,11 @@
return this;
}
+ public QueryOverFetchBuilder<T> Fetch(Expression<Func<T, object>> path)
+ {
+ return new QueryOverFetchBuilder<T>(this, path);
+ }
+
public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path)
{
return new QueryOver<U>(_impl,
@@ -306,6 +311,9 @@
IQueryOver<T> IQueryOver<T>.CacheRegion(string cacheRegion)
{ return CacheRegion(cacheRegion); }
+ IQueryOverFetchBuilder<T> IQueryOver<T>.Fetch(Expression<Func<T, object>> path)
+ { return new IQueryOverFetchBuilder<T>(this, path); }
+
IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, U>> path)
{ return JoinQueryOver(path); }
Added: trunk/nhibernate/src/NHibernate/Criterion/QueryOverFetchBuilder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/QueryOverFetchBuilder.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Criterion/QueryOverFetchBuilder.cs 2009-07-30 16:10:11 UTC (rev 4670)
@@ -0,0 +1,69 @@
+
+using System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+
+using NHibernate.Impl;
+using NHibernate.SqlCommand;
+
+namespace NHibernate.Criterion
+{
+
+ public class QueryOverFetchBuilder<T> : QueryOverFetchBuilderBase<QueryOver<T>, T>
+ {
+
+ public QueryOverFetchBuilder(QueryOver<T> root, Expression<Func<T, object>> path)
+ : base(root, path) { }
+
+ }
+
+ public class IQueryOverFetchBuilder<T> : QueryOverFetchBuilderBase<IQueryOver<T>, T>
+ {
+
+ public IQueryOverFetchBuilder(IQueryOver<T> root, Expression<Func<T, object>> path)
+ : base(root, path) { }
+
+ }
+
+ public class QueryOverFetchBuilderBase<R, T> where R : IQueryOver<T>
+ {
+
+ protected R root;
+ protected string path;
+
+ protected QueryOverFetchBuilderBase(R root, Expression<Func<T, object>> path)
+ {
+ this.root = root;
+ this.path = ExpressionProcessor.FindMemberExpression(path.Body);
+ }
+
+ public R Eager
+ {
+ get
+ {
+ this.root.UnderlyingCriteria.SetFetchMode(path, FetchMode.Eager);
+ return this.root;
+ }
+ }
+
+ public R Lazy
+ {
+ get
+ {
+ this.root.UnderlyingCriteria.SetFetchMode(path, FetchMode.Lazy);
+ return this.root;
+ }
+ }
+
+ public R Default
+ {
+ get
+ {
+ this.root.UnderlyingCriteria.SetFetchMode(path, FetchMode.Default);
+ return this.root;
+ }
+ }
+
+ }
+
+}
Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-30 09:56:14 UTC (rev 4669)
+++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-07-30 16:10:11 UTC (rev 4670)
@@ -122,6 +122,14 @@
IQueryOver<T> CacheRegion(string cacheRegion);
/// <summary>
+ /// Specify an association fetching strategy. Currently, only
+ /// one-to-many and one-to-one associations are supported.
+ /// </summary>
+ /// <param name="path">A lambda expression path (e.g., ChildList[0].Granchildren[0].Pets).</param>
+ /// <returns></returns>
+ IQueryOverFetchBuilder<T> Fetch(Expression<Func<T, object>> path);
+
+ /// <summary>
/// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-30 09:56:14 UTC (rev 4669)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-30 16:10:11 UTC (rev 4670)
@@ -491,6 +491,7 @@
<Compile Include="Cfg\MappingSchema\IDecoratable.cs" />
<Compile Include="Criterion\GroupedProjection.cs" />
<Compile Include="Criterion\IPropertyProjection.cs" />
+ <Compile Include="Criterion\QueryOverFetchBuilder.cs" />
<Compile Include="Criterion\QueryOverJoinBuilder.cs" />
<Compile Include="Criterion\QueryOverOrderBuilder.cs" />
<Compile Include="Dialect\MsSql2008Dialect.cs" />
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-30 09:56:14 UTC (rev 4669)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-07-30 16:10:11 UTC (rev 4670)
@@ -315,6 +315,22 @@
AssertCriteriaAreEqual(expected, actual);
}
+ [Test]
+ public void Fetch()
+ {
+ ICriteria expected =
+ CreateTestCriteria(typeof(Person))
+ .SetFetchMode("PersonList", FetchMode.Eager)
+ .SetFetchMode("PersonList.PersonList", FetchMode.Lazy);
+
+ IQueryOver<Person> actual =
+ CreateTestQueryOver<Person>()
+ .Fetch(p => p.PersonList).Eager
+ .Fetch(p => p.PersonList[0].PersonList).Lazy;
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
}
}
\ 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...> - 2009-08-02 19:56:08
|
Revision: 4674
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4674&view=rev
Author: fabiomaulo
Date: 2009-08-02 19:55:57 +0000 (Sun, 02 Aug 2009)
Log Message:
-----------
Merge r4673 (fix NH-1903)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/MyType.cs
Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs 2009-08-02 19:49:56 UTC (rev 4673)
+++ trunk/nhibernate/src/NHibernate/Impl/AbstractQueryImpl.cs 2009-08-02 19:55:57 UTC (rev 4674)
@@ -260,14 +260,7 @@
public IQuery SetParameter(int position, object val, IType type)
{
- if (parameterMetadata.OrdinalParameterCount == 0)
- {
- throw new ArgumentException("No positional parameters in query: " + QueryString);
- }
- if (position < 0 || position > parameterMetadata.OrdinalParameterCount - 1)
- {
- throw new ArgumentException("Positional parameter does not exist: " + position + " in query: " + QueryString);
- }
+ CheckPositionalParameter(position);
int size = values.Count;
if (position < size)
{
@@ -305,12 +298,26 @@
public IQuery SetParameter<T>(int position, T val)
{
- return SetParameter(position, val, GuessType(typeof (T)));
+ CheckPositionalParameter(position);
+
+ return SetParameter(position, val, parameterMetadata.GetOrdinalParameterExpectedType(position + 1) ?? GuessType(typeof(T)));
}
+ private void CheckPositionalParameter(int position)
+ {
+ if (parameterMetadata.OrdinalParameterCount == 0)
+ {
+ throw new ArgumentException("No positional parameters in query: " + QueryString);
+ }
+ if (position < 0 || position > parameterMetadata.OrdinalParameterCount - 1)
+ {
+ throw new ArgumentException("Positional parameter does not exist: " + position + " in query: " + QueryString);
+ }
+ }
+
public IQuery SetParameter<T>(string name, T val)
{
- return SetParameter(name, val, GuessType(typeof (T)));
+ return SetParameter(name, val, parameterMetadata.GetNamedParameterExpectedType(name) ?? GuessType(typeof (T)));
}
public IQuery SetParameter(string name, object val)
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/Fixture.cs 2009-08-02 19:55:57 UTC (rev 4674)
@@ -0,0 +1,34 @@
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1907
+{
+ public class Something
+ {
+ public virtual string Name { get; set; }
+ public virtual MyType Relation { get; set; }
+ }
+ [TestFixture]
+ public class Fixture: BugTestCase
+ {
+ [Test]
+ public void CanSetParameterQueryByName()
+ {
+ using (ISession s = OpenSession())
+ {
+ var q = s.CreateQuery("from Something s where s.Relation = :aParam");
+ Assert.DoesNotThrow(()=>q.SetParameter("aParam", new MyType{ ToPersist = 1}));
+ }
+ }
+
+ [Test]
+ public void CanSetParameterQueryByPosition()
+ {
+ using (ISession s = OpenSession())
+ {
+ var q = s.CreateQuery("from Something s where s.Relation = ?");
+ q.SetParameter(0, new MyType {ToPersist = 1});
+ Assert.DoesNotThrow(() => q.SetParameter(0, new MyType { ToPersist = 1 }));
+ }
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/Mappings.hbm.xml 2009-08-02 19:55:57 UTC (rev 4674)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH1907">
+
+ <class name="Something">
+ <id type="int">
+ <generator class="hilo"/>
+ </id>
+ <property name="Name"/>
+ <property name="Relation" type="NHibernate.Test.NHSpecificTest.NH1907.SimpleCustomType, NHibernate.Test"/>
+ </class>
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/MyType.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/MyType.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1907/MyType.cs 2009-08-02 19:55:57 UTC (rev 4674)
@@ -0,0 +1,115 @@
+using System;
+using System.Data;
+using NHibernate.SqlTypes;
+using NHibernate.UserTypes;
+
+namespace NHibernate.Test.NHSpecificTest.NH1907
+{
+ public class MyType
+ {
+ public int ToPersist { get; set; }
+
+ public override bool Equals(object obj)
+ {
+ if (obj == null || GetType() != obj.GetType())
+ {
+ return false;
+ }
+ var other = (MyType)obj;
+ return ToPersist == other.ToPersist;
+ }
+
+ public override int GetHashCode()
+ {
+ return ToPersist.GetHashCode();
+ }
+ }
+
+ public class SimpleCustomType : IUserType
+ {
+ private static readonly SqlType[] ReturnSqlTypes = { SqlTypeFactory.Int32 };
+
+
+ #region IUserType Members
+
+ public new bool Equals(object x, object y)
+ {
+ if (ReferenceEquals(x, y))
+ {
+ return true;
+ }
+ if (ReferenceEquals(null, x) || ReferenceEquals(null, y))
+ {
+ return false;
+ }
+
+ return x.Equals(y);
+ }
+
+ public int GetHashCode(object x)
+ {
+ return (x == null) ? 0 : x.GetHashCode();
+ }
+
+ public SqlType[] SqlTypes
+ {
+ get { return ReturnSqlTypes; }
+ }
+
+ public object DeepCopy(object value)
+ {
+ return value;
+ }
+
+ public void NullSafeSet(IDbCommand cmd, object value, int index)
+ {
+ if (value == null)
+ {
+ ((IDbDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
+ }
+ else
+ {
+ ((IDbDataParameter)cmd.Parameters[index]).Value = ((MyType)value).ToPersist;
+ }
+ }
+
+ public System.Type ReturnedType
+ {
+ get { return typeof(Int32); }
+ }
+
+ public object NullSafeGet(IDataReader rs, string[] names, object owner)
+ {
+ int index0 = rs.GetOrdinal(names[0]);
+ if (rs.IsDBNull(index0))
+ {
+ return null;
+ }
+ int value = rs.GetInt32(index0);
+ return new MyType { ToPersist = value};
+ }
+
+ public bool IsMutable
+ {
+ get { return false; }
+ }
+
+ public object Replace(object original, object target, object owner)
+ {
+ return original;
+ }
+
+ public object Assemble(object cached, object owner)
+ {
+ return cached;
+ }
+
+ public object Disassemble(object value)
+ {
+ return value;
+ }
+
+ #endregion
+ }
+
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-02 19:49:56 UTC (rev 4673)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-02 19:55:57 UTC (rev 4674)
@@ -552,6 +552,8 @@
<Compile Include="NHSpecificTest\NH1877\Person.cs" />
<Compile Include="NHSpecificTest\NH1899\DomainClass.cs" />
<Compile Include="NHSpecificTest\NH1899\SampleTest.cs" />
+ <Compile Include="NHSpecificTest\NH1907\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1907\MyType.cs" />
<Compile Include="NHSpecificTest\NH473\Child.cs" />
<Compile Include="NHSpecificTest\NH473\Fixture.cs" />
<Compile Include="NHSpecificTest\NH473\Parent.cs" />
@@ -1965,6 +1967,7 @@
<EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" />
<EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1907\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1899\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1877\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1868\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2009-08-02 22:35:50
|
Revision: 4676
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4676&view=rev
Author: fabiomaulo
Date: 2009-08-02 22:35:41 +0000 (Sun, 02 Aug 2009)
Log Message:
-----------
Merge r4675 (fix NH-1898)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Exec/BasicExecutor.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
trunk/nhibernate/src/NHibernate.Test/Stateless/StatelessSessionFixture.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/DomainClass.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/SampleTest.cs
Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2009-08-02 22:31:07 UTC (rev 4675)
+++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2009-08-02 22:35:41 UTC (rev 4676)
@@ -126,6 +126,7 @@
RegisterFunction("trim", new AnsiTrimEmulationFunction());
RegisterFunction("iif", new SQLFunctionTemplate(null, "case when ?1 then ?2 else ?3 end"));
+ RegisterFunction("replace", new StandardSafeSQLFunction("replace",NHibernateUtil.String, 3));
RegisterKeyword("top");
RegisterKeyword("integer");
Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Exec/BasicExecutor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Exec/BasicExecutor.cs 2009-08-02 22:31:07 UTC (rev 4675)
+++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Exec/BasicExecutor.cs 2009-08-02 22:35:41 UTC (rev 4676)
@@ -58,6 +58,7 @@
{
try
{
+ CheckParametersExpectedType(parameters); // NH Different behavior (NH-1898)
var parameterTypes = new List<SqlType>(Parameters.Count);
foreach (var parameterSpecification in Parameters)
{
@@ -100,6 +101,33 @@
}
}
+ private void CheckParametersExpectedType(QueryParameters parameters)
+ {
+ foreach (var specification in Parameters)
+ {
+ if (specification.ExpectedType == null)
+ {
+ var namedSpec = specification as NamedParameterSpecification;
+ if (namedSpec != null)
+ {
+ TypedValue tv;
+ if(parameters.NamedParameters.TryGetValue(namedSpec.Name, out tv))
+ {
+ specification.ExpectedType = tv.Type;
+ }
+ }
+ else
+ {
+ var posSpec = specification as PositionalParameterSpecification;
+ if (posSpec != null)
+ {
+ specification.ExpectedType = parameters.PositionalParameterTypes[posSpec.HqlPosition];
+ }
+ }
+ }
+ }
+ }
+
protected override IQueryable[] AffectedQueryables
{
get { return new[] { persister }; }
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/DomainClass.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/DomainClass.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/DomainClass.cs 2009-08-02 22:35:41 UTC (rev 4676)
@@ -0,0 +1,9 @@
+namespace NHibernate.Test.NHSpecificTest.NH1898
+{
+ public class DomainClass
+ {
+ public int Id { get; set; }
+
+ public string Data { get; set; }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/Mappings.hbm.xml 2009-08-02 22:35:41 UTC (rev 4676)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH1898"
+ default-lazy="false">
+ <class name="DomainClass">
+ <id name="Id">
+ <generator class="assigned" />
+ </id>
+ <property name="Data" />
+ </class>
+ <query name='replaceQuery'>
+ <query-param name='old' type='String'/>
+ <query-param name='new' type='String'/>
+ <![CDATA[
+ update DomainClass set
+ Data = replace(Data,:old, :new)
+ ]]>
+ </query>
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/SampleTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/SampleTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1898/SampleTest.cs 2009-08-02 22:35:41 UTC (rev 4676)
@@ -0,0 +1,44 @@
+using NHibernate.Dialect;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1898
+{
+ [TestFixture]
+ public class SampleTest : BugTestCase
+ {
+ protected override bool AppliesTo(Dialect.Dialect dialect)
+ {
+ return dialect as MsSql2005Dialect != null;
+ }
+
+ [Test]
+ public void TypeOfParametersShouldBeSetCorrectly()
+ {
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ var entity = new DomainClass {Id = 1, Data = "some oldValue data"};
+ session.Save(entity);
+ tx.Commit();
+ }
+ }
+ using (ISession session = OpenSession())
+ {
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ session.GetNamedQuery("replaceQuery").SetString("old", "oldValue").SetString("new", "newValue").ExecuteUpdate();
+ tx.Commit();
+ }
+ using (ITransaction tx = session.BeginTransaction())
+ {
+ var entity = session.Get<DomainClass>(1);
+
+ Assert.AreEqual("some newValue data", entity.Data);
+ session.Delete(entity);
+ tx.Commit();
+ }
+ }
+ }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-02 22:31:07 UTC (rev 4675)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-02 22:35:41 UTC (rev 4676)
@@ -550,6 +550,8 @@
<Compile Include="NHSpecificTest\NH1868\Model.cs" />
<Compile Include="NHSpecificTest\NH1877\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1877\Person.cs" />
+ <Compile Include="NHSpecificTest\NH1898\DomainClass.cs" />
+ <Compile Include="NHSpecificTest\NH1898\SampleTest.cs" />
<Compile Include="NHSpecificTest\NH1899\DomainClass.cs" />
<Compile Include="NHSpecificTest\NH1899\SampleTest.cs" />
<Compile Include="NHSpecificTest\NH1907\Fixture.cs" />
@@ -1967,6 +1969,7 @@
<EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" />
<EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1898\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1907\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1899\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1877\Mappings.hbm.xml" />
Modified: trunk/nhibernate/src/NHibernate.Test/Stateless/StatelessSessionFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Stateless/StatelessSessionFixture.cs 2009-08-02 22:31:07 UTC (rev 4675)
+++ trunk/nhibernate/src/NHibernate.Test/Stateless/StatelessSessionFixture.cs 2009-08-02 22:35:41 UTC (rev 4676)
@@ -1,7 +1,6 @@
using System;
using System.Collections;
using System.Threading;
-using NHibernate.Hql.Ast.ANTLR;
using NUnit.Framework;
namespace NHibernate.Test.Stateless
@@ -119,27 +118,6 @@
}
[Test]
- public void HqlBulkWithErrorInPropertyName()
- {
- using (IStatelessSession ss = sessions.OpenStatelessSession())
- {
- ITransaction tx = ss.BeginTransaction();
- var doc = new Document("blah blah blah", "Blahs");
- ss.Insert(doc);
- var paper = new Paper {Color = "White"};
- ss.Insert(paper);
- tx.Commit();
-
- Assert.Throws<QuerySyntaxException>(()=>
- ss.CreateQuery("update Document set name = :newName where name = :oldName").SetString("newName", "Foos").SetString
- ("oldName", "Blahs").ExecuteUpdate());
- tx = ss.BeginTransaction();
- ss.CreateQuery("delete Document").ExecuteUpdate();
- ss.CreateQuery("delete Paper").ExecuteUpdate();
- tx.Commit();
- }
- }
- [Test]
public void InitId()
{
Paper paper;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fab...@us...> - 2009-08-03 22:45:45
|
Revision: 4678
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4678&view=rev
Author: fabiomaulo
Date: 2009-08-03 22:45:29 +0000 (Mon, 03 Aug 2009)
Log Message:
-----------
Merge r4677 (Refactoring filter-def check first step)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs
trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Cfg/FilterSecondPassArgs.cs
trunk/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs
trunk/nhibernate/src/NHibernate.Test/FilterTest/FilterSecondPassArgsFixture.cs
trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFiltered.hbm.xml
trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFilteredFiltersDefsOk.hbm.xml
trunk/nhibernate/src/NHibernate.Test/FilterTest/WrongFilterDefInClass.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2009-08-03 22:25:32 UTC (rev 4677)
+++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2009-08-03 22:45:29 UTC (rev 4678)
@@ -5,6 +5,7 @@
using System.Diagnostics;
using System.IO;
using System.Reflection;
+using System.Text;
using System.Xml;
using System.Xml.Schema;
using Iesi.Collections;
@@ -61,6 +62,7 @@
protected IDictionary<string, NHibernate.Mapping.Collection> collections;
protected IDictionary<string, Table> tables;
protected IList<SecondPassCommand> secondPasses;
+ protected Queue<FilterSecondPassArgs> filtersSecondPasses;
protected IList<Mappings.PropertyReference> propertyReferences;
private IInterceptor interceptor;
private IDictionary<string, string> properties;
@@ -113,6 +115,7 @@
tableNameBinding = GetSerialedObject<IDictionary<string, Mappings.TableDescription>>(info, "tableNameBinding");
tables = GetSerialedObject<IDictionary<string, Table>>(info, "tables");
typeDefs = GetSerialedObject<IDictionary<string, TypeDef>>(info, "typeDefs");
+ filtersSecondPasses = GetSerialedObject<Queue<FilterSecondPassArgs>>(info, "filtersSecondPasses");
}
private T GetSerialedObject<T>(SerializationInfo info, string name)
@@ -151,6 +154,7 @@
info.AddValue("tableNameBinding", tableNameBinding);
info.AddValue("tables", tables);
info.AddValue("typeDefs", typeDefs);
+ info.AddValue("filtersSecondPasses", filtersSecondPasses);
}
#endregion
@@ -179,7 +183,7 @@
extendsQueue = new HashedSet<ExtendsQueueEntry>();
tableNameBinding = new Dictionary<string, Mappings.TableDescription>();
columnNameBindingPerTable = new Dictionary<Table, Mappings.ColumnNames>();
-
+ filtersSecondPasses = new Queue<FilterSecondPassArgs>();
}
[Serializable]
private class Mapping : IMapping
@@ -520,7 +524,7 @@
{
ProcessPreMappingBuildProperties();
return new Mappings(classes, collections, tables, NamedQueries, NamedSQLQueries, SqlResultSetMappings, Imports,
- secondPasses, propertyReferences, namingStrategy, typeDefs, FilterDefinitions, extendsQueue,
+ secondPasses, filtersSecondPasses, propertyReferences, namingStrategy, typeDefs, FilterDefinitions, extendsQueue,
auxiliaryDatabaseObjects, tableNameBinding, columnNameBindingPerTable, defaultAssembly,
defaultNamespace, dialect);
}
@@ -904,6 +908,69 @@
private void Validate()
{
+ ValidateEntities();
+
+ ValidateCollections();
+
+ ValidateFilterDefs();
+ }
+
+ private void ValidateFilterDefs()
+ {
+ var filterNames = new HashedSet<string>();
+ foreach (var filterDefinition in FilterDefinitions)
+ {
+ if(filterDefinition.Value == null)
+ {
+ // a class/collection has a filter but the filter-def was not added.
+ filterNames.Add(filterDefinition.Key);
+ }
+ }
+ if(filterNames.Count > 0)
+ {
+ var message = new StringBuilder();
+ message.Append("filter-def for filter named ");
+ foreach (var filterName in filterNames)
+ {
+ message.AppendLine(filterName);
+ }
+ message.AppendLine("was not found.");
+ throw new MappingException(message.ToString());
+ }
+
+ // check filter-def without reference
+ if (FilterDefinitions.Count > 0)
+ {
+ filterNames.Clear();
+ var filterables = new JoinedEnumerable(ClassMappings, CollectionMappings);
+ foreach (IFilterable filterable in filterables)
+ {
+ filterNames.AddAll(filterable.FilterMap.Keys);
+ }
+ foreach (var filterName in FilterDefinitions.Keys)
+ {
+ if (!filterNames.Contains(filterName))
+ {
+ // if you are going to remove this exception at least add a log.Error
+ // because the usage of filter-def, outside its scope, may cause unexpected behaviour
+ // during queries.
+ throw new MappingException("filter-def for filter named '" + filterName
+ + "' was never used to filter classes nor collections.");
+ }
+ }
+ }
+ }
+
+ private void ValidateCollections()
+ {
+ foreach (var col in collections.Values)
+ {
+ col.Validate(mapping);
+ }
+ }
+
+ private void ValidateEntities()
+ {
bool validateProxy = PropertiesHelper.GetBoolean(Environment.UseProxyValidator, properties, true);
HashedSet<string> allProxyErrors = null;
IProxyValidator pvalidator = Environment.BytecodeProvider.ProxyFactoryFactory.ProxyValidator;
@@ -933,11 +1000,6 @@
{
throw new InvalidProxyTypeException(allProxyErrors);
}
-
- foreach (var col in collections.Values)
- {
- col.Validate(mapping);
- }
}
private static ICollection<string> ValidateProxyInterface(PersistentClass persistentClass, IProxyValidator validator)
@@ -1007,6 +1069,23 @@
{
SecondPassCompileForeignKeys(table, done);
}
+
+ log.Info("processing filters (second pass)");
+ foreach (var filterSecondPassArgs in filtersSecondPasses)
+ {
+ FilterDefinition filterDef;
+ var filterName = filterSecondPassArgs.FilterName;
+ FilterDefinitions.TryGetValue(filterName, out filterDef);
+ if(filterDef == null)
+ {
+ throw new MappingException("filter-def for filter named " + filterName + " was not found.");
+ }
+ if(string.IsNullOrEmpty(filterDef.DefaultFilterCondition))
+ {
+ throw new MappingException("no filter condition found for filter: " + filterName);
+ }
+ filterSecondPassArgs.Filterable.FilterMap[filterName] = filterDef.DefaultFilterCondition;
+ }
}
private void SecondPassCompileForeignKeys(Table table, ISet done)
@@ -2189,4 +2268,4 @@
}
-}
\ No newline at end of file
+}
Added: trunk/nhibernate/src/NHibernate/Cfg/FilterSecondPassArgs.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/FilterSecondPassArgs.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/FilterSecondPassArgs.cs 2009-08-03 22:45:29 UTC (rev 4678)
@@ -0,0 +1,28 @@
+using System;
+using NHibernate.Mapping;
+
+namespace NHibernate.Cfg
+{
+ [Serializable]
+ public class FilterSecondPassArgs
+ {
+ // this class is NH specific to solve problems generated by 'order of mapping-doc'
+ // to assign the condition of a filter.
+ public FilterSecondPassArgs(IFilterable filterable, string filterName)
+ {
+ if (filterable == null)
+ {
+ throw new ArgumentNullException("filterable");
+ }
+ if (string.IsNullOrEmpty(filterName))
+ {
+ throw new ArgumentNullException("filterName");
+ }
+ Filterable = filterable;
+ FilterName = filterName;
+ }
+
+ public IFilterable Filterable{ get; private set;}
+ public string FilterName { get; private set; }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs 2009-08-03 22:25:32 UTC (rev 4677)
+++ trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs 2009-08-03 22:45:29 UTC (rev 4678)
@@ -69,6 +69,7 @@
private readonly IList<PropertyReference> propertyReferences;
private readonly IDictionary<string, FilterDefinition> filterDefinitions;
private readonly IList<IAuxiliaryDatabaseObject> auxiliaryDatabaseObjects;
+ private readonly Queue<FilterSecondPassArgs> filtersSecondPasses;
private readonly INamingStrategy namingStrategy;
@@ -98,6 +99,7 @@
IDictionary<string, ResultSetMappingDefinition> resultSetMappings,
IDictionary<string, string> imports,
IList<SecondPassCommand> secondPasses,
+ Queue<FilterSecondPassArgs> filtersSecondPasses,
IList<PropertyReference> propertyReferences,
INamingStrategy namingStrategy,
IDictionary<string, TypeDef> typeDefs,
@@ -108,7 +110,7 @@
IDictionary<Table, ColumnNames> columnNameBindingPerTable,
string defaultAssembly,
string defaultNamespace,
- Dialect.Dialect dialect)
+ Dialect.Dialect dialect)
{
this.classes = classes;
this.collections = collections;
@@ -129,6 +131,7 @@
this.defaultAssembly = defaultAssembly;
this.defaultNamespace = defaultNamespace;
this.dialect = dialect;
+ this.filtersSecondPasses = filtersSecondPasses;
}
/// <summary>
@@ -454,12 +457,22 @@
public void AddFilterDefinition(FilterDefinition definition)
{
- filterDefinitions.Add(definition.FilterName, definition);
+ FilterDefinition fd;
+ if (filterDefinitions.TryGetValue(definition.FilterName, out fd))
+ {
+ if(fd!=null)
+ {
+ throw new MappingException("Duplicated filter-def named: " + definition.FilterName);
+ }
+ }
+ filterDefinitions[definition.FilterName] = definition;
}
public FilterDefinition GetFilterDefinition(string name)
{
- return filterDefinitions[name];
+ FilterDefinition result;
+ filterDefinitions.TryGetValue(name, out result);
+ return result;
}
public void AddAuxiliaryDatabaseObject(IAuxiliaryDatabaseObject auxiliaryDatabaseObject)
@@ -638,6 +651,34 @@
return persistentClass;
}
+ public void ExpectedFilterDefinition(IFilterable filterable, string filterName, string condition)
+ {
+ var fdef = GetFilterDefinition(filterName);
+ if (string.IsNullOrEmpty(condition))
+ {
+ if (fdef != null)
+ {
+ // where immediately available, apply the condition
+ condition = fdef.DefaultFilterCondition;
+ }
+ }
+ if (string.IsNullOrEmpty(condition) && fdef == null)
+ {
+ log.Debug(string.Format("Adding filter second pass [{0}]", filterName));
+ filtersSecondPasses.Enqueue(new FilterSecondPassArgs(filterable, filterName));
+ }
+ else if (string.IsNullOrEmpty(condition) && fdef != null)
+ {
+ // Both sides does not have condition
+ throw new MappingException("no filter condition found for filter: " + filterName);
+ }
+
+ if (fdef == null)
+ {
+ // if not available add an expected filter definition
+ FilterDefinitions[filterName] = null;
+ }
+ }
}
public delegate void SecondPassCommand(IDictionary<string, PersistentClass> persistentClasses);
Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-08-03 22:25:32 UTC (rev 4677)
+++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-08-03 22:45:29 UTC (rev 4678)
@@ -1017,17 +1017,19 @@
condition = (propertyNameNode == null) ? null : propertyNameNode.Value;
}
- //TODO: bad implementation, cos it depends upon ordering of mapping doc
- // fixing this requires that Collection/PersistentClass gain access
- // to the Mappings reference from Configuration (or the filterDefinitions
- // map directly) sometime during Configuration.buildSessionFactory
- // (after all the types/filter-defs are known and before building
- // persisters).
if (StringHelper.IsEmpty(condition))
- condition = mappings.GetFilterDefinition(name).DefaultFilterCondition;
- if (condition == null)
- throw new MappingException("no filter condition found for filter: " + name);
- log.Debug("Applying filter [" + name + "] as [" + condition + "]");
+ {
+ var fdef = mappings.GetFilterDefinition(name);
+ if (fdef != null)
+ {
+ // where immediately available, apply the condition
+ condition = fdef.DefaultFilterCondition;
+ }
+ }
+
+ mappings.ExpectedFilterDefinition(filterable, name, condition);
+
+ log.Debug(string.Format("Applying filter [{0}] as [{1}]", name, condition));
filterable.AddFilter(name, condition);
}
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-08-03 22:25:32 UTC (rev 4677)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-08-03 22:45:29 UTC (rev 4678)
@@ -460,6 +460,7 @@
<Compile Include="Bytecode\UnableToLoadProxyFactoryFactoryException.cs" />
<Compile Include="Cache\FakeCache.cs" />
<Compile Include="Cfg\EntityCacheUsage.cs" />
+ <Compile Include="Cfg\FilterSecondPassArgs.cs" />
<Compile Include="Cfg\Hbm2ddlKeyWords.cs" />
<Compile Include="Cfg\Loquacious\CacheConfiguration.cs" />
<Compile Include="Cfg\Loquacious\ConfigurationExtensions.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/ConfigFixture.cs 2009-08-03 22:45:29 UTC (rev 4678)
@@ -0,0 +1,244 @@
+using System.Collections.Generic;
+using NHibernate.Cfg;
+using NUnit.Framework;
+
+namespace NHibernate.Test.FilterTest
+{
+ [TestFixture]
+ public class ConfigFixture
+ {
+ private class ConfigurationStub: Configuration
+ {
+ public Queue<FilterSecondPassArgs> FiltersSecondPasses { get { return filtersSecondPasses; } }
+ }
+
+ private static ConfigurationStub GetConfiguration()
+ {
+ var result = new ConfigurationStub();
+ if (TestConfigurationHelper.hibernateConfigFile != null)
+ result.Configure(TestConfigurationHelper.hibernateConfigFile);
+ return result;
+ }
+
+ [Test]
+ [Description("Add a class with filters without condition should not Throw exceptions and add secondpass tasks.")]
+ public void AddClassWithFilters()
+ {
+ var cfg = GetConfiguration();
+ Assert.DoesNotThrow(() => cfg.AddResource("NHibernate.Test.FilterTest.SimpleFiltered.hbm.xml", GetType().Assembly));
+ Assert.That(cfg.FiltersSecondPasses.Count, Is.EqualTo(2));
+ }
+
+ [Test]
+ [Description("Add filters-def should change conditions of class filters")]
+ public void AddFilterDefToClassWithFilters()
+ {
+ var cfg = GetConfiguration();
+ cfg.AddResource("NHibernate.Test.FilterTest.SimpleFiltered.hbm.xml", GetType().Assembly);
+ cfg.AddResource("NHibernate.Test.FilterTest.SimpleFilteredFiltersDefsOk.hbm.xml", GetType().Assembly);
+ Assert.That(cfg.FilterDefinitions, Is.Not.Empty);
+ cfg.BuildMappings();
+ var pc = cfg.GetClassMapping(typeof (TestClass));
+ foreach (var filterMap in pc.FilterMap)
+ {
+ Assert.That(filterMap.Value, Is.Not.Null & Is.Not.Empty, "filtername:" + filterMap.Key);
+ }
+ }
+
+ [Test]
+ [Description("Filter def without condition in both sides should throw exception")]
+ public void WrongFilterDefInClass()
+ {
+ var cfg = GetConfiguration();
+ var e = Assert.Throws<MappingException>(() => cfg.AddResource("NHibernate.Test.FilterTest.WrongFilterDefInClass.hbm.xml", GetType().Assembly));
+ Assert.That(e.InnerException, Is.Not.Null);
+ Assert.That(e.InnerException.Message, Text.StartsWith("no filter condition").IgnoreCase);
+ }
+
+ [Test]
+ [Description("Filter def without condition in both sides should throw exception even in secondpass")]
+ public void WrongFilterDefInClassSeconPass()
+ {
+ const string wrongClassMap = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+ default-lazy='false'
+ assembly='NHibernate.Test'
+ namespace='NHibernate.Test.FilterTest' >
+
+ <class name='TestClass'>
+ <id name='Id' column='id'>
+ <generator class='assigned' />
+ </id>
+ <property name='Name'/>
+
+ <property name='Live'/>
+ <filter name='LiveFilter'/>
+ </class>
+
+</hibernate-mapping>";
+
+ const string wrongFilterDef = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2' >
+
+ <filter-def name='LiveFilter'>
+ <filter-param name='LiveParam' type='boolean'/>
+ </filter-def>
+
+</hibernate-mapping>";
+
+ var cfg = GetConfiguration();
+ cfg.AddXmlString(wrongClassMap);
+ cfg.AddXmlString(wrongFilterDef);
+ var e = Assert.Throws<MappingException>(cfg.BuildMappings);
+ Assert.That(e.Message, Text.StartsWith("no filter condition").IgnoreCase);
+ }
+
+ [Test]
+ [Description("Add a class with filters without condition should Throw exceptions at secondpass.")]
+ public void AddClassWithFiltersWithoutFilterDef()
+ {
+ var cfg = GetConfiguration();
+ cfg.AddResource("NHibernate.Test.FilterTest.SimpleFiltered.hbm.xml", GetType().Assembly);
+ var e = Assert.Throws<MappingException>(cfg.BuildMappings);
+ Assert.That(e.Message, Text.StartsWith("filter-def for filter named"));
+ Assert.That(e.Message, Text.Contains("was not found"));
+ }
+
+ [Test]
+ [Description("Class filter with condition does not add secondpass and add an invalid filter-def")]
+ public void ClassNoSecondPass()
+ {
+ const string classMap = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+ default-lazy='false'
+ assembly='NHibernate.Test'
+ namespace='NHibernate.Test.FilterTest' >
+
+ <class name='TestClass'>
+ <id name='Id' column='id'>
+ <generator class='assigned' />
+ </id>
+ <property name='Name'/>
+
+ <property name='Live'/>
+ <filter name='LiveFilter' condition=':LiveParam = Live'/>
+ </class>
+
+</hibernate-mapping>";
+
+ var cfg = GetConfiguration();
+ cfg.AddXmlString(classMap);
+ Assert.That(cfg.FiltersSecondPasses.Count, Is.EqualTo(0));
+ Assert.That(cfg.FilterDefinitions.Keys, Has.Member("LiveFilter"));
+ Assert.That(cfg.FilterDefinitions["LiveFilter"], Is.Null);
+ }
+
+ [Test]
+ [Description("Writing the condition in both sides should not change the condition defined in the class.")]
+ public void ClassConditionInBothSides()
+ {
+ const string classMap = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+ default-lazy='false'
+ assembly='NHibernate.Test'
+ namespace='NHibernate.Test.FilterTest' >
+
+ <class name='TestClass'>
+ <id name='Id' column='id'>
+ <generator class='assigned' />
+ </id>
+ <property name='Name'/>
+
+ <property name='Live'/>
+ <filter name='LiveFilter' condition='Live = 1'/>
+ </class>
+
+</hibernate-mapping>";
+
+ const string filterDef = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2' >
+
+ <filter-def name='LiveFilter' condition=':LiveParam = Live'>
+ <filter-param name='LiveParam' type='boolean'/>
+ </filter-def>
+
+</hibernate-mapping>";
+
+ var cfg = GetConfiguration();
+ cfg.AddXmlString(classMap);
+ cfg.AddXmlString(filterDef);
+ Assert.That(cfg.FiltersSecondPasses.Count, Is.EqualTo(0));
+ Assert.That(cfg.FilterDefinitions.Keys, Has.Member("LiveFilter"));
+ Assert.That(cfg.FilterDefinitions["LiveFilter"], Is.Not.Null);
+
+ cfg.BuildMappings();
+ Assert.That(cfg.FilterDefinitions.Count, Is.EqualTo(1));
+
+ var pc = cfg.GetClassMapping(typeof(TestClass));
+ Assert.That(pc.FilterMap["LiveFilter"], Is.EqualTo("Live = 1"));
+ }
+
+ [Test]
+ [Description("Filter-def duplication should Throw exception")]
+ public void DuplicatedFilterDef()
+ {
+ const string filterDef = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2' >
+
+ <filter-def name='LiveFilter'>
+ <filter-param name='LiveParam' type='boolean'/>
+ </filter-def>
+
+ <filter-def name='LiveFilter'>
+ <filter-param name='LiveParam' type='boolean'/>
+ </filter-def>
+
+</hibernate-mapping>";
+
+ var cfg = GetConfiguration();
+ var e = Assert.Throws<MappingException>(() => cfg.AddXmlString(filterDef));
+ Assert.That(e.InnerException, Is.Not.Null);
+ Assert.That(e.InnerException.Message, Text.Contains("Duplicated filter-def"));
+ }
+
+ [Test]
+ [Description("Add a filtered class with condition but without a filter-def should Throw exception")]
+ public void MissedFilterDef()
+ {
+ const string classMap = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'
+ default-lazy='false'
+ assembly='NHibernate.Test'
+ namespace='NHibernate.Test.FilterTest' >
+
+ <class name='TestClass'>
+ <id name='Id' column='id'>
+ <generator class='assigned' />
+ </id>
+ <property name='Name'/>
+
+ <property name='Live'/>
+ <filter name='LiveFilter' condition='Live = 1'/>
+ </class>
+
+</hibernate-mapping>";
+ var cfg = GetConfiguration();
+ cfg.AddXmlString(classMap);
+ var e = Assert.Throws<MappingException>(()=>cfg.BuildSessionFactory());
+ Assert.That(e.Message, Text.StartsWith("filter-def for filter named"));
+ Assert.That(e.Message, Text.Contains("was not found"));
+ }
+
+ [Test]
+ [Description("Filter-def without reference to it should Throw exception")]
+ public void FilterDefWithoutReference()
+ {
+ const string filterDef = @"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2' >
+
+ <filter-def name='LiveFilter'>
+ <filter-param name='LiveParam' type='boolean'/>
+ </filter-def>
+
+</hibernate-mapping>";
+
+ var cfg = GetConfiguration();
+ cfg.AddXmlString(filterDef);
+ var e = Assert.Throws<MappingException>(() => cfg.BuildSessionFactory());
+ Assert.That(e.Message, Text.StartsWith("filter-def for filter named"));
+ Assert.That(e.Message, Text.Contains("was never used to filter classes nor collections."));
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/FilterTest/FilterSecondPassArgsFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/FilterSecondPassArgsFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/FilterSecondPassArgsFixture.cs 2009-08-03 22:45:29 UTC (rev 4678)
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using NHibernate.Mapping;
+using NUnit.Framework;
+using NHibernate.Cfg;
+
+namespace NHibernate.Test.FilterTest
+{
+ [TestFixture]
+ public class FilterSecondPassArgsFixture
+ {
+ public class FakeFilterable: IFilterable
+ {
+ public void AddFilter(string name, string condition)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IDictionary<string, string> FilterMap
+ {
+ get { throw new NotImplementedException(); }
+ }
+ }
+ [Test]
+ public void CtorProtection()
+ {
+ Assert.Throws<ArgumentNullException>(() => new FilterSecondPassArgs(null, ""));
+ Assert.Throws<ArgumentNullException>(() => new FilterSecondPassArgs(null, "a>1"));
+ Assert.Throws<ArgumentNullException>(() => new FilterSecondPassArgs(new FakeFilterable(), null));
+ Assert.Throws<ArgumentNullException>(() => new FilterSecondPassArgs(new FakeFilterable(), ""));
+ Assert.DoesNotThrow(() => new FilterSecondPassArgs(new FakeFilterable(), "a>1"));
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFiltered.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFiltered.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFiltered.hbm.xml 2009-08-03 22:45:29 UTC (rev 4678)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ default-lazy="false"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.FilterTest" >
+
+ <class name="TestClass">
+ <id name="Id" column="id">
+ <generator class="assigned" />
+ </id>
+ <property name="Name"/>
+ <property name="Live" type="Boolean" />
+ <filter name="LiveFilter" />
+ <filter name="LiveFilter2" />
+ </class>
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFilteredFiltersDefsOk.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFilteredFiltersDefsOk.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/SimpleFilteredFiltersDefsOk.hbm.xml 2009-08-03 22:45:29 UTC (rev 4678)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
+
+ <filter-def name="LiveFilter" condition=":LiveParam = Live">
+ <filter-param name="LiveParam" type="boolean"/>
+ </filter-def>
+
+ <filter-def name="LiveFilter2">
+ <![CDATA[Name = :LiveParam2]]>
+ <filter-param name="LiveParam2" type="string"/>
+ </filter-def>
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/FilterTest/WrongFilterDefInClass.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/WrongFilterDefInClass.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/WrongFilterDefInClass.hbm.xml 2009-08-03 22:45:29 UTC (rev 4678)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ default-lazy="false"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.FilterTest" >
+
+ <class name="TestClass">
+ <id name="Id" column="id">
+ <generator class="assigned" />
+ </id>
+ <property name="Name" type="StringClob" length="100000" />
+
+ <property name="Live" type="Boolean" />
+ <filter name="LiveFilter"/>
+ </class>
+
+ <filter-def name="LiveFilter">
+ <filter-param name="LiveParam" type="boolean"/>
+ </filter-def>
+
+</hibernate-mapping>
Modified: trunk/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml 2009-08-03 22:25:32 UTC (rev 4677)
+++ trunk/nhibernate/src/NHibernate.Test/FilterTest/defs.hbm.xml 2009-08-03 22:45:29 UTC (rev 4678)
@@ -19,8 +19,4 @@
<filter-def name="seniorSalespersons">
<filter-param name="asOfDate" type="DateTime"/>
</filter-def>
-
- <filter-def name="cat">
- <filter-param name="catId" type="long"/>
- </filter-def>
</hibernate-mapping>
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-03 22:25:32 UTC (rev 4677)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-03 22:45:29 UTC (rev 4678)
@@ -271,10 +271,12 @@
<Compile Include="Extralazy\User.cs" />
<Compile Include="FilterTest\BinaryFiltered.cs" />
<Compile Include="FilterTest\Category.cs" />
+ <Compile Include="FilterTest\ConfigFixture.cs" />
<Compile Include="FilterTest\Department.cs" />
<Compile Include="FilterTest\DynamicFilterTest.cs" />
<Compile Include="FilterTest\FilterBinaryParameterTest.cs" />
<Compile Include="FilterTest\FilterConfig.cs" />
+ <Compile Include="FilterTest\FilterSecondPassArgsFixture.cs" />
<Compile Include="FilterTest\LineItem.cs" />
<Compile Include="FilterTest\Order.cs" />
<Compile Include="FilterTest\Product.cs" />
@@ -1969,6 +1971,9 @@
<EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" />
<EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="FilterTest\SimpleFiltered.hbm.xml" />
+ <EmbeddedResource Include="FilterTest\SimpleFilteredFiltersDefsOk.hbm.xml" />
+ <EmbeddedResource Include="FilterTest\WrongFilterDefInClass.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1898\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1907\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1899\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ric...@us...> - 2009-08-04 12:51:24
|
Revision: 4680
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4680&view=rev
Author: ricbrown
Date: 2009-08-04 12:51:17 +0000 (Tue, 04 Aug 2009)
Log Message:
-----------
Merge r4679 (Fix NH-1908)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Model.cs
Modified: trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs 2009-08-04 12:49:38 UTC (rev 4679)
+++ trunk/nhibernate/src/NHibernate/Param/ParameterTranslationsImpl.cs 2009-08-04 12:51:17 UTC (rev 4680)
@@ -72,19 +72,13 @@
// NH Different behaviour NH-1776
// Analyze all named parameters declared after filters
// in general all named parameters but depend on the complexity of the query (see sub query)
- foreach (ParameterInfo entry in _namedParameters.Values)
+ RestoreOriginalParameterLocations();
+ foreach (int filterParameterLocation in parameters.FilteredParameterLocations)
{
- int amountOfPush = 0;
- foreach (int existingParameterLocation in parameters.FilteredParameterLocations)
+ foreach (ParameterInfo entry in _namedParameters.Values)
{
- // a parameter span, at least, one value; where span more than one all values are cosecutive
- // the first position determines the position of the others values
- if (entry.SqlLocations[0]+amountOfPush >= existingParameterLocation)
- {
- amountOfPush++;
- }
+ entry.IncrementLocationAfterFilterLocation(filterParameterLocation);
}
- entry.IncrementLocation(amountOfPush);
}
}
@@ -123,6 +117,14 @@
get { return _ordinalParameters.Length; }
}
+ private void RestoreOriginalParameterLocations()
+ {
+ foreach (ParameterInfo entry in _namedParameters.Values)
+ {
+ entry.RestoreOriginalParameterLocations();
+ }
+ }
+
private ParameterInfo GetOrdinalParameterInfo(int ordinalPosition)
{
// remember that ordinal parameters numbers are 1-based!!!
@@ -169,15 +171,22 @@
public IType ExpectedType { get; private set; }
- public void IncrementLocation(int amountOfPush)
+ public void RestoreOriginalParameterLocations()
{
- if(amountOfPush <= 0)
+ for (int i = 0; i < sqlLocations.Length; i++)
{
- return; // short cut
+ sqlLocations[i] = originalLocation[i];
}
+ }
+
+ public void IncrementLocationAfterFilterLocation(int filterParameterLocation)
+ {
for (int i = 0; i < sqlLocations.Length; i++)
{
- sqlLocations[i] = originalLocation[i] + amountOfPush;
+ if (sqlLocations[i] >= filterParameterLocation)
+ {
+ sqlLocations[i]++;
+ }
}
}
}
Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908
___________________________________________________________________
Added: bugtraq:url
+ http://jira.nhibernate.org/browse/%BUGID%
Added: bugtraq:logregex
+ NH-\d+
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Fixture.cs 2009-08-04 12:51:17 UTC (rev 4680)
@@ -0,0 +1,35 @@
+using System;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH1908
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+
+ [Test]
+ public void QueryPropertyInBothFilterAndQuery()
+ {
+ using (ISession s = OpenSession())
+ {
+ s.EnableFilter("validity")
+ .SetParameter("date", DateTime.Now);
+
+ s.CreateQuery(@"
+ select
+ inv.ID
+ from
+ Invoice inv
+ join inv.Category cat with cat.ValidUntil > :now
+ left join cat.ParentCategory parentCat
+ where
+ inv.ID = :invId
+ and inv.Issued < :now
+ ")
+ .SetDateTime("now", DateTime.Now)
+ .SetInt32("invId", -999)
+ .List();
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Mappings.hbm.xml 2009-08-04 12:51:17 UTC (rev 4680)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH1908">
+
+ <class name="Category">
+ <id name="ID" type="Int32">
+ <generator class="hilo" />
+ </id>
+ <property name="ValidUntil" type="DateTime" />
+ <many-to-one name="ParentCategory" column="CategoryId" class="Category" />
+ <filter name="validity" condition="ValidUntil > :date" />
+ </class>
+
+ <class name="Invoice">
+ <id name="ID" type="Int32">
+ <generator class="hilo" />
+ </id>
+
+ <many-to-one name="Category" column="CategoryId" class="Category" />
+ <property name="Issued" type="DateTime" />
+ </class>
+
+ <filter-def name="validity">
+ <filter-param name="date" type="DateTime"/>
+ </filter-def>
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Model.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1908/Model.cs 2009-08-04 12:51:17 UTC (rev 4680)
@@ -0,0 +1,18 @@
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH1908
+{
+ public class Category
+ {
+ public virtual int ID { get; private set; }
+ public virtual Category ParentCategory { get; set; }
+ public virtual DateTime ValidUntil { get; set; }
+ }
+
+ public class Invoice
+ {
+ public virtual int ID { get; private set; }
+ public virtual DateTime Issued { get; set; }
+ public virtual Category Category { 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 2009-08-04 12:49:38 UTC (rev 4679)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-08-04 12:51:17 UTC (rev 4680)
@@ -558,6 +558,8 @@
<Compile Include="NHSpecificTest\NH1899\SampleTest.cs" />
<Compile Include="NHSpecificTest\NH1907\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1907\MyType.cs" />
+ <Compile Include="NHSpecificTest\NH1908\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1908\Model.cs" />
<Compile Include="NHSpecificTest\NH473\Child.cs" />
<Compile Include="NHSpecificTest\NH473\Fixture.cs" />
<Compile Include="NHSpecificTest\NH473\Parent.cs" />
@@ -1974,6 +1976,7 @@
<EmbeddedResource Include="FilterTest\SimpleFiltered.hbm.xml" />
<EmbeddedResource Include="FilterTest\SimpleFilteredFiltersDefsOk.hbm.xml" />
<EmbeddedResource Include="FilterTest\WrongFilterDefInClass.hbm.xml" />
+ <EmbeddedResource Include="NHSpecificTest\NH1908\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1898\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1907\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1899\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|