diff --git a/today-beans/src/main/java/infra/beans/FieldBeanProperty.java b/today-beans/src/main/java/infra/beans/FieldBeanProperty.java index 82af2a5d22..b80885bdf6 100644 --- a/today-beans/src/main/java/infra/beans/FieldBeanProperty.java +++ b/today-beans/src/main/java/infra/beans/FieldBeanProperty.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,8 +37,11 @@ public final class FieldBeanProperty extends BeanProperty { @Serial private static final long serialVersionUID = 1L; + private final boolean writeable; + FieldBeanProperty(Field field) { super(field); + this.writeable = !Modifier.isFinal(field.getModifiers()); } @Override @@ -68,7 +71,7 @@ public boolean isSynthetic() { @Override public boolean isReadOnly() { - return Modifier.isFinal(field.getModifiers()); + return !writeable; } @Override @@ -78,7 +81,7 @@ public boolean isReadable() { @Override public boolean isWriteable() { - return !isReadOnly(); + return writeable; } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/ObjectPropertySetter.java b/today-jdbc/src/main/java/infra/jdbc/ObjectPropertySetter.java index d2bf4b3b20..c419183ee8 100644 --- a/today-jdbc/src/main/java/infra/jdbc/ObjectPropertySetter.java +++ b/today-jdbc/src/main/java/infra/jdbc/ObjectPropertySetter.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ import infra.beans.BeanProperty; import infra.core.conversion.ConversionException; import infra.core.conversion.ConversionService; +import infra.jdbc.type.SmartTypeHandler; import infra.jdbc.type.TypeHandler; import infra.lang.Assert; import infra.lang.Nullable; @@ -34,30 +35,28 @@ * @see #setTo(Object, ResultSet, int) * @since 2021/1/7 22:49 */ + public class ObjectPropertySetter { @Nullable private final PropertyPath propertyPath; + private final BeanProperty beanProperty; // cache private final TypeHandler typeHandler; + private final ConversionService conversionService; @Nullable private final PrimitiveTypeNullHandler primitiveTypeNullHandler; - public ObjectPropertySetter( - @Nullable PropertyPath propertyPath, BeanProperty beanProperty, RepositoryManager manager) { - this(propertyPath, beanProperty, - manager.getConversionService(), - manager.getTypeHandler(beanProperty), - manager.getPrimitiveTypeNullHandler()); + public ObjectPropertySetter(@Nullable PropertyPath propertyPath, BeanProperty beanProperty, RepositoryManager manager) { + this(propertyPath, beanProperty, manager.getConversionService(), + manager.getTypeHandler(beanProperty), manager.getPrimitiveTypeNullHandler()); } - public ObjectPropertySetter( - @Nullable PropertyPath propertyPath, BeanProperty beanProperty, - ConversionService conversionService, TypeHandler typeHandler, - @Nullable PrimitiveTypeNullHandler primitiveTypeNullHandler) { + public ObjectPropertySetter(@Nullable PropertyPath propertyPath, BeanProperty beanProperty, + ConversionService conversionService, TypeHandler typeHandler, @Nullable PrimitiveTypeNullHandler primitiveTypeNullHandler) { Assert.notNull(typeHandler, "TypeHandler is required"); Assert.notNull(beanProperty, "BeanProperty is required"); Assert.notNull(conversionService, "ConversionService is required"); @@ -76,23 +75,34 @@ public ObjectPropertySetter( * @param columnIndex current column index * @throws SQLException when data fetch failed */ + @SuppressWarnings({ "unchecked", "rawtypes" }) public void setTo(Object obj, ResultSet resultSet, int columnIndex) throws SQLException { - Object result = getResult(resultSet, columnIndex); - if (result == null && beanProperty.isPrimitive()) { - if (primitiveTypeNullHandler != null) { + if (beanProperty.isWriteable()) { + Object result = getResult(resultSet, columnIndex); + if (result == null && beanProperty.isPrimitive()) { + if (primitiveTypeNullHandler != null) { + if (propertyPath != null) { + obj = propertyPath.getNestedObject(obj); + } + primitiveTypeNullHandler.handleNull(beanProperty, obj); + } + } + else { if (propertyPath != null) { - obj = propertyPath.getNestedObject(obj); + propertyPath.set(obj, result); + } + else { + beanProperty.setValue(obj, result); } - primitiveTypeNullHandler.handleNull(beanProperty, obj); } } + else if (typeHandler instanceof SmartTypeHandler handler) { + Object value = beanProperty.getValue(obj); + handler.applyResult(value, resultSet, columnIndex); + } else { - if (propertyPath != null) { - propertyPath.set(obj, result); - } - else { - beanProperty.setValue(obj, result); - } + throw new IllegalStateException("Entity property %s.%s is not writable" + .formatted(beanProperty.getDeclaringClass(), beanProperty.getName())); } } diff --git a/today-jdbc/src/main/java/infra/jdbc/ResultSetIterator.java b/today-jdbc/src/main/java/infra/jdbc/ResultSetIterator.java index 8f18ce0512..e63117c124 100644 --- a/today-jdbc/src/main/java/infra/jdbc/ResultSetIterator.java +++ b/today-jdbc/src/main/java/infra/jdbc/ResultSetIterator.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -374,6 +374,7 @@ protected RuntimeException handleReadError(SQLException ex) { return new PersistenceException("Database read error: " + ex.getMessage(), ex); } + @Nullable protected abstract T readNext(ResultSet resultSet) throws SQLException; static final class ResultSetValue { diff --git a/today-jdbc/src/main/java/infra/jdbc/type/AnyTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/AnyTypeHandler.java index 862c2975b0..6e405b074e 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/AnyTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/AnyTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,8 +39,8 @@ public AnyTypeHandler(Class type) { } @Override - public void setParameter(PreparedStatement ps, int parameterIndex, @Nullable T parameter) throws SQLException { - ps.setObject(parameterIndex, parameter); + public void setParameter(PreparedStatement ps, int parameterIndex, @Nullable T arg) throws SQLException { + ps.setObject(parameterIndex, arg); } @Nullable diff --git a/today-jdbc/src/main/java/infra/jdbc/type/BaseTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/BaseTypeHandler.java index 57deb68d15..13d1deb6ea 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/BaseTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/BaseTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,12 +40,12 @@ public abstract class BaseTypeHandler implements TypeHandler { @Override - public void setParameter(PreparedStatement ps, int parameterIndex, @Nullable T parameter) throws SQLException { - if (parameter == null) { + public void setParameter(PreparedStatement ps, int parameterIndex, @Nullable T arg) throws SQLException { + if (arg == null) { setNullParameter(ps, parameterIndex); } else { - setNonNullParameter(ps, parameterIndex, parameter); + setNonNullParameter(ps, parameterIndex, arg); } } @@ -53,8 +53,8 @@ public void setNullParameter(PreparedStatement ps, int parameterIndex) throws SQ ps.setObject(parameterIndex, null); } - public void setNonNullParameter(PreparedStatement ps, int parameterIndex, T parameter) throws SQLException { - ps.setObject(parameterIndex, parameter); + public void setNonNullParameter(PreparedStatement ps, int parameterIndex, T arg) throws SQLException { + ps.setObject(parameterIndex, arg); } } diff --git a/today-jdbc/src/main/java/infra/jdbc/type/BigDecimalTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/BigDecimalTypeHandler.java index e6a31756cf..2bd4b72fd8 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/BigDecimalTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/BigDecimalTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,8 +31,8 @@ public class BigDecimalTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, BigDecimal parameter) throws SQLException { - ps.setBigDecimal(i, parameter); + public void setNonNullParameter(PreparedStatement ps, int i, BigDecimal arg) throws SQLException { + ps.setBigDecimal(i, arg); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/BigIntegerTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/BigIntegerTypeHandler.java index 6bbe91da8f..4e66947f07 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/BigIntegerTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/BigIntegerTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,8 +32,8 @@ public class BigIntegerTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, BigInteger parameter) throws SQLException { - ps.setBigDecimal(i, new BigDecimal(parameter)); + public void setNonNullParameter(PreparedStatement ps, int i, BigInteger arg) throws SQLException { + ps.setBigDecimal(i, new BigDecimal(arg)); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/BooleanTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/BooleanTypeHandler.java index 08dde45e6b..c89522f266 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/BooleanTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/BooleanTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,8 +30,8 @@ public class BooleanTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, Boolean parameter) throws SQLException { - ps.setBoolean(i, parameter); + public void setNonNullParameter(PreparedStatement ps, int i, Boolean arg) throws SQLException { + ps.setBoolean(i, arg); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/ByteArrayTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/ByteArrayTypeHandler.java index 0bd732aa5d..22c4795811 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/ByteArrayTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/ByteArrayTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,8 +30,8 @@ public class ByteArrayTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, byte[] parameter) throws SQLException { - ps.setBytes(i, parameter); + public void setNonNullParameter(PreparedStatement ps, int i, byte[] arg) throws SQLException { + ps.setBytes(i, arg); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/ByteTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/ByteTypeHandler.java index eed2b257e2..6d87fb291f 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/ByteTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/ByteTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,8 +30,8 @@ public class ByteTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, Byte parameter) throws SQLException { - ps.setByte(i, parameter); + public void setNonNullParameter(PreparedStatement ps, int i, Byte arg) throws SQLException { + ps.setByte(i, arg); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/BytesInputStreamTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/BytesInputStreamTypeHandler.java index 99d4401fb9..de2a6b99af 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/BytesInputStreamTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/BytesInputStreamTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,8 +31,8 @@ public class BytesInputStreamTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int parameterIndex, InputStream parameter) throws SQLException { - ps.setBinaryStream(parameterIndex, parameter); + public void setNonNullParameter(PreparedStatement ps, int parameterIndex, InputStream arg) throws SQLException { + ps.setBinaryStream(parameterIndex, arg); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/CharacterTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/CharacterTypeHandler.java index b9fb99168d..ec11a0489b 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/CharacterTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/CharacterTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,8 +32,8 @@ public class CharacterTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, Character parameter) throws SQLException { - ps.setString(i, parameter.toString()); + public void setNonNullParameter(PreparedStatement ps, int i, Character arg) throws SQLException { + ps.setString(i, arg.toString()); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/DateTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/DateTypeHandler.java index 344384a781..30ebd8ce08 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/DateTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/DateTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,8 +32,8 @@ public class DateTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, Date parameter) throws SQLException { - ps.setTimestamp(i, new Timestamp(parameter.getTime())); + public void setNonNullParameter(PreparedStatement ps, int i, Date arg) throws SQLException { + ps.setTimestamp(i, new Timestamp(arg.getTime())); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/DoubleTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/DoubleTypeHandler.java index 2964b38f27..d398c37657 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/DoubleTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/DoubleTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,8 +30,8 @@ public class DoubleTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, Double parameter) throws SQLException { - ps.setDouble(i, parameter); + public void setNonNullParameter(PreparedStatement ps, int i, Double arg) throws SQLException { + ps.setDouble(i, arg); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/DurationTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/DurationTypeHandler.java index 155a3f5e2c..a1aab2f5cd 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/DurationTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/DurationTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,8 +34,8 @@ public class DurationTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int parameterIndex, Duration parameter) throws SQLException { - ps.setLong(parameterIndex, parameter.toNanos()); + public void setNonNullParameter(PreparedStatement ps, int parameterIndex, Duration arg) throws SQLException { + ps.setLong(parameterIndex, arg.toNanos()); } @Nullable diff --git a/today-jdbc/src/main/java/infra/jdbc/type/EnumOrdinalTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/EnumOrdinalTypeHandler.java index 625bb7acf4..4b8c7f3fac 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/EnumOrdinalTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/EnumOrdinalTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,8 +47,8 @@ public EnumOrdinalTypeHandler(Class type) { } @Override - public void setNonNullParameter(PreparedStatement ps, int i, E parameter) throws SQLException { - ps.setInt(i, parameter.ordinal()); + public void setNonNullParameter(PreparedStatement ps, int i, E arg) throws SQLException { + ps.setInt(i, arg.ordinal()); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/EnumTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/EnumTypeHandler.java index 6d48972bb3..1bab508387 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/EnumTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/EnumTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,8 +43,8 @@ public EnumTypeHandler(Class type) { } @Override - public void setNonNullParameter(PreparedStatement ps, int i, E parameter) throws SQLException { - ps.setString(i, parameter.name()); + public void setNonNullParameter(PreparedStatement ps, int i, E arg) throws SQLException { + ps.setString(i, arg.name()); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/EnumerableEnumTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/EnumerableEnumTypeHandler.java index eded3daa1f..e994bcc444 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/EnumerableEnumTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/EnumerableEnumTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,12 +68,12 @@ static Class getValueType(Class type) { @Override public void setParameter(PreparedStatement ps, - int parameterIndex, @Nullable Enumerable parameter) throws SQLException { - if (parameter == null) { + int parameterIndex, @Nullable Enumerable arg) throws SQLException { + if (arg == null) { delegate.setParameter(ps, parameterIndex, null); } else { - delegate.setParameter(ps, parameterIndex, parameter.getValue()); + delegate.setParameter(ps, parameterIndex, arg.getValue()); } } diff --git a/today-jdbc/src/main/java/infra/jdbc/type/EnumerationValueTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/EnumerationValueTypeHandler.java index 3f1254b57e..70d920882e 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/EnumerationValueTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/EnumerationValueTypeHandler.java @@ -85,9 +85,9 @@ static BeanProperty getAnnotatedProperty(Class type) { } @Override - public void setParameter(PreparedStatement ps, int parameterIndex, @Nullable T parameter) throws SQLException { - if (parameter != null) { - Object propertyValue = valueSupplier.apply(parameter); + public void setParameter(PreparedStatement ps, int parameterIndex, @Nullable T arg) throws SQLException { + if (arg != null) { + Object propertyValue = valueSupplier.apply(arg); delegate.setParameter(ps, parameterIndex, propertyValue); } else { diff --git a/today-jdbc/src/main/java/infra/jdbc/type/FloatTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/FloatTypeHandler.java index 0fb3c5c2be..427f0c2a04 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/FloatTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/FloatTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,8 +28,8 @@ public class FloatTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, Float parameter) throws SQLException { - ps.setFloat(i, parameter); + public void setNonNullParameter(PreparedStatement ps, int i, Float arg) throws SQLException { + ps.setFloat(i, arg); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/IntegerTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/IntegerTypeHandler.java index 0e2d3ea5a8..05701776c3 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/IntegerTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/IntegerTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,8 +29,8 @@ public class IntegerTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, Integer parameter) throws SQLException { - ps.setInt(i, parameter); + public void setNonNullParameter(PreparedStatement ps, int i, Integer arg) throws SQLException { + ps.setInt(i, arg); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/LongTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/LongTypeHandler.java index 0d2f946e2d..066e9ed9a6 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/LongTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/LongTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,8 +29,8 @@ public class LongTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, Long parameter) throws SQLException { - ps.setLong(i, parameter); + public void setNonNullParameter(PreparedStatement ps, int i, Long arg) throws SQLException { + ps.setLong(i, arg); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/MonthTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/MonthTypeHandler.java index 2a561d00df..cef335dddd 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/MonthTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/MonthTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,8 +31,8 @@ public class MonthTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, Month month) throws SQLException { - ps.setInt(i, month.getValue()); + public void setNonNullParameter(PreparedStatement ps, int i, Month arg) throws SQLException { + ps.setInt(i, arg.getValue()); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/ShortTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/ShortTypeHandler.java index d045f48f22..71cc9c0c8e 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/ShortTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/ShortTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,8 +30,8 @@ public class ShortTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, Short parameter) throws SQLException { - ps.setShort(i, parameter); + public void setNonNullParameter(PreparedStatement ps, int i, Short arg) throws SQLException { + ps.setShort(i, arg); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/SmartTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/SmartTypeHandler.java index 8fb63fd208..3f616bb85f 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/SmartTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/SmartTypeHandler.java @@ -17,6 +17,9 @@ package infra.jdbc.type; +import java.sql.ResultSet; +import java.sql.SQLException; + import infra.beans.BeanProperty; /** @@ -25,6 +28,23 @@ */ public interface SmartTypeHandler extends TypeHandler { + /** + * Test this handler can handle input property + * + * @param property bean property + */ boolean supportsProperty(BeanProperty property); + /** + * apply result to a wrapped object + * + * @param value a wrapped object + * @param rs database result set + * @param columnIndex idx + * @throws SQLException database read failed + */ + default void applyResult(T value, ResultSet rs, int columnIndex) throws SQLException { + throw new UnsupportedOperationException(); + } + } diff --git a/today-jdbc/src/main/java/infra/jdbc/type/SqlDateTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/SqlDateTypeHandler.java index 89752f5ee1..935ab4aa06 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/SqlDateTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/SqlDateTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,8 +31,8 @@ public class SqlDateTypeHandler extends BaseTypeHandler { @Override - public void setNonNullParameter(PreparedStatement ps, int i, Date parameter) throws SQLException { - ps.setDate(i, parameter); + public void setNonNullParameter(PreparedStatement ps, int i, Date arg) throws SQLException { + ps.setDate(i, arg); } @Override diff --git a/today-jdbc/src/main/java/infra/jdbc/type/SqlTimeTypeHandler.java b/today-jdbc/src/main/java/infra/jdbc/type/SqlTimeTypeHandler.java index 1a9e977a5d..bcf19428f6 100644 --- a/today-jdbc/src/main/java/infra/jdbc/type/SqlTimeTypeHandler.java +++ b/today-jdbc/src/main/java/infra/jdbc/type/SqlTimeTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,8 +31,8 @@ public class SqlTimeTypeHandler extends BaseTypeHandler