From 49aac9247aa6d51a4b2ebc2a10ac1e72da531e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Fri, 7 Mar 2008 22:12:02 +0000 Subject: [PATCH] formalized Path types --- .../java/com/mysema/query/grammar/Types.java | 101 +++++++++++------- 1 file changed, 65 insertions(+), 36 deletions(-) diff --git a/querydsl-core/src/main/java/com/mysema/query/grammar/Types.java b/querydsl-core/src/main/java/com/mysema/query/grammar/Types.java index f5bcf7669..bd58a75ab 100644 --- a/querydsl-core/src/main/java/com/mysema/query/grammar/Types.java +++ b/querydsl-core/src/main/java/com/mysema/query/grammar/Types.java @@ -39,12 +39,12 @@ public class Types { private final Expr from; private final String to; AliasEntity(PathEntity from, PathEntity to) { - super(from.type); + super(from._type()); this.from = from; this.to = to.toString(); } AliasEntity(PathEntity from, String to) { - super(from.type); + super(from._type()); this.from = from; this.to = to; } @@ -78,12 +78,13 @@ public class Types { } public static abstract class Expr{ - protected final Class type; - Expr(Class type){this.type = type;} + private final Class type; + Expr(Class type){this.type = type;} public ExprBoolean eq(B right){return Grammar.eq(this, right);} public ExprBoolean eq(Expr right){return Grammar.eq(this, right);} public ExprBoolean ne(B right){return Grammar.ne(this, right);} - public ExprBoolean ne(Expr right){return Grammar.ne(this, right);} + public ExprBoolean ne(Expr right){return Grammar.ne(this, right);} + protected Class _type(){ return type;} } public static abstract class ExprBoolean extends ExprNoEntity{ @@ -94,23 +95,23 @@ public class Types { public static abstract class ExprComparable> extends ExprNoEntity{ ExprComparable(Class type) {super(type);} + public ExprBoolean after(D right) {return Grammar.after(this,right);} + public ExprBoolean after(Expr right) {return Grammar.after(this,right);} public OrderSpecifier asc() {return Grammar.asc(this);} - public OrderSpecifier desc() {return Grammar.desc(this);} - public ExprBoolean after(Expr right) {return Grammar.after(this,right);} - public ExprBoolean after(D right) {return Grammar.after(this,right);} + public ExprBoolean before(D right) {return Grammar.before(this,right);} public ExprBoolean before(Expr right) {return Grammar.before(this,right);} - public ExprBoolean before(D right) {return Grammar.before(this,right);} + public ExprBoolean between(D first, D second) {return Grammar.between(this,first,second);} public ExprBoolean between(Expr first, Expr second) {return Grammar.between(this,first,second);} - public ExprBoolean between(D first, D second) {return Grammar.between(this,first,second);} + public OrderSpecifier desc() {return Grammar.desc(this);} public ExprBoolean goe(D right) {return Grammar.goe(this,right);} public ExprBoolean goe(Expr right) {return Grammar.goe(this,right);} public ExprBoolean gt(D right) {return Grammar.gt(this,right);} public ExprBoolean gt(Expr right) {return Grammar.gt(this,right);} - public ExprBoolean loe(D right) {return Grammar.loe(this,right);} + public ExprBoolean in(D... args) {return Grammar.in(this,args);} + public ExprBoolean loe(D right) {return Grammar.loe(this,right);} public ExprBoolean loe(Expr right) {return Grammar.loe(this,right);} public ExprBoolean lt(D right) {return Grammar.lt(this,right);} public ExprBoolean lt(Expr right) {return Grammar.lt(this,right);} - public ExprBoolean in(D... args) {return Grammar.in(this,args);} } public static abstract class ExprEntity extends Expr{ @@ -184,54 +185,71 @@ public class Types { public Expr target; } - public interface Path{ + public interface Path{ + Path _parent(); ExprBoolean isnotnull(); ExprBoolean isnull(); } public static class PathBoolean extends ExprBoolean implements PathNoEntity{ + private final Path parent; private final String path; - PathBoolean(String path) {this.path = path;} + PathBoolean(Path parent,String path) { + this.parent = parent; + this.path = parent.toString()+"."+path; + } + public Path _parent() {return parent;} public ExprBoolean isnotnull() {return Grammar.isnotnull(this);} public ExprBoolean isnull() {return Grammar.isnull(this);} - public String toString(){ return path;} + public String toString(){ return path;} } public static class PathComparable> extends ExprComparable implements PathNoEntity{ + private final Path parent; private final String path; - public PathComparable(Class type, String path) { + public PathComparable(Class type, Path parent, String path) { super(type); - this.path = path; + this.parent = parent; + this.path = parent.toString()+"."+path; } + public Path _parent() {return parent;} public ExprBoolean isnotnull() {return Grammar.isnotnull(this);} public ExprBoolean isnull() {return Grammar.isnull(this);} public String toString() {return path;} } public static class PathEntity extends ExprEntity implements Path{ + private final Path parent; private final String path; protected PathEntity(Class type, String path) { super(type); + this.parent = null; this.path = path; } + protected PathEntity(Class type, Path parent, String path) { + super(type); + this.parent = parent; + this.path = parent.toString()+"."+path; + } protected PathBoolean _boolean(String path){ - return new PathBoolean(this+"."+path); + return new PathBoolean(this, path); } protected PathEntityCollection _collection(String path,Class type) { - return new PathEntityCollection(type, this+"."+path); + return new PathEntityCollection(type, this, path); } protected > PathComparable _comparable(String path,Class type) { - return new PathComparable(type, this+"."+path); + return new PathComparable(type, this, path); } protected PathEntityRenamable _entity(String path, Class type){ - return new PathEntityRenamable(type, this+"."+path); + return new PathEntityRenamable(type, this, path); } + public Path _parent() {return parent;} protected PathNoEntitySimple _simple(String path, Class type){ - return new PathNoEntitySimple(type, this+"."+path); - } - protected PathString _string(String path){ - return new PathString(this+"."+path); + return new PathNoEntitySimple(type, this, path); } + protected PathString _string(String path){ + return new PathString(this, path); + } public ExprBoolean in(ExprEntity> right){return Grammar.in(this, right);} public ExprBoolean isnotnull() {return Grammar.isnotnull(this);} public ExprBoolean isnull() {return Grammar.isnull(this);} @@ -240,22 +258,27 @@ public class Types { } public static class PathEntityCollection extends ExprEntity> implements Path>{ - private final String path; + private final Path parent; + private final String property, path; private final Class type; - PathEntityCollection(Class type, String path) { - super(null); + PathEntityCollection(Class type, Path parent, String path) { + super(null); this.type = type; - this.path = path; + this.parent = parent; + this.property = path; + this.path = parent.toString()+"."+path; } + public Path _parent() {return parent;} public AliasCollection as(PathEntity to) {return Grammar.as(this, to);} + public ExprEntity get(int index) {return new PathEntity(type, _parent(), property + "["+index+"]");} public ExprBoolean isnotnull() {return Grammar.isnotnull(this);} public ExprBoolean isnull() {return Grammar.isnull(this);} public String toString() {return path;} - public ExprEntity get(int index) {return new PathEntity(type,path+"["+index+"]");} + } public static class PathEntityRenamable extends PathEntity{ - protected PathEntityRenamable(Class type, String path) {super(type,path);} + protected PathEntityRenamable(Class type, Path parent, String path) {super(type, parent, path);} public AliasEntity as(PathEntity to) {return Grammar.as(this, to);} } @@ -264,21 +287,27 @@ public class Types { } public static class PathNoEntitySimple extends ExprNoEntity implements PathNoEntity{ - private final String path; - public PathNoEntitySimple(Class type, String path) { + private final Path parent; + private final String path; + public PathNoEntitySimple(Class type, Path parent, String path) { super(type); - this.path = path; + this.parent = parent; + this.path = parent.toString()+"."+path; } + public Path _parent() {return parent;} public ExprBoolean isnotnull() {return Grammar.isnotnull(this);} public ExprBoolean isnull() {return Grammar.isnull(this);} public String toString() {return path;} } public static class PathString extends ExprString implements PathNoEntity{ + private final Path parent; private final String path; - public PathString(String path) { - this.path = path; + public PathString(Path parent, String path) { + this.parent = parent; + this.path = parent.toString()+"."+path; } + public Path _parent() {return parent;} public ExprBoolean isnotnull() {return Grammar.isnotnull(this);} public ExprBoolean isnull() {return Grammar.isnull(this);} public String toString() {return path;}