Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Number apply(Number num1, Number num2) {
}
};

private static final List<Object> nullList = Collections.singletonList((Object) null);
private static final List<Object> nullList = Collections.singletonList(null);

@SuppressWarnings("unused")
public static boolean equals(Object o1, Object o2) {
Expand Down Expand Up @@ -231,7 +231,7 @@ public static Number aggregate(
} else if (aggregator == Ops.AggOps.COUNT_AGG) {
return (long) source.size();
} else if (aggregator == Ops.AggOps.COUNT_DISTINCT_AGG) {
if (!Set.class.isInstance(source)) {
if (!(source instanceof Set)) {
source = new HashSet<>(source);
}
return (long) source.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public Void visit(SubQueryExpression<?> expr, Void context) {
}

private void visitCast(Operator operator, Expression<?> source, Class<?> targetType) {
if (Number.class.isAssignableFrom(source.getType()) && !Constant.class.isInstance(source)) {
if (Number.class.isAssignableFrom(source.getType()) && !(source instanceof Constant)) {
append("new ").append(source.getType().getSimpleName()).append("(");
handle(source);
append(")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.io.Serial;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -252,12 +251,7 @@ public List<JoinExpression> getJoins() {
return Collections.unmodifiableList(joins);
} else {
List<JoinExpression> j = new ArrayList<>(joins);
j.add(
new JoinExpression(
joinType,
joinTarget,
joinCondition,
Collections.unmodifiableSet(new HashSet<>(joinFlags))));
j.add(new JoinExpression(joinType, joinTarget, joinCondition, Set.copyOf(joinFlags)));
return j;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public <A extends Expression<?>> A getCurrentAndReset() {

/** Reset the thread bound expression to null */
public void reset() {
current.set(null);
current.remove();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ public static Expression<String> likeToRegex(Expression<String> expr, boolean ma
if (matchStartAndEnd && !like.endsWith("%")) {
rv.append('$');
}
if (!like.equals(rv.toString())) {
if (!like.contentEquals(rv)) {
return ConstantImpl.create(rv.toString());
}
} else if (expr instanceof Operation<?> o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,9 @@ private void initialise() {
}

/**
* Called during a successful {@link #put(Object,Object)} operation. Default implementation does
* nothing. Override to be notified of property changes in the bean caused by this map.
* Called during a successful {@link #put(String, Object)} (Object,Object)} operation. Default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{@link #put(String, Object)} (Object,Object)}

* implementation does nothing. Override to be notified of property changes in the bean caused by
* this map.
*
* @param key the name of the property that changed
* @param oldValue the old value for that property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ private static boolean needsConstantRemoval(Expression<?> expr) {

private static boolean needsNumberConversion(Expression<?> expr) {
expr = ExpressionUtils.extract(expr);
return Number.class.isAssignableFrom(expr.getType()) && !Path.class.isInstance(expr);
return Number.class.isAssignableFrom(expr.getType()) && !(expr instanceof Path);
}

private static boolean isEntityPathAndNeedsWrapping(Expression<?> expr) {
if ((expr instanceof Path && expr.getType().isAnnotationPresent(Entity.class))
|| (expr instanceof EntityPath && !RelationalPath.class.isInstance(expr))) {
|| (expr instanceof EntityPath && !(expr instanceof RelationalPath))) {
Path<?> path = (Path<?>) expr;
if (path.getMetadata().getParent() == null) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static <U extends BeanPath<? extends T>, T> U treat(
public static <A extends Comparable<? super A>> ComparableExpression<A> avg(
CollectionExpression<?, A> col) {
return Expressions.comparableOperation(
(Class) col.getParameter(0), Ops.QuantOps.AVG_IN_COL, (Expression<?>) col);
(Class) col.getParameter(0), Ops.QuantOps.AVG_IN_COL, col);
}

/**
Expand All @@ -156,7 +156,7 @@ public static <A extends Comparable<? super A>> ComparableExpression<A> avg(
public static <A extends Comparable<? super A>> ComparableExpression<A> max(
CollectionExpression<?, A> left) {
return Expressions.comparableOperation(
(Class) left.getParameter(0), Ops.QuantOps.MAX_IN_COL, (Expression<?>) left);
(Class) left.getParameter(0), Ops.QuantOps.MAX_IN_COL, left);
}

/**
Expand All @@ -168,7 +168,7 @@ public static <A extends Comparable<? super A>> ComparableExpression<A> max(
public static <A extends Comparable<? super A>> ComparableExpression<A> min(
CollectionExpression<?, A> left) {
return Expressions.comparableOperation(
(Class) left.getParameter(0), Ops.QuantOps.MIN_IN_COL, (Expression<?>) left);
(Class) left.getParameter(0), Ops.QuantOps.MIN_IN_COL, left);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public void serializeForInsert(
first = false;
}
append(")");
} else if (inserts != null && inserts.entrySet().size() > 0) {
} else if (inserts != null && !inserts.isEmpty()) {
first = true;
for (Map.Entry<Path<?>, Expression<?>> entry : inserts.entrySet()) {
if (!first) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,8 @@ public void serialize(QueryMetadata metadata, boolean forCountRow) {
Expression<?> projection = metadata.getProjection();
if (projection instanceof Path) {
Path<?> path = (Path<?>) projection;
if (!used.add(path.getMetadata().getName())) {
var alias = "col_1";
aliases.computeIfAbsent(projection, NativeSQLSerializer::createArrayList).add(alias);
projection = ExpressionUtils.as(projection, alias);
modified = true;
} else if (path.getAnnotatedElement().isAnnotationPresent(Column.class)) {
used.add(path.getMetadata().getName());
if (path.getAnnotatedElement().isAnnotationPresent(Column.class)) {
var column = path.getAnnotatedElement().getAnnotation(Column.class);
if (!column.name().isEmpty()) {
aliases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
import com.querydsl.core.types.dsl.Param;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -38,33 +36,31 @@
public final class HibernateUtil {

private static final Set<Class<?>> BUILT_IN =
Collections.unmodifiableSet(
new HashSet<>(
Arrays.asList(
Boolean.class,
Byte.class,
Character.class,
Double.class,
Float.class,
Integer.class,
Long.class,
Short.class,
String.class,
BigDecimal.class,
byte[].class,
Byte[].class,
java.util.Date.class,
java.util.Calendar.class,
java.sql.Date.class,
java.sql.Time.class,
java.sql.Timestamp.class,
java.util.Locale.class,
java.util.TimeZone.class,
java.util.Currency.class,
Class.class,
java.io.Serializable.class,
java.sql.Blob.class,
java.sql.Clob.class)));
Set.of(
Boolean.class,
Byte.class,
Character.class,
Double.class,
Float.class,
Integer.class,
Long.class,
Short.class,
String.class,
BigDecimal.class,
byte[].class,
Byte[].class,
java.util.Date.class,
java.util.Calendar.class,
java.sql.Date.class,
java.sql.Time.class,
java.sql.Timestamp.class,
java.util.Locale.class,
java.util.TimeZone.class,
java.util.Currency.class,
Class.class,
java.io.Serializable.class,
java.sql.Blob.class,
java.sql.Clob.class);

private static final Map<Class<?>, BasicTypeReference<?>> TYPES;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,9 @@ private Query createQuery(boolean forCount) {
query.addEntity(extractEntityExpression(projection).toString(), projection.getType());
} else if (aliases.containsKey(projection)) {
for (String scalar : aliases.get(projection)) {
if (!used.contains(scalar)) {
query.addScalar(scalar);
used.add(scalar);
break;
}
query.addScalar(scalar);
used.add(scalar);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,9 @@ && isEntityExpression(projection)) {
query, extractEntityExpression(projection).toString(), projection.getType());
} else if (aliases.containsKey(projection)) {
for (String scalar : aliases.get(projection)) {
if (!used.contains(scalar)) {
queryHandler.addScalar(query, scalar, projection.getType());
used.add(scalar);
break;
}
queryHandler.addScalar(query, scalar, projection.getType());
used.add(scalar);
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private Queue<Map<Object, Object>> collectConnectorArgs(String operator, Operati
Queue<Map<Object, Object>> pendingDocuments = new LinkedList<>();
for (Expression<?> exp : operation.getArgs()) {
var document = (Map<Object, Object>) handle(exp);
if (document.keySet().size() == 1 && document.containsKey(operator)) {
if (document.size() == 1 && document.containsKey(operator)) {
pendingDocuments.addAll((Collection<Map<Object, Object>>) document.get(operator));
} else {
pendingDocuments.add(document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,19 +1001,13 @@ protected void visitOperation(

} else if (operator == Ops.ALIAS) {
if (stage == Stage.SELECT || stage == Stage.FROM) {
if (stage == SQLSerializer.Stage.SELECT || stage == SQLSerializer.Stage.FROM) {
if (args.get(1) instanceof Path && !((Path<?>) args.get(1)).getMetadata().isRoot()) {
Path<?> path = (Path<?>) args.get(1);
args =
Arrays.asList(
args.get(0),
ExpressionUtils.path(path.getType(), path.getMetadata().getName()));
}
super.visitOperation(type, operator, args);
} else {
// handle only target
handle(args.get(1));
if (args.get(1) instanceof Path && !((Path<?>) args.get(1)).getMetadata().isRoot()) {
Path<?> path = (Path<?>) args.get(1);
args =
Arrays.asList(
args.get(0), ExpressionUtils.path(path.getType(), path.getMetadata().getName()));
}
super.visitOperation(type, operator, args);
} else {
// handle only target
handle(args.get(1));
Expand All @@ -1035,28 +1029,24 @@ protected void visitOperation(
if (templates.getListMaxSize() == 0 || coll.size() <= templates.getListMaxSize()) {
super.visitOperation(type, operator, args);
} else {
if (templates.getListMaxSize() == 0 || coll.size() <= templates.getListMaxSize()) {
super.visitOperation(type, operator, args);
// The type of the path is compatible with the constant
// expression, since the compile time checking mandates it to be
@SuppressWarnings("unchecked")
var path = (Expression<Object>) args.get(0);
if (pathAdded) {
constantPaths.removeLast();
}
Iterable<List<Object>> partitioned =
CollectionUtils.partition(new ArrayList<>(coll), templates.getListMaxSize());
Predicate result;
if (operator == Ops.IN) {
result = ExpressionUtils.inAny(path, partitioned);
} else {
// The type of the path is compatible with the constant
// expression, since the compile time checking mandates it to be
@SuppressWarnings("unchecked")
var path = (Expression<Object>) args.get(0);
if (pathAdded) {
constantPaths.removeLast();
}
Iterable<List<Object>> partitioned =
CollectionUtils.partition(new ArrayList<>(coll), templates.getListMaxSize());
Predicate result;
if (operator == Ops.IN) {
result = ExpressionUtils.inAny(path, partitioned);
} else {
result = ExpressionUtils.notInAny(path, partitioned);
}
append("(");
result.accept(this, null);
append(")");
result = ExpressionUtils.notInAny(path, partitioned);
}
append("(");
result.accept(this, null);
append(")");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static <T> FactoryExpression<T> createProjection(RelationalPath<T> path)

private static <T> FactoryExpression<T> createConstructorProjection(RelationalPath<T> path) {
Expression<?>[] exprs = path.getColumns().toArray(new Expression[0]);
return Projections.<T>constructor((Class) path.getType(), exprs);
return Projections.constructor(path.getType(), exprs);
}

private static <T> FactoryExpression<T> createBeanProjection(RelationalPath<T> path) {
Expand All @@ -56,7 +56,7 @@ private static <T> FactoryExpression<T> createBeanProjection(RelationalPath<T> p
if (bindings.isEmpty()) {
throw new IllegalArgumentException("No bindings could be derived from " + path);
}
return Projections.<T>fields((Class) path.getType(), bindings);
return Projections.fields(path.getType(), bindings);
}

private RelationalPathUtils() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ public void visitConstant(Object constant) {
}
} else {
if (stage == Stage.SELECT
&& !Null.class.isInstance(constant)
&& !(constant instanceof Null)
&& configuration.getTemplates().isWrapSelectParameters()) {
var typeName = configuration.getTypeNameForCast(constant.getClass());
Expression type = Expressions.constant(typeName);
Expand Down Expand Up @@ -1079,7 +1079,7 @@ protected void visitOperation(
&& args.get(1) instanceof Constant<?>
&& operator != Ops.NUMCAST) {
Object constant = ((Constant<?>) args.get(1)).getConstant();
if (!Collection.class.isInstance(constant) || !((Collection) constant).isEmpty()) {
if (!(constant instanceof Collection) || !((Collection) constant).isEmpty()) {
for (Element element : templates.getTemplate(operator).getElements()) {
if (element instanceof Template.ByIndex && ((Template.ByIndex) element).getIndex() == 1) {
constantPaths.add((Path<?>) args.get(0));
Expand Down
Loading