From 3a83024088a91b78fc1cd1aac68968c3dd61325c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Tue, 1 Mar 2011 08:57:05 +0000 Subject: [PATCH] --- .../scala/com/mysema/query/scala/Expressions.scala | 4 +++- .../scala/com/mysema/query/scala/Matchers.scala | 4 +++- .../com/mysema/query/scala/ExpressionTest.scala | 14 +++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/querydsl-scala/src/main/scala/com/mysema/query/scala/Expressions.scala b/querydsl-scala/src/main/scala/com/mysema/query/scala/Expressions.scala index 2af4450d7..4ab0ab172 100644 --- a/querydsl-scala/src/main/scala/com/mysema/query/scala/Expressions.scala +++ b/querydsl-scala/src/main/scala/com/mysema/query/scala/Expressions.scala @@ -70,7 +70,9 @@ trait SimpleExpression[T] extends Expression[T]{ def notIn(right: CollectionExpression[T,_]) = in(right).not; - def not[M <: SimpleExpression[T]](f: (M) => BooleanExpression): BooleanExpression = f(this.asInstanceOf[M]).not(); + def is[M <: SimpleExpression[T]](f: M => BooleanExpression): BooleanExpression = if (f == null) isNull() else f(this.asInstanceOf[M]); + + def not[M <: SimpleExpression[T]](f: M => BooleanExpression): BooleanExpression = f(this.asInstanceOf[M]).not(); } diff --git a/querydsl-scala/src/main/scala/com/mysema/query/scala/Matchers.scala b/querydsl-scala/src/main/scala/com/mysema/query/scala/Matchers.scala index a0c07a32c..d109f09e7 100644 --- a/querydsl-scala/src/main/scala/com/mysema/query/scala/Matchers.scala +++ b/querydsl-scala/src/main/scala/com/mysema/query/scala/Matchers.scala @@ -4,7 +4,9 @@ import com.mysema.query.types._ object Matchers { -// def in[T](values: T*) = (expr: SimpleExpression[T]) => expr.in(values); + def in[T](values: T*) = (expr: SimpleExpression[T]) => expr.in(values:_*); + + def not(v: Void) = (expr: SimpleExpression[_]) => expr.isNotNull(); // map diff --git a/querydsl-scala/src/test/scala/com/mysema/query/scala/ExpressionTest.scala b/querydsl-scala/src/test/scala/com/mysema/query/scala/ExpressionTest.scala index c73f34224..60ffe9bd0 100644 --- a/querydsl-scala/src/test/scala/com/mysema/query/scala/ExpressionTest.scala +++ b/querydsl-scala/src/test/scala/com/mysema/query/scala/ExpressionTest.scala @@ -14,6 +14,18 @@ class ExpressionTest { Assert.assertEquals(expected, actual.toString); } + @Test + def Is_Not_Null { + assertEquals("person.other is not null", person.other isNotNull); + assertEquals("person.other is not null", person.other is not(null) ); + } + + @Test + def Is_Null { + assertEquals("person.other is null", person.other isNull); + assertEquals("person.other is null", person.other is null ); + } + @Test def Long_Path { assertEquals("person.other.firstName = Ben", person.other.firstName eq "Ben"); @@ -98,7 +110,7 @@ class ExpressionTest { @Test def String_Or_With_Operators { - val orClause = (person.firstName like "An%") or (person.firstName like "Be%"); + val orClause = (person.firstName like "An%") || (person.firstName like "Be%"); assertEquals("person.firstName like An% || person.firstName like Be%", orClause); }