From ab3c51d20db6552e36ad3ac24a71646de951070e Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Tue, 1 Apr 2025 14:08:06 +0200 Subject: [PATCH 1/6] add support for custom types a classes --- .../web/CustomTypeScanner.java | 11 +- .../jackson/CustomTypeDeserializer.java | 27 +- .../base/WrappedBigDecimalJavaType.java | 17 +- .../base/WrappedBigIntegerJavaType.java | 17 +- .../javatype/base/WrappedDoubleJavaType.java | 17 +- .../javatype/base/WrappedFloatJavaType.java | 17 +- .../javatype/base/WrappedIntegerJavaType.java | 17 +- .../javatype/base/WrappedLongJavaType.java | 18 +- .../base/WrappedScaledBigDecimalJavaType.java | 17 +- .../javatype/base/WrappedShortJavaType.java | 17 +- .../javatype/base/WrappedStringJavaType.java | 18 +- .../toolbox/web/CustomTypePropertyEditor.java | 30 +- .../javatype/WrapperTypesJpaTest.java | 767 +++++++++++++----- .../javatype/WrapBigDecimalClassJavaType.java | 12 + ...java => WrapBigDecimalRecordJavaType.java} | 8 +- .../javatype/WrapBigIntegerClassJavaType.java | 12 + ...java => WrapBigIntegerRecordJavaType.java} | 8 +- .../javatype/WrapDoubleClassJavaType.java | 12 + ...ype.java => WrapDoubleRecordJavaType.java} | 8 +- .../impl/javatype/WrapFloatClassJavaType.java | 12 + ...Type.java => WrapFloatRecordJavaType.java} | 8 +- .../javatype/WrapIntegerClassJavaType.java | 12 + ...pe.java => WrapIntegerRecordJavaType.java} | 8 +- .../impl/javatype/WrapLongClassJavaType.java | 12 + ...aType.java => WrapLongRecordJavaType.java} | 8 +- .../WrapScaledBigDecimalClassJavaType.java | 12 + ...> WrapScaledBigDecimalRecordJavaType.java} | 8 +- .../impl/javatype/WrapShortClassJavaType.java | 12 + ...Type.java => WrapShortRecordJavaType.java} | 8 +- .../javatype/WrapStringClassJavaType.java | 12 + ...ype.java => WrapStringRecordJavaType.java} | 8 +- .../javatype/impl/jpa/WrapperTypesModel.java | 128 ++- .../impl/jpa/WrapperTypesModelRepository.java | 63 +- .../impl/type/WrapBigDecimalClass.java | 17 + ...Decimal.java => WrapBigDecimalRecord.java} | 2 +- .../impl/type/WrapBigIntegerClass.java | 17 + ...Integer.java => WrapBigIntegerRecord.java} | 2 +- .../javatype/impl/type/WrapDoubleClass.java | 15 + ...{WrapDouble.java => WrapDoubleRecord.java} | 2 +- .../javatype/impl/type/WrapFloatClass.java | 15 + ...{WrapInteger.java => WrapFloatRecord.java} | 2 +- .../javatype/impl/type/WrapIntegerClass.java | 15 + .../javatype/impl/type/WrapIntegerRecord.java | 7 + .../javatype/impl/type/WrapLongClass.java | 15 + .../{WrapShort.java => WrapLongRecord.java} | 2 +- .../impl/type/WrapScaledBigDecimalClass.java | 16 + ...l.java => WrapScaledBigDecimalRecord.java} | 2 +- .../javatype/impl/type/WrapShortClass.java | 15 + .../{WrapLong.java => WrapShortRecord.java} | 2 +- .../javatype/impl/type/WrapString.java | 7 - .../javatype/impl/type/WrapStringClass.java | 15 + .../{WrapFloat.java => WrapStringRecord.java} | 2 +- ...9-06-create-wrapper-type-testing-table.yml | 27 + 53 files changed, 1195 insertions(+), 363 deletions(-) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalClassJavaType.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/{WrapBigDecimalJavaType.java => WrapBigDecimalRecordJavaType.java} (54%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerClassJavaType.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/{WrapBigIntegerJavaType.java => WrapBigIntegerRecordJavaType.java} (54%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleClassJavaType.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/{WrapDoubleJavaType.java => WrapDoubleRecordJavaType.java} (57%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatClassJavaType.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/{WrapFloatJavaType.java => WrapFloatRecordJavaType.java} (57%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerClassJavaType.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/{WrapIntegerJavaType.java => WrapIntegerRecordJavaType.java} (56%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongClassJavaType.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/{WrapLongJavaType.java => WrapLongRecordJavaType.java} (58%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalClassJavaType.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/{WrapScaledBigDecimalJavaType.java => WrapScaledBigDecimalRecordJavaType.java} (51%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortClassJavaType.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/{WrapShortJavaType.java => WrapShortRecordJavaType.java} (57%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringClassJavaType.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/{WrapStringJavaType.java => WrapStringRecordJavaType.java} (57%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigDecimalClass.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/{WrapBigDecimal.java => WrapBigDecimalRecord.java} (64%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigIntegerClass.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/{WrapBigInteger.java => WrapBigIntegerRecord.java} (64%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapDoubleClass.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/{WrapDouble.java => WrapDoubleRecord.java} (63%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapFloatClass.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/{WrapInteger.java => WrapFloatRecord.java} (64%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapIntegerClass.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapIntegerRecord.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapLongClass.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/{WrapShort.java => WrapLongRecord.java} (65%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapScaledBigDecimalClass.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/{WrapScaledBigDecimal.java => WrapScaledBigDecimalRecord.java} (64%) create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapShortClass.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/{WrapLong.java => WrapShortRecord.java} (64%) delete mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapString.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapStringClass.java rename src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/{WrapFloat.java => WrapStringRecord.java} (63%) diff --git a/src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/web/CustomTypeScanner.java b/src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/web/CustomTypeScanner.java index d677d4b..f2ab2e5 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/web/CustomTypeScanner.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/web/CustomTypeScanner.java @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -31,13 +32,17 @@ public void setAdditionalTypePackages(String[] additionalTypePackages) { log.info("CustomTypeConfiguration enabled. Scanning: {}", Arrays.toString(packageNamesToScan)); var classScanner = ClassScannerUtil.getScannerForPackages(packageNamesToScan); - this.relevantTypes = findAllCustomTypeRecords(classScanner); + this.relevantTypes = findAllCustomTypes(classScanner); } @SuppressWarnings("rawtypes") - public static Set> findAllCustomTypeRecords(ClassScannerUtil.ClassScanner classScanner) { + public static Set> findAllCustomTypes(ClassScannerUtil.ClassScanner classScanner) { return classScanner.getSubTypesOf(CustomType.class).stream() - .filter(Record.class::isAssignableFrom) + .filter(item -> + !item.isInterface() + && !item.isAnonymousClass() + && !Modifier.isAbstract(item.getModifiers()) + ) .collect(Collectors.toSet()); } } diff --git a/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java b/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java index 7d39bc0..c2a1443 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java @@ -10,8 +10,10 @@ import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.ParameterizedType; import java.math.BigDecimal; import java.math.BigInteger; +import java.util.Arrays; import java.util.function.Function; public class CustomTypeDeserializer> extends JsonDeserializer { @@ -20,10 +22,33 @@ public class CustomTypeDeserializer> extends JsonDeseria private final Function typeConverter; public CustomTypeDeserializer(Class customType) { + Constructor c; this.customType = customType; - this.constructor = RecordReflectionUtil.getCanonicalConstructor(customType); + if (customType.isRecord()) { + c = RecordReflectionUtil.getCanonicalConstructor(customType); + } else { + try { + var customTypeInterface = Arrays.stream(customType.getGenericInterfaces()) + .filter(i -> + i instanceof ParameterizedType + && CustomType.class.isAssignableFrom((Class) ((ParameterizedType) i).getRawType()) + ).findFirst() + .map(i -> (ParameterizedType) i) + .orElseThrow(); + + var parameterType = (Class) customTypeInterface.getActualTypeArguments()[0]; + + c = customType.getConstructor(parameterType); + } catch (Exception e) { + throw new CustomTypeDeserializerException( + "Unable to find constructor for type: " + customType.getName(), + e + ); + } + } + this.constructor = c; this.typeConverter = getTypeConverter( constructor.getParameterTypes()[0] ); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigDecimalJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigDecimalJavaType.java index d9b2382..e1974aa 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigDecimalJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigDecimalJavaType.java @@ -14,12 +14,23 @@ import java.sql.Types; public abstract class WrappedBigDecimalJavaType> extends AbstractClassJavaType { - private final transient Constructor canonicalConstructor; + private final transient Constructor constructor; protected WrappedBigDecimalJavaType(Class type) { super(type); - this.canonicalConstructor = RecordReflectionUtil.getCanonicalConstructor(type); + Constructor c; + if (type.isRecord()) { + c = RecordReflectionUtil.getCanonicalConstructor(type); + } else { + try { + c = type.getConstructor(BigDecimal.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); + } + } + + this.constructor = c; } @Override @@ -60,7 +71,7 @@ public T wrap(X value, WrapperOptions wrapperOptions) { return (T) value; } if (value instanceof Double doubleValue) { - return canonicalConstructor.newInstance(BigDecimal.valueOf(doubleValue)); + return constructor.newInstance(BigDecimal.valueOf(doubleValue)); } throw unknownWrap(value.getClass()); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigIntegerJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigIntegerJavaType.java index ef2094c..f96d10b 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigIntegerJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigIntegerJavaType.java @@ -14,12 +14,23 @@ import java.sql.Types; public abstract class WrappedBigIntegerJavaType> extends AbstractClassJavaType { - private final transient Constructor canonicalConstructor; + private final transient Constructor constructor; protected WrappedBigIntegerJavaType(Class type) { super(type); - this.canonicalConstructor = RecordReflectionUtil.getCanonicalConstructor(type); + Constructor c; + if (type.isRecord()) { + c = RecordReflectionUtil.getCanonicalConstructor(type); + } else { + try { + c = type.getConstructor(BigInteger.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); + } + } + + this.constructor = c; } @Override @@ -60,7 +71,7 @@ public T wrap(X value, WrapperOptions wrapperOptions) { return (T) value; } if (value instanceof Long longValue) { - return canonicalConstructor.newInstance(BigInteger.valueOf(longValue)); + return constructor.newInstance(BigInteger.valueOf(longValue)); } throw unknownWrap(value.getClass()); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedDoubleJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedDoubleJavaType.java index 37a6b36..b9e9250 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedDoubleJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedDoubleJavaType.java @@ -13,12 +13,23 @@ import java.sql.Types; public abstract class WrappedDoubleJavaType> extends AbstractClassJavaType { - private final transient Constructor canonicalConstructor; + private final transient Constructor constructor; protected WrappedDoubleJavaType(Class type) { super(type); - this.canonicalConstructor = RecordReflectionUtil.getCanonicalConstructor(type); + Constructor c; + if (type.isRecord()) { + c = RecordReflectionUtil.getCanonicalConstructor(type); + } else { + try { + c = type.getConstructor(Double.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); + } + } + + this.constructor = c; } @Override @@ -59,7 +70,7 @@ public T wrap(X value, WrapperOptions wrapperOptions) { return (T) value; } if (value instanceof Double doubleValue) { - return canonicalConstructor.newInstance(doubleValue); + return constructor.newInstance(doubleValue); } throw unknownWrap(value.getClass()); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedFloatJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedFloatJavaType.java index c862e39..55a7533 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedFloatJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedFloatJavaType.java @@ -13,12 +13,23 @@ import java.sql.Types; public abstract class WrappedFloatJavaType> extends AbstractClassJavaType { - private final transient Constructor canonicalConstructor; + private final transient Constructor constructor; protected WrappedFloatJavaType(Class type) { super(type); - this.canonicalConstructor = RecordReflectionUtil.getCanonicalConstructor(type); + Constructor c; + if (type.isRecord()) { + c = RecordReflectionUtil.getCanonicalConstructor(type); + } else { + try { + c = type.getConstructor(Float.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); + } + } + + this.constructor = c; } @Override @@ -59,7 +70,7 @@ public T wrap(X value, WrapperOptions wrapperOptions) { return (T) value; } if (value instanceof Float floatValue) { - return canonicalConstructor.newInstance(floatValue); + return constructor.newInstance(floatValue); } throw unknownWrap(value.getClass()); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedIntegerJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedIntegerJavaType.java index 8c4d933..639785b 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedIntegerJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedIntegerJavaType.java @@ -13,12 +13,23 @@ import java.sql.Types; public abstract class WrappedIntegerJavaType> extends AbstractClassJavaType { - private final transient Constructor canonicalConstructor; + private final transient Constructor constructor; protected WrappedIntegerJavaType(Class type) { super(type); - this.canonicalConstructor = RecordReflectionUtil.getCanonicalConstructor(type); + Constructor c; + if (type.isRecord()) { + c = RecordReflectionUtil.getCanonicalConstructor(type); + } else { + try { + c = type.getConstructor(Integer.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); + } + } + + this.constructor = c; } @Override @@ -59,7 +70,7 @@ public T wrap(X value, WrapperOptions wrapperOptions) { return (T) value; } if (value instanceof Integer integerValue) { - return canonicalConstructor.newInstance(integerValue); + return constructor.newInstance(integerValue); } throw unknownWrap(value.getClass()); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedLongJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedLongJavaType.java index 4949394..bfe42ef 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedLongJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedLongJavaType.java @@ -13,12 +13,24 @@ import java.sql.Types; public abstract class WrappedLongJavaType> extends AbstractClassJavaType { - private final transient Constructor canonicalConstructor; + private final transient Constructor constructor; + @SneakyThrows protected WrappedLongJavaType(Class type) { super(type); - this.canonicalConstructor = RecordReflectionUtil.getCanonicalConstructor(type); + Constructor c; + if (type.isRecord()) { + c = RecordReflectionUtil.getCanonicalConstructor(type); + } else { + try { + c = type.getConstructor(Long.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); + } + } + + this.constructor = c; } @Override @@ -59,7 +71,7 @@ public T wrap(X value, WrapperOptions wrapperOptions) { return (T) value; } if (value instanceof Long longValue) { - return canonicalConstructor.newInstance(longValue); + return constructor.newInstance(longValue); } throw unknownWrap(value.getClass()); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedScaledBigDecimalJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedScaledBigDecimalJavaType.java index 3450c14..5b9a2e8 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedScaledBigDecimalJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedScaledBigDecimalJavaType.java @@ -14,12 +14,23 @@ import java.sql.Types; public abstract class WrappedScaledBigDecimalJavaType> extends AbstractClassJavaType { - private final transient Constructor canonicalConstructor; + private final transient Constructor constructor; protected WrappedScaledBigDecimalJavaType(Class type) { super(type); - this.canonicalConstructor = RecordReflectionUtil.getCanonicalConstructor(type); + Constructor c; + if (type.isRecord()) { + c = RecordReflectionUtil.getCanonicalConstructor(type); + } else { + try { + c = type.getConstructor(ScaledBigDecimal.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); + } + } + + this.constructor = c; } @Override @@ -60,7 +71,7 @@ public T wrap(X value, WrapperOptions wrapperOptions) { return (T) value; } if (value instanceof Double doubleValue) { - return canonicalConstructor.newInstance(new ScaledBigDecimal(doubleValue)); + return constructor.newInstance(new ScaledBigDecimal(doubleValue)); } throw unknownWrap(value.getClass()); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedShortJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedShortJavaType.java index b5782fa..e4adb6d 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedShortJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedShortJavaType.java @@ -13,12 +13,23 @@ import java.sql.Types; public abstract class WrappedShortJavaType> extends AbstractClassJavaType { - private final transient Constructor canonicalConstructor; + private final transient Constructor constructor; protected WrappedShortJavaType(Class type) { super(type); - this.canonicalConstructor = RecordReflectionUtil.getCanonicalConstructor(type); + Constructor c; + if (type.isRecord()) { + c = RecordReflectionUtil.getCanonicalConstructor(type); + } else { + try { + c = type.getConstructor(Short.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); + } + } + + this.constructor = c; } @Override @@ -59,7 +70,7 @@ public T wrap(X value, WrapperOptions wrapperOptions) { return (T) value; } if (value instanceof Short shortValue) { - return canonicalConstructor.newInstance(shortValue); + return constructor.newInstance(shortValue); } throw unknownWrap(value.getClass()); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedStringJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedStringJavaType.java index 35b9fd6..9daf9e7 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedStringJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedStringJavaType.java @@ -13,12 +13,24 @@ import java.sql.Types; public abstract class WrappedStringJavaType> extends AbstractClassJavaType { - private final transient Constructor canonicalConstructor; + private final transient Constructor constructor; protected WrappedStringJavaType(Class type) { super(type); - this.canonicalConstructor = RecordReflectionUtil.getCanonicalConstructor(type); + Constructor c; + if (type.isRecord()) { + c = RecordReflectionUtil.getCanonicalConstructor(type); + } else { + try { + c = type.getConstructor(String.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); + } + } + + + this.constructor = c; } @Override @@ -59,7 +71,7 @@ public T wrap(X value, WrapperOptions wrapperOptions) { return (T) value; } if (value instanceof String stringValue) { - return canonicalConstructor.newInstance(stringValue); + return constructor.newInstance(stringValue); } throw unknownWrap(value.getClass()); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/web/CustomTypePropertyEditor.java b/src/main/java/it/aboutbits/springboot/toolbox/web/CustomTypePropertyEditor.java index f8e57de..dd1ee16 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/web/CustomTypePropertyEditor.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/web/CustomTypePropertyEditor.java @@ -1,26 +1,50 @@ package it.aboutbits.springboot.toolbox.web; +import it.aboutbits.springboot.toolbox.jackson.CustomTypeDeserializer; import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; import lombok.NonNull; -import lombok.SneakyThrows; import org.springframework.lang.Nullable; import java.beans.PropertyEditorSupport; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.ParameterizedType; import java.math.BigDecimal; import java.math.BigInteger; +import java.util.Arrays; import java.util.function.Function; public final class CustomTypePropertyEditor> extends PropertyEditorSupport { private final Constructor constructor; private final Function typeConverter; - @SneakyThrows public CustomTypePropertyEditor(@NonNull Class customType) { - this.constructor = RecordReflectionUtil.getCanonicalConstructor(customType); + Constructor c; + if (customType.isRecord()) { + c = RecordReflectionUtil.getCanonicalConstructor(customType); + } else { + try { + var customTypeInterface = Arrays.stream(customType.getGenericInterfaces()) + .filter(i -> + i instanceof ParameterizedType + && CustomType.class.isAssignableFrom((Class) ((ParameterizedType) i).getRawType()) + ).findFirst() + .map(i -> (ParameterizedType) i) + .orElseThrow(); + + var parameterType = (Class) customTypeInterface.getActualTypeArguments()[0]; + + c = customType.getConstructor(parameterType); + } catch (Exception e) { + throw new CustomTypeDeserializer.CustomTypeDeserializerException( + "Unable to find constructor for type: " + customType.getName(), + e + ); + } + } + this.constructor = c; this.typeConverter = getTextToTypeConverter( constructor.getParameters()[0].getType() ); diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/WrapperTypesJpaTest.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/WrapperTypesJpaTest.java index c54b8b3..0369b78 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/WrapperTypesJpaTest.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/WrapperTypesJpaTest.java @@ -2,15 +2,24 @@ import it.aboutbits.springboot.toolbox.persistence.javatype.impl.jpa.WrapperTypesModel; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.jpa.WrapperTypesModelRepository; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimal; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigInteger; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDouble; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloat; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapInteger; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLong; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimal; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShort; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapString; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapIntegerClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapIntegerRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLongClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLongRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimalClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimalRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShortClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShortRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapStringClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapStringRecord; import it.aboutbits.springboot.toolbox.support.ApplicationTest; import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; import org.junit.jupiter.api.Nested; @@ -30,308 +39,620 @@ public class WrapperTypesJpaTest { WrapperTypesModelRepository repository; @Nested - class WrapBigDecimalType { - @Test - void givenNull_inAndOut_shouldSucceed() { - var item = new WrapperTypesModel(); - item.setBigDecimalValue(null); + class RecordTypes { + @Nested + class WrapBigDecimalRecordType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setBigDecimalValue(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByBigDecimalValue(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(double doubleValue) { + var item = new WrapperTypesModel(); + item.setBigDecimalValue(new WrapBigDecimalRecord(BigDecimal.valueOf(doubleValue))); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByBigDecimalValue(savedItem.getBigDecimalValue()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + } - var savedItem = repository.save(item); + @Nested + class WrapBigIntegerRecordType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setBigIntegerValue(null); - var retrievedItem = repository.findByBigDecimalValue(null); + var savedItem = repository.save(item); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); - } + var retrievedItem = repository.findByBigIntegerValue(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } - @ParameterizedTest - @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) - void givenValues_inAndOut_shouldSucceed(double doubleValue) { - var item = new WrapperTypesModel(); - item.setBigDecimalValue(new WrapBigDecimal(BigDecimal.valueOf(doubleValue))); + @ParameterizedTest + @ValueSource(ints = {-1, 0, 1, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(int intValue) { + var item = new WrapperTypesModel(); + item.setBigIntegerValue(new WrapBigIntegerRecord(BigInteger.valueOf(intValue))); - var savedItem = repository.save(item); + var savedItem = repository.save(item); - var retrievedItem = repository.findByBigDecimalValue(savedItem.getBigDecimalValue()); + var retrievedItem = repository.findByBigIntegerValue(savedItem.getBigIntegerValue()); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - } - @Nested - class WrapBigIntegerType { - @Test - void givenNull_inAndOut_shouldSucceed() { - var item = new WrapperTypesModel(); - item.setBigIntegerValue(null); + @Nested + class WrapDoubleRecordType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setDoubleValue(null); - var savedItem = repository.save(item); + var savedItem = repository.save(item); - var retrievedItem = repository.findByBigIntegerValue(null); + var retrievedItem = repository.findByDoubleValue(null); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); - } + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } - @ParameterizedTest - @ValueSource(ints = {-1, 0, 1, -100_000_000, 100_000_000}) - void givenValues_inAndOut_shouldSucceed(int intValue) { - var item = new WrapperTypesModel(); - item.setBigIntegerValue(new WrapBigInteger(BigInteger.valueOf(intValue))); + @ParameterizedTest + @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(double doubleValue) { + var item = new WrapperTypesModel(); + item.setDoubleValue(new WrapDoubleRecord(doubleValue)); - var savedItem = repository.save(item); + var savedItem = repository.save(item); - var retrievedItem = repository.findByBigIntegerValue(savedItem.getBigIntegerValue()); + var retrievedItem = repository.findByDoubleValue(savedItem.getDoubleValue()); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - } - @Nested - class WrapDoubleType { - @Test - void givenNull_inAndOut_shouldSucceed() { - var item = new WrapperTypesModel(); - item.setDoubleValue(null); + @Nested + class WrapFloatRecordType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setFloatValue(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByFloatValue(null); - var savedItem = repository.save(item); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } - var retrievedItem = repository.findByDoubleValue(null); + @ParameterizedTest + @ValueSource(floats = {-1, 0, 1, -0.001f, 0.001f, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(float floatValue) { + var item = new WrapperTypesModel(); + item.setFloatValue(new WrapFloatRecord(floatValue)); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + var savedItem = repository.save(item); + + var retrievedItem = repository.findByFloatValue(savedItem.getFloatValue()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - @ParameterizedTest - @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) - void givenValues_inAndOut_shouldSucceed(double doubleValue) { - var item = new WrapperTypesModel(); - item.setDoubleValue(new WrapDouble(doubleValue)); + @Nested + class WrapIntegerRecordType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setIntegerValue(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByIntegerValue(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } - var savedItem = repository.save(item); + @ParameterizedTest + @ValueSource(ints = {-1, 0, 1, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(int intValue) { + var item = new WrapperTypesModel(); + item.setIntegerValue(new WrapIntegerRecord(intValue)); - var retrievedItem = repository.findByDoubleValue(savedItem.getDoubleValue()); + var savedItem = repository.save(item); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + var retrievedItem = repository.findByIntegerValue(savedItem.getIntegerValue()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - } - @Nested - class WrapFloatType { - @Test - void givenNull_inAndOut_shouldSucceed() { - var item = new WrapperTypesModel(); - item.setFloatValue(null); + @Nested + class WrapLongRecordType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setLongValue(null); + + var savedItem = repository.save(item); - var savedItem = repository.save(item); + var retrievedItem = repository.findByLongValue(null); - var retrievedItem = repository.findByFloatValue(null); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + @ParameterizedTest + @ValueSource(longs = {-1, 0, 1, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(long longValue) { + var item = new WrapperTypesModel(); + item.setLongValue(new WrapLongRecord(longValue)); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByLongValue(savedItem.getLongValue()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - @ParameterizedTest - @ValueSource(floats = {-1, 0, 1, -0.001f, 0.001f, -100_000_000, 100_000_000}) - void givenValues_inAndOut_shouldSucceed(float floatValue) { - var item = new WrapperTypesModel(); - item.setFloatValue(new WrapFloat(floatValue)); + @Nested + class WrapScaledBigDecimalRecordType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setScaledBigDecimalValue(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByScaledBigDecimalValue(null); - var savedItem = repository.save(item); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } - var retrievedItem = repository.findByFloatValue(savedItem.getFloatValue()); + @ParameterizedTest + @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(double doubleValue) { + var item = new WrapperTypesModel(); + item.setScaledBigDecimalValue(new WrapScaledBigDecimalRecord(new ScaledBigDecimal(doubleValue))); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + var savedItem = repository.save(item); + + var retrievedItem = repository.findByScaledBigDecimalValue(savedItem.getScaledBigDecimalValue()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - } - @Nested - class WrapIntegerType { - @Test - void givenNull_inAndOut_shouldSucceed() { - var item = new WrapperTypesModel(); - item.setIntegerValue(null); + @Nested + class WrapShortRecordType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setShortValue(null); + + var savedItem = repository.save(item); - var savedItem = repository.save(item); + var retrievedItem = repository.findByShortValue(null); - var retrievedItem = repository.findByIntegerValue(null); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + @ParameterizedTest + @ValueSource(shorts = {-1, 0, 1, -10_000, 10_000}) + void givenValues_inAndOut_shouldSucceed(short shortValue) { + var item = new WrapperTypesModel(); + item.setShortValue(new WrapShortRecord(shortValue)); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByShortValue(savedItem.getShortValue()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - @ParameterizedTest - @ValueSource(ints = {-1, 0, 1, -100_000_000, 100_000_000}) - void givenValues_inAndOut_shouldSucceed(int intValue) { - var item = new WrapperTypesModel(); - item.setIntegerValue(new WrapInteger(intValue)); + @Nested + class WrapStringRecordType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setStringValue(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByStringValue(null); - var savedItem = repository.save(item); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } - var retrievedItem = repository.findByIntegerValue(savedItem.getIntegerValue()); + @ParameterizedTest + @ValueSource(strings = {"", " ", "test", "some longer test", "\r", "\n"}) + void givenValues_inAndOut_shouldSucceed(String stringValue) { + var item = new WrapperTypesModel(); + item.setStringValue(new WrapStringRecord(stringValue)); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + var savedItem = repository.save(item); + + var retrievedItem = repository.findByStringValue(savedItem.getStringValue()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } } @Nested - class WrapLongType { - @Test - void givenNull_inAndOut_shouldSucceed() { - var item = new WrapperTypesModel(); - item.setLongValue(null); + class ClassTypes { + @Nested + class WrapBigDecimalClassType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setBigDecimalValueClass(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByBigDecimalValueClass(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(double doubleValue) { + var item = new WrapperTypesModel(); + item.setBigDecimalValueClass(new WrapBigDecimalClass(BigDecimal.valueOf(doubleValue))); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByBigDecimalValueClass(savedItem.getBigDecimalValueClass()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + } + + @Nested + class WrapBigIntegerClassType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setBigIntegerValueClass(null); - var savedItem = repository.save(item); + var savedItem = repository.save(item); - var retrievedItem = repository.findByLongValue(null); + var retrievedItem = repository.findByBigIntegerValueClass(null); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(ints = {-1, 0, 1, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(int intValue) { + var item = new WrapperTypesModel(); + item.setBigIntegerValueClass(new WrapBigIntegerClass(BigInteger.valueOf(intValue))); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByBigIntegerValueClass(savedItem.getBigIntegerValueClass()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - @ParameterizedTest - @ValueSource(longs = {-1, 0, 1, -100_000_000, 100_000_000}) - void givenValues_inAndOut_shouldSucceed(long longValue) { - var item = new WrapperTypesModel(); - item.setLongValue(new WrapLong(longValue)); + @Nested + class WrapDoubleClassType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setDoubleValueClass(null); + + var savedItem = repository.save(item); - var savedItem = repository.save(item); + var retrievedItem = repository.findByDoubleValueClass(null); - var retrievedItem = repository.findByLongValue(savedItem.getLongValue()); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + @ParameterizedTest + @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(double doubleValue) { + var item = new WrapperTypesModel(); + item.setDoubleValueClass(new WrapDoubleClass(doubleValue)); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByDoubleValueClass(savedItem.getDoubleValueClass()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - } - @Nested - class WrapScaledBigDecimalType { - @Test - void givenNull_inAndOut_shouldSucceed() { - var item = new WrapperTypesModel(); - item.setScaledBigDecimalValue(null); + @Nested + class WrapFloatClassType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setFloatValueClass(null); - var savedItem = repository.save(item); + var savedItem = repository.save(item); - var retrievedItem = repository.findByScaledBigDecimalValue(null); + var retrievedItem = repository.findByFloatValueClass(null); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(floats = {-1, 0, 1, -0.001f, 0.001f, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(float floatValue) { + var item = new WrapperTypesModel(); + item.setFloatValueClass(new WrapFloatClass(floatValue)); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByFloatValueClass(savedItem.getFloatValueClass()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - @ParameterizedTest - @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) - void givenValues_inAndOut_shouldSucceed(double doubleValue) { - var item = new WrapperTypesModel(); - item.setScaledBigDecimalValue(new WrapScaledBigDecimal(new ScaledBigDecimal(doubleValue))); + @Nested + class WrapIntegerClassType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setIntegerValueClass(null); + + var savedItem = repository.save(item); - var savedItem = repository.save(item); + var retrievedItem = repository.findByIntegerValueClass(null); - var retrievedItem = repository.findByScaledBigDecimalValue(savedItem.getScaledBigDecimalValue()); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + @ParameterizedTest + @ValueSource(ints = {-1, 0, 1, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(int intValue) { + var item = new WrapperTypesModel(); + item.setIntegerValueClass(new WrapIntegerClass(intValue)); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByIntegerValueClass(savedItem.getIntegerValueClass()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - } - @Nested - class WrapShortType { - @Test - void givenNull_inAndOut_shouldSucceed() { - var item = new WrapperTypesModel(); - item.setShortValue(null); + @Nested + class WrapLongClassType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setLongValueClass(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByLongValueClass(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(longs = {-1, 0, 1, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(long longValue) { + var item = new WrapperTypesModel(); + item.setLongValueClass(new WrapLongClass(longValue)); - var savedItem = repository.save(item); + var savedItem = repository.save(item); - var retrievedItem = repository.findByShortValue(null); + var retrievedItem = repository.findByLongValueClass(savedItem.getLongValueClass()); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - @ParameterizedTest - @ValueSource(shorts = {-1, 0, 1, -10_000, 10_000}) - void givenValues_inAndOut_shouldSucceed(short shortValue) { - var item = new WrapperTypesModel(); - item.setShortValue(new WrapShort(shortValue)); + @Nested + class WrapScaledBigDecimalClassType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setScaledBigDecimalValueClass(null); - var savedItem = repository.save(item); + var savedItem = repository.save(item); - var retrievedItem = repository.findByShortValue(savedItem.getShortValue()); + var retrievedItem = repository.findByScaledBigDecimalValueClass(null); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) + void givenValues_inAndOut_shouldSucceed(double doubleValue) { + var item = new WrapperTypesModel(); + item.setScaledBigDecimalValueClass(new WrapScaledBigDecimalClass(new ScaledBigDecimal(doubleValue))); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByScaledBigDecimalValueClass(savedItem.getScaledBigDecimalValueClass()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - } - @Nested - class WrapStringType { - @Test - void givenNull_inAndOut_shouldSucceed() { - var item = new WrapperTypesModel(); - item.setStringValue(null); + @Nested + class WrapShortClassType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setShortValueClass(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByShortValueClass(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(shorts = {-1, 0, 1, -10_000, 10_000}) + void givenValues_inAndOut_shouldSucceed(short shortValue) { + var item = new WrapperTypesModel(); + item.setShortValueClass(new WrapShortClass(shortValue)); - var savedItem = repository.save(item); + var savedItem = repository.save(item); - var retrievedItem = repository.findByStringValue(null); + var retrievedItem = repository.findByShortValueClass(savedItem.getShortValueClass()); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } - @ParameterizedTest - @ValueSource(strings = {"", " ", "test", "some longer test", "\r", "\n"}) - void givenValues_inAndOut_shouldSucceed(String stringValue) { - var item = new WrapperTypesModel(); - item.setStringValue(new WrapString(stringValue)); + @Nested + class WrapStringClassType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setStringValueClass(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByStringValueClass(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(strings = {"", " ", "test", "some longer test", "\r", "\n"}) + void givenValues_inAndOut_shouldSucceed(String stringValue) { + var item = new WrapperTypesModel(); + item.setStringValueClass(new WrapStringClass(stringValue)); - var savedItem = repository.save(item); + var savedItem = repository.save(item); - var retrievedItem = repository.findByStringValue(savedItem.getStringValue()); + var retrievedItem = repository.findByStringValueClass(savedItem.getStringValueClass()); - assertThat(retrievedItem).isPresent() - .get() - .usingRecursiveComparison() - .isEqualTo(savedItem); + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } } } } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalClassJavaType.java new file mode 100644 index 0000000..b9f3970 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalClassJavaType.java @@ -0,0 +1,12 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedBigDecimalJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalRecord; + +public final class WrapBigDecimalClassJavaType extends WrappedBigDecimalJavaType implements AutoRegisteredJavaType { + public WrapBigDecimalClassJavaType() { + super(WrapBigDecimalClass.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalRecordJavaType.java similarity index 54% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalJavaType.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalRecordJavaType.java index f754b8c..65bd53c 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalRecordJavaType.java @@ -2,10 +2,10 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedBigDecimalJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimal; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalRecord; -public final class WrapBigDecimalJavaType extends WrappedBigDecimalJavaType implements AutoRegisteredJavaType { - public WrapBigDecimalJavaType() { - super(WrapBigDecimal.class); +public final class WrapBigDecimalRecordJavaType extends WrappedBigDecimalJavaType implements AutoRegisteredJavaType { + public WrapBigDecimalRecordJavaType() { + super(WrapBigDecimalRecord.class); } } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerClassJavaType.java new file mode 100644 index 0000000..c975700 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerClassJavaType.java @@ -0,0 +1,12 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedBigIntegerJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerRecord; + +public final class WrapBigIntegerClassJavaType extends WrappedBigIntegerJavaType implements AutoRegisteredJavaType { + public WrapBigIntegerClassJavaType() { + super(WrapBigIntegerClass.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerRecordJavaType.java similarity index 54% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerJavaType.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerRecordJavaType.java index 71d2a5d..95a7396 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerRecordJavaType.java @@ -2,10 +2,10 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedBigIntegerJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigInteger; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerRecord; -public final class WrapBigIntegerJavaType extends WrappedBigIntegerJavaType implements AutoRegisteredJavaType { - public WrapBigIntegerJavaType() { - super(WrapBigInteger.class); +public final class WrapBigIntegerRecordJavaType extends WrappedBigIntegerJavaType implements AutoRegisteredJavaType { + public WrapBigIntegerRecordJavaType() { + super(WrapBigIntegerRecord.class); } } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleClassJavaType.java new file mode 100644 index 0000000..813a343 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleClassJavaType.java @@ -0,0 +1,12 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedDoubleJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleRecord; + +public final class WrapDoubleClassJavaType extends WrappedDoubleJavaType implements AutoRegisteredJavaType { + public WrapDoubleClassJavaType() { + super(WrapDoubleClass.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleRecordJavaType.java similarity index 57% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleJavaType.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleRecordJavaType.java index 2e69f31..bf5b975 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleRecordJavaType.java @@ -2,10 +2,10 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedDoubleJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDouble; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleRecord; -public final class WrapDoubleJavaType extends WrappedDoubleJavaType implements AutoRegisteredJavaType { - public WrapDoubleJavaType() { - super(WrapDouble.class); +public final class WrapDoubleRecordJavaType extends WrappedDoubleJavaType implements AutoRegisteredJavaType { + public WrapDoubleRecordJavaType() { + super(WrapDoubleRecord.class); } } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatClassJavaType.java new file mode 100644 index 0000000..0e4a5bb --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatClassJavaType.java @@ -0,0 +1,12 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedFloatJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatRecord; + +public final class WrapFloatClassJavaType extends WrappedFloatJavaType implements AutoRegisteredJavaType { + public WrapFloatClassJavaType() { + super(WrapFloatClass.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatRecordJavaType.java similarity index 57% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatJavaType.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatRecordJavaType.java index 81a1815..7784534 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatRecordJavaType.java @@ -2,10 +2,10 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedFloatJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloat; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatRecord; -public final class WrapFloatJavaType extends WrappedFloatJavaType implements AutoRegisteredJavaType { - public WrapFloatJavaType() { - super(WrapFloat.class); +public final class WrapFloatRecordJavaType extends WrappedFloatJavaType implements AutoRegisteredJavaType { + public WrapFloatRecordJavaType() { + super(WrapFloatRecord.class); } } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerClassJavaType.java new file mode 100644 index 0000000..dc8088d --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerClassJavaType.java @@ -0,0 +1,12 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedIntegerJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapIntegerClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapIntegerRecord; + +public final class WrapIntegerClassJavaType extends WrappedIntegerJavaType implements AutoRegisteredJavaType { + public WrapIntegerClassJavaType() { + super(WrapIntegerClass.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerRecordJavaType.java similarity index 56% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerJavaType.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerRecordJavaType.java index d20de96..4f20a8a 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerRecordJavaType.java @@ -2,10 +2,10 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedIntegerJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapInteger; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapIntegerRecord; -public final class WrapIntegerJavaType extends WrappedIntegerJavaType implements AutoRegisteredJavaType { - public WrapIntegerJavaType() { - super(WrapInteger.class); +public final class WrapIntegerRecordJavaType extends WrappedIntegerJavaType implements AutoRegisteredJavaType { + public WrapIntegerRecordJavaType() { + super(WrapIntegerRecord.class); } } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongClassJavaType.java new file mode 100644 index 0000000..b1a19e7 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongClassJavaType.java @@ -0,0 +1,12 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedLongJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLongClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLongRecord; + +public final class WrapLongClassJavaType extends WrappedLongJavaType implements AutoRegisteredJavaType { + public WrapLongClassJavaType() { + super(WrapLongClass.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongRecordJavaType.java similarity index 58% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongJavaType.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongRecordJavaType.java index 9375633..c9aa18b 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongRecordJavaType.java @@ -2,10 +2,10 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedLongJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLong; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLongRecord; -public final class WrapLongJavaType extends WrappedLongJavaType implements AutoRegisteredJavaType { - public WrapLongJavaType() { - super(WrapLong.class); +public final class WrapLongRecordJavaType extends WrappedLongJavaType implements AutoRegisteredJavaType { + public WrapLongRecordJavaType() { + super(WrapLongRecord.class); } } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalClassJavaType.java new file mode 100644 index 0000000..9e2eb39 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalClassJavaType.java @@ -0,0 +1,12 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedScaledBigDecimalJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimalClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimalRecord; + +public final class WrapScaledBigDecimalClassJavaType extends WrappedScaledBigDecimalJavaType implements AutoRegisteredJavaType { + public WrapScaledBigDecimalClassJavaType() { + super(WrapScaledBigDecimalClass.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalRecordJavaType.java similarity index 51% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalJavaType.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalRecordJavaType.java index 0959545..dea2da4 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalRecordJavaType.java @@ -2,10 +2,10 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedScaledBigDecimalJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimal; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimalRecord; -public final class WrapScaledBigDecimalJavaType extends WrappedScaledBigDecimalJavaType implements AutoRegisteredJavaType { - public WrapScaledBigDecimalJavaType() { - super(WrapScaledBigDecimal.class); +public final class WrapScaledBigDecimalRecordJavaType extends WrappedScaledBigDecimalJavaType implements AutoRegisteredJavaType { + public WrapScaledBigDecimalRecordJavaType() { + super(WrapScaledBigDecimalRecord.class); } } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortClassJavaType.java new file mode 100644 index 0000000..8dc7e2d --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortClassJavaType.java @@ -0,0 +1,12 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedShortJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShortClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShortRecord; + +public final class WrapShortClassJavaType extends WrappedShortJavaType implements AutoRegisteredJavaType { + public WrapShortClassJavaType() { + super(WrapShortClass.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortRecordJavaType.java similarity index 57% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortJavaType.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortRecordJavaType.java index 78d3a36..77885ba 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortRecordJavaType.java @@ -2,10 +2,10 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedShortJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShort; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShortRecord; -public final class WrapShortJavaType extends WrappedShortJavaType implements AutoRegisteredJavaType { - public WrapShortJavaType() { - super(WrapShort.class); +public final class WrapShortRecordJavaType extends WrappedShortJavaType implements AutoRegisteredJavaType { + public WrapShortRecordJavaType() { + super(WrapShortRecord.class); } } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringClassJavaType.java new file mode 100644 index 0000000..3f7be66 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringClassJavaType.java @@ -0,0 +1,12 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedStringJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapStringClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapStringRecord; + +public final class WrapStringClassJavaType extends WrappedStringJavaType implements AutoRegisteredJavaType { + public WrapStringClassJavaType() { + super(WrapStringClass.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringRecordJavaType.java similarity index 57% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringJavaType.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringRecordJavaType.java index 43466e3..5e9bc43 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringRecordJavaType.java @@ -2,10 +2,10 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedStringJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapString; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapStringRecord; -public final class WrapStringJavaType extends WrappedStringJavaType implements AutoRegisteredJavaType { - public WrapStringJavaType() { - super(WrapString.class); +public final class WrapStringRecordJavaType extends WrappedStringJavaType implements AutoRegisteredJavaType { + public WrapStringRecordJavaType() { + super(WrapStringRecord.class); } } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModel.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModel.java index f2b5d84..edd5e1c 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModel.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModel.java @@ -1,27 +1,45 @@ package it.aboutbits.springboot.toolbox.persistence.javatype.impl.jpa; import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedLongJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapBigDecimalClassJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapBigDecimalRecordJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapBigIntegerClassJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapBigIntegerRecordJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapDoubleClassJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapDoubleRecordJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapFloatClassJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapFloatRecordJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapIntegerClassJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapIntegerRecordJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapLongClassJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapLongRecordJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapScaledBigDecimalClassJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapScaledBigDecimalRecordJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapShortClassJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapShortRecordJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapStringClassJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapStringRecordJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapIntegerClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapIntegerRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLongClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLongRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimalClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimalRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShortClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShortRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapStringClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapStringRecord; import it.aboutbits.springboot.toolbox.type.identity.EntityId; import it.aboutbits.springboot.toolbox.type.identity.Identified; -import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedLongJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapBigDecimalJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapBigIntegerJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapDoubleJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapFloatJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapIntegerJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapLongJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapScaledBigDecimalJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapShortJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapStringJavaType; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimal; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigInteger; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDouble; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloat; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapInteger; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLong; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimal; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShort; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapString; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -42,40 +60,76 @@ public class WrapperTypesModel implements Identified { private ID id; @SuppressWarnings("JpaAttributeTypeInspection") - @JavaType(WrapBigDecimalJavaType.class) - private WrapBigDecimal bigDecimalValue; + @JavaType(WrapBigDecimalRecordJavaType.class) + private WrapBigDecimalRecord bigDecimalValue; + + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapBigIntegerRecordJavaType.class) + private WrapBigIntegerRecord bigIntegerValue; + + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapDoubleRecordJavaType.class) + private WrapDoubleRecord doubleValue; + + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapFloatRecordJavaType.class) + private WrapFloatRecord floatValue; + + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapIntegerRecordJavaType.class) + private WrapIntegerRecord integerValue; + + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapLongRecordJavaType.class) + private WrapLongRecord longValue; + + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapScaledBigDecimalRecordJavaType.class) + private WrapScaledBigDecimalRecord scaledBigDecimalValue; + + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapShortRecordJavaType.class) + private WrapShortRecord shortValue; + + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapStringRecordJavaType.class) + private WrapStringRecord stringValue; + + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapBigDecimalClassJavaType.class) + private WrapBigDecimalClass bigDecimalValueClass; @SuppressWarnings("JpaAttributeTypeInspection") - @JavaType(WrapBigIntegerJavaType.class) - private WrapBigInteger bigIntegerValue; + @JavaType(WrapBigIntegerClassJavaType.class) + private WrapBigIntegerClass bigIntegerValueClass; @SuppressWarnings("JpaAttributeTypeInspection") - @JavaType(WrapDoubleJavaType.class) - private WrapDouble doubleValue; + @JavaType(WrapDoubleClassJavaType.class) + private WrapDoubleClass doubleValueClass; @SuppressWarnings("JpaAttributeTypeInspection") - @JavaType(WrapFloatJavaType.class) - private WrapFloat floatValue; + @JavaType(WrapFloatClassJavaType.class) + private WrapFloatClass floatValueClass; @SuppressWarnings("JpaAttributeTypeInspection") - @JavaType(WrapIntegerJavaType.class) - private WrapInteger integerValue; + @JavaType(WrapIntegerClassJavaType.class) + private WrapIntegerClass integerValueClass; @SuppressWarnings("JpaAttributeTypeInspection") - @JavaType(WrapLongJavaType.class) - private WrapLong longValue; + @JavaType(WrapLongClassJavaType.class) + private WrapLongClass longValueClass; @SuppressWarnings("JpaAttributeTypeInspection") - @JavaType(WrapScaledBigDecimalJavaType.class) - private WrapScaledBigDecimal scaledBigDecimalValue; + @JavaType(WrapScaledBigDecimalClassJavaType.class) + private WrapScaledBigDecimalClass scaledBigDecimalValueClass; @SuppressWarnings("JpaAttributeTypeInspection") - @JavaType(WrapShortJavaType.class) - private WrapShort shortValue; + @JavaType(WrapShortClassJavaType.class) + private WrapShortClass shortValueClass; @SuppressWarnings("JpaAttributeTypeInspection") - @JavaType(WrapStringJavaType.class) - private WrapString stringValue; + @JavaType(WrapStringClassJavaType.class) + private WrapStringClass stringValueClass; public record ID( Long value diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModelRepository.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModelRepository.java index e7c2459..9705ff8 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModelRepository.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModelRepository.java @@ -1,34 +1,61 @@ package it.aboutbits.springboot.toolbox.persistence.javatype.impl.jpa; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimal; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigInteger; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDouble; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloat; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapInteger; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLong; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimal; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShort; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapString; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapIntegerClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapIntegerRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLongClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLongRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimalClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimalRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShortClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShortRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapStringClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapStringRecord; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; public interface WrapperTypesModelRepository extends JpaRepository { - Optional findByBigDecimalValue(WrapBigDecimal value); + Optional findByBigDecimalValue(WrapBigDecimalRecord value); - Optional findByBigIntegerValue(WrapBigInteger value); + Optional findByBigIntegerValue(WrapBigIntegerRecord value); - Optional findByDoubleValue(WrapDouble value); + Optional findByDoubleValue(WrapDoubleRecord value); - Optional findByFloatValue(WrapFloat value); + Optional findByFloatValue(WrapFloatRecord value); - Optional findByIntegerValue(WrapInteger value); + Optional findByIntegerValue(WrapIntegerRecord value); - Optional findByLongValue(WrapLong value); + Optional findByLongValue(WrapLongRecord value); - Optional findByScaledBigDecimalValue(WrapScaledBigDecimal value); + Optional findByScaledBigDecimalValue(WrapScaledBigDecimalRecord value); - Optional findByShortValue(WrapShort value); + Optional findByShortValue(WrapShortRecord value); - Optional findByStringValue(WrapString value); + Optional findByStringValue(WrapStringRecord value); + + Optional findByBigDecimalValueClass(WrapBigDecimalClass value); + + Optional findByBigIntegerValueClass(WrapBigIntegerClass value); + + Optional findByDoubleValueClass(WrapDoubleClass value); + + Optional findByFloatValueClass(WrapFloatClass value); + + Optional findByIntegerValueClass(WrapIntegerClass value); + + Optional findByLongValueClass(WrapLongClass value); + + Optional findByScaledBigDecimalValueClass(WrapScaledBigDecimalClass value); + + Optional findByShortValueClass(WrapShortClass value); + + Optional findByStringValueClass(WrapStringClass value); } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigDecimalClass.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigDecimalClass.java new file mode 100644 index 0000000..177142b --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigDecimalClass.java @@ -0,0 +1,17 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +import java.math.BigDecimal; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@RequiredArgsConstructor +public class WrapBigDecimalClass implements CustomType { + private final BigDecimal value; +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigDecimal.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigDecimalRecord.java similarity index 64% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigDecimal.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigDecimalRecord.java index 5b3b2b8..5291d1b 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigDecimal.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigDecimalRecord.java @@ -4,6 +4,6 @@ import java.math.BigDecimal; -public record WrapBigDecimal(BigDecimal value) implements CustomType { +public record WrapBigDecimalRecord(BigDecimal value) implements CustomType { } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigIntegerClass.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigIntegerClass.java new file mode 100644 index 0000000..366a187 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigIntegerClass.java @@ -0,0 +1,17 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +import java.math.BigInteger; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@RequiredArgsConstructor +public class WrapBigIntegerClass implements CustomType { + private final BigInteger value; +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigInteger.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigIntegerRecord.java similarity index 64% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigInteger.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigIntegerRecord.java index f97a743..7c86200 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigInteger.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBigIntegerRecord.java @@ -4,6 +4,6 @@ import java.math.BigInteger; -public record WrapBigInteger(BigInteger value) implements CustomType { +public record WrapBigIntegerRecord(BigInteger value) implements CustomType { } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapDoubleClass.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapDoubleClass.java new file mode 100644 index 0000000..2b56662 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapDoubleClass.java @@ -0,0 +1,15 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@RequiredArgsConstructor +public class WrapDoubleClass implements CustomType { + private final Double value; +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapDouble.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapDoubleRecord.java similarity index 63% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapDouble.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapDoubleRecord.java index 467527e..e2825a8 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapDouble.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapDoubleRecord.java @@ -2,6 +2,6 @@ import it.aboutbits.springboot.toolbox.type.CustomType; -public record WrapDouble(Double value) implements CustomType { +public record WrapDoubleRecord(Double value) implements CustomType { } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapFloatClass.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapFloatClass.java new file mode 100644 index 0000000..9feb2b7 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapFloatClass.java @@ -0,0 +1,15 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@RequiredArgsConstructor +public class WrapFloatClass implements CustomType { + private final Float value; +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapInteger.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapFloatRecord.java similarity index 64% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapInteger.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapFloatRecord.java index 73a08af..62b966d 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapInteger.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapFloatRecord.java @@ -2,6 +2,6 @@ import it.aboutbits.springboot.toolbox.type.CustomType; -public record WrapInteger(Integer value) implements CustomType { +public record WrapFloatRecord(Float value) implements CustomType { } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapIntegerClass.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapIntegerClass.java new file mode 100644 index 0000000..8c12927 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapIntegerClass.java @@ -0,0 +1,15 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@RequiredArgsConstructor +public class WrapIntegerClass implements CustomType { + private final Integer value; +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapIntegerRecord.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapIntegerRecord.java new file mode 100644 index 0000000..08ba7f1 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapIntegerRecord.java @@ -0,0 +1,7 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; + +public record WrapIntegerRecord(Integer value) implements CustomType { + +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapLongClass.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapLongClass.java new file mode 100644 index 0000000..5ace546 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapLongClass.java @@ -0,0 +1,15 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@RequiredArgsConstructor +public class WrapLongClass implements CustomType { + private final Long value; +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapShort.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapLongRecord.java similarity index 65% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapShort.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapLongRecord.java index 5933d1d..e77c55e 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapShort.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapLongRecord.java @@ -2,6 +2,6 @@ import it.aboutbits.springboot.toolbox.type.CustomType; -public record WrapShort(Short value) implements CustomType { +public record WrapLongRecord(Long value) implements CustomType { } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapScaledBigDecimalClass.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapScaledBigDecimalClass.java new file mode 100644 index 0000000..b078910 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapScaledBigDecimalClass.java @@ -0,0 +1,16 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@RequiredArgsConstructor +public class WrapScaledBigDecimalClass implements CustomType { + private final ScaledBigDecimal value; +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapScaledBigDecimal.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapScaledBigDecimalRecord.java similarity index 64% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapScaledBigDecimal.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapScaledBigDecimalRecord.java index 87746eb..966f2c6 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapScaledBigDecimal.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapScaledBigDecimalRecord.java @@ -3,6 +3,6 @@ import it.aboutbits.springboot.toolbox.type.CustomType; import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; -public record WrapScaledBigDecimal(ScaledBigDecimal value) implements CustomType { +public record WrapScaledBigDecimalRecord(ScaledBigDecimal value) implements CustomType { } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapShortClass.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapShortClass.java new file mode 100644 index 0000000..7d2b8a5 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapShortClass.java @@ -0,0 +1,15 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@RequiredArgsConstructor +public class WrapShortClass implements CustomType { + private final Short value; +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapLong.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapShortRecord.java similarity index 64% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapLong.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapShortRecord.java index fc54ee0..742e668 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapLong.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapShortRecord.java @@ -2,6 +2,6 @@ import it.aboutbits.springboot.toolbox.type.CustomType; -public record WrapLong(Long value) implements CustomType { +public record WrapShortRecord(Short value) implements CustomType { } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapString.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapString.java deleted file mode 100644 index af28f4d..0000000 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapString.java +++ /dev/null @@ -1,7 +0,0 @@ -package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; - -import it.aboutbits.springboot.toolbox.type.CustomType; - -public record WrapString(String value) implements CustomType { - -} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapStringClass.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapStringClass.java new file mode 100644 index 0000000..b435c6c --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapStringClass.java @@ -0,0 +1,15 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@RequiredArgsConstructor +public class WrapStringClass implements CustomType { + private final String value; +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapFloat.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapStringRecord.java similarity index 63% rename from src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapFloat.java rename to src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapStringRecord.java index 357b8aa..964f2b5 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapFloat.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapStringRecord.java @@ -2,6 +2,6 @@ import it.aboutbits.springboot.toolbox.type.CustomType; -public record WrapFloat(Float value) implements CustomType { +public record WrapStringRecord(String value) implements CustomType { } diff --git a/src/test/resources/db/changelog/2024-09-06-create-wrapper-type-testing-table.yml b/src/test/resources/db/changelog/2024-09-06-create-wrapper-type-testing-table.yml index 1ae8cb5..6276531 100644 --- a/src/test/resources/db/changelog/2024-09-06-create-wrapper-type-testing-table.yml +++ b/src/test/resources/db/changelog/2024-09-06-create-wrapper-type-testing-table.yml @@ -40,3 +40,30 @@ databaseChangeLog: - column: name: string_value type: text + - column: + name: big_decimal_value_class + type: double + - column: + name: big_integer_value_class + type: bigint + - column: + name: double_value_class + type: double + - column: + name: float_value_class + type: double + - column: + name: integer_value_class + type: bigint + - column: + name: long_value_class + type: bigint + - column: + name: scaled_big_decimal_value_class + type: double + - column: + name: short_value_class + type: bigint + - column: + name: string_value_class + type: text From 87e78b95bfcc4526b8aa47ba0d81e4f6a7ab45b3 Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Tue, 1 Apr 2025 14:43:52 +0200 Subject: [PATCH 2/6] improve type reflection --- .../web/CustomTypeScanner.java | 11 +++ .../jackson/CustomTypeDeserializer.java | 34 ++----- .../base/WrappedBigDecimalJavaType.java | 16 +--- .../base/WrappedBigIntegerJavaType.java | 16 +--- .../javatype/base/WrappedDoubleJavaType.java | 16 +--- .../javatype/base/WrappedFloatJavaType.java | 16 +--- .../javatype/base/WrappedIntegerJavaType.java | 16 +--- .../javatype/base/WrappedLongJavaType.java | 17 +--- .../base/WrappedScaledBigDecimalJavaType.java | 16 +--- .../javatype/base/WrappedShortJavaType.java | 16 +--- .../javatype/base/WrappedStringJavaType.java | 17 +--- .../util/CustomTypeReflectionUtil.java | 34 +++++++ .../type/CustomTypeModelConverter.java | 8 +- .../type/CustomTypePropertyCustomizer.java | 15 ++-- .../toolbox/web/CustomTypePropertyEditor.java | 35 ++------ .../impl/jpa/CustomTypeTestModel.java | 4 +- .../impl/jpa/ReferencedTestModel.java | 2 +- .../javatype/WrapBigDecimalClassJavaType.java | 1 - .../javatype/WrapBigIntegerClassJavaType.java | 1 - .../javatype/WrapDoubleClassJavaType.java | 1 - .../impl/javatype/WrapFloatClassJavaType.java | 1 - .../javatype/WrapIntegerClassJavaType.java | 1 - .../impl/javatype/WrapLongClassJavaType.java | 1 - .../WrapScaledBigDecimalClassJavaType.java | 1 - .../impl/javatype/WrapShortClassJavaType.java | 1 - .../javatype/WrapStringClassJavaType.java | 1 - .../util/CustomTypeReflectionUtilTest.java | 89 +++++++++++++++++++ 27 files changed, 201 insertions(+), 186 deletions(-) create mode 100644 src/main/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtil.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtilTest.java diff --git a/src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/web/CustomTypeScanner.java b/src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/web/CustomTypeScanner.java index f2ab2e5..f374c31 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/web/CustomTypeScanner.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/web/CustomTypeScanner.java @@ -5,6 +5,10 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; @@ -42,7 +46,14 @@ public static Set> findAllCustomTypes(ClassScannerUt !item.isInterface() && !item.isAnonymousClass() && !Modifier.isAbstract(item.getModifiers()) + && !item.isAnnotationPresent(DisableCustomTypeConfiguration.class) ) .collect(Collectors.toSet()); } + + @Target({ElementType.TYPE}) + @Retention(RetentionPolicy.RUNTIME) + public @interface DisableCustomTypeConfiguration { + + } } diff --git a/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java b/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java index c2a1443..fe23ee3 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java @@ -3,17 +3,15 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; +import it.aboutbits.springboot.toolbox.reflection.util.CustomTypeReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.ParameterizedType; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.Arrays; import java.util.function.Function; public class CustomTypeDeserializer> extends JsonDeserializer { @@ -22,33 +20,17 @@ public class CustomTypeDeserializer> extends JsonDeseria private final Function typeConverter; public CustomTypeDeserializer(Class customType) { - Constructor c; this.customType = customType; - if (customType.isRecord()) { - c = RecordReflectionUtil.getCanonicalConstructor(customType); - } else { - try { - var customTypeInterface = Arrays.stream(customType.getGenericInterfaces()) - .filter(i -> - i instanceof ParameterizedType - && CustomType.class.isAssignableFrom((Class) ((ParameterizedType) i).getRawType()) - ).findFirst() - .map(i -> (ParameterizedType) i) - .orElseThrow(); - - var parameterType = (Class) customTypeInterface.getActualTypeArguments()[0]; - - c = customType.getConstructor(parameterType); - } catch (Exception e) { - throw new CustomTypeDeserializerException( - "Unable to find constructor for type: " + customType.getName(), - e - ); - } + try { + this.constructor = CustomTypeReflectionUtil.getCustomTypeConstructor(customType); + } catch (NoSuchMethodException e) { + throw new CustomTypeDeserializerException( + "Unable to find constructor for type: " + customType.getName(), + e + ); } - this.constructor = c; this.typeConverter = getTypeConverter( constructor.getParameterTypes()[0] ); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigDecimalJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigDecimalJavaType.java index e1974aa..01e5415 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigDecimalJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigDecimalJavaType.java @@ -1,6 +1,5 @@ package it.aboutbits.springboot.toolbox.persistence.javatype.base; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import lombok.SneakyThrows; import org.hibernate.type.descriptor.WrapperOptions; @@ -19,18 +18,11 @@ public abstract class WrappedBigDecimalJavaType protected WrappedBigDecimalJavaType(Class type) { super(type); - Constructor c; - if (type.isRecord()) { - c = RecordReflectionUtil.getCanonicalConstructor(type); - } else { - try { - c = type.getConstructor(BigDecimal.class); - } catch (NoSuchMethodException e) { - throw new IllegalStateException("No constructor found for " + type.getName(), e); - } + try { + this.constructor = type.getConstructor(BigDecimal.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); } - - this.constructor = c; } @Override diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigIntegerJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigIntegerJavaType.java index f96d10b..e22a8fb 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigIntegerJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBigIntegerJavaType.java @@ -1,6 +1,5 @@ package it.aboutbits.springboot.toolbox.persistence.javatype.base; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import lombok.SneakyThrows; import org.hibernate.type.descriptor.WrapperOptions; @@ -19,18 +18,11 @@ public abstract class WrappedBigIntegerJavaType protected WrappedBigIntegerJavaType(Class type) { super(type); - Constructor c; - if (type.isRecord()) { - c = RecordReflectionUtil.getCanonicalConstructor(type); - } else { - try { - c = type.getConstructor(BigInteger.class); - } catch (NoSuchMethodException e) { - throw new IllegalStateException("No constructor found for " + type.getName(), e); - } + try { + this.constructor = type.getConstructor(BigInteger.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); } - - this.constructor = c; } @Override diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedDoubleJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedDoubleJavaType.java index b9e9250..de8becf 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedDoubleJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedDoubleJavaType.java @@ -1,6 +1,5 @@ package it.aboutbits.springboot.toolbox.persistence.javatype.base; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import lombok.SneakyThrows; import org.hibernate.type.descriptor.WrapperOptions; @@ -18,18 +17,11 @@ public abstract class WrappedDoubleJavaType> extend protected WrappedDoubleJavaType(Class type) { super(type); - Constructor c; - if (type.isRecord()) { - c = RecordReflectionUtil.getCanonicalConstructor(type); - } else { - try { - c = type.getConstructor(Double.class); - } catch (NoSuchMethodException e) { - throw new IllegalStateException("No constructor found for " + type.getName(), e); - } + try { + this.constructor = type.getConstructor(Double.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); } - - this.constructor = c; } @Override diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedFloatJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedFloatJavaType.java index 55a7533..271daae 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedFloatJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedFloatJavaType.java @@ -1,6 +1,5 @@ package it.aboutbits.springboot.toolbox.persistence.javatype.base; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import lombok.SneakyThrows; import org.hibernate.type.descriptor.WrapperOptions; @@ -18,18 +17,11 @@ public abstract class WrappedFloatJavaType> extends protected WrappedFloatJavaType(Class type) { super(type); - Constructor c; - if (type.isRecord()) { - c = RecordReflectionUtil.getCanonicalConstructor(type); - } else { - try { - c = type.getConstructor(Float.class); - } catch (NoSuchMethodException e) { - throw new IllegalStateException("No constructor found for " + type.getName(), e); - } + try { + this.constructor = type.getConstructor(Float.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); } - - this.constructor = c; } @Override diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedIntegerJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedIntegerJavaType.java index 639785b..8a97853 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedIntegerJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedIntegerJavaType.java @@ -1,6 +1,5 @@ package it.aboutbits.springboot.toolbox.persistence.javatype.base; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import lombok.SneakyThrows; import org.hibernate.type.descriptor.WrapperOptions; @@ -18,18 +17,11 @@ public abstract class WrappedIntegerJavaType> exte protected WrappedIntegerJavaType(Class type) { super(type); - Constructor c; - if (type.isRecord()) { - c = RecordReflectionUtil.getCanonicalConstructor(type); - } else { - try { - c = type.getConstructor(Integer.class); - } catch (NoSuchMethodException e) { - throw new IllegalStateException("No constructor found for " + type.getName(), e); - } + try { + this.constructor = type.getConstructor(Integer.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); } - - this.constructor = c; } @Override diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedLongJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedLongJavaType.java index bfe42ef..eadaddb 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedLongJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedLongJavaType.java @@ -1,6 +1,5 @@ package it.aboutbits.springboot.toolbox.persistence.javatype.base; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import lombok.SneakyThrows; import org.hibernate.type.descriptor.WrapperOptions; @@ -15,22 +14,14 @@ public abstract class WrappedLongJavaType> extends AbstractClassJavaType { private final transient Constructor constructor; - @SneakyThrows protected WrappedLongJavaType(Class type) { super(type); - Constructor c; - if (type.isRecord()) { - c = RecordReflectionUtil.getCanonicalConstructor(type); - } else { - try { - c = type.getConstructor(Long.class); - } catch (NoSuchMethodException e) { - throw new IllegalStateException("No constructor found for " + type.getName(), e); - } + try { + this.constructor = type.getConstructor(Long.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); } - - this.constructor = c; } @Override diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedScaledBigDecimalJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedScaledBigDecimalJavaType.java index 5b9a2e8..db7cd1a 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedScaledBigDecimalJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedScaledBigDecimalJavaType.java @@ -1,6 +1,5 @@ package it.aboutbits.springboot.toolbox.persistence.javatype.base; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; import lombok.SneakyThrows; @@ -19,18 +18,11 @@ public abstract class WrappedScaledBigDecimalJavaType type) { super(type); - Constructor c; - if (type.isRecord()) { - c = RecordReflectionUtil.getCanonicalConstructor(type); - } else { - try { - c = type.getConstructor(ScaledBigDecimal.class); - } catch (NoSuchMethodException e) { - throw new IllegalStateException("No constructor found for " + type.getName(), e); - } + try { + this.constructor = type.getConstructor(ScaledBigDecimal.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); } - - this.constructor = c; } @Override diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedShortJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedShortJavaType.java index e4adb6d..3dac3f0 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedShortJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedShortJavaType.java @@ -1,6 +1,5 @@ package it.aboutbits.springboot.toolbox.persistence.javatype.base; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import lombok.SneakyThrows; import org.hibernate.type.descriptor.WrapperOptions; @@ -18,18 +17,11 @@ public abstract class WrappedShortJavaType> extends protected WrappedShortJavaType(Class type) { super(type); - Constructor c; - if (type.isRecord()) { - c = RecordReflectionUtil.getCanonicalConstructor(type); - } else { - try { - c = type.getConstructor(Short.class); - } catch (NoSuchMethodException e) { - throw new IllegalStateException("No constructor found for " + type.getName(), e); - } + try { + this.constructor = type.getConstructor(Short.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); } - - this.constructor = c; } @Override diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedStringJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedStringJavaType.java index 9daf9e7..fcd7a46 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedStringJavaType.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedStringJavaType.java @@ -1,6 +1,5 @@ package it.aboutbits.springboot.toolbox.persistence.javatype.base; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import lombok.SneakyThrows; import org.hibernate.type.descriptor.WrapperOptions; @@ -18,19 +17,11 @@ public abstract class WrappedStringJavaType> extend protected WrappedStringJavaType(Class type) { super(type); - Constructor c; - if (type.isRecord()) { - c = RecordReflectionUtil.getCanonicalConstructor(type); - } else { - try { - c = type.getConstructor(String.class); - } catch (NoSuchMethodException e) { - throw new IllegalStateException("No constructor found for " + type.getName(), e); - } + try { + this.constructor = type.getConstructor(String.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); } - - - this.constructor = c; } @Override diff --git a/src/main/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtil.java b/src/main/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtil.java new file mode 100644 index 0000000..96e5d1f --- /dev/null +++ b/src/main/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtil.java @@ -0,0 +1,34 @@ +package it.aboutbits.springboot.toolbox.reflection.util; + +import it.aboutbits.springboot.toolbox.type.CustomType; + +import java.lang.reflect.Constructor; +import java.lang.reflect.ParameterizedType; +import java.util.Arrays; + +public final class CustomTypeReflectionUtil { + private CustomTypeReflectionUtil() { + } + + public static > Constructor getCustomTypeConstructor(Class customType) throws NoSuchMethodException { + try { + return customType.getConstructor( + getWrappedType(customType) + ); + } catch (NoSuchMethodException | SecurityException e) { + throw new NoSuchMethodException(); + } + } + + public static Class getWrappedType(Class> customType) { + var customTypeInterface = Arrays.stream(customType.getGenericInterfaces()) + .filter(i -> + i instanceof ParameterizedType + && CustomType.class.isAssignableFrom((Class) ((ParameterizedType) i).getRawType()) + ).findFirst() + .map(i -> (ParameterizedType) i) + .orElseThrow(); + + return (Class) customTypeInterface.getActualTypeArguments()[0]; + } +} diff --git a/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java b/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java index 4f66df2..d9bab9c 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java @@ -4,7 +4,7 @@ import io.swagger.v3.core.converter.ModelConverter; import io.swagger.v3.core.converter.ModelConverterContext; import io.swagger.v3.oas.models.media.Schema; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; +import it.aboutbits.springboot.toolbox.reflection.util.CustomTypeReflectionUtil; import it.aboutbits.springboot.toolbox.swagger.SwaggerMetaUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; @@ -28,8 +28,10 @@ public Schema resolve( if (type instanceof Class clazz) { Schema result = null; if (CustomType.class.isAssignableFrom(clazz)) { - var constructor = RecordReflectionUtil.getCanonicalConstructor(clazz); - var wrappedType = constructor.getParameters()[0].getType(); + @SuppressWarnings("unchecked") + var wrappedType = CustomTypeReflectionUtil.getWrappedType( + (Class>) clazz + ); if (Short.class.isAssignableFrom(wrappedType)) { result = context.resolve(new AnnotatedType(Short.TYPE)); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypePropertyCustomizer.java b/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypePropertyCustomizer.java index bd58893..d296d32 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypePropertyCustomizer.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypePropertyCustomizer.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.databind.type.SimpleType; import io.swagger.v3.core.converter.AnnotatedType; import io.swagger.v3.oas.models.media.Schema; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; +import it.aboutbits.springboot.toolbox.reflection.util.CustomTypeReflectionUtil; import it.aboutbits.springboot.toolbox.swagger.SwaggerMetaUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; @@ -30,14 +30,11 @@ public Schema customize(Schema property, AnnotatedType annotatedType) { )); } - if (CustomType.class.isAssignableFrom(simpleType.getRawClass())) { - Class wrappedType; - if (rawClass.equals(EntityId.class)) { - wrappedType = simpleType.getBindings().getBoundType(0).getRawClass(); - } else { - var constructor = RecordReflectionUtil.getCanonicalConstructor(rawClass); - wrappedType = constructor.getParameters()[0].getType(); - } + if (CustomType.class.isAssignableFrom(rawClass)) { + @SuppressWarnings("unchecked") + var wrappedType = CustomTypeReflectionUtil.getWrappedType( + (Class>) rawClass + ); var isIdentity = EntityId.class.isAssignableFrom(rawClass); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/web/CustomTypePropertyEditor.java b/src/main/java/it/aboutbits/springboot/toolbox/web/CustomTypePropertyEditor.java index dd1ee16..6f95381 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/web/CustomTypePropertyEditor.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/web/CustomTypePropertyEditor.java @@ -1,7 +1,7 @@ package it.aboutbits.springboot.toolbox.web; import it.aboutbits.springboot.toolbox.jackson.CustomTypeDeserializer; -import it.aboutbits.springboot.toolbox.reflection.util.RecordReflectionUtil; +import it.aboutbits.springboot.toolbox.reflection.util.CustomTypeReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; import lombok.NonNull; @@ -10,10 +10,8 @@ import java.beans.PropertyEditorSupport; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.ParameterizedType; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.Arrays; import java.util.function.Function; public final class CustomTypePropertyEditor> extends PropertyEditorSupport { @@ -21,30 +19,15 @@ public final class CustomTypePropertyEditor> extends Pro private final Function typeConverter; public CustomTypePropertyEditor(@NonNull Class customType) { - Constructor c; - if (customType.isRecord()) { - c = RecordReflectionUtil.getCanonicalConstructor(customType); - } else { - try { - var customTypeInterface = Arrays.stream(customType.getGenericInterfaces()) - .filter(i -> - i instanceof ParameterizedType - && CustomType.class.isAssignableFrom((Class) ((ParameterizedType) i).getRawType()) - ).findFirst() - .map(i -> (ParameterizedType) i) - .orElseThrow(); - - var parameterType = (Class) customTypeInterface.getActualTypeArguments()[0]; - - c = customType.getConstructor(parameterType); - } catch (Exception e) { - throw new CustomTypeDeserializer.CustomTypeDeserializerException( - "Unable to find constructor for type: " + customType.getName(), - e - ); - } + try { + this.constructor = CustomTypeReflectionUtil.getCustomTypeConstructor(customType); + } catch (NoSuchMethodException e) { + throw new CustomTypeDeserializer.CustomTypeDeserializerException( + "Unable to find constructor for type: " + customType.getName(), + e + ); } - this.constructor = c; + this.typeConverter = getTextToTypeConverter( constructor.getParameters()[0].getType() ); diff --git a/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/persistence/impl/jpa/CustomTypeTestModel.java b/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/persistence/impl/jpa/CustomTypeTestModel.java index 73e2d15..08db44d 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/persistence/impl/jpa/CustomTypeTestModel.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/persistence/impl/jpa/CustomTypeTestModel.java @@ -1,8 +1,6 @@ package it.aboutbits.springboot.toolbox.autoconfiguration.persistence.impl.jpa; import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; -import it.aboutbits.springboot.toolbox.type.identity.EntityId; -import it.aboutbits.springboot.toolbox.type.identity.Identified; import it.aboutbits.springboot.toolbox.persistence.javatype.EmailAddressJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.IbanJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.ScaledBigDecimalJavaType; @@ -10,6 +8,8 @@ import it.aboutbits.springboot.toolbox.type.EmailAddress; import it.aboutbits.springboot.toolbox.type.Iban; import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; +import it.aboutbits.springboot.toolbox.type.identity.EntityId; +import it.aboutbits.springboot.toolbox.type.identity.Identified; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; diff --git a/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/persistence/impl/jpa/ReferencedTestModel.java b/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/persistence/impl/jpa/ReferencedTestModel.java index 38ca9a7..9c646bc 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/persistence/impl/jpa/ReferencedTestModel.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/persistence/impl/jpa/ReferencedTestModel.java @@ -1,8 +1,8 @@ package it.aboutbits.springboot.toolbox.autoconfiguration.persistence.impl.jpa; import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; -import it.aboutbits.springboot.toolbox.type.identity.EntityId; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedLongJavaType; +import it.aboutbits.springboot.toolbox.type.identity.EntityId; public class ReferencedTestModel { // we just use this to have and ID we can actually reference diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalClassJavaType.java index b9f3970..ec5b845 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalClassJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigDecimalClassJavaType.java @@ -3,7 +3,6 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedBigDecimalJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalClass; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalRecord; public final class WrapBigDecimalClassJavaType extends WrappedBigDecimalJavaType implements AutoRegisteredJavaType { public WrapBigDecimalClassJavaType() { diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerClassJavaType.java index c975700..708dbb7 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerClassJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBigIntegerClassJavaType.java @@ -3,7 +3,6 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedBigIntegerJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerClass; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerRecord; public final class WrapBigIntegerClassJavaType extends WrappedBigIntegerJavaType implements AutoRegisteredJavaType { public WrapBigIntegerClassJavaType() { diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleClassJavaType.java index 813a343..3effe47 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleClassJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapDoubleClassJavaType.java @@ -3,7 +3,6 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedDoubleJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleClass; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleRecord; public final class WrapDoubleClassJavaType extends WrappedDoubleJavaType implements AutoRegisteredJavaType { public WrapDoubleClassJavaType() { diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatClassJavaType.java index 0e4a5bb..6d6ea8f 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatClassJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapFloatClassJavaType.java @@ -3,7 +3,6 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedFloatJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatClass; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatRecord; public final class WrapFloatClassJavaType extends WrappedFloatJavaType implements AutoRegisteredJavaType { public WrapFloatClassJavaType() { diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerClassJavaType.java index dc8088d..18d9448 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerClassJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapIntegerClassJavaType.java @@ -3,7 +3,6 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedIntegerJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapIntegerClass; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapIntegerRecord; public final class WrapIntegerClassJavaType extends WrappedIntegerJavaType implements AutoRegisteredJavaType { public WrapIntegerClassJavaType() { diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongClassJavaType.java index b1a19e7..9e3d566 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongClassJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapLongClassJavaType.java @@ -3,7 +3,6 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedLongJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLongClass; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapLongRecord; public final class WrapLongClassJavaType extends WrappedLongJavaType implements AutoRegisteredJavaType { public WrapLongClassJavaType() { diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalClassJavaType.java index 9e2eb39..a667252 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalClassJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapScaledBigDecimalClassJavaType.java @@ -3,7 +3,6 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedScaledBigDecimalJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimalClass; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapScaledBigDecimalRecord; public final class WrapScaledBigDecimalClassJavaType extends WrappedScaledBigDecimalJavaType implements AutoRegisteredJavaType { public WrapScaledBigDecimalClassJavaType() { diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortClassJavaType.java index 8dc7e2d..f1d62d2 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortClassJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapShortClassJavaType.java @@ -3,7 +3,6 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedShortJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShortClass; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapShortRecord; public final class WrapShortClassJavaType extends WrappedShortJavaType implements AutoRegisteredJavaType { public WrapShortClassJavaType() { diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringClassJavaType.java index 3f7be66..def61a4 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringClassJavaType.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapStringClassJavaType.java @@ -3,7 +3,6 @@ import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedStringJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapStringClass; -import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapStringRecord; public final class WrapStringClassJavaType extends WrappedStringJavaType implements AutoRegisteredJavaType { public WrapStringClassJavaType() { diff --git a/src/test/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtilTest.java b/src/test/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtilTest.java new file mode 100644 index 0000000..7c6d5f6 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtilTest.java @@ -0,0 +1,89 @@ +package it.aboutbits.springboot.toolbox.reflection.util; + +import it.aboutbits.springboot.toolbox.autoconfiguration.web.CustomTypeScanner; +import it.aboutbits.springboot.toolbox.type.CustomType; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +class CustomTypeReflectionUtilTest { + @Test + void testGetCustomTypeConstructorWithValidCustomType() throws Exception { + // given + var customTypeClass = ValidCustomType.class; + + // when + var constructor = CustomTypeReflectionUtil.getCustomTypeConstructor(customTypeClass); + + // then + assertThat(constructor).isNotNull(); + assertThat(constructor.getParameterCount()).isEqualTo(1); + assertThat(constructor.getParameterTypes()[0]).isEqualTo(String.class); + } + + @Test + void testGetCustomTypeConstructorWithMissingConstructor() { + // given + var customTypeClass = InvalidCustomType.class; + + // then + assertThatExceptionOfType(NoSuchMethodException.class).isThrownBy( + () -> CustomTypeReflectionUtil.getCustomTypeConstructor(customTypeClass) // when + ); + } + + @Test + void testGetCustomTypeConstructorWithMismatchingConstructor() { + // given + var customTypeClass = OtherInvalidCustomType.class; + + // then + assertThatExceptionOfType(NoSuchMethodException.class).isThrownBy( + () -> CustomTypeReflectionUtil.getCustomTypeConstructor(customTypeClass) // when + ); + } + + @CustomTypeScanner.DisableCustomTypeConfiguration + public static class ValidCustomType implements CustomType { + private final String value; + + public ValidCustomType(Long otherValue) { + this.value = ""; + } + + public ValidCustomType(String value) { + this.value = value; + } + + @Override + public String value() { + return value; + } + } + + @CustomTypeScanner.DisableCustomTypeConfiguration + public static class InvalidCustomType implements CustomType { + @Override + public String value() { + return null; + } + + // Missing the required constructor + } + + @CustomTypeScanner.DisableCustomTypeConfiguration + public static class OtherInvalidCustomType implements CustomType { + private final String value; + + // wrong type constructor + public OtherInvalidCustomType(Long value) { + this.value = ""; + } + + @Override + public String value() { + return value; + } + } +} From 60af3f286adb4fae1de97f4151ac01889f17c0c3 Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Tue, 1 Apr 2025 14:45:34 +0200 Subject: [PATCH 3/6] add checkstyle exception --- .../toolbox/reflection/util/CustomTypeReflectionUtilTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtilTest.java b/src/test/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtilTest.java index 7c6d5f6..b36fc4a 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtilTest.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtilTest.java @@ -44,6 +44,7 @@ void testGetCustomTypeConstructorWithMismatchingConstructor() { ); } + @SuppressWarnings("checkstyle:RedundantModifier") @CustomTypeScanner.DisableCustomTypeConfiguration public static class ValidCustomType implements CustomType { private final String value; @@ -72,6 +73,7 @@ public String value() { // Missing the required constructor } + @SuppressWarnings("checkstyle:RedundantModifier") @CustomTypeScanner.DisableCustomTypeConfiguration public static class OtherInvalidCustomType implements CustomType { private final String value; From 6777f8049f4d6ae303e294ea2ed2981df1127469 Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Tue, 1 Apr 2025 15:04:48 +0200 Subject: [PATCH 4/6] fix reflection for inheritance --- .../util/CustomTypeReflectionUtil.java | 30 ++++++++++----- .../type/CustomTypeModelConverter.java | 2 + .../type/CustomTypePropertyCustomizer.java | 2 + .../util/CustomTypeReflectionUtilTest.java | 37 +++++++++++++++++++ 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/main/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtil.java b/src/main/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtil.java index 96e5d1f..a8700a6 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtil.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtil.java @@ -20,15 +20,25 @@ public static > Constructor getCustomTypeConstructor( } } - public static Class getWrappedType(Class> customType) { - var customTypeInterface = Arrays.stream(customType.getGenericInterfaces()) - .filter(i -> - i instanceof ParameterizedType - && CustomType.class.isAssignableFrom((Class) ((ParameterizedType) i).getRawType()) - ).findFirst() - .map(i -> (ParameterizedType) i) - .orElseThrow(); - - return (Class) customTypeInterface.getActualTypeArguments()[0]; + public static Class getWrappedType(Class> customType) throws NoSuchMethodException { + Class currentClass = customType; + while (currentClass != null) { + // Check interfaces of the current class + var customTypeInterface = Arrays.stream(currentClass.getGenericInterfaces()) + .filter(i -> + i instanceof ParameterizedType + && CustomType.class.isAssignableFrom((Class) ((ParameterizedType) i).getRawType()) + ).findFirst() + .map(i -> (ParameterizedType) i); + + if (customTypeInterface.isPresent()) { + return (Class) customTypeInterface.get().getActualTypeArguments()[0]; + } + + // Move to the parent class + currentClass = currentClass.getSuperclass(); + } + + throw new NoSuchMethodException(); } } diff --git a/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java b/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java index d9bab9c..866b983 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java @@ -9,6 +9,7 @@ import it.aboutbits.springboot.toolbox.type.CustomType; import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; import it.aboutbits.springboot.toolbox.type.identity.EntityId; +import lombok.SneakyThrows; import java.math.BigDecimal; import java.math.BigInteger; @@ -17,6 +18,7 @@ public class CustomTypeModelConverter implements ModelConverter { @Override + @SneakyThrows(NoSuchMethodException.class) public Schema resolve( AnnotatedType annotatedType, ModelConverterContext context, diff --git a/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypePropertyCustomizer.java b/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypePropertyCustomizer.java index d296d32..6af500f 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypePropertyCustomizer.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypePropertyCustomizer.java @@ -8,6 +8,7 @@ import it.aboutbits.springboot.toolbox.type.CustomType; import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; import it.aboutbits.springboot.toolbox.type.identity.EntityId; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springdoc.core.customizers.PropertyCustomizer; @@ -17,6 +18,7 @@ @Slf4j public class CustomTypePropertyCustomizer implements PropertyCustomizer { @Override + @SneakyThrows(NoSuchMethodException.class) public Schema customize(Schema property, AnnotatedType annotatedType) { var type = annotatedType.getType(); diff --git a/src/test/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtilTest.java b/src/test/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtilTest.java index b36fc4a..48c9f7c 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtilTest.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/reflection/util/CustomTypeReflectionUtilTest.java @@ -44,6 +44,20 @@ void testGetCustomTypeConstructorWithMismatchingConstructor() { ); } + @Test + void testGetCustomTypeConstructorWithInheritedCustomType() throws Exception { + // given + var customTypeClass = ChildClass.class; + + // when + var constructor = CustomTypeReflectionUtil.getCustomTypeConstructor(customTypeClass); + + // then + assertThat(constructor).isNotNull(); + assertThat(constructor.getParameterCount()).isEqualTo(1); + assertThat(constructor.getParameterTypes()[0]).isEqualTo(Integer.class); + } + @SuppressWarnings("checkstyle:RedundantModifier") @CustomTypeScanner.DisableCustomTypeConfiguration public static class ValidCustomType implements CustomType { @@ -88,4 +102,27 @@ public String value() { return value; } } + + @SuppressWarnings("checkstyle:RedundantModifier") + @CustomTypeScanner.DisableCustomTypeConfiguration + public static class ParentClass implements CustomType { + private final Integer value; + + public ParentClass(Integer value) { + this.value = value; + } + + @Override + public Integer value() { + return value; + } + } + + @SuppressWarnings("checkstyle:RedundantModifier") + @CustomTypeScanner.DisableCustomTypeConfiguration + public static class ChildClass extends ParentClass { + public ChildClass(Integer value) { + super(value); + } + } } From 3b86ba1a846d8e7703ad2dc1cfb0e1e73d457076 Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Wed, 2 Apr 2025 10:25:46 +0200 Subject: [PATCH 5/6] add double suffix --- .../persistence/javatype/WrapperTypesJpaTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/WrapperTypesJpaTest.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/WrapperTypesJpaTest.java index 0369b78..01f74bc 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/WrapperTypesJpaTest.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/WrapperTypesJpaTest.java @@ -58,7 +58,7 @@ void givenNull_inAndOut_shouldSucceed() { } @ParameterizedTest - @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) + @ValueSource(doubles = {-1, 0, 1, -0.001d, 0.001d, -100_000_000, 100_000_000}) void givenValues_inAndOut_shouldSucceed(double doubleValue) { var item = new WrapperTypesModel(); item.setBigDecimalValue(new WrapBigDecimalRecord(BigDecimal.valueOf(doubleValue))); @@ -126,7 +126,7 @@ void givenNull_inAndOut_shouldSucceed() { } @ParameterizedTest - @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) + @ValueSource(doubles = {-1, 0, 1, -0.001d, 0.001d, -100_000_000, 100_000_000}) void givenValues_inAndOut_shouldSucceed(double doubleValue) { var item = new WrapperTypesModel(); item.setDoubleValue(new WrapDoubleRecord(doubleValue)); @@ -262,7 +262,7 @@ void givenNull_inAndOut_shouldSucceed() { } @ParameterizedTest - @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) + @ValueSource(doubles = {-1, 0, 1, -0.001d, 0.001d, -100_000_000, 100_000_000}) void givenValues_inAndOut_shouldSucceed(double doubleValue) { var item = new WrapperTypesModel(); item.setScaledBigDecimalValue(new WrapScaledBigDecimalRecord(new ScaledBigDecimal(doubleValue))); @@ -367,7 +367,7 @@ void givenNull_inAndOut_shouldSucceed() { } @ParameterizedTest - @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) + @ValueSource(doubles = {-1, 0, 1, -0.001d, 0.001d, -100_000_000, 100_000_000}) void givenValues_inAndOut_shouldSucceed(double doubleValue) { var item = new WrapperTypesModel(); item.setBigDecimalValueClass(new WrapBigDecimalClass(BigDecimal.valueOf(doubleValue))); @@ -435,7 +435,7 @@ void givenNull_inAndOut_shouldSucceed() { } @ParameterizedTest - @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) + @ValueSource(doubles = {-1, 0, 1, -0.001d, 0.001d, -100_000_000, 100_000_000}) void givenValues_inAndOut_shouldSucceed(double doubleValue) { var item = new WrapperTypesModel(); item.setDoubleValueClass(new WrapDoubleClass(doubleValue)); @@ -571,7 +571,7 @@ void givenNull_inAndOut_shouldSucceed() { } @ParameterizedTest - @ValueSource(doubles = {-1, 0, 1, -0.001, 0.001, -100_000_000, 100_000_000}) + @ValueSource(doubles = {-1, 0, 1, -0.001d, 0.001d, -100_000_000, 100_000_000}) void givenValues_inAndOut_shouldSucceed(double doubleValue) { var item = new WrapperTypesModel(); item.setScaledBigDecimalValueClass(new WrapScaledBigDecimalClass(new ScaledBigDecimal(doubleValue))); From cb7c9b9e2e30a1b2a0be324623b650a5d292aaa3 Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Wed, 2 Apr 2025 11:20:23 +0200 Subject: [PATCH 6/6] add missing primitive types --- .../jackson/CustomTypeDeserializer.java | 43 ++++ .../javatype/base/WrappedBooleanJavaType.java | 70 ++++++ .../javatype/base/WrappedByteJavaType.java | 70 ++++++ .../base/WrappedCharacterJavaType.java | 76 +++++++ .../type/CustomTypeModelConverter.java | 9 + .../type/CustomTypePropertyCustomizer.java | 28 ++- .../toolbox/web/CustomTypePropertyEditor.java | 14 ++ .../javatype/WrapperTypesJpaTest.java | 210 ++++++++++++++++++ .../javatype/WrapBooleanClassJavaType.java | 11 + .../javatype/WrapBooleanRecordJavaType.java | 11 + .../impl/javatype/WrapByteClassJavaType.java | 11 + .../impl/javatype/WrapByteRecordJavaType.java | 11 + .../javatype/WrapCharacterClassJavaType.java | 11 + .../javatype/WrapCharacterRecordJavaType.java | 11 + .../javatype/impl/jpa/WrapperTypesModel.java | 37 +++ .../impl/jpa/WrapperTypesModelRepository.java | 18 ++ .../javatype/impl/type/WrapBooleanClass.java | 15 ++ .../javatype/impl/type/WrapBooleanRecord.java | 7 + .../javatype/impl/type/WrapByteClass.java | 15 ++ .../javatype/impl/type/WrapByteRecord.java | 7 + .../impl/type/WrapCharacterClass.java | 15 ++ .../impl/type/WrapCharacterRecord.java | 7 + ...9-06-create-wrapper-type-testing-table.yml | 18 ++ 23 files changed, 724 insertions(+), 1 deletion(-) create mode 100644 src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBooleanJavaType.java create mode 100644 src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedByteJavaType.java create mode 100644 src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedCharacterJavaType.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBooleanClassJavaType.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBooleanRecordJavaType.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapByteClassJavaType.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapByteRecordJavaType.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapCharacterClassJavaType.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapCharacterRecordJavaType.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBooleanClass.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBooleanRecord.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapByteClass.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapByteRecord.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapCharacterClass.java create mode 100644 src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapCharacterRecord.java diff --git a/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java b/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java index fe23ee3..a21106a 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java @@ -56,9 +56,18 @@ public T deserialize(JsonParser jsonParser, DeserializationContext deserializati } private static Function getTypeConverter(Class wrappedType) { + if (Byte.class.isAssignableFrom(wrappedType)) { + return getByteConverter(); + } + if (Boolean.class.isAssignableFrom(wrappedType)) { + return getBooleanConverter(); + } if (String.class.isAssignableFrom(wrappedType)) { return getStringConverter(); } + if (Character.class.isAssignableFrom(wrappedType)) { + return getCharConverter(); + } if (Short.class.isAssignableFrom(wrappedType)) { return getShortConverter(); } @@ -86,6 +95,26 @@ private static Function getTypeConverter(Class wrappedTyp throw new CustomTypeDeserializerException("Value type not supported: " + wrappedType.getName()); } + private static Function getByteConverter() { + return jsonParser -> { + try { + return jsonParser.getByteValue(); + } catch (IOException e) { + throw new CustomTypeDeserializerException("Failed to read value as Byte.", e); + } + }; + } + + private static Function getBooleanConverter() { + return jsonParser -> { + try { + return jsonParser.getBooleanValue(); + } catch (IOException e) { + throw new CustomTypeDeserializerException("Failed to read value as Boolean.", e); + } + }; + } + private static Function getScaledBigDecimalConverter() { return jsonParser -> { try { @@ -176,6 +205,20 @@ private static Function getStringConverter() { }; } + private static Function getCharConverter() { + return jsonParser -> { + try { + var value = jsonParser.getValueAsString(); + if (value == null || value.length() != 1) { + throw new IOException(); + } + return value.charAt(0); + } catch (IOException e) { + throw new CustomTypeDeserializerException("Failed to read value as Char.", e); + } + }; + } + public static final class CustomTypeDeserializerException extends RuntimeException { public CustomTypeDeserializerException(String message) { super(message); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBooleanJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBooleanJavaType.java new file mode 100644 index 0000000..8ccc5c8 --- /dev/null +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedBooleanJavaType.java @@ -0,0 +1,70 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.base; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.SneakyThrows; +import org.hibernate.type.descriptor.WrapperOptions; +import org.hibernate.type.descriptor.java.AbstractClassJavaType; +import org.hibernate.type.descriptor.jdbc.JdbcType; +import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.sql.Types; + +public abstract class WrappedBooleanJavaType> extends AbstractClassJavaType { + private final transient Constructor constructor; + + protected WrappedBooleanJavaType(Class type) { + super(type); + + try { + this.constructor = type.getConstructor(Boolean.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); + } + } + + @Override + public JdbcType getRecommendedJdbcType(JdbcTypeIndicators indicators) { + return indicators.getTypeConfiguration() + .getJdbcTypeRegistry() + .getDescriptor(Types.BOOLEAN); + } + + @SuppressWarnings("unchecked") + @Override + public X unwrap(T id, Class aClass, WrapperOptions wrapperOptions) { + var javaTypeClass = getJavaTypeClass(); + + if (id == null) { + return null; + } + if (javaTypeClass.isAssignableFrom(aClass)) { + return (X) id; + } + if (Boolean.class.isAssignableFrom(aClass)) { + return (X) id.value(); + } + + throw unknownUnwrap(aClass); + } + + @SuppressWarnings("unchecked") + @SneakyThrows({InstantiationException.class, IllegalAccessException.class, InvocationTargetException.class}) + @Override + public T wrap(X value, WrapperOptions wrapperOptions) { + var clazz = getJavaTypeClass(); + + if (value == null) { + return null; + } + if (clazz.isInstance(value)) { + return (T) value; + } + if (value instanceof Boolean booleanValue) { + return constructor.newInstance(booleanValue); + } + + throw unknownWrap(value.getClass()); + } +} diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedByteJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedByteJavaType.java new file mode 100644 index 0000000..300c4ed --- /dev/null +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedByteJavaType.java @@ -0,0 +1,70 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.base; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.SneakyThrows; +import org.hibernate.type.descriptor.WrapperOptions; +import org.hibernate.type.descriptor.java.AbstractClassJavaType; +import org.hibernate.type.descriptor.jdbc.JdbcType; +import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.sql.Types; + +public abstract class WrappedByteJavaType> extends AbstractClassJavaType { + private final transient Constructor constructor; + + protected WrappedByteJavaType(Class type) { + super(type); + + try { + this.constructor = type.getConstructor(Byte.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); + } + } + + @Override + public JdbcType getRecommendedJdbcType(JdbcTypeIndicators indicators) { + return indicators.getTypeConfiguration() + .getJdbcTypeRegistry() + .getDescriptor(Types.TINYINT); + } + + @SuppressWarnings("unchecked") + @Override + public X unwrap(T id, Class aClass, WrapperOptions wrapperOptions) { + var javaTypeClass = getJavaTypeClass(); + + if (id == null) { + return null; + } + if (javaTypeClass.isAssignableFrom(aClass)) { + return (X) id; + } + if (Byte.class.isAssignableFrom(aClass)) { + return (X) id.value(); + } + + throw unknownUnwrap(aClass); + } + + @SuppressWarnings("unchecked") + @SneakyThrows({InstantiationException.class, IllegalAccessException.class, InvocationTargetException.class}) + @Override + public T wrap(X value, WrapperOptions wrapperOptions) { + var clazz = getJavaTypeClass(); + + if (value == null) { + return null; + } + if (clazz.isInstance(value)) { + return (T) value; + } + if (value instanceof Byte byteValue) { + return constructor.newInstance(byteValue); + } + + throw unknownWrap(value.getClass()); + } +} diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedCharacterJavaType.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedCharacterJavaType.java new file mode 100644 index 0000000..7400993 --- /dev/null +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedCharacterJavaType.java @@ -0,0 +1,76 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.base; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.SneakyThrows; +import org.hibernate.type.descriptor.WrapperOptions; +import org.hibernate.type.descriptor.java.AbstractClassJavaType; +import org.hibernate.type.descriptor.jdbc.JdbcType; +import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.sql.Types; + +public abstract class WrappedCharacterJavaType> extends AbstractClassJavaType { + private final transient Constructor constructor; + + protected WrappedCharacterJavaType(Class type) { + super(type); + + try { + this.constructor = type.getConstructor(Character.class); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("No constructor found for " + type.getName(), e); + } + } + + @Override + public JdbcType getRecommendedJdbcType(JdbcTypeIndicators indicators) { + return indicators.getTypeConfiguration() + .getJdbcTypeRegistry() + .getDescriptor(Types.CHAR); + } + + @SuppressWarnings("unchecked") + @Override + public X unwrap(T id, Class aClass, WrapperOptions wrapperOptions) { + var javaTypeClass = getJavaTypeClass(); + + if (id == null) { + return null; + } + if (javaTypeClass.isAssignableFrom(aClass)) { + return (X) id; + } + if (Character.class.isAssignableFrom(aClass)) { + return (X) id.value(); + } + if (String.class.isAssignableFrom(aClass)) { + return (X) String.valueOf(id.value()); + } + + throw unknownUnwrap(aClass); + } + + @SuppressWarnings("unchecked") + @SneakyThrows({InstantiationException.class, IllegalAccessException.class, InvocationTargetException.class}) + @Override + public T wrap(X value, WrapperOptions wrapperOptions) { + var clazz = getJavaTypeClass(); + + if (value == null) { + return null; + } + if (clazz.isInstance(value)) { + return (T) value; + } + if (value instanceof Character charValue) { + return constructor.newInstance(charValue); + } + if (value instanceof String stringValue && stringValue.length() == 1) { + return constructor.newInstance(stringValue.charAt(0)); + } + + throw unknownWrap(value.getClass()); + } +} diff --git a/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java b/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java index 866b983..66e1e77 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypeModelConverter.java @@ -35,6 +35,12 @@ public Schema resolve( (Class>) clazz ); + if (Boolean.class.isAssignableFrom(wrappedType)) { + result = context.resolve(new AnnotatedType(Boolean.TYPE)); + } + if (Byte.class.isAssignableFrom(wrappedType)) { + result = context.resolve(new AnnotatedType(Byte.TYPE)); + } if (Short.class.isAssignableFrom(wrappedType)) { result = context.resolve(new AnnotatedType(Short.TYPE)); } @@ -62,6 +68,9 @@ public Schema resolve( if (String.class.isAssignableFrom(wrappedType)) { result = context.resolve(new AnnotatedType(String.class)); } + if (Character.class.isAssignableFrom(wrappedType)) { + result = context.resolve(new AnnotatedType(Character.TYPE)); + } if (result != null) { var isIdentity = EntityId.class.isAssignableFrom(clazz); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypePropertyCustomizer.java b/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypePropertyCustomizer.java index 6af500f..169e024 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypePropertyCustomizer.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/swagger/type/CustomTypePropertyCustomizer.java @@ -42,6 +42,22 @@ public Schema customize(Schema property, AnnotatedType annotatedType) { var description = SwaggerMetaUtil.setIsIdentity(property.getDescription(), isIdentity); + if (Boolean.class.isAssignableFrom(wrappedType)) { + property.type("boolean"); + property.format(null); + property.setDescription(description); + property.setProperties(null); + property.set$ref(null); + return property; + } + if (Byte.class.isAssignableFrom(wrappedType)) { + property.type("integer"); + property.format(""); + property.setDescription(description); + property.setProperties(null); + property.set$ref(null); + return property; + } if (Short.class.isAssignableFrom(wrappedType)) { property.type("integer"); property.format(""); @@ -98,7 +114,6 @@ public Schema customize(Schema property, AnnotatedType annotatedType) { property.set$ref(null); return property; } - if (ScaledBigDecimal.class.isAssignableFrom(wrappedType)) { property.type("number"); property.format(""); @@ -115,6 +130,17 @@ public Schema customize(Schema property, AnnotatedType annotatedType) { property.set$ref(null); return property; } + if (Character.class.isAssignableFrom(wrappedType)) { + property.type("string"); + property.format(null); + property.minLength(1); + property.maxLength(1); + property.setDescription(description); + property.setProperties(null); + property.set$ref(null); + return property; + } + log.warn("Property {} of type WrappedValue: Can not resolve parameter type!", property.getName()); } } diff --git a/src/main/java/it/aboutbits/springboot/toolbox/web/CustomTypePropertyEditor.java b/src/main/java/it/aboutbits/springboot/toolbox/web/CustomTypePropertyEditor.java index 6f95381..e76a007 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/web/CustomTypePropertyEditor.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/web/CustomTypePropertyEditor.java @@ -59,9 +59,23 @@ public void setAsText(String text) throws IllegalArgumentException { } private static Function getTextToTypeConverter(Class wrappedType) { + if (Boolean.class.isAssignableFrom(wrappedType)) { + return Boolean::parseBoolean; + } if (String.class.isAssignableFrom(wrappedType)) { return text -> text; } + if (Character.class.isAssignableFrom(wrappedType)) { + return text -> { + if (text == null || text.length() != 1) { + throw new IllegalArgumentException("Unable to convert text to type: " + wrappedType.getName()); + } + return text.charAt(0); + }; + } + if (Byte.class.isAssignableFrom(wrappedType)) { + return Byte::parseByte; + } if (Short.class.isAssignableFrom(wrappedType)) { return Short::parseShort; } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/WrapperTypesJpaTest.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/WrapperTypesJpaTest.java index 01f74bc..54a8779 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/WrapperTypesJpaTest.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/WrapperTypesJpaTest.java @@ -6,6 +6,12 @@ import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalRecord; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerClass; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBooleanClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBooleanRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapByteClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapByteRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapCharacterClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapCharacterRecord; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleClass; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleRecord; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatClass; @@ -345,6 +351,108 @@ void givenValues_inAndOut_shouldSucceed(String stringValue) { .isEqualTo(savedItem); } } + + @Nested + class WrapCharacterRecordType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setCharValue(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByCharValue(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(chars = {'t', 's', '\r', '\n'}) + void givenValues_inAndOut_shouldSucceed(Character charValue) { + var item = new WrapperTypesModel(); + item.setCharValue(new WrapCharacterRecord(charValue)); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByCharValue(savedItem.getCharValue()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + } + + @Nested + class WrapByteRecordType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setByteValue(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByByteValue(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(bytes = {-1, 0, 1, -128, 127}) + void givenValues_inAndOut_shouldSucceed(Byte byteValue) { + var item = new WrapperTypesModel(); + item.setByteValue(new WrapByteRecord(byteValue)); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByByteValue(savedItem.getByteValue()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + } + + @Nested + class WrapBooleanRecordType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setBoolValue(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByBoolValue(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void givenValues_inAndOut_shouldSucceed(Boolean boolValue) { + var item = new WrapperTypesModel(); + item.setBoolValue(new WrapBooleanRecord(boolValue)); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByBoolValue(savedItem.getBoolValue()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + } } @Nested @@ -654,5 +762,107 @@ void givenValues_inAndOut_shouldSucceed(String stringValue) { .isEqualTo(savedItem); } } + + @Nested + class WrapCharacterClassType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setCharValue(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByCharValue(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(chars = {'t', 's', '\r', '\n'}) + void givenValues_inAndOut_shouldSucceed(Character charValue) { + var item = new WrapperTypesModel(); + item.setCharValueClass(new WrapCharacterClass(charValue)); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByCharValueClass(savedItem.getCharValueClass()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + } + + @Nested + class WrapByteClassType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setByteValue(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByByteValue(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(bytes = {-1, 0, 1, -128, 127}) + void givenValues_inAndOut_shouldSucceed(Byte byteValue) { + var item = new WrapperTypesModel(); + item.setByteValueClass(new WrapByteClass(byteValue)); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByByteValueClass(savedItem.getByteValueClass()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + } + + @Nested + class WrapBooleanClassType { + @Test + void givenNull_inAndOut_shouldSucceed() { + var item = new WrapperTypesModel(); + item.setBoolValue(null); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByBoolValue(null); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void givenValues_inAndOut_shouldSucceed(Boolean boolValue) { + var item = new WrapperTypesModel(); + item.setBoolValueClass(new WrapBooleanClass(boolValue)); + + var savedItem = repository.save(item); + + var retrievedItem = repository.findByBoolValueClass(savedItem.getBoolValueClass()); + + assertThat(retrievedItem).isPresent() + .get() + .usingRecursiveComparison() + .isEqualTo(savedItem); + } + } } } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBooleanClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBooleanClassJavaType.java new file mode 100644 index 0000000..a2af7fa --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBooleanClassJavaType.java @@ -0,0 +1,11 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedBooleanJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBooleanClass; + +public final class WrapBooleanClassJavaType extends WrappedBooleanJavaType implements AutoRegisteredJavaType { + public WrapBooleanClassJavaType() { + super(WrapBooleanClass.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBooleanRecordJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBooleanRecordJavaType.java new file mode 100644 index 0000000..3514fc7 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapBooleanRecordJavaType.java @@ -0,0 +1,11 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedBooleanJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBooleanRecord; + +public final class WrapBooleanRecordJavaType extends WrappedBooleanJavaType implements AutoRegisteredJavaType { + public WrapBooleanRecordJavaType() { + super(WrapBooleanRecord.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapByteClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapByteClassJavaType.java new file mode 100644 index 0000000..987f4bb --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapByteClassJavaType.java @@ -0,0 +1,11 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedByteJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapByteClass; + +public final class WrapByteClassJavaType extends WrappedByteJavaType implements AutoRegisteredJavaType { + public WrapByteClassJavaType() { + super(WrapByteClass.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapByteRecordJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapByteRecordJavaType.java new file mode 100644 index 0000000..ce2992c --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapByteRecordJavaType.java @@ -0,0 +1,11 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedByteJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapByteRecord; + +public final class WrapByteRecordJavaType extends WrappedByteJavaType implements AutoRegisteredJavaType { + public WrapByteRecordJavaType() { + super(WrapByteRecord.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapCharacterClassJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapCharacterClassJavaType.java new file mode 100644 index 0000000..d83cccc --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapCharacterClassJavaType.java @@ -0,0 +1,11 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedCharacterJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapCharacterClass; + +public final class WrapCharacterClassJavaType extends WrappedCharacterJavaType implements AutoRegisteredJavaType { + public WrapCharacterClassJavaType() { + super(WrapCharacterClass.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapCharacterRecordJavaType.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapCharacterRecordJavaType.java new file mode 100644 index 0000000..b044f46 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/javatype/WrapCharacterRecordJavaType.java @@ -0,0 +1,11 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype; + +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.AutoRegisteredJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.base.WrappedCharacterJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapCharacterRecord; + +public final class WrapCharacterRecordJavaType extends WrappedCharacterJavaType implements AutoRegisteredJavaType { + public WrapCharacterRecordJavaType() { + super(WrapCharacterRecord.class); + } +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModel.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModel.java index edd5e1c..6be216d 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModel.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModel.java @@ -6,6 +6,12 @@ import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapBigDecimalRecordJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapBigIntegerClassJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapBigIntegerRecordJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapBooleanClassJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapBooleanRecordJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapByteClassJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapByteRecordJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapCharacterClassJavaType; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapCharacterRecordJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapDoubleClassJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapDoubleRecordJavaType; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.javatype.WrapFloatClassJavaType; @@ -24,6 +30,12 @@ import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalRecord; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerClass; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBooleanClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBooleanRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapByteClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapByteRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapCharacterClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapCharacterRecord; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleClass; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleRecord; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatClass; @@ -91,10 +103,22 @@ public class WrapperTypesModel implements Identified { @JavaType(WrapShortRecordJavaType.class) private WrapShortRecord shortValue; + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapByteRecordJavaType.class) + private WrapByteRecord byteValue; + @SuppressWarnings("JpaAttributeTypeInspection") @JavaType(WrapStringRecordJavaType.class) private WrapStringRecord stringValue; + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapCharacterRecordJavaType.class) + private WrapCharacterRecord charValue; + + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapBooleanRecordJavaType.class) + private WrapBooleanRecord boolValue; + @SuppressWarnings("JpaAttributeTypeInspection") @JavaType(WrapBigDecimalClassJavaType.class) private WrapBigDecimalClass bigDecimalValueClass; @@ -127,10 +151,23 @@ public class WrapperTypesModel implements Identified { @JavaType(WrapShortClassJavaType.class) private WrapShortClass shortValueClass; + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapByteClassJavaType.class) + private WrapByteClass byteValueClass; + @SuppressWarnings("JpaAttributeTypeInspection") @JavaType(WrapStringClassJavaType.class) private WrapStringClass stringValueClass; + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapCharacterClassJavaType.class) + private WrapCharacterClass charValueClass; + + @SuppressWarnings("JpaAttributeTypeInspection") + @JavaType(WrapBooleanClassJavaType.class) + private WrapBooleanClass boolValueClass; + + public record ID( Long value ) implements EntityId { diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModelRepository.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModelRepository.java index 9705ff8..10b271f 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModelRepository.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModelRepository.java @@ -4,6 +4,12 @@ import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigDecimalRecord; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerClass; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBigIntegerRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBooleanClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapBooleanRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapByteClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapByteRecord; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapCharacterClass; +import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapCharacterRecord; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleClass; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapDoubleRecord; import it.aboutbits.springboot.toolbox.persistence.javatype.impl.type.WrapFloatClass; @@ -41,6 +47,12 @@ public interface WrapperTypesModelRepository extends JpaRepository findByStringValue(WrapStringRecord value); + Optional findByBoolValue(WrapBooleanRecord value); + + Optional findByByteValue(WrapByteRecord value); + + Optional findByCharValue(WrapCharacterRecord value); + Optional findByBigDecimalValueClass(WrapBigDecimalClass value); Optional findByBigIntegerValueClass(WrapBigIntegerClass value); @@ -58,4 +70,10 @@ public interface WrapperTypesModelRepository extends JpaRepository findByShortValueClass(WrapShortClass value); Optional findByStringValueClass(WrapStringClass value); + + Optional findByBoolValueClass(WrapBooleanClass value); + + Optional findByByteValueClass(WrapByteClass value); + + Optional findByCharValueClass(WrapCharacterClass value); } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBooleanClass.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBooleanClass.java new file mode 100644 index 0000000..70325a9 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBooleanClass.java @@ -0,0 +1,15 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@RequiredArgsConstructor +public class WrapBooleanClass implements CustomType { + private final Boolean value; +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBooleanRecord.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBooleanRecord.java new file mode 100644 index 0000000..f0319ae --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapBooleanRecord.java @@ -0,0 +1,7 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; + +public record WrapBooleanRecord(Boolean value) implements CustomType { + +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapByteClass.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapByteClass.java new file mode 100644 index 0000000..6f15e3a --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapByteClass.java @@ -0,0 +1,15 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@RequiredArgsConstructor +public class WrapByteClass implements CustomType { + private final Byte value; +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapByteRecord.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapByteRecord.java new file mode 100644 index 0000000..a30f64e --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapByteRecord.java @@ -0,0 +1,7 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; + +public record WrapByteRecord(Byte value) implements CustomType { + +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapCharacterClass.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapCharacterClass.java new file mode 100644 index 0000000..46c0e6d --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapCharacterClass.java @@ -0,0 +1,15 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@RequiredArgsConstructor +public class WrapCharacterClass implements CustomType { + private final Character value; +} diff --git a/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapCharacterRecord.java b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapCharacterRecord.java new file mode 100644 index 0000000..3a52373 --- /dev/null +++ b/src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/type/WrapCharacterRecord.java @@ -0,0 +1,7 @@ +package it.aboutbits.springboot.toolbox.persistence.javatype.impl.type; + +import it.aboutbits.springboot.toolbox.type.CustomType; + +public record WrapCharacterRecord(Character value) implements CustomType { + +} diff --git a/src/test/resources/db/changelog/2024-09-06-create-wrapper-type-testing-table.yml b/src/test/resources/db/changelog/2024-09-06-create-wrapper-type-testing-table.yml index 6276531..fd963ca 100644 --- a/src/test/resources/db/changelog/2024-09-06-create-wrapper-type-testing-table.yml +++ b/src/test/resources/db/changelog/2024-09-06-create-wrapper-type-testing-table.yml @@ -37,9 +37,18 @@ databaseChangeLog: - column: name: short_value type: bigint + - column: + name: byte_value + type: integer - column: name: string_value type: text + - column: + name: char_value + type: char + - column: + name: bool_value + type: boolean - column: name: big_decimal_value_class type: double @@ -64,6 +73,15 @@ databaseChangeLog: - column: name: short_value_class type: bigint + - column: + name: byte_value_class + type: integer - column: name: string_value_class type: text + - column: + name: char_value_class + type: char + - column: + name: bool_value_class + type: boolean