Browse Source

Apply "instanceof pattern matching" in remainder of spring-r2dbc module

See gh-30067
pull/30074/head
Sam Brannen 2 years ago
parent
commit
eea000d034
  1. 3
      spring-r2dbc/src/main/java/org/springframework/r2dbc/BadSqlGrammarException.java
  2. 14
      spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java
  3. 10
      spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactory.java
  4. 1
      spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ConnectionFunction.java
  5. 3
      spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterExpander.java
  6. 11
      spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java

3
spring-r2dbc/src/main/java/org/springframework/r2dbc/BadSqlGrammarException.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import io.r2dbc.spi.R2dbcException; @@ -20,7 +20,6 @@ import io.r2dbc.spi.R2dbcException;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
/**
* Exception thrown when SQL specified is invalid. Such exceptions always have a
* {@link io.r2dbc.spi.R2dbcException} root cause.

14
spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java

@ -301,13 +301,13 @@ public abstract class ConnectionFactoryUtils { @@ -301,13 +301,13 @@ public abstract class ConnectionFactoryUtils {
* @return the innermost target Connection, or the passed-in one if not wrapped
* @see Wrapped#unwrap()
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Connection getTargetConnection(Connection con) {
Connection conToUse = con;
while (conToUse instanceof Wrapped<?>) {
conToUse = ((Wrapped<Connection>) conToUse).unwrap();
Object conToUse = con;
while (conToUse instanceof Wrapped wrapped) {
conToUse = wrapped.unwrap();
}
return conToUse;
return (Connection) conToUse;
}
/**
@ -321,9 +321,9 @@ public abstract class ConnectionFactoryUtils { @@ -321,9 +321,9 @@ public abstract class ConnectionFactoryUtils {
private static int getConnectionSynchronizationOrder(ConnectionFactory connectionFactory) {
int order = CONNECTION_SYNCHRONIZATION_ORDER;
ConnectionFactory current = connectionFactory;
while (current instanceof DelegatingConnectionFactory) {
while (current instanceof DelegatingConnectionFactory delegatingConnectionFactory) {
order--;
current = ((DelegatingConnectionFactory) current).getTargetConnectionFactory();
current = delegatingConnectionFactory.getTargetConnectionFactory();
}
return order;
}

10
spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactory.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -168,11 +168,11 @@ public abstract class AbstractRoutingConnectionFactory implements ConnectionFact @@ -168,11 +168,11 @@ public abstract class AbstractRoutingConnectionFactory implements ConnectionFact
protected ConnectionFactory resolveSpecifiedConnectionFactory(Object connectionFactory)
throws IllegalArgumentException {
if (connectionFactory instanceof ConnectionFactory) {
return (ConnectionFactory) connectionFactory;
if (connectionFactory instanceof ConnectionFactory factory) {
return factory;
}
else if (connectionFactory instanceof String) {
return this.connectionFactoryLookup.getConnectionFactory((String) connectionFactory);
else if (connectionFactory instanceof String factoryName) {
return this.connectionFactoryLookup.getConnectionFactory(factoryName);
}
else {
throw new IllegalArgumentException("Illegal connection factory value - " +

1
spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ConnectionFunction.java

@ -20,7 +20,6 @@ import java.util.function.Function; @@ -20,7 +20,6 @@ import java.util.function.Function;
import io.r2dbc.spi.Connection;
/**
* Union type combining {@link Function} and {@link SqlProvider} to expose the SQL
* that is related to the underlying action. The {@code SqlProvider} can support

3
spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterExpander.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,7 +21,6 @@ import java.util.List; @@ -21,7 +21,6 @@ import java.util.List;
import org.springframework.r2dbc.core.binding.BindMarkersFactory;
import org.springframework.util.ConcurrentLruCache;
/**
* SQL translation support allowing the use of named parameters
* rather than native placeholders.

11
spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -299,8 +299,8 @@ abstract class NamedParameterUtils { @@ -299,8 +299,8 @@ abstract class NamedParameterUtils {
NamedParameters.NamedParameter marker = markerHolder.getOrCreate(paramName);
if (paramSource.hasValue(paramName)) {
Parameter parameter = paramSource.getValue(paramName);
if (parameter.getValue() instanceof Collection<?> c) {
Iterator<?> entryIter = c.iterator();
if (parameter.getValue() instanceof Collection<?> collection) {
Iterator<?> entryIter = collection.iterator();
int k = 0;
int counter = 0;
while (entryIter.hasNext()) {
@ -513,15 +513,14 @@ abstract class NamedParameterUtils { @@ -513,15 +513,14 @@ abstract class NamedParameterUtils {
this.parameterSource = parameterSource;
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void bind(BindTarget target, String identifier, Parameter parameter) {
List<BindMarker> bindMarkers = getBindMarkers(identifier);
if (bindMarkers == null) {
target.bind(identifier, parameter);
return;
}
if (parameter.getValue() instanceof Collection) {
Collection<Object> collection = (Collection<Object>) parameter.getValue();
if (parameter.getValue() instanceof Collection collection) {
Iterator<Object> iterator = collection.iterator();
Iterator<BindMarker> markers = bindMarkers.iterator();
while (iterator.hasNext()) {

Loading…
Cancel
Save