mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
improvements based on Sonar checks
This commit is contained in:
parent
5f9751030d
commit
cbf7c033b2
@ -29,7 +29,7 @@ public abstract class CustomQueryable<SubType extends CustomQueryable<SubType>>
|
||||
|
||||
public CustomQueryable(QueryMetadata metadata, EvaluatorFactory evaluatorFactory) {
|
||||
super(new ColQueryImpl(metadata, evaluatorFactory));
|
||||
query = (ColQueryImpl) projectable;
|
||||
query = (ColQueryImpl) getProjectable();
|
||||
}
|
||||
|
||||
protected QueryMetadata getMetadata() {
|
||||
|
||||
@ -55,7 +55,7 @@ public class ColQuerySerializer extends SerializerBase<ColQuerySerializer> {
|
||||
args.add((Expr<?>)path.getMetadata().getParent());
|
||||
}
|
||||
args.add(path.getMetadata().getExpression());
|
||||
Template template = templates.getTemplate(pathType);
|
||||
Template template = getTemplate(pathType);
|
||||
for (Template.Element element : template.getElements()){
|
||||
if (element.getStaticText() != null){
|
||||
append(element.getStaticText());
|
||||
|
||||
@ -121,12 +121,13 @@ public enum TypeCategory {
|
||||
* @return
|
||||
*/
|
||||
public boolean isSubCategoryOf(TypeCategory ancestor){
|
||||
if (this == ancestor)
|
||||
if (this == ancestor){
|
||||
return true;
|
||||
else if (superType == null)
|
||||
}else if (superType == null){
|
||||
return false;
|
||||
else
|
||||
}else{
|
||||
return superType == ancestor || superType.isSubCategoryOf(ancestor);
|
||||
}
|
||||
}
|
||||
|
||||
public static TypeCategory get(String className){
|
||||
|
||||
@ -33,32 +33,40 @@ import com.mysema.query.types.path.PathType;
|
||||
*/
|
||||
public abstract class SerializerBase<SubType extends SerializerBase<SubType>> extends VisitorBase<SubType> {
|
||||
|
||||
private final StringBuilder builder = new StringBuilder();
|
||||
|
||||
private final Map<Object,String> constantToLabel = new HashMap<Object,String>();
|
||||
|
||||
protected String constantPrefix = "a";
|
||||
|
||||
protected final Templates templates;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private final SubType _this = (SubType) this;
|
||||
|
||||
private final StringBuilder builder = new StringBuilder();
|
||||
|
||||
private String constantPrefix = "a";
|
||||
|
||||
private final Map<Object,String> constantToLabel = new HashMap<Object,String>();
|
||||
|
||||
private final Templates templates;
|
||||
|
||||
public SerializerBase(Templates patterns) {
|
||||
this.templates = Assert.notNull(patterns,"patterns is null");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public SubType append(String... str) {
|
||||
for (String s : str) {
|
||||
builder.append(s);
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
|
||||
|
||||
protected String getConstantPrefix() {
|
||||
return constantPrefix;
|
||||
}
|
||||
|
||||
public Map<Object,String> getConstantToLabel() {
|
||||
return constantToLabel;
|
||||
}
|
||||
|
||||
protected Template getTemplate(Operator<?> op) {
|
||||
return templates.getTemplate(op);
|
||||
}
|
||||
|
||||
public final SubType handle(String sep, List<? extends Expr<?>> expressions) {
|
||||
boolean first = true;
|
||||
for (Expr<?> expr : expressions) {
|
||||
@ -80,6 +88,17 @@ public abstract class SerializerBase<SubType extends SerializerBase<SubType>> ex
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Constant<?> expr) {
|
||||
if (!constantToLabel.containsKey(expr.getConstant())) {
|
||||
String constLabel = constantPrefix + (constantToLabel.size() + 1);
|
||||
constantToLabel.put(expr.getConstant(), constLabel);
|
||||
append(constLabel);
|
||||
} else {
|
||||
append(constantToLabel.get(expr.getConstant()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Custom<?> expr) {
|
||||
for (Template.Element element : expr.getTemplate().getElements()){
|
||||
@ -97,17 +116,6 @@ public abstract class SerializerBase<SubType extends SerializerBase<SubType>> ex
|
||||
handle(", ", oa.getArgs()).append("}");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Constant<?> expr) {
|
||||
if (!constantToLabel.containsKey(expr.getConstant())) {
|
||||
String constLabel = constantPrefix + (constantToLabel.size() + 1);
|
||||
constantToLabel.put(expr.getConstant(), constLabel);
|
||||
append(constLabel);
|
||||
} else {
|
||||
append(constantToLabel.get(expr.getConstant()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(EConstructor<?> expr) {
|
||||
append("new ").append(expr.getType().getName()).append("(");
|
||||
|
||||
@ -22,11 +22,15 @@ import com.mysema.query.types.expr.Expr;
|
||||
*/
|
||||
public class ProjectableAdapter implements Projectable {
|
||||
|
||||
protected final Projectable projectable;
|
||||
private final Projectable projectable;
|
||||
|
||||
public ProjectableAdapter(Projectable projectable) {
|
||||
this.projectable = Assert.notNull(projectable,"projectable is null");
|
||||
}
|
||||
|
||||
protected Projectable getProjectable(){
|
||||
return projectable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
|
||||
@ -14,7 +14,7 @@ import com.mysema.query.types.Visitor;
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class EBooleanConst extends EBoolean implements Constant<Boolean>{
|
||||
public final class EBooleanConst extends EBoolean implements Constant<Boolean>{
|
||||
|
||||
public static final EBoolean FALSE = new EBooleanConst(Boolean.FALSE);
|
||||
|
||||
|
||||
@ -27,15 +27,25 @@ public final class MathUtils {
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <D extends Number & Comparable<?>> D cast(BigDecimal num, Class<D> type){
|
||||
Number rv;
|
||||
if (type.equals(Double.class)) rv = num.byteValue();
|
||||
else if (type.equals(Double.class)) rv = num.doubleValue();
|
||||
else if (type.equals(Float.class)) rv = num.floatValue();
|
||||
else if (type.equals(Integer.class)) rv = num.intValue();
|
||||
else if (type.equals(Long.class)) rv = num.longValue();
|
||||
else if (type.equals(Short.class)) rv = num.shortValue();
|
||||
else if (type.equals(BigDecimal.class)) rv = num;
|
||||
else if (type.equals(BigInteger.class)) rv = num.toBigInteger();
|
||||
else throw new IllegalArgumentException(String.format("Illegal type : %s", type.getSimpleName()));
|
||||
if (type.equals(Double.class)){
|
||||
rv = num.byteValue();
|
||||
}else if (type.equals(Double.class)){
|
||||
rv = num.doubleValue();
|
||||
}else if (type.equals(Float.class)){
|
||||
rv = num.floatValue();
|
||||
}else if (type.equals(Integer.class)){
|
||||
rv = num.intValue();
|
||||
}else if (type.equals(Long.class)){
|
||||
rv = num.longValue();
|
||||
}else if (type.equals(Short.class)){
|
||||
rv = num.shortValue();
|
||||
}else if (type.equals(BigDecimal.class)){
|
||||
rv = num;
|
||||
}else if (type.equals(BigInteger.class)){
|
||||
rv = num.toBigInteger();
|
||||
}else{
|
||||
throw new IllegalArgumentException(String.format("Illegal type : %s", type.getSimpleName()));
|
||||
}
|
||||
return (D) rv;
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ public class HQLSerializer extends SerializerBase<HQLSerializer> {
|
||||
}
|
||||
append(":");
|
||||
if (!getConstantToLabel().containsKey(expr.getConstant())) {
|
||||
String constLabel = constantPrefix + (getConstantToLabel().size()+1);
|
||||
String constLabel = getConstantPrefix() + (getConstantToLabel().size()+1);
|
||||
getConstantToLabel().put(expr.getConstant(), constLabel);
|
||||
append(constLabel);
|
||||
} else {
|
||||
|
||||
@ -28,7 +28,7 @@ public class HibernateSQLSerializer extends SQLSerializer{
|
||||
@Override
|
||||
public void visit(Constant<?> expr) {
|
||||
if (!getConstantToLabel().containsKey(expr.getConstant())) {
|
||||
String constLabel = constantPrefix + (getConstantToLabel().size() + 1);
|
||||
String constLabel = getConstantPrefix() + (getConstantToLabel().size() + 1);
|
||||
getConstantToLabel().put(expr.getConstant(), constLabel);
|
||||
append(":"+constLabel);
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user