Polishing

This commit is contained in:
Juergen Hoeller
2023-07-26 12:07:11 +02:00
parent bbde68c49e
commit 2573ba4a50
9 changed files with 62 additions and 73 deletions

View File

@@ -57,15 +57,17 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
* Default implementation of {@link DatabaseClient}.
* The default implementation of {@link DatabaseClient},
* as created by the static factory method.
*
* @author Mark Paluch
* @author Mingyuan Wu
* @author Bogdan Ilchyshyn
* @author Simon Baslé
* @since 5.3
* @see DatabaseClient#create(ConnectionFactory)
*/
class DefaultDatabaseClient implements DatabaseClient {
final class DefaultDatabaseClient implements DatabaseClient {
private final Log logger = LogFactory.getLog(getClass());
@@ -251,11 +253,12 @@ class DefaultDatabaseClient implements DatabaseClient {
"Value at index %d must not be null. Use bindNull(…) instead.", index));
Map<Integer, Parameter> byIndex = new LinkedHashMap<>(this.byIndex);
if (value instanceof Parameter p) {
byIndex.put(index, p);
if (value instanceof Parameter param) {
byIndex.put(index, param);
}
else if (value instanceof org.springframework.r2dbc.core.Parameter p) {
byIndex.put(index, p.hasValue() ? Parameters.in(p.getValue()) : Parameters.in(p.getType()));
else if (value instanceof org.springframework.r2dbc.core.Parameter param) {
Object pv = param.getValue();
byIndex.put(index, (pv != null ? Parameters.in(pv) : Parameters.in(param.getType())));
}
else {
byIndex.put(index, Parameters.in(value));

View File

@@ -22,7 +22,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
@@ -380,6 +379,7 @@ abstract class NamedParameterUtils {
private final int endIndex;
ParameterHolder(String parameterName, int startIndex, int endIndex) {
Assert.notNull(parameterName, "Parameter name must not be null");
this.parameterName = parameterName;
this.startIndex = startIndex;
this.endIndex = endIndex;
@@ -398,20 +398,15 @@ abstract class NamedParameterUtils {
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ParameterHolder that)) {
return false;
}
return this.startIndex == that.startIndex && this.endIndex == that.endIndex
&& Objects.equals(this.parameterName, that.parameterName);
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof ParameterHolder that &&
this.startIndex == that.startIndex && this.endIndex == that.endIndex &&
this.parameterName.equals(that.parameterName)));
}
@Override
public int hashCode() {
return Objects.hash(this.parameterName, this.startIndex, this.endIndex);
return this.parameterName.hashCode();
}
}

View File

@@ -16,8 +16,6 @@
package org.springframework.r2dbc.core;
import java.util.Objects;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -111,20 +109,15 @@ public final class Parameter {
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Parameter other)) {
return false;
}
return (ObjectUtils.nullSafeEquals(this.value, other.value) &&
ObjectUtils.nullSafeEquals(this.type, other.type));
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof Parameter that &&
ObjectUtils.nullSafeEquals(this.value, that.value) &&
ObjectUtils.nullSafeEquals(this.type, that.type)));
}
@Override
public int hashCode() {
return Objects.hash(this.value, this.type);
return ObjectUtils.nullSafeHashCode(this.value) + ObjectUtils.nullSafeHashCode(this.type);
}
@Override