From dc2e14ce816246df3a2a7af62a31b8f1cf8de3f1 Mon Sep 17 00:00:00 2001 From: Tran Ngoc Nhan Date: Mon, 23 Sep 2024 20:23:46 +0700 Subject: [PATCH] Minor refactoring. Original pull request #1895 --- .../jdbc/core/convert/Jsr310TimestampBasedConverters.java | 4 ---- .../data/r2dbc/convert/MappingR2dbcConverter.java | 2 +- .../data/r2dbc/core/NamedParameterUtils.java | 6 ++---- .../org/springframework/data/r2dbc/mapping/OutboundRow.java | 2 +- .../repository/support/ReactivePageableExecutionUtils.java | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/Jsr310TimestampBasedConverters.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/Jsr310TimestampBasedConverters.java index 2823273d6cc..43993e0dca3 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/Jsr310TimestampBasedConverters.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/Jsr310TimestampBasedConverters.java @@ -19,15 +19,11 @@ import static java.time.ZoneId.*; import java.sql.Timestamp; -import java.time.Duration; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; -import java.time.Period; -import java.time.ZoneId; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.List; diff --git a/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/convert/MappingR2dbcConverter.java b/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/convert/MappingR2dbcConverter.java index 46888a7f377..e4bb257361b 100644 --- a/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/convert/MappingR2dbcConverter.java +++ b/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/convert/MappingR2dbcConverter.java @@ -442,7 +442,7 @@ public BiFunction populateIdIfNecessary(T object) { Object id = propertyAccessor.getProperty(idProperty); if (idProperty.getType().isPrimitive()) { - idPropertyUpdateNeeded = id instanceof Number && ((Number) id).longValue() == 0; + idPropertyUpdateNeeded = id instanceof Number number && number.longValue() == 0; } else { idPropertyUpdateNeeded = id == null; } diff --git a/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/NamedParameterUtils.java b/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/NamedParameterUtils.java index 1d2f6bfc8a4..287d8d71f9a 100644 --- a/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/NamedParameterUtils.java +++ b/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/NamedParameterUtils.java @@ -297,8 +297,7 @@ public static PreparedOperation substituteNamedParameters(ParsedSql pars } k++; Object entryItem = entryIter.next(); - if (entryItem instanceof Object[]) { - Object[] expressionList = (Object[]) entryItem; + if (entryItem instanceof Object[] expressionList) { actualSql.append('('); for (int m = 0; m < expressionList.length; m++) { if (m > 0) { @@ -520,8 +519,7 @@ public void bind(org.springframework.r2dbc.core.binding.BindTarget target, Strin Object valueToBind = iterator.next(); - if (valueToBind instanceof Object[]) { - Object[] objects = (Object[]) valueToBind; + if (valueToBind instanceof Object[] objects) { for (Object object : objects) { bind(target, markers, object); } diff --git a/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/mapping/OutboundRow.java b/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/mapping/OutboundRow.java index 8535b6f6f43..a25f82512b4 100644 --- a/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/mapping/OutboundRow.java +++ b/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/mapping/OutboundRow.java @@ -227,6 +227,6 @@ public void forEach(BiConsumer action) } private static Object convertKeyIfNecessary(Object key) { - return key instanceof String ? SqlIdentifier.unquoted((String) key) : key; + return key instanceof String string ? SqlIdentifier.unquoted(string) : key; } } diff --git a/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/repository/support/ReactivePageableExecutionUtils.java b/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/repository/support/ReactivePageableExecutionUtils.java index 432d4ba8522..8151247e8a8 100644 --- a/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/repository/support/ReactivePageableExecutionUtils.java +++ b/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/repository/support/ReactivePageableExecutionUtils.java @@ -60,7 +60,7 @@ public static Mono> getPage(List content, Pageable pageable, Mono return totalSupplier.map(total -> new PageImpl<>(content, pageable, total)); } - if (content.size() != 0 && pageable.getPageSize() > content.size()) { + if (!content.isEmpty() && pageable.getPageSize() > content.size()) { return Mono.just(new PageImpl<>(content, pageable, pageable.getOffset() + content.size())); }