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
7b39cfb076
commit
4a65a3ceb4
@ -20,9 +20,9 @@ import com.mysema.query.types.path.PEntity;
|
||||
*/
|
||||
public class QueryMixin<T>{
|
||||
|
||||
protected T self;
|
||||
private T self;
|
||||
|
||||
protected final QueryMetadata metadata;
|
||||
private final QueryMetadata metadata;
|
||||
|
||||
public QueryMixin(QueryMetadata metadata){
|
||||
this.metadata = Assert.notNull(metadata);
|
||||
@ -133,6 +133,10 @@ public class QueryMixin<T>{
|
||||
return metadata.isDistinct();
|
||||
}
|
||||
|
||||
public T getSelf(){
|
||||
return self;
|
||||
}
|
||||
|
||||
public void setSelf(T self){
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ public final class EntityModel extends TypeModelAdapter implements Comparable<En
|
||||
|
||||
@Override
|
||||
public int compareTo(EntityModel o) {
|
||||
return typeModel.getSimpleName().compareTo(o.typeModel.getSimpleName());
|
||||
return getTypeModel().getSimpleName().compareTo(o.getTypeModel().getSimpleName());
|
||||
}
|
||||
|
||||
public TypeCategory getCategory() {
|
||||
@ -105,7 +105,7 @@ public final class EntityModel extends TypeModelAdapter implements Comparable<En
|
||||
|
||||
public String getLocalGenericName(){
|
||||
try {
|
||||
return typeModel.getLocalGenericName(this, new StringBuilder(), false).toString();
|
||||
return getTypeModel().getLocalGenericName(this, new StringBuilder(), false).toString();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
@ -113,7 +113,7 @@ public final class EntityModel extends TypeModelAdapter implements Comparable<En
|
||||
|
||||
public String getLocalRawName() {
|
||||
try {
|
||||
return typeModel.getLocalRawName(this, new StringBuilder()).toString();
|
||||
return getTypeModel().getLocalRawName(this, new StringBuilder()).toString();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
@ -182,7 +182,7 @@ public final class EntityModel extends TypeModelAdapter implements Comparable<En
|
||||
|
||||
private PropertyModel validateField(PropertyModel field) {
|
||||
if (field.getName().equals(this.uncapSimpleName)) {
|
||||
uncapSimpleName = StringUtils.uncapitalize(typeModel.getSimpleName())+ (escapeSuffix++);
|
||||
uncapSimpleName = StringUtils.uncapitalize(getTypeModel().getSimpleName())+ (escapeSuffix++);
|
||||
}
|
||||
return field;
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ public class TypeExtendsModel extends TypeModelAdapter{
|
||||
if (!asArgType){
|
||||
builder.append("? extends ");
|
||||
}
|
||||
return typeModel.getLocalGenericName(context, builder, true);
|
||||
return getTypeModel().getLocalGenericName(context, builder, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,17 +17,22 @@ import com.mysema.commons.lang.Assert;
|
||||
*/
|
||||
public class TypeModelAdapter implements TypeModel{
|
||||
|
||||
protected final TypeModel typeModel;
|
||||
private final TypeModel typeModel;
|
||||
|
||||
public TypeModelAdapter(TypeModel typeModel){
|
||||
this.typeModel = Assert.notNull(typeModel);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TypeModel as(TypeCategory category) {
|
||||
return typeModel.as(category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeModel asArrayType() {
|
||||
return typeModel.asArrayType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o){
|
||||
return typeModel.equals(o);
|
||||
@ -93,6 +98,10 @@ public class TypeModelAdapter implements TypeModel{
|
||||
return typeModel.getSimpleName();
|
||||
}
|
||||
|
||||
protected TypeModel getTypeModel(){
|
||||
return typeModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEntityFields() {
|
||||
return typeModel.hasEntityFields();
|
||||
@ -107,20 +116,15 @@ public class TypeModelAdapter implements TypeModel{
|
||||
public boolean isFinal() {
|
||||
return typeModel.isFinal();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isPrimitive() {
|
||||
return typeModel.isPrimitive();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return typeModel.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeModel asArrayType() {
|
||||
return typeModel.asArrayType();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ public abstract class SerializerBase<SubType extends SerializerBase<SubType>> ex
|
||||
|
||||
private final StringBuilder builder = new StringBuilder();
|
||||
|
||||
protected Map<Object,String> constantToLabel = new HashMap<Object,String>();
|
||||
private final Map<Object,String> constantToLabel = new HashMap<Object,String>();
|
||||
|
||||
protected String constantPrefix = "a";
|
||||
|
||||
|
||||
@ -54,123 +54,123 @@ public class HQLQueryMixin<T> extends QueryMixin<T> {
|
||||
}
|
||||
|
||||
public T fetch(){
|
||||
List<JoinExpression> joins = metadata.getJoins();
|
||||
List<JoinExpression> joins = getMetadata().getJoins();
|
||||
joins.get(joins.size()-1).setFlag(HQLFlags.FETCH);
|
||||
return self;
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public T fetchAll(){
|
||||
List<JoinExpression> joins = metadata.getJoins();
|
||||
List<JoinExpression> joins = getMetadata().getJoins();
|
||||
joins.get(joins.size()-1).setFlag(HQLFlags.FETCH_ALL);
|
||||
return self;
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T fullJoin(Path<? extends Collection<P>> target) {
|
||||
metadata.addJoin(JoinType.FULLJOIN, target.asExpr());
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.FULLJOIN, target.asExpr());
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
|
||||
public <P> T fullJoin(Path<? extends Collection<P>> target, Path<P> alias) {
|
||||
metadata.addJoin(JoinType.FULLJOIN, createAlias(target, alias));
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.FULLJOIN, createAlias(target, alias));
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T fullJoin(PEntity<P> target, PEntity<P> alias) {
|
||||
metadata.addJoin(JoinType.FULLJOIN, createAlias(target, alias));
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.FULLJOIN, createAlias(target, alias));
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T fullJoin(PMap<?,P,?> target) {
|
||||
metadata.addJoin(JoinType.FULLJOIN, target);
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.FULLJOIN, target);
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T fullJoin(PMap<?,P,?> target, Path<P> alias) {
|
||||
metadata.addJoin(JoinType.FULLJOIN, createAlias(target, alias));
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.FULLJOIN, createAlias(target, alias));
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T innerJoin(Path<? extends Collection<P>> target) {
|
||||
metadata.addJoin(JoinType.INNERJOIN, target.asExpr());
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.INNERJOIN, target.asExpr());
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T innerJoin(Path<? extends Collection<P>>target, Path<P> alias) {
|
||||
metadata.addJoin(JoinType.INNERJOIN, createAlias(target, alias));
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.INNERJOIN, createAlias(target, alias));
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T innerJoin(PEntity<P> target, PEntity<P> alias) {
|
||||
metadata.addJoin(JoinType.INNERJOIN, createAlias(target, alias));
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.INNERJOIN, createAlias(target, alias));
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T innerJoin(PMap<?,P,?> target) {
|
||||
metadata.addJoin(JoinType.INNERJOIN, target);
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.INNERJOIN, target);
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T innerJoin(PMap<?,P,?> target, Path<P> alias) {
|
||||
metadata.addJoin(JoinType.INNERJOIN, createAlias(target, alias));
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.INNERJOIN, createAlias(target, alias));
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T join(Path<? extends Collection<P>> target) {
|
||||
metadata.addJoin(JoinType.JOIN, target.asExpr());
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.JOIN, target.asExpr());
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T join(Path<? extends Collection<P>> target, Path<P> alias) {
|
||||
metadata.addJoin(JoinType.JOIN, createAlias(target, alias));
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.JOIN, createAlias(target, alias));
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T join(PEntity<P> target, PEntity<P> alias) {
|
||||
metadata.addJoin(JoinType.JOIN, createAlias(target, alias));
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.JOIN, createAlias(target, alias));
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T join(PMap<?,P,?> target) {
|
||||
metadata.addJoin(JoinType.JOIN, target);
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.JOIN, target);
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T join(PMap<?,P,?> target, Path<P> alias) {
|
||||
metadata.addJoin(JoinType.JOIN, createAlias(target, alias));
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.JOIN, createAlias(target, alias));
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T leftJoin(Path<? extends Collection<P>> target) {
|
||||
metadata.addJoin(JoinType.LEFTJOIN, target.asExpr());
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.LEFTJOIN, target.asExpr());
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T leftJoin(Path<? extends Collection<P>> target, Path<P> alias) {
|
||||
metadata.addJoin(JoinType.LEFTJOIN, createAlias(target, alias));
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.LEFTJOIN, createAlias(target, alias));
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T leftJoin(PEntity<P> target, PEntity<P> alias) {
|
||||
metadata.addJoin(JoinType.LEFTJOIN, createAlias(target, alias));
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.LEFTJOIN, createAlias(target, alias));
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T leftJoin(PMap<?,P,?> target) {
|
||||
metadata.addJoin(JoinType.LEFTJOIN, target);
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.LEFTJOIN, target);
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public <P> T leftJoin(PMap<?,P,?> target, Path<P> alias) {
|
||||
metadata.addJoin(JoinType.LEFTJOIN, createAlias(target, alias));
|
||||
return self;
|
||||
getMetadata().addJoin(JoinType.LEFTJOIN, createAlias(target, alias));
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
public T with(EBoolean... conditions){
|
||||
for (EBoolean condition : conditions){
|
||||
metadata.addJoinCondition(condition);
|
||||
getMetadata().addJoinCondition(condition);
|
||||
}
|
||||
return self;
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -175,12 +175,12 @@ public class HQLSerializer extends SerializerBase<HQLSerializer> {
|
||||
append("(");
|
||||
}
|
||||
append(":");
|
||||
if (!constantToLabel.containsKey(expr.getConstant())) {
|
||||
String constLabel = constantPrefix + (constantToLabel.size()+1);
|
||||
constantToLabel.put(expr.getConstant(), constLabel);
|
||||
if (!getConstantToLabel().containsKey(expr.getConstant())) {
|
||||
String constLabel = constantPrefix + (getConstantToLabel().size()+1);
|
||||
getConstantToLabel().put(expr.getConstant(), constLabel);
|
||||
append(constLabel);
|
||||
} else {
|
||||
append(constantToLabel.get(expr.getConstant()));
|
||||
append(getConstantToLabel().get(expr.getConstant()));
|
||||
}
|
||||
if (wrap) {
|
||||
append(")");
|
||||
|
||||
@ -27,12 +27,12 @@ public class HibernateSQLSerializer extends SQLSerializer{
|
||||
|
||||
@Override
|
||||
public void visit(Constant<?> expr) {
|
||||
if (!constantToLabel.containsKey(expr.getConstant())) {
|
||||
String constLabel = constantPrefix + (constantToLabel.size() + 1);
|
||||
constantToLabel.put(expr.getConstant(), constLabel);
|
||||
if (!getConstantToLabel().containsKey(expr.getConstant())) {
|
||||
String constLabel = constantPrefix + (getConstantToLabel().size() + 1);
|
||||
getConstantToLabel().put(expr.getConstant(), constLabel);
|
||||
append(":"+constLabel);
|
||||
} else {
|
||||
append(":"+constantToLabel.get(expr.getConstant()));
|
||||
append(":"+getConstantToLabel().get(expr.getConstant()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ public class JDOQLQueryMixin<T> extends QueryMixin<T>{
|
||||
super.addToProjection(expr);
|
||||
}
|
||||
}
|
||||
return self;
|
||||
return getSelf();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user