|
From: <Ric...@us...> - 2009-06-24 18:58:46
|
Revision: 4524
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4524&view=rev
Author: RicBrown
Date: 2009-06-24 18:58:43 +0000 (Wed, 24 Jun 2009)
Log Message:
-----------
Added first cut of ICriteria<T> interface.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/LambdaFixtureBase.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs
trunk/nhibernate/src/NHibernate/Impl/CriteriaOfTImpl.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/CriteriaOfTFixture.cs
Added: trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/ICriteriaOfT.cs 2009-06-24 18:58:43 UTC (rev 4524)
@@ -0,0 +1,32 @@
+
+using System;
+using System.Linq.Expressions;
+
+namespace NHibernate
+{
+
+ /// <summary>
+ /// Criteria<T> is an API for retrieving entities by composing
+ /// <see cref="Criterion.Expression" /> objects expressed using Lambda expression syntax.
+ /// </summary>
+ /// <remarks>
+ /// <code>
+ /// IList<Cat> cats = session.QueryOver<Cat>()
+ /// .Add( c => c.Name == "Tigger" )
+ /// .Add( c => c.Weight > minWeight ) )
+ /// .List();
+ /// </code>
+ /// </remarks>
+ public interface ICriteria<T>
+ {
+
+ /// <summary>
+ /// Add criterion expressed as a lambda expression
+ /// </summary>
+ /// <param name="expression">Lambda expression</param>
+ /// <returns>criteria instance</returns>
+ ICriteria<T> Add(Expression<Func<T, bool>> expression);
+
+ }
+
+}
Added: trunk/nhibernate/src/NHibernate/Impl/CriteriaOfTImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/CriteriaOfTImpl.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Impl/CriteriaOfTImpl.cs 2009-06-24 18:58:43 UTC (rev 4524)
@@ -0,0 +1,35 @@
+
+using System;
+using System.Linq.Expressions;
+
+namespace NHibernate.Impl
+{
+
+ /// <summary>
+ /// Implementation of the <see cref="ICriteria<T>"/> interface
+ /// </summary>
+ [Serializable]
+ public class CriteriaImpl<T> : ICriteria<T>
+ {
+
+ private ICriteria _criteria;
+
+ public CriteriaImpl(ICriteria criteria)
+ {
+ _criteria = criteria;
+ }
+
+ public ICriteria UnderlyingCriteria
+ {
+ get { return _criteria; }
+ }
+
+ ICriteria<T> ICriteria<T>.Add(Expression<Func<T, bool>> expression)
+ {
+ _criteria.Add(expression);
+ return this;
+ }
+
+ }
+
+}
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-06-24 03:57:43 UTC (rev 4523)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-06-24 18:58:43 UTC (rev 4524)
@@ -515,6 +515,8 @@
<Compile Include="Hql\Ast\ANTLR\Tree\ASTErrorNode.cs" />
<Compile Include="Hql\Ast\ANTLR\Tree\InsertStatement.cs" />
<Compile Include="Hql\Ast\ANTLR\Tree\UpdateStatement.cs" />
+ <Compile Include="ICriteriaOfT.cs" />
+ <Compile Include="Impl\CriteriaOfTImpl.cs" />
<Compile Include="Impl\ExpressionProcessor.cs" />
<Compile Include="Impl\SessionIdLoggingContext.cs" />
<Compile Include="Param\AbstractExplicitParameterSpecification.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/CriteriaOfTFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/CriteriaOfTFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/CriteriaOfTFixture.cs 2009-06-24 18:58:43 UTC (rev 4524)
@@ -0,0 +1,34 @@
+using System;
+using System.Collections;
+
+using NUnit.Framework;
+
+using NHibernate.Criterion;
+using NHibernate.Transform;
+using NHibernate.Type;
+using NHibernate.Util;
+
+namespace NHibernate.Test.Criteria.Lambda
+{
+
+ [TestFixture]
+ public class CriteriaOfTFixture : LambdaFixtureBase
+ {
+
+ [Test]
+ public void Equality()
+ {
+ ICriteria expected =
+ CreateTestCriteria(typeof(Person))
+ .Add(Restrictions.Eq("Name", "test name"));
+
+ ICriteria<Person> actual =
+ CreateTestCriteria<Person>()
+ .Add(p => p.Name == "test name");
+
+ AssertCriteriaAreEqual(expected, actual);
+ }
+
+ }
+
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/LambdaFixtureBase.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/LambdaFixtureBase.cs 2009-06-24 03:57:43 UTC (rev 4523)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/LambdaFixtureBase.cs 2009-06-24 18:58:43 UTC (rev 4524)
@@ -29,6 +29,26 @@
return new CriteriaImpl(persistentClass, alias, null);
}
+ protected ICriteria<T> CreateTestCriteria<T>()
+ {
+ return new CriteriaImpl<T>(new CriteriaImpl(typeof(T), null));
+ }
+
+ protected void AssertCriteriaAreEqual(ICriteria expected, ICriteria actual)
+ {
+ AssertObjectsAreEqual(expected, actual);
+ }
+
+ protected void AssertCriteriaAreEqual(DetachedCriteria expected, DetachedCriteria actual)
+ {
+ AssertObjectsAreEqual(expected, actual);
+ }
+
+ protected void AssertCriteriaAreEqual<T>(ICriteria expected, ICriteria<T> actual)
+ {
+ AssertObjectsAreEqual(expected, ((CriteriaImpl<T>)actual).UnderlyingCriteria);
+ }
+
private void AssertDictionariesAreEqual(IDictionary expected, IDictionary actual)
{
Assert.AreEqual(expected.Keys.Count, actual.Keys.Count, _fieldPath.Peek() + ".Count");
@@ -127,16 +147,6 @@
AssertObjectsAreEqual(expected, actual, expected.GetType().Name);
}
- protected void AssertCriteriaAreEqual(ICriteria expected, ICriteria actual)
- {
- AssertObjectsAreEqual(expected, actual);
- }
-
- protected void AssertCriteriaAreEqual(DetachedCriteria expected, DetachedCriteria actual)
- {
- AssertObjectsAreEqual(expected, actual);
- }
-
}
}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-24 03:57:43 UTC (rev 4523)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-24 18:58:43 UTC (rev 4524)
@@ -145,6 +145,7 @@
<Compile Include="Criteria\Enrolment.cs" />
<Compile Include="Criteria\Lambda\CriteriaAssertFixture.cs" />
<Compile Include="Criteria\Lambda\CriteriaFixture.cs" />
+ <Compile Include="Criteria\Lambda\CriteriaOfTFixture.cs" />
<Compile Include="Criteria\Lambda\IntegrationFixture.cs" />
<Compile Include="Criteria\Lambda\LambdaFixtureBase.cs" />
<Compile Include="Criteria\Lambda\Model.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|