diff --git a/.classpath b/.classpath index dcd6adf86..50ba5042f 100644 --- a/.classpath +++ b/.classpath @@ -3,5 +3,8 @@ + + + \ No newline at end of file diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 0b7530669..8850ba047 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/pom.xml b/pom.xml index 746be6173..9a06ecec1 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,11 @@ jar - + + com.mysema.commons + mysema-core + 0.3.2 + junit junit @@ -30,5 +34,5 @@ - + \ No newline at end of file diff --git a/src/main/java/com/mysema/query/ExtQuery.java b/src/main/java/com/mysema/query/ExtQuery.java index 0c18674a3..cd83e0b2c 100644 --- a/src/main/java/com/mysema/query/ExtQuery.java +++ b/src/main/java/com/mysema/query/ExtQuery.java @@ -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 diff --git a/src/main/java/com/mysema/query/Query.java b/src/main/java/com/mysema/query/Query.java index 9e81f81fd..06c8cdccc 100644 --- a/src/main/java/com/mysema/query/Query.java +++ b/src/main/java/com/mysema/query/Query.java @@ -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 diff --git a/src/main/java/com/mysema/query/grammar/Grammar.java b/src/main/java/com/mysema/query/grammar/Grammar.java index 18ae6a956..ca3e6c75e 100644 --- a/src/main/java/com/mysema/query/grammar/Grammar.java +++ b/src/main/java/com/mysema/query/grammar/Grammar.java @@ -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 Operation _binOp(Op type, Expr left, Expr right) { - BinaryOperation op = new BinaryOperation(); + static BooleanOperation _binOp(Op type, Expr left, Expr right) { + BinaryBooleanOperation op = new BinaryBooleanOperation(); op.type = type; op.left = left; op.right = right; return op; } - static BooleanOperation _binOp(Op type, Expr left, Expr right) { - BinaryBooleanOperation op = new BinaryBooleanOperation(); + static Operation _binOp(Op type, Expr left, Expr right) { + BinaryOperation op = new BinaryOperation(); op.type = type; op.left = left; op.right = right; @@ -40,18 +41,27 @@ public class Grammar { return e; } - static OrderSpecifier _orderAsc(Expr target) { + static > OrderSpecifier _orderAsc(Expr target) { OrderSpecifier os = new OrderSpecifier(); os.order = Order.ASC; os.target = target; return os; } - static OrderSpecifier _orderDesc(Expr target) { + static > OrderSpecifier _orderDesc(Expr target) { OrderSpecifier os = new OrderSpecifier(); os.order = Order.DESC; os.target = target; return os; + } + + static BooleanOperation _terOp(Op type, Expr fst, Expr snd, Expr trd){ + TertiaryBooleanOperation op = new TertiaryBooleanOperation(); + op.type = type; + op.first = fst; + op.second = snd; + op.third = trd; + return op; } static Operation _terOp(Op type, Expr fst, Expr snd, Expr trd){ @@ -63,13 +73,6 @@ public class Grammar { return op; } - static Operation _unOp(Op type, Expr left) { - UnaryOperation op = new UnaryOperation(); - op.type = type; - op.left = left; - return op; - } - static BooleanOperation _unOp(Op type, Expr left) { UnaryBooleanOperation op = new UnaryBooleanOperation(); 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 Operation _unOp(Op type, Expr left) { + UnaryOperation op = new UnaryOperation(); + op.type = type; + op.left = left; + return op; + } + + public static BooleanExpr after(Expr left, Date right){ + // NOTE : basically same as gt + return _binOp(DateOp.AFTER, left, _const(right)); } - public static OrderSpecifier asc(Expr target){ + public static BooleanExpr after(Expr left, Expr 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 > OrderSpecifier asc(Expr target){ return _orderAsc(target); + } + + public static BooleanExpr before(Expr left, Date right){ + // NOTE : basically same as lt + return _binOp(DateOp.BEFORE, left, _const(right)); + } + + public static BooleanExpr before(Expr left, Expr right){ + // NOTE : basically same as lt + return _binOp(DateOp.BEFORE, left, right); + } + + public static > BooleanExpr between(Expr left, A start, A end){ + return _terOp(CompOp.BETWEEN, left, _const(start), _const(end)); } public static Expr concat(Expr left, Expr right){ return _binOp(StrOp.CONCAT, left, right); - } - - public static OrderSpecifier desc(Expr target){ - return _orderDesc(target); } - public static BooleanExpr eq(Expr left, Expr right){ - return _binOp(NumOp.EQ, left, right); - } + public static > OrderSpecifier desc(Expr target){ + return _orderDesc(target); + } - public static BooleanExpr eq(Expr left, A right){ - return _binOp(NumOp.EQ, left, _const(right)); - } + public static BooleanExpr eq(Expr left, B right){ + return _binOp(Op.EQ, left, _const(right)); + } + + public static BooleanExpr eq(Expr left, Expr right){ + return _binOp(Op.EQ, left, right); + } - public static BooleanExpr goe(Expr left, A right){ + public static > BooleanExpr goe(Expr left, A right){ return _binOp(NumOp.GOE, left, _const(right)); - } + } - public static BooleanExpr goe(Expr left, Expr right){ + public static > BooleanExpr goe(Expr left, Expr right){ return _binOp(NumOp.GOE, left, right); } - public static BooleanExpr gt(Expr left, A right){ + public static > BooleanExpr gt(Expr left, A right){ return _binOp(NumOp.GT, left, _const(right)); - } + } - public static BooleanExpr gt(Expr left, Expr right){ + public static > BooleanExpr gt(Expr left, Expr right){ return _binOp(NumOp.GT, left, right); + } + + public static BooleanExpr in(Expr left, A... rest){ + // TODO + return null; } public static BooleanExpr like(Expr left, String right){ return _binOp(StrOp.LIKE, left, _const(right)); } - public static BooleanExpr loe(Expr left, Expr right){ + public static > BooleanExpr loe(Expr left, A right){ + return _binOp(NumOp.LOE, left, _const(right)); + } + + public static > BooleanExpr loe(Expr left, Expr right){ return _binOp(NumOp.LOE, left, right); } @@ -129,40 +172,43 @@ public class Grammar { return _unOp(StrOp.LOWER, left); } - public static BooleanExpr lt(Expr left, A right){ + public static > BooleanExpr lt(Expr left, A right){ return _binOp(NumOp.LT, left, _const(right)); - } + } - public static BooleanExpr lt(Expr left, Expr right){ + public static > BooleanExpr lt(Expr left, Expr right){ return _binOp(NumOp.LT, left, right); } - public static BooleanExpr ne(Expr left, A right){ - return _binOp(NumOp.NE, left, _const(right)); + public static BooleanExpr ne(Expr left, B right){ + return _binOp(Op.NE, left, _const(right)); } - public static BooleanExpr ne(Expr left, Expr right){ - return _binOp(NumOp.NE, left, right); - } + public static BooleanExpr ne(Expr left, Expr 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 substr(Expr left, int start){ - return _binOp(StrOp.SUBSTRING, left, _const(start)); + return _binOp(StrOp.SUBSTR, left, _const(start)); + } + + public static Expr substr(Expr left, int start, int offset){ + return _terOp(StrOp.SUBSTR, left, _const(start), _const(offset)); } - public static Expr substr(Expr left, int start, int offset){ - return _terOp(StrOp.SUBSTRING, left, _const(start), _const(offset)); + public static BooleanExpr typeOf(Expr left, Class right){ + return _binOp(Op.ISTYPEOF, left, _const(right)); } - + public static Expr upper(Expr left){ return _unOp(StrOp.UPPER, left); } - } diff --git a/src/main/java/com/mysema/query/grammar/Types.java b/src/main/java/com/mysema/query/grammar/Types.java index 5ffb9a25c..3e662f8e8 100644 --- a/src/main/java/com/mysema/query/grammar/Types.java +++ b/src/main/java/com/mysema/query/grammar/Types.java @@ -16,10 +16,15 @@ public class Types { public static class Alias extends Reference implements EntityExpr{ public Reference from, to; Alias(Reference from, Reference to) { - super(to._path); + super(to.toString()); } } + public static class BinaryBooleanOperation extends BinaryOperation + implements BooleanOperation { + + } + public static class BinaryOperation implements Operation{ /** * arguments don't need to be of same type as return type @@ -29,19 +34,22 @@ public class Types { public Op type; } - public static class BinaryBooleanOperation extends BinaryOperation - implements BooleanOperation { - - } + /** + * NOTE : BooleanExpr as a concrete interface instead of Expr avoids + * compiler warnings when used in Query#where(BooleanExpr... objects); + */ + public interface BooleanExpr extends Expr{ } + + public interface BooleanOperation extends Operation, BooleanExpr {} public static class BooleanProperty extends Reference implements BooleanExpr{ public BooleanProperty(String path) {super(path);} } - + /** * Boolean operators (operators used with boolean operands) */ - public interface BoOp extends Op{ + public interface BoOp extends CompOp{ BoOp AND = new BoOpImpl(); BoOp NOT = new BoOpImpl(); BoOp OR = new BoOpImpl(); @@ -50,34 +58,47 @@ public class Types { } static class BoOpImpl implements BoOp{} - - public static class CharProperty extends Reference{ - public CharProperty(String path) {super(path);} + + /** + * Operators for Comparable objects + */ + public interface CompOp extends Op{ + CompOp BETWEEN = new CompOpImpl(); + CompOp GOE = new CompOpImpl(); + CompOp GT = new CompOpImpl(); + CompOp LOE = new CompOpImpl(); + CompOp LT = new CompOpImpl(); } + static class CompOpImpl implements CompOp {} + public static class ConstantExpr implements Expr{ public A constant; } + /** + * Date Operators (operators used with Date operands) + */ + public interface DateOp extends CompOp{ + DateOp AFTER = new DateOpImpl(); + DateOp BEFORE = new DateOpImpl(); + } + + static class DateOpImpl implements DateOp{} + public static class DomainType extends Reference implements EntityExpr{ protected DomainType(DomainType type, String path) { - super(type._path+"."+path); + super(type+"."+path); } protected DomainType(String path) {super(path);} public EntityExpr as(DomainType to){ return new Alias(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 Reference _prop(String path,Class type) { + return new Reference(this+"."+path); } } @@ -86,28 +107,14 @@ public class Types { */ public static interface EntityExpr extends Expr{} - public interface Expr { } - - /** - * NOTE : BooleanExpr as a concrete interface instead of Expr avoids - * compiler warnings when used in Query#where(BooleanExpr... objects); - */ - public interface BooleanExpr extends Expr{ } - - public static class NumberProperty extends Reference{ - public NumberProperty(String path) {super(path);} - } - + public interface Expr { } + /** * Numeric Operators (operators used with numeric operands) */ - public interface NumOp extends Op{ + public interface NumOp extends CompOp{ NumOp ADD = new NumOpImpl(); - NumOp DIV = new NumOpImpl(); - NumOp GOE = new NumOpImpl(); - NumOp GT = new NumOpImpl(); - NumOp LOE = new NumOpImpl(); - NumOp LT = new NumOpImpl(); + NumOp DIV = new NumOpImpl(); NumOp MOD = new NumOpImpl(); NumOp MULT = new NumOpImpl(); NumOp SUB = new NumOpImpl(); @@ -120,46 +127,48 @@ public class Types { */ public interface Op { Op EQ = new OpImpl(); - Op NE = new OpImpl(); + Op ISTYPEOF = new OpImpl(); + Op NE = new OpImpl(); } - - public interface Operation extends Expr {} - public interface BooleanOperation extends Operation, BooleanExpr {} + public interface Operation extends Expr {} static class OpImpl implements Op {} - public enum Order{ ASC,DESC } + public enum Order{ ASC,DESC } - public static class OrderSpecifier{ + public static class OrderSpecifier>{ public Order order; public Expr target; } - public static class Reference implements Expr{ - public final String _path; - public Reference(String path) { - this._path = path; + public static class Reference implements Expr{ + // _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{ - public StringProperty(String path) {super(path);} + public final String toString(){ return path; } } - + /** * String Operators (operators used with String operands) */ - public interface StrOp extends Op{ + public interface StrOp extends CompOp{ StrOp CONCAT = new StrOpImpl(); StrOp LIKE = new StrOpImpl(); StrOp LOWER = new StrOpImpl(); - StrOp SUBSTRING = new StrOpImpl(); + StrOp SUBSTR = new StrOpImpl(); StrOp UPPER = new StrOpImpl(); } static class StrOpImpl implements StrOp{} + public static class TertiaryBooleanOperation extends TertiaryOperation + implements BooleanOperation{ + + } + public static class TertiaryOperation implements Operation{ /** * arguments don't need to be of same type as return type @@ -170,7 +179,7 @@ public class Types { public Op type; } - public static class TertiaryBooleanOperation extends TertiaryOperation + public static class UnaryBooleanOperation extends UnaryOperation implements BooleanOperation{ } @@ -182,10 +191,5 @@ public class Types { public Expr left; public Op type; } - - public static class UnaryBooleanOperation extends UnaryOperation - implements BooleanOperation{ - - } } diff --git a/src/test/java/com/mysema/query/test/QueryBase.java b/src/test/java/com/mysema/query/test/QueryBase.java index 5da0de1a2..73e2b0be3 100644 --- a/src/test/java/com/mysema/query/test/QueryBase.java +++ b/src/test/java/com/mysema/query/test/QueryBase.java @@ -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 { public QueryBase with(BooleanExpr... objects) { return this; - } - - + } } diff --git a/src/test/java/com/mysema/query/test/QueryTest.java b/src/test/java/com/mysema/query/test/QueryTest.java index 2c4865074..2641a3e8b 100644 --- a/src/test/java/com/mysema/query/test/QueryTest.java +++ b/src/test/java/com/mysema/query/test/QueryTest.java @@ -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 + } + } diff --git a/src/test/java/com/mysema/query/test/domain/AuditLog.java b/src/test/java/com/mysema/query/test/domain/AuditLog.java new file mode 100644 index 000000000..b2e5ff772 --- /dev/null +++ b/src/test/java/com/mysema/query/test/domain/AuditLog.java @@ -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; + } + +} diff --git a/src/test/java/com/mysema/query/test/domain/Cat.java b/src/test/java/com/mysema/query/test/domain/Cat.java index c45d6853e..e982be98b 100644 --- a/src/test/java/com/mysema/query/test/domain/Cat.java +++ b/src/test/java/com/mysema/query/test/domain/Cat.java @@ -16,6 +16,7 @@ public class Cat { private Cat mate; private int bodyWeight; private String name; + private boolean alive; public Collection 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; + } } diff --git a/src/test/java/com/mysema/query/test/domain/Document.java b/src/test/java/com/mysema/query/test/domain/Document.java index c11c3b3a7..94130ca8b 100644 --- a/src/test/java/com/mysema/query/test/domain/Document.java +++ b/src/test/java/com/mysema/query/test/domain/Document.java @@ -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; + } + } diff --git a/src/test/java/com/mysema/query/test/domain/Domain.java b/src/test/java/com/mysema/query/test/domain/Domain.java index 8a84dbd37..cef791f75 100644 --- a/src/test/java/com/mysema/query/test/domain/Domain.java +++ b/src/test/java/com/mysema/query/test/domain/Domain.java @@ -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 log = new qAuditLog("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 = 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 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 = 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"); // Customer - public static final qCustomer cust = new qCustomer("cust"); + public static final qCustomer cust = new qCustomer("cust"); // Document - public static final qDocument doc = new qDocument("doc"); + public static final qDocument doc = new qDocument("doc"); + + // DomesticCat + public static final qDomesticCat domesticCat = new qDomesticCat("domesticCat"); + + // Payment + public static final qPayment payment = new qPayment("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 = 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{ + public static class qAuditLog extends DomainType{ + qAuditLog(String path) {super(path);} + qAuditLog(DomainType type, String path) {super(type,path);} + + private qItem item; + public qItem item() { + if (item == null) item = new qItem(this,"item"); + return item; + } + } + + public static class qCat extends DomainType{ 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 bodyWeight = _prop("bodyWeight",Integer.class); + public final Reference name = _prop("name",String.class); + + private qCat kittens; + 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"); + } + private qCat mate; + public final qCat mate(){ + if (mate == null) mate = new qCat(this,"mate"); return mate; } } - public static class qCustomer extends DomainType{ + public static class qDomesticCat extends qCat{ + qDomesticCat(String path) {super(path);} + qDomesticCat(DomainType type, String path) {super(type,path);} + } + + public static class qCustomer extends DomainType{ 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; + public final qName name(){ + if (name == null) name = new qName(this, "name"); return name; } } - public static class qCompany extends DomainType{ + public static class qCompany extends DomainType{ 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 id = _prop("id",Long.class); + public final Reference name = _prop("name",String.class); } - public static class qDocument extends DomainType{ + public static class qDocument extends DomainType{ qDocument(String path){super(path);} qDocument(DomainType type, String path) {super(type,path);} - public final StringProperty name = str("name"); + public final Reference name = _prop("name",String.class); + public final Reference validTo = _prop("validTo",Date.class); } - public static class qName extends DomainType{ + public static class qItem extends DomainType{ + qItem(String path){super(path);} + qItem(DomainType type, String path) {super(type,path);} + public Reference id = _prop("id",String.class); + } + + public static class qName extends DomainType{ qName(String path){super(path);} qName(DomainType type, String path) {super(type,path);} - public final StringProperty firstName = str("firstName"); + public final Reference firstName = _prop("firstName",String.class); } - public static class qUser extends DomainType{ + public static class qPayment extends qItem{ + qPayment(String path){super(path);} + qPayment(DomainType type, String path) {super(type,path);} + } + + public static class qUser extends DomainType{ 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 id = _prop("id",Long.class); + public final Reference userName = _prop("userName",String.class); + public final Reference firstName = _prop("firstName",String.class); + public final Reference lastName = _prop("lastName",String.class); + + private qCompany company; + public final qCompany company(){ + if (company == null) company = new qCompany(this,"company"); return company; } } diff --git a/src/test/java/com/mysema/query/test/domain/DomesticCat.java b/src/test/java/com/mysema/query/test/domain/DomesticCat.java new file mode 100644 index 000000000..340256e44 --- /dev/null +++ b/src/test/java/com/mysema/query/test/domain/DomesticCat.java @@ -0,0 +1,11 @@ +package com.mysema.query.test.domain; + +/** + * DomesticCat provides + * + * @author tiwe + * @version $Id$ + */ +public class DomesticCat extends Cat{ + +} diff --git a/src/test/java/com/mysema/query/test/domain/Item.java b/src/test/java/com/mysema/query/test/domain/Item.java new file mode 100644 index 000000000..777712fd1 --- /dev/null +++ b/src/test/java/com/mysema/query/test/domain/Item.java @@ -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; + } + +} diff --git a/src/test/java/com/mysema/query/test/domain/Payment.java b/src/test/java/com/mysema/query/test/domain/Payment.java new file mode 100644 index 000000000..27edf46e0 --- /dev/null +++ b/src/test/java/com/mysema/query/test/domain/Payment.java @@ -0,0 +1,11 @@ +package com.mysema.query.test.domain; + +/** + * Payment provides + * + * @author tiwe + * @version $Id$ + */ +public class Payment extends Item{ + +} diff --git a/src/test/java/com/mysema/query/test/domain/User.java b/src/test/java/com/mysema/query/test/domain/User.java index edd810ea3..04d618c8d 100644 --- a/src/test/java/com/mysema/query/test/domain/User.java +++ b/src/test/java/com/mysema/query/test/domain/User.java @@ -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() {