mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
small improvements to toString methods
This commit is contained in:
parent
7fb5128dc2
commit
02bab0bb62
@ -26,13 +26,13 @@ public interface ExprFactory {
|
||||
|
||||
<D> Expr<D> createAny(D arg);
|
||||
|
||||
EBoolean createBoolean(Boolean arg);
|
||||
PBoolean createBoolean(Boolean arg);
|
||||
|
||||
PBooleanArray createBooleanArray(Boolean[] args);
|
||||
|
||||
<D extends Number & Comparable<? super D>> ENumber<D> createNumber(D arg);
|
||||
<D extends Number & Comparable<? super D>> PNumber<D> createNumber(D arg);
|
||||
|
||||
<D extends Comparable<? super D>> EComparable<D> createComparable(D arg);
|
||||
<D extends Comparable<? super D>> PComparable<D> createComparable(D arg);
|
||||
|
||||
<D> PEntity<D> createEntity(D arg);
|
||||
|
||||
@ -44,7 +44,7 @@ public interface ExprFactory {
|
||||
|
||||
<D extends Comparable<? super D>> PComparableArray<D> createComparableArray(D[] args);
|
||||
|
||||
EString createString(String arg);
|
||||
PString createString(String arg);
|
||||
|
||||
PStringArray createStringArray(String[] args);
|
||||
|
||||
|
||||
@ -22,10 +22,12 @@ public class JoinExpression<T> {
|
||||
private final JoinType type;
|
||||
private final T metadata;
|
||||
|
||||
public JoinExpression(Expr<?> target){
|
||||
this(JoinType.DEFAULT, target, null);
|
||||
}
|
||||
|
||||
public JoinExpression(JoinType type, Expr<?> target) {
|
||||
this.type = type;
|
||||
this.target = Assert.notNull(target);
|
||||
this.metadata = null;
|
||||
this(type, target, null);
|
||||
}
|
||||
|
||||
public JoinExpression(JoinType type, Expr<?> target, T metadata) {
|
||||
@ -55,7 +57,12 @@ public class JoinExpression<T> {
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return type + " " + target;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(type).append(" ").append(target);
|
||||
if (condition != null){
|
||||
builder.append(" ON ").append(condition);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -12,5 +12,15 @@ package com.mysema.query;
|
||||
* @version $Id$
|
||||
*/
|
||||
public enum JoinType {
|
||||
DEFAULT, INNERJOIN, JOIN, LEFTJOIN, FULLJOIN
|
||||
DEFAULT,
|
||||
INNERJOIN {
|
||||
public String toString(){ return "INNER JOIN"; }
|
||||
},
|
||||
JOIN,
|
||||
LEFTJOIN {
|
||||
public String toString(){ return "LEFT JOIN"; }
|
||||
},
|
||||
FULLJOIN {
|
||||
public String toString(){ return "FULL JOIN"; }
|
||||
}
|
||||
}
|
||||
@ -115,7 +115,7 @@ public class SimpleExprFactory implements ExprFactory {
|
||||
}
|
||||
});
|
||||
|
||||
private final Map<String,PString> strToExtPath = new PathFactory<String,PString>(new Transformer<String,PString>(){
|
||||
private final Map<String,PString> strToPath = new PathFactory<String,PString>(new Transformer<String,PString>(){
|
||||
public PString transform(String str) {
|
||||
return new PString(md());
|
||||
}
|
||||
@ -125,7 +125,7 @@ public class SimpleExprFactory implements ExprFactory {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public EBoolean createBoolean(Boolean arg){
|
||||
public PBoolean createBoolean(Boolean arg){
|
||||
return arg.booleanValue() ? btrue : bfalse;
|
||||
}
|
||||
|
||||
@ -139,13 +139,13 @@ public class SimpleExprFactory implements ExprFactory {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <D extends Comparable<? super D>> EComparable<D> createComparable(D arg){
|
||||
return (EComparable<D>) comToPath.get(arg);
|
||||
public <D extends Comparable<? super D>> PComparable<D> createComparable(D arg){
|
||||
return (PComparable<D>) comToPath.get(arg);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <D extends Number & Comparable<? super D>> ENumber<D> createNumber(D arg) {
|
||||
return (ENumber<D>) numToPath.get(arg);
|
||||
public <D extends Number & Comparable<? super D>> PNumber<D> createNumber(D arg) {
|
||||
return (PNumber<D>) numToPath.get(arg);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -168,8 +168,8 @@ public class SimpleExprFactory implements ExprFactory {
|
||||
return (PEntityList<D>) elToPath.get(arg);
|
||||
}
|
||||
|
||||
public EString createString(String arg){
|
||||
return StringUtils.isEmpty(arg) ? str : strToExtPath.get(arg);
|
||||
public PString createString(String arg){
|
||||
return StringUtils.isEmpty(arg) ? str : strToPath.get(arg);
|
||||
}
|
||||
|
||||
public PStringArray createStringArray(String[] args){
|
||||
|
||||
@ -11,10 +11,6 @@ import java.util.Map;
|
||||
|
||||
import com.mysema.query.SimpleExprFactory;
|
||||
import com.mysema.query.grammar.types.Expr;
|
||||
import com.mysema.query.grammar.types.Expr.EBoolean;
|
||||
import com.mysema.query.grammar.types.Expr.EComparable;
|
||||
import com.mysema.query.grammar.types.Expr.ENumber;
|
||||
import com.mysema.query.grammar.types.Expr.EString;
|
||||
import com.mysema.query.grammar.types.Path.*;
|
||||
|
||||
/**
|
||||
@ -43,8 +39,8 @@ public class AliasAwareExprFactory extends SimpleExprFactory{
|
||||
}
|
||||
}
|
||||
|
||||
public EBoolean createBoolean(Boolean arg){
|
||||
EBoolean rv = aliasFactory.<PBoolean>getCurrentAndReset();
|
||||
public PBoolean createBoolean(Boolean arg){
|
||||
PBoolean rv = aliasFactory.<PBoolean>getCurrentAndReset();
|
||||
return rv != null ? rv : super.createBoolean(arg);
|
||||
}
|
||||
|
||||
@ -58,13 +54,13 @@ public class AliasAwareExprFactory extends SimpleExprFactory{
|
||||
return rv != null ? rv : super.createEntityCollection(arg);
|
||||
}
|
||||
|
||||
public <D extends Comparable<? super D>> EComparable<D> createComparable(D arg){
|
||||
EComparable<D> rv = aliasFactory.<EComparable<D>>getCurrentAndReset();
|
||||
public <D extends Comparable<? super D>> PComparable<D> createComparable(D arg){
|
||||
PComparable<D> rv = aliasFactory.<PComparable<D>>getCurrentAndReset();
|
||||
return rv != null ? rv : super.createComparable(arg);
|
||||
}
|
||||
|
||||
public <D extends Number & Comparable<? super D>> ENumber<D> createNumber(D arg){
|
||||
ENumber<D> rv = aliasFactory.<ENumber<D>>getCurrentAndReset();
|
||||
public <D extends Number & Comparable<? super D>> PNumber<D> createNumber(D arg){
|
||||
PNumber<D> rv = aliasFactory.<PNumber<D>>getCurrentAndReset();
|
||||
return rv != null ? rv : super.createNumber(arg);
|
||||
}
|
||||
|
||||
@ -95,8 +91,8 @@ public class AliasAwareExprFactory extends SimpleExprFactory{
|
||||
return rv != null ? rv : super.createEntityList(arg);
|
||||
}
|
||||
|
||||
public EString createString(String arg){
|
||||
EString rv = aliasFactory.<EString>getCurrentAndReset();
|
||||
public PString createString(String arg){
|
||||
PString rv = aliasFactory.<PString>getCurrentAndReset();
|
||||
return rv != null ? rv : super.createString(arg);
|
||||
}
|
||||
|
||||
|
||||
@ -132,10 +132,6 @@ class PropertyAccessInvocationHandler implements MethodInterceptor{
|
||||
}
|
||||
aliasFactory.setCurrent(propToExpr.get(propKey));
|
||||
|
||||
}else if (isContains(method)){
|
||||
rv = false;
|
||||
aliasFactory.setCurrent(Grammar.in(args[0], (CollectionType<Object>)path));
|
||||
|
||||
}else if (isToString(method)){
|
||||
rv = path.toString();
|
||||
|
||||
@ -155,10 +151,6 @@ class PropertyAccessInvocationHandler implements MethodInterceptor{
|
||||
return checkMethod(method, "toString", 0, String.class);
|
||||
}
|
||||
|
||||
private boolean isContains(Method method){
|
||||
return checkMethod(method, "contains", 1, boolean.class);
|
||||
}
|
||||
|
||||
private boolean isGetMappedPath(Method method){
|
||||
return checkMethod(method, "__mappedPath", 0, PEntity.class);
|
||||
}
|
||||
|
||||
@ -17,10 +17,6 @@ import com.mysema.query.alias.AliasFactory;
|
||||
import com.mysema.query.alias.SimpleAliasFactory;
|
||||
import com.mysema.query.grammar.types.Expr;
|
||||
import com.mysema.query.grammar.types.PathMetadata;
|
||||
import com.mysema.query.grammar.types.Expr.EBoolean;
|
||||
import com.mysema.query.grammar.types.Expr.EComparable;
|
||||
import com.mysema.query.grammar.types.Expr.ENumber;
|
||||
import com.mysema.query.grammar.types.Expr.EString;
|
||||
import com.mysema.query.grammar.types.Path.*;
|
||||
|
||||
/**
|
||||
@ -49,47 +45,47 @@ public class GrammarWithAlias extends Grammar{
|
||||
aliasFactory.reset();
|
||||
}
|
||||
|
||||
public static EBoolean $(Boolean arg){
|
||||
public static PBoolean $(Boolean arg){
|
||||
return exprFactory.createBoolean(arg);
|
||||
}
|
||||
|
||||
public static <D extends Comparable<? super D>> EComparable<D> $(D arg){
|
||||
public static <D extends Comparable<? super D>> PComparable<D> $(D arg){
|
||||
return exprFactory.createComparable(arg);
|
||||
}
|
||||
|
||||
public static ENumber<BigDecimal> $(BigDecimal arg){
|
||||
public static PNumber<BigDecimal> $(BigDecimal arg){
|
||||
return exprFactory.createNumber(arg);
|
||||
}
|
||||
|
||||
public static ENumber<BigInteger> $(BigInteger arg){
|
||||
public static PNumber<BigInteger> $(BigInteger arg){
|
||||
return exprFactory.createNumber(arg);
|
||||
}
|
||||
|
||||
public static ENumber<Byte> $(Byte arg){
|
||||
public static PNumber<Byte> $(Byte arg){
|
||||
return exprFactory.createNumber(arg);
|
||||
}
|
||||
|
||||
public static ENumber<Double> $(Double arg){
|
||||
public static PNumber<Double> $(Double arg){
|
||||
return exprFactory.createNumber(arg);
|
||||
}
|
||||
|
||||
public static ENumber<Float> $(Float arg){
|
||||
public static PNumber<Float> $(Float arg){
|
||||
return exprFactory.createNumber(arg);
|
||||
}
|
||||
|
||||
public static ENumber<Integer> $(Integer arg){
|
||||
public static PNumber<Integer> $(Integer arg){
|
||||
return exprFactory.createNumber(arg);
|
||||
}
|
||||
|
||||
public static ENumber<Long> $(Long arg){
|
||||
public static PNumber<Long> $(Long arg){
|
||||
return exprFactory.createNumber(arg);
|
||||
}
|
||||
|
||||
public static ENumber<Short> $(Short arg){
|
||||
public static PNumber<Short> $(Short arg){
|
||||
return exprFactory.createNumber(arg);
|
||||
}
|
||||
|
||||
public static EString $(String arg){
|
||||
public static PString $(String arg){
|
||||
return exprFactory.createString(arg);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user