mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
This commit is contained in:
parent
8f7af7efd7
commit
a64105f03e
@ -38,10 +38,18 @@ trait SimpleExpression[T] extends Expression[T]{
|
||||
|
||||
def eq(right: Expression[T]) = boolean(EQ_OBJECT, this, right);
|
||||
|
||||
def ===(right: T) = eq(right);
|
||||
|
||||
def ===(right: Expression[T]) = eq(right);
|
||||
|
||||
def ne(right: T): BooleanExpression = ne(constant(right));
|
||||
|
||||
def ne(right: Expression[T]) = boolean(NE_OBJECT, this, right);
|
||||
|
||||
def !==(right: T) = ne(right);
|
||||
|
||||
def !==(right: Expression[T]) = ne(right);
|
||||
|
||||
def count() = number[java.lang.Long](classOf[java.lang.Long], AggOps.COUNT_AGG, this);
|
||||
|
||||
def in(right: Collection[T]) = boolean(IN, this, constant(right));
|
||||
@ -135,6 +143,10 @@ trait ComparableExpression[T <: Comparable[_]] extends ComparableExpressionBase[
|
||||
|
||||
def lt(right: Expression[T]): BooleanExpression = boolean(BEFORE, this, right);
|
||||
|
||||
def <(right: T) = lt(right);
|
||||
|
||||
def <(right: Expression[T]) = lt(right);
|
||||
|
||||
def between(left: T, right: T): BooleanExpression = between(constant(left), constant(right));
|
||||
|
||||
def between(left: Expression[T], right: Expression[T]) = boolean(BETWEEN, this, left, right); ;
|
||||
@ -147,13 +159,25 @@ trait ComparableExpression[T <: Comparable[_]] extends ComparableExpressionBase[
|
||||
|
||||
def gt(right: Expression[T]) = boolean(AFTER, this, right);
|
||||
|
||||
def >(right: T) = gt(right);
|
||||
|
||||
def >(right: Expression[T]) = gt(right);
|
||||
|
||||
def goe(right: T): BooleanExpression = goe(constant(right));
|
||||
|
||||
def goe(right: Expression[T]) = boolean(AOE, this, right);
|
||||
|
||||
def >=(right: T) = goe(right);
|
||||
|
||||
def >=(right: Expression[T]) = goe(right);
|
||||
|
||||
def loe(right: T): BooleanExpression = loe(constant(right));
|
||||
|
||||
def loe(right: Expression[T]) = boolean(BOE, this, right);
|
||||
|
||||
def <=(right: T) = loe(right);
|
||||
|
||||
def <=(right: Expression[T]) = loe(right);
|
||||
|
||||
override def as(right: Path[T]) = comparable(getType, ALIAS.asInstanceOf[Operator[T]], this, right);
|
||||
|
||||
@ -175,9 +199,17 @@ trait NumberExpression[T <: Number with Comparable[T]] extends ComparableExpress
|
||||
|
||||
def goe(right: NumberExpr) = boolean(Ops.GOE, this, right);
|
||||
|
||||
def >=(right: Number) = goe(right);
|
||||
|
||||
def >=(right: NumberExpr) = goe(right);
|
||||
|
||||
def gt(right: Number): BooleanExpression = gt(constant(right));
|
||||
|
||||
def gt(right: NumberExpr) = boolean(Ops.GT, this, right);
|
||||
|
||||
def >(right: Number) = gt(right);
|
||||
|
||||
def >(right: NumberExpr) = gt(right);
|
||||
|
||||
def between(left: Number, right: Number) = boolean(Ops.BETWEEN, this, constant(left), constant(right));
|
||||
|
||||
@ -190,10 +222,18 @@ trait NumberExpression[T <: Number with Comparable[T]] extends ComparableExpress
|
||||
def loe(right: Number): BooleanExpression = loe(constant(right));
|
||||
|
||||
def loe(right: NumberExpr) = boolean(Ops.LOE, this, right);
|
||||
|
||||
def <=(right: Number) = loe(right);
|
||||
|
||||
def <=(right: NumberExpr) = loe(right);
|
||||
|
||||
def lt(right: Number): BooleanExpression = lt(constant(right));
|
||||
|
||||
def lt(right: NumberExpr) = boolean(Ops.LT, this, right);
|
||||
|
||||
def <(right: Number) = lt(right);
|
||||
|
||||
def <(right: NumberExpr) = lt(right);
|
||||
|
||||
def in(right: NumberArray) = boolean(IN, this, constant(asList(right: _*)));
|
||||
|
||||
@ -265,8 +305,12 @@ trait BooleanExpression extends ComparableExpression[java.lang.Boolean] with Pre
|
||||
|
||||
def and(right: Predicate) = boolean(Ops.AND, this, right);
|
||||
|
||||
def &&(right: Predicate) = and(right);
|
||||
|
||||
def or(right: Predicate) = boolean(Ops.OR, this, right);
|
||||
|
||||
def ||(right: Predicate) = or(right);
|
||||
|
||||
def not() = boolean(Ops.NOT, this);
|
||||
|
||||
override def as(right: Path[java.lang.Boolean]) = boolean(ALIAS.asInstanceOf[Operator[java.lang.Boolean]], this, right);
|
||||
@ -284,6 +328,10 @@ trait StringExpression extends ComparableExpression[String] {
|
||||
def append(right: Expression[String]) = string(Ops.CONCAT, this, right);
|
||||
|
||||
def append(right: String): StringExpression = append(constant(right));
|
||||
|
||||
def +(right: Expression[String]) = append(right);
|
||||
|
||||
def +(right: String) = append(right);
|
||||
|
||||
def concat(right: Expression[String]) = append(right);
|
||||
|
||||
|
||||
@ -22,7 +22,8 @@ import scala.collection.mutable.Set
|
||||
class ScalaMetaDataSerializer(namePrefix: String, nameSuffix: String, val namingStrategy: NamingStrategy)
|
||||
extends ScalaEntitySerializer(namePrefix, nameSuffix) {
|
||||
|
||||
override val classHeaderFormat = "%1$s(path: String) extends RelationalPathImpl[%2$s](classOf[%2$s], path)";
|
||||
// override val classHeaderFormat = "%1$s(path: String) extends RelationalPathImpl[%2$s](classOf[%2$s], path)";
|
||||
override val classHeaderFormat = "%1$s(cl: Class[_ <: %2$s], md: PathMetadata[_]) extends RelationalPathImpl[%2$s](cl, md)";
|
||||
|
||||
def this(namePrefix: String, namingStrategy: NamingStrategy) = this(namePrefix, "", namingStrategy);
|
||||
|
||||
|
||||
@ -178,7 +178,7 @@ class AliasTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
def Complex_Starts_With_And_Less_Than_And_Is_Null() {
|
||||
def Complex_Starts_With_And_Less_Than_And_Is_Null {
|
||||
val expr: Predicate = (person.firstName $startsWith person.lastName) $and (person.javaInt $lt person.scalaInt) $or (person.javaDouble $isNull);
|
||||
assertEquals("startsWith(person.firstName,person.lastName) " +
|
||||
"&& person.javaInt < person.scalaInt " +
|
||||
@ -186,41 +186,41 @@ class AliasTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
def Lt_and_Gt() {
|
||||
def Lt_and_Gt {
|
||||
val expr: Predicate = (person.javaInt $lt 5) $and (person.scalaInt $gt 7);
|
||||
assertEquals("person.javaInt < 5 && person.scalaInt > 7", expr);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Gt_and_Lt() {
|
||||
def Gt_and_Lt {
|
||||
val expr: Predicate = (person.javaInt $gt 5) $and (person.scalaInt $lt 7);
|
||||
assertEquals("person.javaInt > 5 && person.scalaInt < 7", expr);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Lt_or_Gt() {
|
||||
def Lt_or_Gt {
|
||||
val expr: Predicate = (person.javaInt $lt 5) $or (person.scalaInt $gt 7);
|
||||
assertEquals("person.javaInt < 5 || person.scalaInt > 7", expr);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Gt_or_Lt() {
|
||||
def Gt_or_Lt {
|
||||
val expr: Predicate = (person.javaInt $gt 5) $or (person.scalaInt $lt 7);
|
||||
assertEquals("person.javaInt > 5 || person.scalaInt < 7", expr);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Starts_with() {
|
||||
def Starts_with {
|
||||
assertEquals("startsWith(person.firstName,amin)", person.firstName $startsWith "amin");
|
||||
}
|
||||
|
||||
@Test
|
||||
def Ends_with() {
|
||||
def Ends_with {
|
||||
assertEquals("endsWith(person.firstName,amin)", person.firstName $endsWith "amin");
|
||||
}
|
||||
|
||||
@Test
|
||||
def Prefix(){
|
||||
def Prefix {
|
||||
assertEquals("count(person)", count(person));
|
||||
assertEquals("min(person.javaInt)", min(person.javaInt));
|
||||
assertEquals("min(person.scalaInt)", min(person.scalaInt));
|
||||
|
||||
@ -17,10 +17,20 @@ class ExpressionTest {
|
||||
assertEquals("person.other.firstName = Ben", person.other.firstName eq "Ben");
|
||||
}
|
||||
|
||||
@Test
|
||||
def Long_Path_With_Operators {
|
||||
assertEquals("person.other.firstName = Ben", person.other.firstName === "Ben");
|
||||
}
|
||||
|
||||
@Test
|
||||
def Path_Equality {
|
||||
assertEquals("person.firstName = person.lastName", person.firstName eq person.lastName);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Path_Equality_With_Operators {
|
||||
assertEquals("person.firstName = person.lastName", person.firstName === person.lastName);
|
||||
}
|
||||
|
||||
@Test
|
||||
def String_Equality {
|
||||
@ -28,6 +38,13 @@ class ExpressionTest {
|
||||
assertEquals("person.firstName != Ben", person.firstName ne "Ben");
|
||||
assertEquals("person.firstName != Ben", person.firstName ne "Ben");
|
||||
}
|
||||
|
||||
@Test
|
||||
def String_Equality_With_Operators {
|
||||
assertEquals("person.firstName = Ben", person.firstName === "Ben");
|
||||
assertEquals("person.firstName != Ben", person.firstName !== "Ben");
|
||||
assertEquals("person.firstName != Ben", person.firstName !== "Ben");
|
||||
}
|
||||
|
||||
@Test
|
||||
def String_Like {
|
||||
@ -44,10 +61,20 @@ class ExpressionTest {
|
||||
assertEquals("person.firstName + x", person.firstName append "x");
|
||||
}
|
||||
|
||||
@Test
|
||||
def String_Append_With_Operators {
|
||||
assertEquals("person.firstName + x", person.firstName + "x");
|
||||
}
|
||||
|
||||
@Test
|
||||
def String_Append2 {
|
||||
assertEquals("person.firstName + + person.lastName", person.firstName append " " append person.lastName);
|
||||
}
|
||||
|
||||
@Test
|
||||
def String_Append2_With_Operators {
|
||||
assertEquals("person.firstName + + person.lastName", person.firstName + " " + person.lastName);
|
||||
}
|
||||
|
||||
@Test
|
||||
def String_And {
|
||||
@ -88,6 +115,18 @@ class ExpressionTest {
|
||||
assertEquals("person.javaInt = 5", person.javaInt eq 5.asInstanceOf[Integer]); // FIXME
|
||||
assertEquals("person.javaInt != 5", person.javaInt ne 5.asInstanceOf[Integer]); // FIXME
|
||||
}
|
||||
|
||||
@Test
|
||||
def Number_Comparison_With_Operators {
|
||||
assertEquals("person.scalaInt < 5", person.scalaInt < 5);
|
||||
assertEquals("person.scalaInt = 5", person.scalaInt === 5);
|
||||
assertEquals("person.javaInt < 5", person.javaInt < 5);
|
||||
assertEquals("person.javaInt > 5", person.javaInt > 5);
|
||||
assertEquals("person.javaInt <= 5", person.javaInt <= 5);
|
||||
assertEquals("person.javaInt >= 5", person.javaInt >= 5);
|
||||
assertEquals("person.javaInt = 5", person.javaInt === 5);
|
||||
assertEquals("person.javaInt != 5", person.javaInt !== 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Number_Between {
|
||||
@ -178,7 +217,7 @@ class ExpressionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
def Complex_Starts_With_And_Less_Than_And_Is_Null() {
|
||||
def Complex_Starts_With_And_Less_Than_And_Is_Null {
|
||||
val expr: Predicate = (person.firstName startsWith person.lastName) and (person.javaInt lt person.scalaInt) or (person.javaDouble isNull);
|
||||
assertEquals("startsWith(person.firstName,person.lastName) " +
|
||||
"&& person.javaInt < person.scalaInt " +
|
||||
@ -186,36 +225,63 @@ class ExpressionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
def Lt_and_Gt() {
|
||||
def Complex_Starts_With_And_Less_Than_And_Is_Null_With_Operators {
|
||||
val expr: Predicate = (person.firstName startsWith person.lastName) and (person.javaInt lt person.scalaInt) or (person.javaDouble isNull);
|
||||
assertEquals("startsWith(person.firstName,person.lastName) && person.javaInt < person.scalaInt || person.javaDouble is null",
|
||||
person.firstName.startsWith(person.lastName) && person.javaInt < person.scalaInt || person.javaDouble.isNull);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Lt_and_Gt {
|
||||
val expr: Predicate = (person.javaInt lt 5) and (person.scalaInt gt 7);
|
||||
assertEquals("person.javaInt < 5 && person.scalaInt > 7", expr);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Gt_and_Lt() {
|
||||
def Lt_and_Gt_With_Operators {
|
||||
assertEquals("person.javaInt < 5 && person.scalaInt > 7", person.javaInt < 5 && person.scalaInt > 7);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Gt_and_Lt {
|
||||
val expr: Predicate = (person.javaInt gt 5) and (person.scalaInt lt 7);
|
||||
assertEquals("person.javaInt > 5 && person.scalaInt < 7", expr);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Lt_or_Gt() {
|
||||
def Gt_and_Lt_With_Operators {
|
||||
assertEquals("person.javaInt > 5 && person.scalaInt < 7", person.javaInt > 5 && person.scalaInt < 7);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Lt_or_Gt {
|
||||
val expr: Predicate = (person.javaInt lt 5) or (person.scalaInt gt 7);
|
||||
assertEquals("person.javaInt < 5 || person.scalaInt > 7", expr);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Gt_or_Lt() {
|
||||
def Lt_or_Gt_With_Operators {
|
||||
assertEquals("person.javaInt < 5 || person.scalaInt > 7", person.javaInt < 5 || person.scalaInt > 7);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Gt_or_Lt {
|
||||
val expr: Predicate = (person.javaInt gt 5) or (person.scalaInt lt 7);
|
||||
assertEquals("person.javaInt > 5 || person.scalaInt < 7", expr);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Gt_or_Lt_With_Operators {
|
||||
assertEquals("person.javaInt > 5 || person.scalaInt < 7", person.javaInt > 5 || person.scalaInt < 7);
|
||||
}
|
||||
|
||||
@Test
|
||||
def Starts_with() {
|
||||
def Starts_with {
|
||||
assertEquals("startsWith(person.firstName,amin)", person.firstName startsWith "amin");
|
||||
}
|
||||
|
||||
@Test
|
||||
def Ends_with() {
|
||||
def Ends_with {
|
||||
assertEquals("endsWith(person.firstName,amin)", person.firstName endsWith "amin");
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user