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

See gh-30067
This commit is contained in:
Sam Brannen 2023-03-06 17:19:55 +01:00
parent a6338fcc43
commit eea000d034
6 changed files with 19 additions and 23 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import io.r2dbc.spi.R2dbcException;
import org.springframework.dao.InvalidDataAccessResourceUsageException; import org.springframework.dao.InvalidDataAccessResourceUsageException;
/** /**
* Exception thrown when SQL specified is invalid. Such exceptions always have a * Exception thrown when SQL specified is invalid. Such exceptions always have a
* {@link io.r2dbc.spi.R2dbcException} root cause. * {@link io.r2dbc.spi.R2dbcException} root cause.

View File

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

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -168,11 +168,11 @@ public abstract class AbstractRoutingConnectionFactory implements ConnectionFact
protected ConnectionFactory resolveSpecifiedConnectionFactory(Object connectionFactory) protected ConnectionFactory resolveSpecifiedConnectionFactory(Object connectionFactory)
throws IllegalArgumentException { throws IllegalArgumentException {
if (connectionFactory instanceof ConnectionFactory) { if (connectionFactory instanceof ConnectionFactory factory) {
return (ConnectionFactory) connectionFactory; return factory;
} }
else if (connectionFactory instanceof String) { else if (connectionFactory instanceof String factoryName) {
return this.connectionFactoryLookup.getConnectionFactory((String) connectionFactory); return this.connectionFactoryLookup.getConnectionFactory(factoryName);
} }
else { else {
throw new IllegalArgumentException("Illegal connection factory value - " + throw new IllegalArgumentException("Illegal connection factory value - " +

View File

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

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,7 +21,6 @@ import java.util.List;
import org.springframework.r2dbc.core.binding.BindMarkersFactory; import org.springframework.r2dbc.core.binding.BindMarkersFactory;
import org.springframework.util.ConcurrentLruCache; import org.springframework.util.ConcurrentLruCache;
/** /**
* SQL translation support allowing the use of named parameters * SQL translation support allowing the use of named parameters
* rather than native placeholders. * rather than native placeholders.

View File

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