|
From: <ric...@us...> - 2010-07-31 08:30:24
|
Revision: 5083
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5083&view=rev
Author: ricbrown
Date: 2010-07-31 08:30:17 +0000 (Sat, 31 Jul 2010)
Log Message:
-----------
Returned AbstractCriterion from LambdaRestrictionBuilder to allow operator overloading syntax.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Criterion/AbstractEmptinessExpression.cs
trunk/nhibernate/src/NHibernate/Criterion/Lambda/LambdaRestrictionBuilder.cs
trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Criterion/AbstractEmptinessExpression.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/AbstractEmptinessExpression.cs 2010-07-30 17:03:00 UTC (rev 5082)
+++ trunk/nhibernate/src/NHibernate/Criterion/AbstractEmptinessExpression.cs 2010-07-31 08:30:17 UTC (rev 5083)
@@ -10,7 +10,7 @@
namespace NHibernate.Criterion
{
[Serializable]
- public abstract class AbstractEmptinessExpression : ICriterion
+ public abstract class AbstractEmptinessExpression : AbstractCriterion
{
private readonly TypedValue[] NO_VALUES = new TypedValue[0];
private readonly string propertyName;
@@ -23,19 +23,17 @@
this.propertyName = propertyName;
}
- public TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
+ public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return NO_VALUES;
}
- public abstract IProjection[] GetProjections();
-
public override sealed string ToString()
{
return propertyName + (ExcludeEmpty ? " is not empty" : " is empty");
}
- public SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
+ public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
string entityName = criteriaQuery.GetEntityName(criteria, propertyName);
string actualPropertyName = criteriaQuery.GetPropertyName(propertyName);
@@ -92,54 +90,5 @@
throw new QueryException("collection role not found: " + role, e);
}
}
-
- #region Operator Overloading
-
- public static AbstractCriterion operator &(AbstractEmptinessExpression lhs, AbstractEmptinessExpression rhs)
- {
- return new AndExpression(lhs, rhs);
- }
-
- public static AbstractCriterion operator |(AbstractEmptinessExpression lhs, AbstractEmptinessExpression rhs)
- {
- return new OrExpression(lhs, rhs);
- }
-
-
- public static AbstractCriterion operator &(AbstractEmptinessExpression lhs, AbstractCriterion rhs)
- {
- return new AndExpression(lhs, rhs);
- }
-
- public static AbstractCriterion operator |(AbstractEmptinessExpression lhs, AbstractCriterion rhs)
- {
- return new OrExpression(lhs, rhs);
- }
-
-
- public static AbstractCriterion operator !(AbstractEmptinessExpression crit)
- {
- return new NotExpression(crit);
- }
-
- /// <summary>
- /// See here for details:
- /// http://steve.emxsoftware.com/NET/Overloading+the++and++operators
- /// </summary>
- public static bool operator false(AbstractEmptinessExpression criteria)
- {
- return false;
- }
-
- /// <summary>
- /// See here for details:
- /// http://steve.emxsoftware.com/NET/Overloading+the++and++operators
- /// </summary>
- public static bool operator true(AbstractEmptinessExpression criteria)
- {
- return false;
- }
-
- #endregion
}
}
Modified: trunk/nhibernate/src/NHibernate/Criterion/Lambda/LambdaRestrictionBuilder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Criterion/Lambda/LambdaRestrictionBuilder.cs 2010-07-30 17:03:00 UTC (rev 5082)
+++ trunk/nhibernate/src/NHibernate/Criterion/Lambda/LambdaRestrictionBuilder.cs 2010-07-31 08:30:17 UTC (rev 5083)
@@ -37,7 +37,7 @@
private string propertyName;
private bool isNot;
- private ICriterion Process(ICriterion criterion)
+ private AbstractCriterion Process(AbstractCriterion criterion)
{
if (isNot)
return Restrictions.Not(criterion);
@@ -73,7 +73,7 @@
/// <summary>
/// Apply an "in" constraint to the named property
/// </summary>
- public ICriterion IsIn(ICollection values)
+ public AbstractCriterion IsIn(ICollection values)
{
return Process(Restrictions.In(propertyName, values));
}
@@ -81,7 +81,7 @@
/// <summary>
/// Apply an "in" constraint to the named property
/// </summary>
- public ICriterion IsIn(object[] values)
+ public AbstractCriterion IsIn(object[] values)
{
return Process(Restrictions.In(propertyName, values));
}
@@ -89,7 +89,7 @@
/// <summary>
/// Apply an "in" constraint to the named property
/// </summary>
- public ICriterion IsInG<T>(ICollection<T> values)
+ public AbstractCriterion IsInG<T>(ICollection<T> values)
{
return Process(Restrictions.InG(propertyName, values));
}
@@ -97,7 +97,7 @@
/// <summary>
/// A case-insensitive "like", similar to Postgres "ilike" operator
/// </summary>
- public ICriterion IsInsensitiveLike(object value)
+ public AbstractCriterion IsInsensitiveLike(object value)
{
return Process(Restrictions.InsensitiveLike(propertyName, value));
}
@@ -105,7 +105,7 @@
/// <summary>
/// A case-insensitive "like", similar to Postgres "ilike" operator
/// </summary>
- public ICriterion IsInsensitiveLike(string value, MatchMode matchMode)
+ public AbstractCriterion IsInsensitiveLike(string value, MatchMode matchMode)
{
return Process(Restrictions.InsensitiveLike(propertyName, value, matchMode));
}
@@ -113,7 +113,7 @@
/// <summary>
/// Apply an "is empty" constraint to the named property
/// </summary>
- public ICriterion IsEmpty
+ public AbstractCriterion IsEmpty
{
get { return Process(Restrictions.IsEmpty(propertyName)); }
}
@@ -121,7 +121,7 @@
/// <summary>
/// Apply a "not is empty" constraint to the named property
/// </summary>
- public ICriterion IsNotEmpty
+ public AbstractCriterion IsNotEmpty
{
get { return Process(Restrictions.IsNotEmpty(propertyName)); }
}
@@ -129,7 +129,7 @@
/// <summary>
/// Apply an "is null" constraint to the named property
/// </summary>
- public ICriterion IsNull
+ public AbstractCriterion IsNull
{
get { return Process(Restrictions.IsNull(propertyName)); }
}
@@ -137,7 +137,7 @@
/// <summary>
/// Apply an "not is null" constraint to the named property
/// </summary>
- public ICriterion IsNotNull
+ public AbstractCriterion IsNotNull
{
get { return Process(Restrictions.IsNotNull(propertyName)); }
}
@@ -145,7 +145,7 @@
/// <summary>
/// Apply a "like" constraint to the named property
/// </summary>
- public ICriterion IsLike(object value)
+ public AbstractCriterion IsLike(object value)
{
return Process(Restrictions.Like(propertyName, value));
}
@@ -153,7 +153,7 @@
/// <summary>
/// Apply a "like" constraint to the named property
/// </summary>
- public ICriterion IsLike(string value, MatchMode matchMode)
+ public AbstractCriterion IsLike(string value, MatchMode matchMode)
{
return Process(Restrictions.Like(propertyName, value, matchMode));
}
@@ -161,7 +161,7 @@
/// <summary>
/// Apply a "like" constraint to the named property
/// </summary>
- public ICriterion IsLike(string value, MatchMode matchMode, char? escapeChar)
+ public AbstractCriterion IsLike(string value, MatchMode matchMode, char? escapeChar)
{
return Process(Restrictions.Like(propertyName, value, matchMode, escapeChar));
}
Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2010-07-30 17:03:00 UTC (rev 5082)
+++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2010-07-31 08:30:17 UTC (rev 5083)
@@ -41,6 +41,7 @@
.Add(Restrictions.Between("Age", 18, 65))
.Add(Restrictions.Between("personAlias.Age", 18, 65))
.Add(Restrictions.Not(Restrictions.Between("personAlias.Age", 10, 20)))
+ .Add(!Restrictions.In("Name", new string[] { "name4" }))
.Add(Restrictions.In("Name", new string[] { "name1", "name2", "name3" }))
.Add(Restrictions.In("Name", new ArrayList() { "name1", "name2", "name3" }))
.Add(Restrictions.InG<int>("Age", new int[] { 1, 2, 3 }))
@@ -64,6 +65,7 @@
.Where(Restrictions.On<Person>(p => p.Age).IsBetween(18).And(65))
.And(Restrictions.On(() => personAlias.Age).IsBetween(18).And(65))
.And(Restrictions.On(() => personAlias.Age).Not.IsBetween(10).And(20))
+ .And(!Restrictions.On<Person>(p => p.Name).IsIn(new string[] { "name4" }))
.And(Restrictions.On<Person>(p => p.Name).IsIn(new string[] { "name1", "name2", "name3" }))
.And(Restrictions.On<Person>(p => p.Name).IsIn(new ArrayList() { "name1", "name2", "name3" }))
.And(Restrictions.On<Person>(p => p.Age).IsInG<int>(new int[] { 1, 2, 3 }))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|