mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-21 21:14:12 +08:00
worked on querydsl
This commit is contained in:
parent
e80405410e
commit
4b608a406f
15
src/main/java/com/mysema/query/ExtQuery.java
Normal file
15
src/main/java/com/mysema/query/ExtQuery.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.mysema.query;
|
||||
|
||||
import com.mysema.query.grammar.Types.*;
|
||||
|
||||
/**
|
||||
* ExtQuery provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface ExtQuery<A extends ExtQuery<?>> extends Query<A> {
|
||||
// A innerJoin(EntityPathExpr<?>... objects);
|
||||
// A leftJoin(EntityPathExpr<?>... objects);
|
||||
// A with(Expr<Boolean>... objects);
|
||||
}
|
||||
@ -1,9 +1,6 @@
|
||||
package com.mysema.query;
|
||||
|
||||
import com.mysema.query.grammar.GrammarTypes.BooleanExpr;
|
||||
import com.mysema.query.grammar.GrammarTypes.DomainType;
|
||||
import com.mysema.query.grammar.GrammarTypes.Expr;
|
||||
import com.mysema.query.grammar.GrammarTypes.OrderSpecifier;
|
||||
import com.mysema.query.grammar.Types.*;
|
||||
|
||||
/**
|
||||
* Query provides
|
||||
@ -12,12 +9,14 @@ import com.mysema.query.grammar.GrammarTypes.OrderSpecifier;
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface Query<A extends Query<?>>{
|
||||
A select(Expr... objects);
|
||||
A from(DomainType<?>... objects);
|
||||
A innerJoin(DomainType<?>... objects);
|
||||
A leftJoin(DomainType<?>... objects);
|
||||
A with(BooleanExpr... objects);
|
||||
A where(BooleanExpr... objects);
|
||||
A groupBy(Expr... objects);
|
||||
A orderBy(OrderSpecifier... objects);
|
||||
A select(Expr<?>... objects);
|
||||
A from(EntityPathExpr<?>... objects);
|
||||
A where(Expr<Boolean>... objects);
|
||||
A groupBy(Expr<?>... objects);
|
||||
A orderBy(OrderSpecifier<?>... objects);
|
||||
|
||||
// TODO : move back to ExtQuery when querydsl has stabilized
|
||||
A innerJoin(EntityPathExpr<?>... objects);
|
||||
A leftJoin(EntityPathExpr<?>... objects);
|
||||
A with(Expr<Boolean>... objects);
|
||||
}
|
||||
@ -1,13 +1,7 @@
|
||||
package com.mysema.query.grammar;
|
||||
|
||||
|
||||
import com.mysema.query.grammar.GrammarTypes.BooleanExpr;
|
||||
import com.mysema.query.grammar.GrammarTypes.Op;
|
||||
import com.mysema.query.grammar.GrammarTypes.Expr;
|
||||
import com.mysema.query.grammar.GrammarTypes.Order;
|
||||
import com.mysema.query.grammar.GrammarTypes.OrderSpecifier;
|
||||
|
||||
import static com.mysema.query.grammar.InternalGrammar.*;
|
||||
import com.mysema.query.grammar.Types.*;
|
||||
|
||||
/**
|
||||
* Grammar provides
|
||||
@ -18,60 +12,99 @@ import static com.mysema.query.grammar.InternalGrammar.*;
|
||||
public class Grammar {
|
||||
// order
|
||||
|
||||
public static OrderSpecifier asc(Expr target){
|
||||
OrderSpecifier os = new OrderSpecifier();
|
||||
os.order = Order.ASC;
|
||||
os.target = target;
|
||||
return os;
|
||||
}
|
||||
public static OrderSpecifier desc(Expr target){
|
||||
OrderSpecifier os = new OrderSpecifier();
|
||||
os.order = Order.DESC;
|
||||
os.target = target;
|
||||
return os;
|
||||
public static <A> OrderSpecifier<A> asc(Expr<A> target){
|
||||
return _asc(target);
|
||||
}
|
||||
public static <A> OrderSpecifier<A> desc(Expr<A> target){
|
||||
return _desc(target);
|
||||
}
|
||||
|
||||
// boolean
|
||||
|
||||
public static BooleanExpr and(BooleanExpr left, BooleanExpr right){
|
||||
return bbe(Op.AND, left, right);
|
||||
public static Expr<Boolean> and(Expr<Boolean> left, Expr<Boolean> right){
|
||||
return _bbe(BoOp.AND, left, right);
|
||||
}
|
||||
public static BooleanExpr not(BooleanExpr left){
|
||||
return bue(Op.NE, left);
|
||||
public static Expr<Boolean> not(Expr<Boolean> left){
|
||||
return _bue(BoOp.NE, left);
|
||||
}
|
||||
public static BooleanExpr or(BooleanExpr left, BooleanExpr right){
|
||||
return bbe(Op.OR, left, right);
|
||||
public static Expr<Boolean> or(Expr<Boolean> left, Expr<Boolean> right){
|
||||
return _bbe(BoOp.OR, left, right);
|
||||
}
|
||||
|
||||
// number compariosn
|
||||
|
||||
public static BooleanExpr eq(Object left, Object right){
|
||||
return bbe(Op.EQ, left, right);
|
||||
public static Expr<Boolean> eq(Object left, Object right){
|
||||
return _bbe(BoOp.EQ, left, right);
|
||||
}
|
||||
public static BooleanExpr goe(Object left, Object right){
|
||||
return bbe(Op.GOE, left, right);
|
||||
public static Expr<Boolean> goe(Object left, Object right){
|
||||
return _bbe(BoOp.GOE, left, right);
|
||||
}
|
||||
public static BooleanExpr gt(Object left, Object right){
|
||||
return bbe(Op.GT, left, right);
|
||||
public static Expr<Boolean> gt(Object left, Object right){
|
||||
return _bbe(BoOp.GT, left, right);
|
||||
}
|
||||
public static BooleanExpr loe(Object left, Object right){
|
||||
return bbe(Op.LOE, left, right);
|
||||
public static Expr<Boolean> loe(Object left, Object right){
|
||||
return _bbe(BoOp.LOE, left, right);
|
||||
}
|
||||
public static BooleanExpr lt(Object left, Object right){
|
||||
return bbe(Op.LT, left, right);
|
||||
public static Expr<Boolean> lt(Object left, Object right){
|
||||
return _bbe(BoOp.LT, left, right);
|
||||
}
|
||||
public static BooleanExpr ne(Object left, Object right){
|
||||
return bbe(Op.NE, left, right);
|
||||
public static Expr<Boolean> ne(Object left, Object right){
|
||||
return _bbe(BoOp.NE, left, right);
|
||||
}
|
||||
|
||||
// string comparison
|
||||
|
||||
public static BooleanExpr like(Object left, String right){
|
||||
return bbe(Op.LIKE, left, right);
|
||||
public static Expr<Boolean> like(Expr<String> left, String right){
|
||||
return _bbe(BoOp.LIKE, left, right);
|
||||
}
|
||||
|
||||
public static Expr<String> lower(Expr<String> path){
|
||||
return null;
|
||||
}
|
||||
|
||||
// arithmetic operations
|
||||
|
||||
// TODO
|
||||
// TODO : +,-,*,/,mod,div
|
||||
|
||||
// order
|
||||
|
||||
static <A> OrderSpecifier<A> _asc(Expr<A> target) {
|
||||
OrderSpecifier<A> os = new OrderSpecifier<A>();
|
||||
os.order = Order.ASC;
|
||||
os.target = target;
|
||||
return os;
|
||||
}
|
||||
|
||||
static <A> OrderSpecifier<A> _desc(Expr<A> target) {
|
||||
OrderSpecifier<A> os = new OrderSpecifier<A>();
|
||||
os.order = Order.DESC;
|
||||
os.target = target;
|
||||
return os;
|
||||
}
|
||||
|
||||
// constants
|
||||
|
||||
static <A> Expr<A> _co(A obj){
|
||||
ConstantExpr<A> e = new ConstantExpr<A>();
|
||||
e.constant = obj;
|
||||
return e;
|
||||
}
|
||||
|
||||
// boolean
|
||||
|
||||
static BooleanBinaryExpr _bbe(BoOp type,Object left, Object right){
|
||||
BooleanBinaryExpr bbe = new BooleanBinaryExpr();
|
||||
bbe.type = type;
|
||||
bbe.left = left instanceof Expr ? (Expr)left : _co(left);
|
||||
bbe.right = right instanceof Expr ? (Expr)right : _co(left);
|
||||
return bbe;
|
||||
}
|
||||
static BooleanUnaryExpr _bue(BoOp type, Expr<Boolean> left){
|
||||
BooleanUnaryExpr bue = new BooleanUnaryExpr();
|
||||
bue.type = type;
|
||||
bue.left = left;
|
||||
return bue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,88 +0,0 @@
|
||||
package com.mysema.query.grammar;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Query provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class GrammarTypes {
|
||||
|
||||
// order
|
||||
|
||||
public enum Order{ ASC,DESC }
|
||||
|
||||
public static class OrderSpecifier{
|
||||
public Order order;
|
||||
public Expr target;
|
||||
}
|
||||
|
||||
// expressions
|
||||
|
||||
public interface Expr { }
|
||||
|
||||
// constant
|
||||
|
||||
public static class ConstantExpr implements Expr{
|
||||
public Object constant;
|
||||
}
|
||||
|
||||
// boolean
|
||||
|
||||
public interface BooleanExpr extends Expr{ }
|
||||
|
||||
public enum Op { AND, EQ, GOE, GT,LOE, LT, NE, NOT, OR, XOR, LIKE }
|
||||
|
||||
public static class BooleanUnaryExpr implements BooleanExpr{
|
||||
public Op type;
|
||||
public Expr left;
|
||||
}
|
||||
|
||||
public static class BooleanBinaryExpr implements BooleanExpr{
|
||||
public Op type;
|
||||
public Expr left; public Expr right;
|
||||
}
|
||||
|
||||
// references
|
||||
|
||||
public static class Reference<T> implements Expr{
|
||||
public Reference(String path) {
|
||||
this._path = path;
|
||||
}
|
||||
protected CharProperty ch(String path) {
|
||||
return new CharProperty(this._path+"."+path);
|
||||
}
|
||||
protected StringProperty str(String path) {
|
||||
return new StringProperty(this._path+"."+path);
|
||||
}
|
||||
protected NumberProperty num(String path) {
|
||||
return new NumberProperty(this._path+"."+path);
|
||||
}
|
||||
// protected CollectionProperty colProp(String path) {
|
||||
// return new CollectionProperty(this._path+"."+path);
|
||||
// }
|
||||
public final String _path;
|
||||
}
|
||||
public static class CharProperty extends Reference<Character>{
|
||||
public CharProperty(String path) {super(path);}
|
||||
}
|
||||
public static class StringProperty extends Reference<String>{
|
||||
public StringProperty(String path) {super(path);}
|
||||
}
|
||||
public static class NumberProperty extends Reference<Number>{
|
||||
public NumberProperty(String path) {super(path);}
|
||||
}
|
||||
// public static class CollectionProperty extends Reference<Collection<?>>{
|
||||
// public CollectionProperty(String path) {super(path);}
|
||||
// }
|
||||
public static class DomainType<D> extends Reference<D>{
|
||||
public DomainType(String path) {super(path);}
|
||||
public DomainType<D> as(DomainType<D> d){
|
||||
// TODO
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
package com.mysema.query.grammar;
|
||||
|
||||
import com.mysema.query.grammar.GrammarTypes.BooleanBinaryExpr;
|
||||
import com.mysema.query.grammar.GrammarTypes.BooleanExpr;
|
||||
import com.mysema.query.grammar.GrammarTypes.Op;
|
||||
import com.mysema.query.grammar.GrammarTypes.BooleanUnaryExpr;
|
||||
import com.mysema.query.grammar.GrammarTypes.ConstantExpr;
|
||||
import com.mysema.query.grammar.GrammarTypes.Expr;
|
||||
|
||||
|
||||
/**
|
||||
* InternalGrammar provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
class InternalGrammar {
|
||||
static Expr co(Object str){
|
||||
ConstantExpr e = new ConstantExpr();
|
||||
e.constant = str;
|
||||
return e;
|
||||
}
|
||||
static BooleanBinaryExpr bbe(Op type,Object left, Object right){
|
||||
BooleanBinaryExpr bbe = new BooleanBinaryExpr();
|
||||
bbe.type = type;
|
||||
bbe.left = left instanceof Expr ? (Expr)left : co(left);
|
||||
bbe.right = right instanceof Expr ? (Expr)right : co(left);
|
||||
return bbe;
|
||||
}
|
||||
static BooleanUnaryExpr bue(Op type, BooleanExpr left){
|
||||
BooleanUnaryExpr bue = new BooleanUnaryExpr();
|
||||
bue.type = type;
|
||||
bue.left = left;
|
||||
return bue;
|
||||
}
|
||||
|
||||
}
|
||||
133
src/main/java/com/mysema/query/grammar/Types.java
Normal file
133
src/main/java/com/mysema/query/grammar/Types.java
Normal file
@ -0,0 +1,133 @@
|
||||
package com.mysema.query.grammar;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Query provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Types {
|
||||
|
||||
// order
|
||||
|
||||
public enum Order{ ASC,DESC }
|
||||
|
||||
public static class OrderSpecifier<A>{
|
||||
public Order order;
|
||||
public Expr<A> target;
|
||||
}
|
||||
|
||||
// expressions
|
||||
|
||||
public interface Expr<A> { }
|
||||
|
||||
// constant
|
||||
|
||||
public static class ConstantExpr<A> implements Expr<A>{
|
||||
public A constant;
|
||||
}
|
||||
|
||||
public interface Op {}
|
||||
|
||||
// operators
|
||||
|
||||
public enum BoOp implements Op{
|
||||
// boolean
|
||||
AND,
|
||||
NOT,
|
||||
OR,
|
||||
XOR,
|
||||
XNOR,
|
||||
|
||||
// comparison
|
||||
EQ,
|
||||
NE,
|
||||
GOE,
|
||||
GT,
|
||||
LOE,
|
||||
LT,
|
||||
|
||||
// string comparison
|
||||
LIKE,
|
||||
}
|
||||
|
||||
public enum StrOp implements Op{
|
||||
// string manipulation
|
||||
LOWER,
|
||||
UPPER,
|
||||
}
|
||||
|
||||
public enum NumOp implements Op{
|
||||
// arithmetic
|
||||
PLUS,
|
||||
MINUS,
|
||||
MULT,
|
||||
DIV,
|
||||
MOD
|
||||
}
|
||||
|
||||
public static class BooleanUnaryExpr implements Expr<Boolean>{
|
||||
public BoOp type;
|
||||
public Expr<Boolean> left;
|
||||
}
|
||||
|
||||
public static class BooleanBinaryExpr implements Expr<Boolean>{
|
||||
public BoOp type;
|
||||
public Expr<Boolean> left; public Expr<Boolean> right;
|
||||
}
|
||||
|
||||
// references
|
||||
|
||||
public static interface EntityPathExpr<T> extends Expr<T>{}
|
||||
|
||||
public static class Reference<T> implements Expr<T>{
|
||||
public Reference(String path) {
|
||||
this._path = path;
|
||||
}
|
||||
protected CharProperty ch(String path) {
|
||||
return new CharProperty(this._path+"."+path);
|
||||
}
|
||||
protected StringProperty str(String path) {
|
||||
return new StringProperty(this._path+"."+path);
|
||||
}
|
||||
protected NumberProperty num(String path) {
|
||||
return new NumberProperty(this._path+"."+path);
|
||||
}
|
||||
protected BooleanProperty bool(String path){
|
||||
return new BooleanProperty(this._path+"."+_path);
|
||||
}
|
||||
public final String _path;
|
||||
}
|
||||
|
||||
public static class BooleanProperty extends Reference<Boolean>{
|
||||
public BooleanProperty(String path) {super(path);}
|
||||
}
|
||||
public static class CharProperty extends Reference<Character>{
|
||||
public CharProperty(String path) {super(path);}
|
||||
}
|
||||
public static class NumberProperty extends Reference<Number>{
|
||||
public NumberProperty(String path) {super(path);}
|
||||
}
|
||||
public static class StringProperty extends Reference<String>{
|
||||
public StringProperty(String path) {super(path);}
|
||||
}
|
||||
public static class DomainType<D> extends Reference<D> implements EntityPathExpr<D>{
|
||||
protected DomainType(String path) {super(path);}
|
||||
protected DomainType(DomainType<?> type, String path) {
|
||||
super(type._path+"."+path);
|
||||
}
|
||||
public EntityPathExpr<D> as(DomainType<D> to){
|
||||
return new AsExpr<D>(this, to);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AsExpr<D> extends Reference<D> implements EntityPathExpr<D>{
|
||||
AsExpr(Reference<D> from, Reference<D> to) {
|
||||
super(to._path);
|
||||
}
|
||||
public Reference<D> from, to;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
package com.mysema.query.test;
|
||||
|
||||
import static com.mysema.query.grammar.Grammar.gt;
|
||||
import static com.mysema.query.grammar.Grammar.like;
|
||||
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.kitten;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* DomainTest provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DomainTest extends QueryBase{
|
||||
|
||||
@Test
|
||||
public void testQuery1(){
|
||||
// from Cat as cat left join cat.kittens as kitten
|
||||
// with kitten.bodyWeight > 10.0
|
||||
from(cat).leftJoin(cat.kittens().as(kitten))
|
||||
.with(gt(kitten.bodyWeight,10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuery2(){
|
||||
// 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())
|
||||
.leftJoin(cat.kittens().as(child)).leftJoin(child.kittens());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuery3(){
|
||||
// from Cat as cat where cat.mate.name like '%s%'
|
||||
from(cat).where(like(cat.mate().name,"%s%"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,49 +1,47 @@
|
||||
package com.mysema.query.test;
|
||||
|
||||
import com.mysema.query.Query;
|
||||
import com.mysema.query.grammar.GrammarTypes.BooleanExpr;
|
||||
import com.mysema.query.grammar.GrammarTypes.DomainType;
|
||||
import com.mysema.query.grammar.GrammarTypes.Expr;
|
||||
import com.mysema.query.grammar.GrammarTypes.OrderSpecifier;
|
||||
|
||||
import com.mysema.query.*;
|
||||
import com.mysema.query.grammar.Types.*;
|
||||
/**
|
||||
* QueryBase provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class QueryBase implements Query<QueryBase> {
|
||||
public class QueryBase implements ExtQuery<QueryBase> {
|
||||
|
||||
public QueryBase from(DomainType<?>... objects) {
|
||||
public QueryBase from(EntityPathExpr<?>... objects) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryBase groupBy(Expr<?>... objects) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryBase groupBy(Expr... objects) {
|
||||
public QueryBase orderBy(OrderSpecifier<?>... objects) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryBase orderBy(OrderSpecifier... objects) {
|
||||
public QueryBase select(Expr<?>... objects) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryBase select(Expr... objects) {
|
||||
public QueryBase where(Expr<Boolean>... objects) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryBase where(BooleanExpr... objects) {
|
||||
public QueryBase innerJoin(EntityPathExpr<?>... objects) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryBase leftJoin(DomainType<?>... objects) {
|
||||
public QueryBase leftJoin(EntityPathExpr<?>... objects) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryBase with(BooleanExpr... objects) {
|
||||
public QueryBase with(Expr<Boolean>... objects) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryBase innerJoin(DomainType<?>... objects) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
66
src/test/java/com/mysema/query/test/QueryTest.java
Normal file
66
src/test/java/com/mysema/query/test/QueryTest.java
Normal file
@ -0,0 +1,66 @@
|
||||
package com.mysema.query.test;
|
||||
|
||||
import static com.mysema.query.grammar.Grammar.*;
|
||||
import static com.mysema.query.test.domain.Domain.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* DomainTest provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class QueryTest extends QueryBase{
|
||||
|
||||
// cats
|
||||
|
||||
@Test
|
||||
public void testQueryCat1(){
|
||||
// from Cat as cat left join cat.kittens as kitten
|
||||
// with kitten.bodyWeight > 10.0
|
||||
from(cat).leftJoin(cat.kittens().as(kitten))
|
||||
.with(gt(kitten.bodyWeight,10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryCat2(){
|
||||
// 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())
|
||||
.leftJoin(cat.kittens().as(child)).leftJoin(child.kittens());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryCat3(){
|
||||
// from Cat as cat where cat.mate.name like '%s%'
|
||||
from(cat).where(like(cat.mate().name,"%s%"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDomesticCat1(){
|
||||
// select cat.name from DomesticCat cat where cat.name like 'fri%'
|
||||
select(cat).from(cat).where(like(cat.name, "%fri%"));
|
||||
}
|
||||
|
||||
// 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%"));
|
||||
}
|
||||
|
||||
// customers
|
||||
|
||||
@Test
|
||||
public void testCustomers(){
|
||||
// select cust.name.firstName from Customer as cust
|
||||
select(cust.name().firstName).from(cust);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
44
src/test/java/com/mysema/query/test/domain/Cat.java
Normal file
44
src/test/java/com/mysema/query/test/domain/Cat.java
Normal file
@ -0,0 +1,44 @@
|
||||
package com.mysema.query.test.domain;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Cat provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Cat {
|
||||
// private Cat kittens, mate;
|
||||
// public final NumberProperty bodyWeight = num("bodyWeight");
|
||||
// public final StringProperty name = str("name");
|
||||
private Collection<Cat> kittens;
|
||||
private Cat mate;
|
||||
private int bodyWeight;
|
||||
private String name;
|
||||
public Collection<Cat> getKittens() {
|
||||
return kittens;
|
||||
}
|
||||
public void setKittens(Collection<Cat> kittens) {
|
||||
this.kittens = kittens;
|
||||
}
|
||||
public Cat getMate() {
|
||||
return mate;
|
||||
}
|
||||
public void setMate(Cat mate) {
|
||||
this.mate = mate;
|
||||
}
|
||||
public int getBodyWeight() {
|
||||
return bodyWeight;
|
||||
}
|
||||
public void setBodyWeight(int bodyWeight) {
|
||||
this.bodyWeight = bodyWeight;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
28
src/test/java/com/mysema/query/test/domain/Company.java
Normal file
28
src/test/java/com/mysema/query/test/domain/Company.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.mysema.query.test.domain;
|
||||
|
||||
|
||||
/**
|
||||
* Company provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Company {
|
||||
// public final NumberProperty id = num("id");
|
||||
// public final StringProperty name = str("name");
|
||||
private long id;
|
||||
private String name;
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
20
src/test/java/com/mysema/query/test/domain/Customer.java
Normal file
20
src/test/java/com/mysema/query/test/domain/Customer.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.mysema.query.test.domain;
|
||||
|
||||
/**
|
||||
* Customer provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Customer {
|
||||
private Name name;
|
||||
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
20
src/test/java/com/mysema/query/test/domain/Document.java
Normal file
20
src/test/java/com/mysema/query/test/domain/Document.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.mysema.query.test.domain;
|
||||
|
||||
/**
|
||||
* Document provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Document {
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
package com.mysema.query.test.domain;
|
||||
|
||||
import com.mysema.query.grammar.GrammarTypes.DomainType;
|
||||
import com.mysema.query.grammar.GrammarTypes.NumberProperty;
|
||||
import com.mysema.query.grammar.GrammarTypes.StringProperty;
|
||||
import com.mysema.query.grammar.Types.DomainType;
|
||||
import com.mysema.query.grammar.Types.NumberProperty;
|
||||
import com.mysema.query.grammar.Types.StringProperty;
|
||||
|
||||
|
||||
/**
|
||||
@ -12,55 +12,100 @@ import com.mysema.query.grammar.GrammarTypes.StringProperty;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Domain {
|
||||
// User
|
||||
public static final User user = new User("user");
|
||||
public static final User user1 = new User("user1");
|
||||
public static final User user2 = new User("user2");
|
||||
public static final User user3 = new User("user3");
|
||||
public static final User user4 = new User("user4");
|
||||
public static final User user5 = new User("user5");
|
||||
|
||||
// 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");
|
||||
|
||||
public static final qCat kitten = new qCat("kitten");
|
||||
public static final qCat child = new qCat("child");
|
||||
public static final qCat mate = new qCat("mate");
|
||||
|
||||
// Company
|
||||
public static final Company company = new Company("company");
|
||||
public static final Company company1 = new Company("company1");
|
||||
public static final Company company2 = new Company("company2");
|
||||
public static final Company company3 = new Company("company3");
|
||||
public static final Company company4 = new Company("company4");
|
||||
public static final Company company5 = new Company("company5");
|
||||
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");
|
||||
|
||||
// Cat
|
||||
public static final Cat cat = new Cat("cat");
|
||||
public static final Cat cat1 = new Cat("cat1");
|
||||
public static final Cat cat2 = new Cat("cat2");
|
||||
public static final Cat cat3 = new Cat("cat3");
|
||||
public static final Cat cat4 = new Cat("cat4");
|
||||
public static final Cat cat5 = new Cat("cat5");
|
||||
// Customer
|
||||
public static final qCustomer cust = new qCustomer("cust");
|
||||
|
||||
public static final Cat kitten = new Cat("kitten");
|
||||
public static final Cat child = new Cat("child");
|
||||
public static final Cat mate = new Cat("mate");
|
||||
// Document
|
||||
public static final qDocument doc = new qDocument("doc");
|
||||
|
||||
public static class User extends DomainType<User>{
|
||||
User(String path) {super(path);}
|
||||
// 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");
|
||||
|
||||
// type declarations
|
||||
|
||||
public static class qCat extends DomainType<Cat>{
|
||||
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");
|
||||
return kittens;
|
||||
}
|
||||
public final qCat mate(){
|
||||
if (mate == null) mate = new qCat(this,"mate");
|
||||
return mate;
|
||||
}
|
||||
}
|
||||
|
||||
public static class qCustomer extends DomainType<Customer>{
|
||||
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");
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class qCompany extends DomainType<Company>{
|
||||
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 static class qDocument extends DomainType<Document>{
|
||||
qDocument(String path){super(path);}
|
||||
qDocument(DomainType<?> type, String path) {super(type,path);}
|
||||
public final StringProperty name = str("name");
|
||||
}
|
||||
|
||||
public static class qName extends DomainType<Name>{
|
||||
qName(String path){super(path);}
|
||||
qName(DomainType<?> type, String path) {super(type,path);}
|
||||
public final StringProperty firstName = str("firstName");
|
||||
}
|
||||
|
||||
public static class qUser extends DomainType<User>{
|
||||
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 Company company(){ return new Company(_path+".company");}
|
||||
}
|
||||
|
||||
public static class Company extends DomainType<Company>{
|
||||
Company(String path) {super(path);}
|
||||
public final NumberProperty id = num("id");
|
||||
public final StringProperty name = str("name");
|
||||
}
|
||||
|
||||
public static class Cat extends DomainType<Cat>{
|
||||
Cat(String path) {super(path);}
|
||||
public final NumberProperty bodyWeight = num("bodyWeight");
|
||||
public final Cat kittens(){ return new Cat(_path+".kittens");}
|
||||
public final Cat mate(){ return new Cat(_path+".mate");}
|
||||
public final StringProperty name = str("name");
|
||||
public final qCompany company(){
|
||||
if (company == null) company = new qCompany(this,"company");
|
||||
return company;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
28
src/test/java/com/mysema/query/test/domain/Name.java
Normal file
28
src/test/java/com/mysema/query/test/domain/Name.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.mysema.query.test.domain;
|
||||
|
||||
/**
|
||||
* Name provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Name {
|
||||
private String firstName, lastName;
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
}
|
||||
53
src/test/java/com/mysema/query/test/domain/User.java
Normal file
53
src/test/java/com/mysema/query/test/domain/User.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.mysema.query.test.domain;
|
||||
|
||||
import com.mysema.query.grammar.Types.NumberProperty;
|
||||
import com.mysema.query.grammar.Types.StringProperty;
|
||||
import com.mysema.query.test.domain.Domain.qCompany;
|
||||
|
||||
/**
|
||||
* User provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class User {
|
||||
// private Company 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");
|
||||
private qCompany company;
|
||||
private long id;
|
||||
private String userName, firstName, lastName;
|
||||
public qCompany getCompany() {
|
||||
return company;
|
||||
}
|
||||
public void setCompany(qCompany company) {
|
||||
this.company = company;
|
||||
}
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user