mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-09 21:13:03 +08:00
formalized Path types
This commit is contained in:
parent
982675ef0c
commit
ed4646ca9c
@ -98,7 +98,6 @@ public class HqlGrammar extends Grammar{
|
||||
super(type);
|
||||
this.args = args;
|
||||
}
|
||||
public Class<D> getType(){ return type;}
|
||||
}
|
||||
|
||||
public static class CountExpr extends ExprComparable<Long>{
|
||||
|
||||
@ -9,7 +9,7 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mysema.query.grammar.Ops.Op;
|
||||
import com.mysema.query.grammar.Ops;
|
||||
|
||||
/**
|
||||
* Ops provides
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
*/
|
||||
package com.mysema.query.grammar;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -22,19 +21,7 @@ import com.mysema.query.grammar.Types.*;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
|
||||
|
||||
private static final Field typeField;
|
||||
|
||||
static{
|
||||
try {
|
||||
typeField = Expr.class.getDeclaredField("type");
|
||||
typeField.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
String error = "Caught " + e.getClass().getName();
|
||||
throw new RuntimeException(error, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private StringBuilder builder = new StringBuilder();
|
||||
|
||||
private List<Object> constants = new ArrayList<Object>();
|
||||
@ -52,15 +39,6 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private Class<?> _getType(PathEntity<?> expr) {
|
||||
try {
|
||||
return (Class<?>) typeField.get(expr);
|
||||
} catch (Exception e) {
|
||||
String error = "Caught " + e.getClass().getName();
|
||||
throw new RuntimeException(error, e);
|
||||
}
|
||||
}
|
||||
|
||||
private String _toString(Expr<?> expr) {
|
||||
StringBuilder old = builder;
|
||||
@ -97,7 +75,7 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
|
||||
}
|
||||
// type specifier
|
||||
if (je.target instanceof PathEntity && !je.target.toString().contains(".")){
|
||||
_append(_getType((PathEntity<?>)je.target).getSimpleName())._append(" ");
|
||||
_append(((PathEntity<?>)je.target)._type().getSimpleName())._append(" ");
|
||||
}
|
||||
handle(je.target);
|
||||
if (je.conditions != null){
|
||||
@ -148,7 +126,7 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
|
||||
}
|
||||
|
||||
protected void visit(Constructor<?> expr){
|
||||
_append("new ")._append(expr.type.getName())._append("(");
|
||||
_append("new ")._append(expr._type().getName())._append("(");
|
||||
_append(", ",Arrays.asList(expr.args))._append(")");
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,9 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mysema.query.grammar.HqlQueryBase;
|
||||
import com.mysema.query.grammar.Types.*;
|
||||
import com.mysema.query.grammar.Types.ExprBoolean;
|
||||
import com.mysema.query.grammar.Types.PathEntity;
|
||||
import com.mysema.query.grammar.Types.PathNoEntitySimple;
|
||||
|
||||
/**
|
||||
* HqlQuery provides a fluent statically typed interface for creating HQL queries
|
||||
@ -65,7 +67,7 @@ public class HqlQuery extends HqlQueryBase<HqlQuery>{
|
||||
&& !entry.getKey().equals("class")
|
||||
&& !entry.getKey().equals("created")
|
||||
&& !entry.getKey().equals("modified")){
|
||||
PathNoEntitySimple path = new PathNoEntitySimple(Object.class,entity+"."+entry.getKey());
|
||||
PathNoEntitySimple path = new PathNoEntitySimple(Object.class, entity, entry.getKey());
|
||||
if (entry.getValue() != null){
|
||||
conds.add(path.eq(entry.getValue()));
|
||||
}else{
|
||||
|
||||
@ -10,5 +10,6 @@ import javax.persistence.Entity;
|
||||
*/
|
||||
@Entity
|
||||
public class EvilType {
|
||||
protected EvilType isnull, isnotnull, asc, desc, get, toString, hashCode, getClass, notify, notifyAll, wait;
|
||||
protected EvilType isnull, isnotnull, asc, desc, get, _type, path, _parent;
|
||||
protected EvilType toString, hashCode, getClass, notify, notifyAll, wait;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user