replaced type specific property factory methods in DomainType with generic ones

removed type specific property types
This commit is contained in:
Timo Westkämper 2008-02-21 19:40:18 +00:00
parent 876922e351
commit e0e8e32d09
17 changed files with 478 additions and 211 deletions

View File

@ -3,5 +3,8 @@
<classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="M2_REPO/com/mysema/commons/mysema-core/0.3.2/mysema-core-0.3.2.jar" sourcepath="M2_REPO/com/mysema/commons/mysema-core/0.3.2/mysema-core-0.3.2-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-io/commons-io/1.4-SNAPSHOT/commons-io-1.4-SNAPSHOT.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-lang/commons-lang/2.3/commons-lang-2.3.jar" sourcepath="M2_REPO/commons-lang/commons-lang/2.3/commons-lang-2.3-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/4.4/junit-4.4.jar" sourcepath="M2_REPO/junit/junit/4.4/junit-4.4-sources.jar"/>
</classpath>

View File

@ -1,7 +1,5 @@
#Wed Feb 20 22:05:00 EET 2008
#Thu Feb 21 18:44:46 EET 2008
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.compliance=1.5

View File

@ -16,7 +16,11 @@
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.mysema.commons</groupId>
<artifactId>mysema-core</artifactId>
<version>0.3.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -30,5 +34,5 @@
</exclusions>
</dependency>
</dependencies>
</project>

View File

@ -5,7 +5,8 @@
*/
package com.mysema.query;
import com.mysema.query.grammar.Types.*;
import com.mysema.query.grammar.Types.BooleanExpr;
import com.mysema.query.grammar.Types.EntityExpr;
/**
* ExtQuery externds the Query interface to provide innerJoin, leftJoin and with methods

View File

@ -5,7 +5,10 @@
*/
package com.mysema.query;
import com.mysema.query.grammar.Types.*;
import com.mysema.query.grammar.Types.BooleanExpr;
import com.mysema.query.grammar.Types.EntityExpr;
import com.mysema.query.grammar.Types.Expr;
import com.mysema.query.grammar.Types.OrderSpecifier;
/**
* Query provides a fluent query interface, operations can be constructed via the

View File

@ -5,6 +5,7 @@
*/
package com.mysema.query.grammar;
import java.util.Date;
import com.mysema.query.grammar.Types.*;
@ -16,16 +17,16 @@ import com.mysema.query.grammar.Types.*;
*/
public class Grammar {
static <RT,L,R> Operation<RT> _binOp(Op<RT> type, Expr<L> left, Expr<R> right) {
BinaryOperation<RT,L,R> op = new BinaryOperation<RT,L,R>();
static <L,R> BooleanOperation _binOp(Op<Boolean> type, Expr<L> left, Expr<R> right) {
BinaryBooleanOperation<L,R> op = new BinaryBooleanOperation<L,R>();
op.type = type;
op.left = left;
op.right = right;
return op;
}
static <L,R> BooleanOperation _binOp(Op<Boolean> type, Expr<L> left, Expr<R> right) {
BinaryBooleanOperation<L,R> op = new BinaryBooleanOperation<L,R>();
static <RT,L,R> Operation<RT> _binOp(Op<RT> type, Expr<L> left, Expr<R> right) {
BinaryOperation<RT,L,R> op = new BinaryOperation<RT,L,R>();
op.type = type;
op.left = left;
op.right = right;
@ -40,18 +41,27 @@ public class Grammar {
return e;
}
static <A> OrderSpecifier<A> _orderAsc(Expr<A> target) {
static <A extends Comparable<A>> OrderSpecifier<A> _orderAsc(Expr<A> target) {
OrderSpecifier<A> os = new OrderSpecifier<A>();
os.order = Order.ASC;
os.target = target;
return os;
}
static <A> OrderSpecifier<A> _orderDesc(Expr<A> target) {
static <A extends Comparable<A>> OrderSpecifier<A> _orderDesc(Expr<A> target) {
OrderSpecifier<A> os = new OrderSpecifier<A>();
os.order = Order.DESC;
os.target = target;
return os;
}
static <F,S,T> BooleanOperation _terOp(Op<Boolean> type, Expr<F> fst, Expr<S> snd, Expr<T> trd){
TertiaryBooleanOperation<F,S,T> op = new TertiaryBooleanOperation<F,S,T>();
op.type = type;
op.first = fst;
op.second = snd;
op.third = trd;
return op;
}
static <RT,F,S,T> Operation<RT> _terOp(Op<RT> type, Expr<F> fst, Expr<S> snd, Expr<T> trd){
@ -63,13 +73,6 @@ public class Grammar {
return op;
}
static <RT,A> Operation<RT> _unOp(Op<RT> type, Expr<A> left) {
UnaryOperation<RT,A> op = new UnaryOperation<RT,A>();
op.type = type;
op.left = left;
return op;
}
static <A> BooleanOperation _unOp(Op<Boolean> type, Expr<A> left) {
UnaryBooleanOperation<A> op = new UnaryBooleanOperation<A>();
op.type = type;
@ -77,51 +80,91 @@ public class Grammar {
return op;
}
public static BooleanExpr and(BooleanExpr left, BooleanExpr right){
return _binOp(BoOp.AND, left, right);
static <RT,A> Operation<RT> _unOp(Op<RT> type, Expr<A> left) {
UnaryOperation<RT,A> op = new UnaryOperation<RT,A>();
op.type = type;
op.left = left;
return op;
}
public static BooleanExpr after(Expr<Date> left, Date right){
// NOTE : basically same as gt
return _binOp(DateOp.AFTER, left, _const(right));
}
public static <A> OrderSpecifier<A> asc(Expr<A> target){
public static BooleanExpr after(Expr<Date> left, Expr<Date> right){
// NOTE : basically same as gt
return _binOp(DateOp.AFTER, left, right);
}
public static BooleanExpr and(BooleanExpr left, BooleanExpr right){
return _binOp(BoOp.AND, left, right);
}
public static <A extends Comparable<A>> OrderSpecifier<A> asc(Expr<A> target){
return _orderAsc(target);
}
public static BooleanExpr before(Expr<Date> left, Date right){
// NOTE : basically same as lt
return _binOp(DateOp.BEFORE, left, _const(right));
}
public static BooleanExpr before(Expr<Date> left, Expr<Date> right){
// NOTE : basically same as lt
return _binOp(DateOp.BEFORE, left, right);
}
public static <A extends Comparable<A>> BooleanExpr between(Expr<A> left, A start, A end){
return _terOp(CompOp.BETWEEN, left, _const(start), _const(end));
}
public static Expr<String> concat(Expr<String> left, Expr<String> right){
return _binOp(StrOp.CONCAT, left, right);
}
public static <A> OrderSpecifier<A> desc(Expr<A> target){
return _orderDesc(target);
}
public static <A> BooleanExpr eq(Expr<A> left, Expr<A> right){
return _binOp(NumOp.EQ, left, right);
}
public static <A extends Comparable<A>> OrderSpecifier<A> desc(Expr<A> target){
return _orderDesc(target);
}
public static <A> BooleanExpr eq(Expr<A> left, A right){
return _binOp(NumOp.EQ, left, _const(right));
}
public static <A,B extends A> BooleanExpr eq(Expr<A> left, B right){
return _binOp(Op.EQ, left, _const(right));
}
public static <A,B extends A> BooleanExpr eq(Expr<A> left, Expr<B> right){
return _binOp(Op.EQ, left, right);
}
public static <A> BooleanExpr goe(Expr<A> left, A right){
public static <A extends Comparable<A>> BooleanExpr goe(Expr<A> left, A right){
return _binOp(NumOp.GOE, left, _const(right));
}
}
public static <A> BooleanExpr goe(Expr<A> left, Expr<A> right){
public static <A extends Comparable<A>> BooleanExpr goe(Expr<A> left, Expr<A> right){
return _binOp(NumOp.GOE, left, right);
}
public static <A> BooleanExpr gt(Expr<A> left, A right){
public static <A extends Comparable<A>> BooleanExpr gt(Expr<A> left, A right){
return _binOp(NumOp.GT, left, _const(right));
}
}
public static <A> BooleanExpr gt(Expr<A> left, Expr<A> right){
public static <A extends Comparable<A>> BooleanExpr gt(Expr<A> left, Expr<A> right){
return _binOp(NumOp.GT, left, right);
}
public static <A> BooleanExpr in(Expr<A> left, A... rest){
// TODO
return null;
}
public static BooleanExpr like(Expr<String> left, String right){
return _binOp(StrOp.LIKE, left, _const(right));
}
public static <A> BooleanExpr loe(Expr<A> left, Expr<A> right){
public static <A extends Comparable<A>> BooleanExpr loe(Expr<A> left, A right){
return _binOp(NumOp.LOE, left, _const(right));
}
public static <A extends Comparable<A>> BooleanExpr loe(Expr<A> left, Expr<A> right){
return _binOp(NumOp.LOE, left, right);
}
@ -129,40 +172,43 @@ public class Grammar {
return _unOp(StrOp.LOWER, left);
}
public static <A> BooleanExpr lt(Expr<A> left, A right){
public static <A extends Comparable<A>> BooleanExpr lt(Expr<A> left, A right){
return _binOp(NumOp.LT, left, _const(right));
}
}
public static <A> BooleanExpr lt(Expr<A> left, Expr<A> right){
public static <A extends Comparable<A>> BooleanExpr lt(Expr<A> left, Expr<A> right){
return _binOp(NumOp.LT, left, right);
}
public static <A> BooleanExpr ne(Expr<A> left, A right){
return _binOp(NumOp.NE, left, _const(right));
public static <A,B extends A> BooleanExpr ne(Expr<A> left, B right){
return _binOp(Op.NE, left, _const(right));
}
public static <A> BooleanExpr ne(Expr<A> left, Expr<A> right){
return _binOp(NumOp.NE, left, right);
}
public static <A,B extends A> BooleanExpr ne(Expr<A> left, Expr<B> right){
return _binOp(Op.NE, left, right);
}
public static BooleanExpr not(BooleanExpr left){
return _unOp(BoOp.NOT, left);
}
}
public static BooleanExpr or(BooleanExpr left, BooleanExpr right){
return _binOp(BoOp.OR, left, right);
}
public static Expr<String> substr(Expr<String> left, int start){
return _binOp(StrOp.SUBSTRING, left, _const(start));
return _binOp(StrOp.SUBSTR, left, _const(start));
}
public static Expr<String> substr(Expr<String> left, int start, int offset){
return _terOp(StrOp.SUBSTR, left, _const(start), _const(offset));
}
public static Expr<String> substr(Expr<String> left, int start, int offset){
return _terOp(StrOp.SUBSTRING, left, _const(start), _const(offset));
public static <A,B extends A> BooleanExpr typeOf(Expr<A> left, Class<B> right){
return _binOp(Op.ISTYPEOF, left, _const(right));
}
public static Expr<String> upper(Expr<String> left){
return _unOp(StrOp.UPPER, left);
}
}

View File

@ -16,10 +16,15 @@ public class Types {
public static class Alias<D> extends Reference<D> implements EntityExpr<D>{
public Reference<D> from, to;
Alias(Reference<D> from, Reference<D> to) {
super(to._path);
super(to.toString());
}
}
public static class BinaryBooleanOperation<L,R> extends BinaryOperation<Boolean,L,R>
implements BooleanOperation {
}
public static class BinaryOperation<RT,L,R> implements Operation<RT>{
/**
* arguments don't need to be of same type as return type
@ -29,19 +34,22 @@ public class Types {
public Op<RT> type;
}
public static class BinaryBooleanOperation<L,R> extends BinaryOperation<Boolean,L,R>
implements BooleanOperation {
}
/**
* NOTE : BooleanExpr as a concrete interface instead of Expr<Boolean> avoids
* compiler warnings when used in Query#where(BooleanExpr... objects);
*/
public interface BooleanExpr extends Expr<Boolean>{ }
public interface BooleanOperation extends Operation<Boolean>, BooleanExpr {}
public static class BooleanProperty extends Reference<Boolean> implements BooleanExpr{
public BooleanProperty(String path) {super(path);}
}
/**
* Boolean operators (operators used with boolean operands)
*/
public interface BoOp<RT> extends Op<RT>{
public interface BoOp<RT> extends CompOp<RT>{
BoOp<Boolean> AND = new BoOpImpl<Boolean>();
BoOp<Boolean> NOT = new BoOpImpl<Boolean>();
BoOp<Boolean> OR = new BoOpImpl<Boolean>();
@ -50,34 +58,47 @@ public class Types {
}
static class BoOpImpl<RT> implements BoOp<RT>{}
public static class CharProperty extends Reference<Character>{
public CharProperty(String path) {super(path);}
/**
* Operators for Comparable objects
*/
public interface CompOp<RT> extends Op<RT>{
CompOp<Boolean> BETWEEN = new CompOpImpl<Boolean>();
CompOp<Boolean> GOE = new CompOpImpl<Boolean>();
CompOp<Boolean> GT = new CompOpImpl<Boolean>();
CompOp<Boolean> LOE = new CompOpImpl<Boolean>();
CompOp<Boolean> LT = new CompOpImpl<Boolean>();
}
static class CompOpImpl<RT> implements CompOp<RT> {}
public static class ConstantExpr<A> implements Expr<A>{
public A constant;
}
/**
* Date Operators (operators used with Date operands)
*/
public interface DateOp<RT> extends CompOp<RT>{
DateOp<Boolean> AFTER = new DateOpImpl<Boolean>();
DateOp<Boolean> BEFORE = new DateOpImpl<Boolean>();
}
static class DateOpImpl<RT> implements DateOp<RT>{}
public static class DomainType<D> extends Reference<D> implements EntityExpr<D>{
protected DomainType(DomainType<?> type, String path) {
super(type._path+"."+path);
super(type+"."+path);
}
protected DomainType(String path) {super(path);}
public EntityExpr<D> as(DomainType<D> to){
return new Alias<D>(this, to);
}
protected BooleanProperty bool(String path){
return new BooleanProperty(this._path+"."+_path);
protected BooleanProperty _boolean(String path){
return new BooleanProperty(this+"."+path);
}
protected CharProperty ch(String path) {
return new CharProperty(this._path+"."+path);
}
protected NumberProperty num(String path) {
return new NumberProperty(this._path+"."+path);
}
protected StringProperty str(String path) {
return new StringProperty(this._path+"."+path);
protected <A> Reference<A> _prop(String path,Class<A> type) {
return new Reference<A>(this+"."+path);
}
}
@ -86,28 +107,14 @@ public class Types {
*/
public static interface EntityExpr<T> extends Expr<T>{}
public interface Expr<A> { }
/**
* NOTE : BooleanExpr as a concrete interface instead of Expr<Boolean> avoids
* compiler warnings when used in Query#where(BooleanExpr... objects);
*/
public interface BooleanExpr extends Expr<Boolean>{ }
public static class NumberProperty extends Reference<Number>{
public NumberProperty(String path) {super(path);}
}
public interface Expr<A> { }
/**
* Numeric Operators (operators used with numeric operands)
*/
public interface NumOp<RT> extends Op<RT>{
public interface NumOp<RT> extends CompOp<RT>{
NumOp<Number> ADD = new NumOpImpl<Number>();
NumOp<Number> DIV = new NumOpImpl<Number>();
NumOp<Boolean> GOE = new NumOpImpl<Boolean>();
NumOp<Boolean> GT = new NumOpImpl<Boolean>();
NumOp<Boolean> LOE = new NumOpImpl<Boolean>();
NumOp<Boolean> LT = new NumOpImpl<Boolean>();
NumOp<Number> DIV = new NumOpImpl<Number>();
NumOp<Number> MOD = new NumOpImpl<Number>();
NumOp<Number> MULT = new NumOpImpl<Number>();
NumOp<Number> SUB = new NumOpImpl<Number>();
@ -120,46 +127,48 @@ public class Types {
*/
public interface Op<RT> {
Op<Boolean> EQ = new OpImpl<Boolean>();
Op<Boolean> NE = new OpImpl<Boolean>();
Op<Boolean> ISTYPEOF = new OpImpl<Boolean>();
Op<Boolean> NE = new OpImpl<Boolean>();
}
public interface Operation<RT> extends Expr<RT> {}
public interface BooleanOperation extends Operation<Boolean>, BooleanExpr {}
public interface Operation<RT> extends Expr<RT> {}
static class OpImpl<RT> implements Op<RT> {}
public enum Order{ ASC,DESC }
public enum Order{ ASC,DESC }
public static class OrderSpecifier<A>{
public static class OrderSpecifier<A extends Comparable<A>>{
public Order order;
public Expr<A> target;
}
public static class Reference<T> implements Expr<T>{
public final String _path;
public Reference(String path) {
this._path = path;
public static class Reference<T> implements Expr<T>{
// _path is hidden to not pollute the namespace of the domain types
private final String path;
public Reference(String p) {
path = p;
}
}
public static class StringProperty extends Reference<String>{
public StringProperty(String path) {super(path);}
public final String toString(){ return path; }
}
/**
* String Operators (operators used with String operands)
*/
public interface StrOp<RT> extends Op<RT>{
public interface StrOp<RT> extends CompOp<RT>{
StrOp<String> CONCAT = new StrOpImpl<String>();
StrOp<Boolean> LIKE = new StrOpImpl<Boolean>();
StrOp<String> LOWER = new StrOpImpl<String>();
StrOp<String> SUBSTRING = new StrOpImpl<String>();
StrOp<String> SUBSTR = new StrOpImpl<String>();
StrOp<String> UPPER = new StrOpImpl<String>();
}
static class StrOpImpl<RT> implements StrOp<RT>{}
public static class TertiaryBooleanOperation<F,S,T> extends TertiaryOperation<Boolean,F,S,T>
implements BooleanOperation{
}
public static class TertiaryOperation<RT,F,S,T> implements Operation<RT>{
/**
* arguments don't need to be of same type as return type
@ -170,7 +179,7 @@ public class Types {
public Op<RT> type;
}
public static class TertiaryBooleanOperation<F,S,T> extends TertiaryOperation<Boolean,F,S,T>
public static class UnaryBooleanOperation<A> extends UnaryOperation<Boolean,A>
implements BooleanOperation{
}
@ -182,10 +191,5 @@ public class Types {
public Expr<A> left;
public Op<RT> type;
}
public static class UnaryBooleanOperation<A> extends UnaryOperation<Boolean,A>
implements BooleanOperation{
}
}

View File

@ -1,7 +1,10 @@
package com.mysema.query.test;
import com.mysema.query.*;
import com.mysema.query.grammar.Types.*;
import com.mysema.query.ExtQuery;
import com.mysema.query.grammar.Types.BooleanExpr;
import com.mysema.query.grammar.Types.EntityExpr;
import com.mysema.query.grammar.Types.Expr;
import com.mysema.query.grammar.Types.OrderSpecifier;
/**
* QueryBase provides
*
@ -40,8 +43,6 @@ public class QueryBase implements ExtQuery<QueryBase> {
public QueryBase with(BooleanExpr... objects) {
return this;
}
}
}

View File

@ -1,21 +1,15 @@
package com.mysema.query.test;
import static com.mysema.query.grammar.Grammar.concat;
import static com.mysema.query.grammar.Grammar.eq;
import static com.mysema.query.grammar.Grammar.gt;
import static com.mysema.query.grammar.Grammar.like;
import static com.mysema.query.grammar.Grammar.lower;
import static com.mysema.query.grammar.Grammar.substr;
import static com.mysema.query.grammar.Grammar.upper;
import static com.mysema.query.test.domain.Domain.cat;
import static com.mysema.query.test.domain.Domain.child;
import static com.mysema.query.test.domain.Domain.cust;
import static com.mysema.query.test.domain.Domain.doc;
import static com.mysema.query.test.domain.Domain.kitten;
import static com.mysema.query.grammar.Grammar.*;
import static com.mysema.query.test.domain.Domain.*;
import java.util.Date;
import org.junit.Test;
import com.mysema.query.grammar.Types.BooleanExpr;
import com.mysema.query.test.domain.DomesticCat;
import com.mysema.query.test.domain.Payment;
@ -26,6 +20,12 @@ import com.mysema.query.grammar.Types.BooleanExpr;
* @version $Id$
*/
public class QueryTest extends QueryBase{
@Test
public void testPath(){
assert cat.mate().name.toString().equals("cat.mate.name");
assert cust.name().firstName.toString().equals("cust.name.firstName");
}
@Test
public void testVarious(){
@ -33,16 +33,39 @@ public class QueryTest extends QueryBase{
BooleanExpr be = eq(cat.name,cust.name().firstName);
where(be);
with(be);
// select(cat.name.as("cat_name")); // not allowed
from(cat,cust).where(gt(cat.name,cust.name().firstName));
select(lower(cat.name)).from(cat).where(eq(substr(cat.name,0,2),"Mi"));
select(upper(cat.name)).from(cat);
select(concat(lower(cat.name),cat.mate().name)).from(cat);
cat.as(kitten);
// cat.as(company); // not allowed
// asc(cust.name()); // not allowed
asc(cust.name().firstName);
desc(cust.name().firstName);
// gt(cat, cat.mate()); // not allowed
// lt(cat, cat.mate()); // not allowed
// goe(cat, cat.mate()); // not allowed
// loe(cat, cat.mate()); // not allowed
}
// cats
@Test
public void testOperations(){
gt(kitten.bodyWeight, 10);
lt(kitten.bodyWeight, 10);
goe(kitten.bodyWeight, 10);
loe(kitten.bodyWeight, 10);
gt(cat.name, "ABC");
lt(cust.name().firstName, "Albert");
lower(cust.name().firstName);
upper(cust.name().firstName);
}
@Test
public void testQueryCat1(){
public void testCat1(){
// from Cat as cat left join cat.kittens as kitten
// with kitten.bodyWeight > 10.0
from(cat).leftJoin(cat.kittens().as(kitten))
@ -50,7 +73,7 @@ public class QueryTest extends QueryBase{
}
@Test
public void testQueryCat2(){
public void testCat2(){
// from Cat as cat inner join fetch cat.mate
// left join fetch cat.kittens child left join fetch child.kittens
from(cat).innerJoin(cat.mate())
@ -58,33 +81,94 @@ public class QueryTest extends QueryBase{
}
@Test
public void testQueryCat3(){
public void testCat3(){
// from Cat as cat where cat.mate.name like '%s%'
from(cat).where(like(cat.mate().name,"%s%"));
}
@Test
public void testCat4(){
// from Cat cat where cat.alive = true
from(cat).where(cat.alive);
from(cat).where(eq(cat.alive,true));
// from Cat cat where cat.kittens.size > 0
// TODO
// from Cat cat where size(cat.kittens) > 0
// TODO
}
@Test
public void testCat5(){
// select mother from Cat as mother, Cat as kit
// where kit in elements(foo.kittens)
// TODO
}
@Test
public void testDomesticCat1(){
// select cat.name from DomesticCat cat where cat.name like 'fri%'
select(cat).from(cat).where(like(cat.name, "%fri%"));
}
@Test
public void testDomesticCat2(){
// from Cat cat where cat.class = DomesticCat
from(cat).where(typeOf(cat,DomesticCat.class));
}
@Test
public void testDomesticCat3(){
// from DomesticCat cat where cat.name between 'A' and 'B'
from(cat).where(between(cat.name, "A","B"));
// from DomesticCat cat where cat.name in ( 'Foo', 'Bar', 'Baz' )
from(cat).where(in(cat.name, "Foo","Bar","Baz"));
// from DomesticCat cat where cat.name not between 'A' and 'B'
from(cat).where(not(between(cat.name,"A","B")));
from(doc).where(between(doc.validTo,new Date(), new Date()));
// from DomesticCat cat where cat.name not in ( 'Foo', 'Bar', 'Baz' )
from(cat).where(not(in(cat.name, "Foo","Bar","Baz")));
}
// docs
@Test
public void testQueryDoc1(){
// from Document doc fetch all properties where lower(doc.name) like '%cats%'
from(doc).where(like(lower(doc.name),"%cats%"));
// from Document doc fetch all properties where lower(doc.name) like '%cats%'
from(doc).where(like(lower(doc.name),"%cats%"));
from(doc).where(after(doc.validTo, new Date()));
from(doc).where(before(doc.validTo, new Date()));
}
// customers
@Test
public void testCustomers(){
// select cust.name.firstName from Customer as cust
// select cust.name.firstName from Customer as cust
select(cust.name().firstName).from(cust);
}
@Test
public void testAuditLog1(){
// from AuditLog log, Payment payment
// where log.item.class = 'Payment' and log.item.id = payment.id
from(log,payment)
.where(typeOf(log.item(),Payment.class),eq(log.item().id,payment.id));
}
@Test
public void testOrder1(){
// from Order order where maxindex(order.items) > 100
// TODO
}
@Test
public void testOrder2(){
// from Order order where minelement(order.items) > 10000
// TODO
}
}

View File

@ -0,0 +1,20 @@
package com.mysema.query.test.domain;
/**
* AuditLog provides
*
* @author tiwe
* @version $Id$
*/
public class AuditLog {
private Item item;
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
}

View File

@ -16,6 +16,7 @@ public class Cat {
private Cat mate;
private int bodyWeight;
private String name;
private boolean alive;
public Collection<Cat> getKittens() {
return kittens;
}
@ -40,5 +41,11 @@ public class Cat {
public void setName(String name) {
this.name = name;
}
public boolean isAlive() {
return alive;
}
public void setAlive(boolean alive) {
this.alive = alive;
}
}

View File

@ -1,5 +1,7 @@
package com.mysema.query.test.domain;
import java.util.Date;
/**
* Document provides
*
@ -8,7 +10,8 @@ package com.mysema.query.test.domain;
*/
public class Document {
private String name;
private Date validTo;
public String getName() {
return name;
}
@ -16,5 +19,14 @@ public class Document {
public void setName(String name) {
this.name = name;
}
public Date getValidTo() {
return validTo;
}
public void setValidTo(Date validTo) {
this.validTo = validTo;
}
}

View File

@ -1,8 +1,10 @@
package com.mysema.query.test.domain;
import java.util.Date;
import com.mysema.query.grammar.Types.BooleanProperty;
import com.mysema.query.grammar.Types.DomainType;
import com.mysema.query.grammar.Types.NumberProperty;
import com.mysema.query.grammar.Types.StringProperty;
import com.mysema.query.grammar.Types.Reference;
/**
@ -12,98 +14,139 @@ import com.mysema.query.grammar.Types.StringProperty;
* @version $Id$
*/
public class Domain {
// Cat
public static final qCat cat = new qCat("cat");
public static final qCat cat1 = new qCat("cat1");
public static final qCat cat2 = new qCat("cat2");
public static final qCat cat3 = new qCat("cat3");
public static final qCat cat4 = new qCat("cat4");
public static final qCat cat5 = new qCat("cat5");
// AuditLog
public static final qAuditLog<AuditLog> log = new qAuditLog<AuditLog>("log");
public static final qCat kitten = new qCat("kitten");
public static final qCat child = new qCat("child");
public static final qCat mate = new qCat("mate");
// Cat
public static final qCat<Cat> cat = new qCat<Cat>("cat");
public static final qCat<Cat> cat1 = new qCat<Cat>("cat1");
public static final qCat<Cat> cat2 = new qCat<Cat>("cat2");
public static final qCat<Cat> cat3 = new qCat<Cat>("cat3");
public static final qCat<Cat> cat4 = new qCat<Cat>("cat4");
public static final qCat<Cat> cat5 = new qCat<Cat>("cat5");
public static final qCat<Cat> kitten = new qCat<Cat>("kitten");
public static final qCat<Cat> child = new qCat<Cat>("child");
public static final qCat<Cat> mate = new qCat<Cat>("mate");
// Company
public static final qCompany company = new qCompany("company");
public static final qCompany company1 = new qCompany("company1");
public static final qCompany company2 = new qCompany("company2");
public static final qCompany company3 = new qCompany("company3");
public static final qCompany company4 = new qCompany("company4");
public static final qCompany company5 = new qCompany("company5");
public static final qCompany<Company> company = new qCompany<Company>("company");
public static final qCompany<Company> company1 = new qCompany<Company>("company1");
public static final qCompany<Company> company2 = new qCompany<Company>("company2");
public static final qCompany<Company> company3 = new qCompany<Company>("company3");
public static final qCompany<Company> company4 = new qCompany<Company>("company4");
public static final qCompany<Company> company5 = new qCompany<Company>("company5");
// Customer
public static final qCustomer cust = new qCustomer("cust");
public static final qCustomer<Customer> cust = new qCustomer<Customer>("cust");
// Document
public static final qDocument doc = new qDocument("doc");
public static final qDocument<Document> doc = new qDocument<Document>("doc");
// DomesticCat
public static final qDomesticCat<DomesticCat> domesticCat = new qDomesticCat<DomesticCat>("domesticCat");
// Payment
public static final qPayment<Payment> payment = new qPayment<Payment>("payment");
// User
public static final qUser user = new qUser("user");
public static final qUser user1 = new qUser("user1");
public static final qUser user2 = new qUser("user2");
public static final qUser user3 = new qUser("user3");
public static final qUser user4 = new qUser("user4");
public static final qUser user5 = new qUser("user5");
public static final qUser<User> user = new qUser<User>("user");
public static final qUser<User> user1 = new qUser<User>("user1");
public static final qUser<User> user2 = new qUser<User>("user2");
public static final qUser<User> user3 = new qUser<User>("user3");
public static final qUser<User> user4 = new qUser<User>("user4");
public static final qUser<User> user5 = new qUser<User>("user5");
// type declarations
public static class qCat extends DomainType<Cat>{
public static class qAuditLog<T extends AuditLog> extends DomainType<T>{
qAuditLog(String path) {super(path);}
qAuditLog(DomainType<?> type, String path) {super(type,path);}
private qItem<Item> item;
public qItem<Item> item() {
if (item == null) item = new qItem<Item>(this,"item");
return item;
}
}
public static class qCat<T extends Cat> extends DomainType<T>{
qCat(String path) {super(path);}
qCat(DomainType<?> type, String path) {super(type,path);}
private qCat kittens, mate;
public final NumberProperty bodyWeight = num("bodyWeight");
public final StringProperty name = str("name");
public final qCat kittens(){
if (kittens == null) kittens = new qCat(this,"kittens");
qCat(DomainType<?> type, String path) {super(type,path);}
public final BooleanProperty alive = _boolean("alive");
public final Reference<Integer> bodyWeight = _prop("bodyWeight",Integer.class);
public final Reference<String> name = _prop("name",String.class);
private qCat<Cat> kittens;
public final qCat<Cat> kittens(){
if (kittens == null) kittens = new qCat<Cat>(this,"kittens");
return kittens;
}
public final qCat mate(){
if (mate == null) mate = new qCat(this,"mate");
}
private qCat<Cat> mate;
public final qCat<Cat> mate(){
if (mate == null) mate = new qCat<Cat>(this,"mate");
return mate;
}
}
public static class qCustomer extends DomainType<Customer>{
public static class qDomesticCat<T extends DomesticCat> extends qCat<T>{
qDomesticCat(String path) {super(path);}
qDomesticCat(DomainType<?> type, String path) {super(type,path);}
}
public static class qCustomer<T extends Customer> extends DomainType<T>{
qCustomer(String path) {super(path);}
qCustomer(DomainType<?> type, String path) {super(type,path);}
private qName name;
public final qName name(){
if (name == null) name = new qName(this, "name");
private qName<Name> name;
public final qName<Name> name(){
if (name == null) name = new qName<Name>(this, "name");
return name;
}
}
public static class qCompany extends DomainType<Company>{
public static class qCompany<T extends Company> extends DomainType<T>{
qCompany(String path) {super(path);}
qCompany(DomainType<?> type, String path) {super(type,path);}
public final NumberProperty id = num("id");
public final StringProperty name = str("name");
public final Reference<Long> id = _prop("id",Long.class);
public final Reference<String> name = _prop("name",String.class);
}
public static class qDocument extends DomainType<Document>{
public static class qDocument<T extends Document> extends DomainType<T>{
qDocument(String path){super(path);}
qDocument(DomainType<?> type, String path) {super(type,path);}
public final StringProperty name = str("name");
public final Reference<String> name = _prop("name",String.class);
public final Reference<Date> validTo = _prop("validTo",Date.class);
}
public static class qName extends DomainType<Name>{
public static class qItem<T extends Item> extends DomainType<T>{
qItem(String path){super(path);}
qItem(DomainType<?> type, String path) {super(type,path);}
public Reference<String> id = _prop("id",String.class);
}
public static class qName<T extends Name> extends DomainType<T>{
qName(String path){super(path);}
qName(DomainType<?> type, String path) {super(type,path);}
public final StringProperty firstName = str("firstName");
public final Reference<String> firstName = _prop("firstName",String.class);
}
public static class qUser extends DomainType<User>{
public static class qPayment<T extends Payment> extends qItem<T>{
qPayment(String path){super(path);}
qPayment(DomainType<?> type, String path) {super(type,path);}
}
public static class qUser<T extends User> extends DomainType<T>{
qUser(String path) {super(path);}
qUser(DomainType<?> type, String path) {super(type,path);}
private qCompany company;
public final NumberProperty id = num("id");
public final StringProperty userName = str("userName");
public final StringProperty firstName = str("firstName");
public final StringProperty lastName = str("lastName");
public final qCompany company(){
if (company == null) company = new qCompany(this,"company");
qUser(DomainType<?> type, String path) {super(type,path);}
public final Reference<Long> id = _prop("id",Long.class);
public final Reference<String> userName = _prop("userName",String.class);
public final Reference<String> firstName = _prop("firstName",String.class);
public final Reference<String> lastName = _prop("lastName",String.class);
private qCompany<Company> company;
public final qCompany<Company> company(){
if (company == null) company = new qCompany<Company>(this,"company");
return company;
}
}

View File

@ -0,0 +1,11 @@
package com.mysema.query.test.domain;
/**
* DomesticCat provides
*
* @author tiwe
* @version $Id$
*/
public class DomesticCat extends Cat{
}

View File

@ -0,0 +1,20 @@
package com.mysema.query.test.domain;
/**
* Item provides
*
* @author tiwe
* @version $Id$
*/
public class Item {
private long id;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}

View File

@ -0,0 +1,11 @@
package com.mysema.query.test.domain;
/**
* Payment provides
*
* @author tiwe
* @version $Id$
*/
public class Payment extends Item{
}

View File

@ -1,6 +1,5 @@
package com.mysema.query.test.domain;
import com.mysema.query.test.domain.Domain.qCompany;
/**
* User provides
@ -14,13 +13,13 @@ public class User {
// public final StringProperty userName = str("userName");
// public final StringProperty firstName = str("firstName");
// public final StringProperty lastName = str("lastName");
private qCompany company;
private Company company;
private long id;
private String userName, firstName, lastName;
public qCompany getCompany() {
public Company getCompany() {
return company;
}
public void setCompany(qCompany company) {
public void setCompany(Company company) {
this.company = company;
}
public long getId() {