From 1d12dc0499b224563c070814d2b0feb560e27c50 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Thu, 29 Aug 2024 22:13:29 +0200 Subject: [PATCH] HHH-18547, HHH-17114 add default implementations to UserType and deprecate the wrong-signature nullSafeGet() method Signed-off-by: Gavin King --- .../java/org/hibernate/type/EnumType.java | 6 +- .../usertype/BaseUserTypeSupport.java | 2 +- .../usertype/StaticUserTypeSupport.java | 6 +- .../java/org/hibernate/usertype/UserType.java | 94 ++++++++++++++++--- .../embeddables/DollarValueUserType.java | 5 +- .../embeddables/MyDateUserType.java | 5 +- .../custom_types/FirstLetterType.java | 5 +- .../custom_types/LastNumberType.java | 5 +- .../test/annotations/generics/StateType.java | 6 +- .../dynamicparameterized/MyGenericType.java | 6 +- .../dynamicparameterized/MyStringType.java | 6 +- .../orm/test/boot/models/xml/MyUserType.java | 2 +- ...AvailableDuringCustomUserTypeInitTest.java | 6 +- .../hibernate/orm/test/cdi/type/UrlType.java | 6 +- .../orm/test/hql/ClassificationType.java | 6 +- .../id/usertype/UserTypeComparableIdTest.java | 4 +- .../usertype/UserTypeNonComparableIdTest.java | 4 +- .../query/QueryParametersValidationTest.java | 3 +- .../jpa/query/TypedValueParametersTest.java | 3 +- .../basic/RepeatedMappingUserTypeTests.java | 3 +- .../mapping/basic/bitset/BitSetUserType.java | 2 +- .../test/mapping/usertypes/EnumUserType.java | 5 +- .../usertypes/UserTypeFunctionsTest.java | 2 +- .../hibernate/orm/test/rowid/RowIdType.java | 5 +- .../orm/test/type/BasicTypeRegistryTest.java | 2 +- .../orm/test/type/contributor/ArrayType.java | 6 +- .../usertype/StringWrapperUserType.java | 5 +- .../DefaultValueIntegerType.java | 5 +- .../orm/test/version/UserVersionTest.java | 5 +- .../internal/entities/RevisionTypeType.java | 7 +- .../customtype/ParametrizedTestUserType.java | 5 +- .../entities/ids/CustomEnumUserType.java | 5 +- .../components/dynamic/AgeType.java | 5 +- .../CommaDelimitedStringsMapType.java | 10 +- 34 files changed, 174 insertions(+), 78 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/EnumType.java b/hibernate-core/src/main/java/org/hibernate/type/EnumType.java index cc0c1ff324..0b48a402a7 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/EnumType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/EnumType.java @@ -221,7 +221,8 @@ public class EnumType> } @Override - public T nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public T nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { verifyConfigured(); return jdbcType.getExtractor( enumJavaType ).extract( rs, position, session ); } @@ -233,7 +234,8 @@ public class EnumType> } @Override - public void nullSafeSet(PreparedStatement st, T value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { + public void nullSafeSet(PreparedStatement st, T value, int index, SharedSessionContractImplementor session) + throws SQLException { verifyConfigured(); jdbcType.getBinder( enumJavaType ).bind( st, value, index, session ); } diff --git a/hibernate-core/src/main/java/org/hibernate/usertype/BaseUserTypeSupport.java b/hibernate-core/src/main/java/org/hibernate/usertype/BaseUserTypeSupport.java index f6e50722d7..7315818a81 100644 --- a/hibernate-core/src/main/java/org/hibernate/usertype/BaseUserTypeSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/usertype/BaseUserTypeSupport.java @@ -82,7 +82,7 @@ public abstract class BaseUserTypeSupport implements UserType { } @Override - public T nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public T nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) throws SQLException { ensureResolved(); return jdbcValueExtractor.extract( rs, position, session ); } diff --git a/hibernate-core/src/main/java/org/hibernate/usertype/StaticUserTypeSupport.java b/hibernate-core/src/main/java/org/hibernate/usertype/StaticUserTypeSupport.java index 2f8515a1e5..921a79b1bd 100644 --- a/hibernate-core/src/main/java/org/hibernate/usertype/StaticUserTypeSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/usertype/StaticUserTypeSupport.java @@ -115,7 +115,8 @@ public class StaticUserTypeSupport implements UserType { } @Override - public T nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public T nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { final Object extracted = jdbcValueExtractor.extract( rs, position, session ); if ( valueConverter != null ) { @@ -127,7 +128,8 @@ public class StaticUserTypeSupport implements UserType { } @Override - public void nullSafeSet(PreparedStatement st, T value, int index, SharedSessionContractImplementor session) throws SQLException { + public void nullSafeSet(PreparedStatement st, T value, int index, SharedSessionContractImplementor session) + throws SQLException { final Object valueToBind; if ( valueConverter != null ) { valueToBind = valueConverter.toRelationalValue( value ); diff --git a/hibernate-core/src/main/java/org/hibernate/usertype/UserType.java b/hibernate-core/src/main/java/org/hibernate/usertype/UserType.java index df644261ff..367bd8d75d 100644 --- a/hibernate-core/src/main/java/org/hibernate/usertype/UserType.java +++ b/hibernate-core/src/main/java/org/hibernate/usertype/UserType.java @@ -10,6 +10,7 @@ import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Objects; import org.hibernate.Incubating; import org.hibernate.dialect.Dialect; @@ -65,9 +66,9 @@ import org.hibernate.type.spi.TypeConfiguration; * * @Override * public Period nullSafeGet(ResultSet rs, int position, - * SharedSessionContractImplementor session, Object owner) + * SharedSessionContractImplementor session) * throws SQLException { - * String string = rs.getString( position ); + * String string = rs.getString(position); * return rs.wasNull() ? null : Period.parse(string); * } * @@ -171,7 +172,7 @@ import org.hibernate.type.spi.TypeConfiguration; * * @Override * public BitSet nullSafeGet(ResultSet rs, int position, - * SharedSessionContractImplementor session, Object owner) + * SharedSessionContractImplementor session) * throws SQLException { * String string = rs.getString(position); * return rs.wasNull()? null : parseBitSet(columnValue); @@ -271,35 +272,76 @@ public interface UserType { * Compare two instances of the Java class mapped by this custom * type for persistence "equality", that is, equality of their * persistent state. + * + * @implNote The default implementation calls {@link Objects#equals}. */ - boolean equals(J x, J y); + default boolean equals(J x, J y) { + return Objects.equals( x, y ); + } /** * Get a hash code for the given instance of the Java class mapped * by this custom type, consistent with the definition of * {@linkplain #equals(Object, Object) persistence "equality"} for * this custom type. + * + * @implNote The default implementation calls {@link Objects#hashCode}. */ - int hashCode(J x); + default int hashCode(J x) { + return Objects.hashCode( x ); + } /** * Read an instance of the Java class mapped by this custom type * from the given JDBC {@link ResultSet}. Implementors must handle * null column values. * - * @param owner in Hibernate 6, this is always null + * @param owner since Hibernate 6, this is always null + * + * @deprecated Implement {@link #nullSafeGet(ResultSet, int, SharedSessionContractImplementor)} */ - J nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, @Deprecated Object owner) - throws SQLException; + @Deprecated(since = "7", forRemoval = true) + default J nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, @Deprecated Object owner) + throws SQLException { + return nullSafeGet( rs, position, session ); + } + + /** + * Read an instance of the Java class mapped by this custom type + * from the given JDBC {@link ResultSet}. Implementors must handle + * null column values. + * + * @implNote The default implementation calls + * {@link ResultSet#getObject(int, Class)} with the + * given {@code position} and with the + * {@linkplain #returnedClass returned class}. + */ + default J nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { + J result = rs.getObject( position, returnedClass() ); + return rs.wasNull() ? null : result; + } /** * Write an instance of the Java class mapped by this custom type * to the given JDBC {@link PreparedStatement}. Implementors must * handle null values of the Java class. A multi-column type should * be written to parameters starting from {@code index}. + * + * @implNote The default implementation calls + * {@link PreparedStatement#setObject(int, Object, int)} + * with the given {@code position} and {@code value} and + * with the {@linkplain #getSqlType SQL type}. */ - void nullSafeSet(PreparedStatement st, J value, int index, SharedSessionContractImplementor session) - throws SQLException; + default void nullSafeSet(PreparedStatement st, J value, int position, SharedSessionContractImplementor session) + throws SQLException { + if ( value == null ) { + st.setNull( position, getSqlType() ); + } + else { + st.setObject( position, value, getSqlType() ); + } + } /** * Return a clone of the given instance of the Java class mapped @@ -317,7 +359,8 @@ public interface UserType { * * * @param value the object to be cloned, which may be null - * @return a clone + * @return a clone if the argument is mutable, or the argument if + * it's an immutable object */ J deepCopy(J value); @@ -344,12 +387,25 @@ public interface UserType { * This is an optional operation, but, if left unimplemented, * this type will not be cacheable in the second-level cache. * + * @implNote The default implementation calls {@link #deepCopy} + * and then casts the result to {@link Serializable}. + * * @param value the object to be cached * @return a cacheable representation of the object + * @throws UnsupportedOperationException if this type cannot + * be cached in the second-level cache. * * @see org.hibernate.Cache */ - Serializable disassemble(J value); + default Serializable disassemble(J value) { + if ( Serializable.class.isAssignableFrom( returnedClass() ) ) { + return (Serializable) deepCopy( value ); + } + else { + throw new UnsupportedOperationException( "User-defined type '" + + getClass().getName() + "' does not override 'disassemble()'" ); + } + } /** * Reconstruct a value from its destructured representation, @@ -364,13 +420,25 @@ public interface UserType { * This is an optional operation, but, if left unimplemented, * this type will not be cacheable in the second-level cache. * + * @implNote The default implementation calls {@link #deepCopy}. + * * @param cached the object to be cached * @param owner the owner of the cached object * @return a reconstructed object from the cacheable representation + * @throws UnsupportedOperationException if this type cannot + * be cached in the second-level cache. * * @see org.hibernate.Cache */ - J assemble(Serializable cached, Object owner); + default J assemble(Serializable cached, Object owner) { + if ( returnedClass().isInstance( cached) ) { + return deepCopy( (J) cached ); + } + else { + throw new UnsupportedOperationException( "User-defined type '" + + getClass().getName() + "' does not override 'assemble()'" ); + } + } /** * During merge, replace the existing (target) value in the diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/DollarValueUserType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/DollarValueUserType.java index e07bce19d5..0da69c96ea 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/DollarValueUserType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/DollarValueUserType.java @@ -42,7 +42,8 @@ public class DollarValueUserType implements UserType { } @Override - public DollarValue nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public DollarValue nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { return new DollarValue( rs.getBigDecimal( position ) ); } @@ -51,7 +52,7 @@ public class DollarValueUserType implements UserType { PreparedStatement st, DollarValue value, int index, - SharedSessionContractImplementor session) throws HibernateException, SQLException { + SharedSessionContractImplementor session) throws SQLException { st.setBigDecimal(index, value.getAmount()); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/MyDateUserType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/MyDateUserType.java index a81ffc6d1e..fb16aa3002 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/MyDateUserType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/MyDateUserType.java @@ -42,7 +42,8 @@ public class MyDateUserType implements UserType { } @Override - public MyDate nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public MyDate nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { return new MyDate( rs.getDate( position ) ); } @@ -51,7 +52,7 @@ public class MyDateUserType implements UserType { PreparedStatement st, MyDate value, int index, - SharedSessionContractImplementor session) throws HibernateException, SQLException { + SharedSessionContractImplementor session) throws SQLException { st.setDate(index, new java.sql.Date(value.getDate().getTime())); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/FirstLetterType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/FirstLetterType.java index 721152ca7e..01a8387bfc 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/FirstLetterType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/FirstLetterType.java @@ -26,7 +26,8 @@ public class FirstLetterType extends org.hibernate.type.EnumType { } @Override - public FirstLetter nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public FirstLetter nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { String persistValue = (String) rs.getObject( position ); if ( rs.wasNull() ) { return null; @@ -36,7 +37,7 @@ public class FirstLetterType extends org.hibernate.type.EnumType { @Override public void nullSafeSet(PreparedStatement st, FirstLetter value, int index, SharedSessionContractImplementor session) - throws HibernateException, SQLException { + throws SQLException { if ( value == null ) { st.setNull( index, getSqlType() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/LastNumberType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/LastNumberType.java index d5a0f08c43..0c3c41c0da 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/LastNumberType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/custom_types/LastNumberType.java @@ -26,7 +26,8 @@ public class LastNumberType extends org.hibernate.type.EnumType { } @Override - public LastNumber nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public LastNumber nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { String persistValue = (String) rs.getObject( position ); if ( rs.wasNull() ) { return null; @@ -36,7 +37,7 @@ public class LastNumberType extends org.hibernate.type.EnumType { @Override public void nullSafeSet(PreparedStatement st, LastNumber value, int index, SharedSessionContractImplementor session) - throws HibernateException, SQLException { + throws SQLException { if ( value == null ) { st.setNull( index, getSqlType() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/generics/StateType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/generics/StateType.java index 36a8ee5b1f..7d0033a62e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/generics/StateType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/generics/StateType.java @@ -41,14 +41,16 @@ public class StateType implements UserType { } @Override - public State nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public State nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { int result = rs.getInt( position ); if ( rs.wasNull() ) return null; return State.values()[result]; } @Override - public void nullSafeSet(PreparedStatement st, State value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { + public void nullSafeSet(PreparedStatement st, State value, int index, SharedSessionContractImplementor session) + throws HibernateException, SQLException { if (value == null) { st.setNull( index, Types.INTEGER ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/type/dynamicparameterized/MyGenericType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/type/dynamicparameterized/MyGenericType.java index e026ac112c..1b2171d0df 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/type/dynamicparameterized/MyGenericType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/type/dynamicparameterized/MyGenericType.java @@ -51,12 +51,14 @@ public class MyGenericType implements UserType, DynamicParameterizedType } @Override - public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws SQLException { + public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) + throws SQLException { st.setString( index, null ); } @Override - public Object nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public Object nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { return null; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/type/dynamicparameterized/MyStringType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/type/dynamicparameterized/MyStringType.java index ff02bf8352..41999c9f4b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/type/dynamicparameterized/MyStringType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/type/dynamicparameterized/MyStringType.java @@ -98,12 +98,14 @@ public class MyStringType implements UserType, DynamicParameterizedType } @Override - public void nullSafeSet(PreparedStatement st, String value, int index, SharedSessionContractImplementor session) throws SQLException { + public void nullSafeSet(PreparedStatement st, String value, int index, SharedSessionContractImplementor session) + throws SQLException { st.setString( index, this.value ); } @Override - public String nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public String nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { return rs.getString( position ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/MyUserType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/MyUserType.java index 827d04455c..bacee92dc9 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/MyUserType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/MyUserType.java @@ -41,7 +41,7 @@ public class MyUserType implements UserType { } @Override - public UUID nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) + public UUID nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) throws SQLException { return null; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/lifecycle/ExtendedBeanManagerNotAvailableDuringCustomUserTypeInitTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/lifecycle/ExtendedBeanManagerNotAvailableDuringCustomUserTypeInitTest.java index 4adf4ff3a5..f503680a3a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/lifecycle/ExtendedBeanManagerNotAvailableDuringCustomUserTypeInitTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/lifecycle/ExtendedBeanManagerNotAvailableDuringCustomUserTypeInitTest.java @@ -93,13 +93,15 @@ public class ExtendedBeanManagerNotAvailableDuringCustomUserTypeInitTest { } @Override - public Object nullSafeGet(ResultSet rs, int i, SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws SQLException { + public Object nullSafeGet(ResultSet rs, int i, SharedSessionContractImplementor sharedSessionContractImplementor) + throws SQLException { String xmldoc = rs.getString(i); return rs.wasNull() ? null : xmldoc; } @Override - public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { + public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) + throws SQLException { if (value == null) { st.setNull(index, Types.OTHER); } else { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/type/UrlType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/type/UrlType.java index 8286e005b1..d2332d836d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/type/UrlType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/type/UrlType.java @@ -60,12 +60,14 @@ public class UrlType implements UserType { } @Override - public URL nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public URL nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { throw new UnsupportedOperationException( "Not used" ); } @Override - public void nullSafeSet(PreparedStatement st, URL value, int index, SharedSessionContractImplementor session) throws SQLException { + public void nullSafeSet(PreparedStatement st, URL value, int index, SharedSessionContractImplementor session) + throws SQLException { throw new UnsupportedOperationException( "Not used" ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/hql/ClassificationType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/hql/ClassificationType.java index 0852994e6c..573fc80671 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/hql/ClassificationType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/hql/ClassificationType.java @@ -59,7 +59,8 @@ public class ClassificationType implements EnhancedUserType, Val } @Override - public Classification nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public Classification nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { final int intValue = rs.getInt( position ); if ( rs.wasNull() ) { return null; @@ -68,7 +69,8 @@ public class ClassificationType implements EnhancedUserType, Val } @Override - public void nullSafeSet(PreparedStatement st, Classification value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { + public void nullSafeSet(PreparedStatement st, Classification value, int index, SharedSessionContractImplementor session) + throws SQLException { if ( value == null ) { st.setNull( index, Types.INTEGER ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/usertype/UserTypeComparableIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/usertype/UserTypeComparableIdTest.java index 71cb09d7e5..0afd461271 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/usertype/UserTypeComparableIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/usertype/UserTypeComparableIdTest.java @@ -131,7 +131,7 @@ public class UserTypeComparableIdTest { } @Override - public CustomId nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) + public CustomId nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) throws SQLException { Long value = rs.getLong( position ); @@ -143,7 +143,7 @@ public class UserTypeComparableIdTest { PreparedStatement preparedStatement, CustomId customId, int index, - SharedSessionContractImplementor sessionImplementor) throws HibernateException, SQLException { + SharedSessionContractImplementor sessionImplementor) throws SQLException { if ( customId == null ) { preparedStatement.setNull( index, Types.BIGINT ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/usertype/UserTypeNonComparableIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/usertype/UserTypeNonComparableIdTest.java index 7b25f5c466..3986412e1b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/usertype/UserTypeNonComparableIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/usertype/UserTypeNonComparableIdTest.java @@ -118,7 +118,7 @@ public class UserTypeNonComparableIdTest { } @Override - public CustomId nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) + public CustomId nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) throws SQLException { Long value = rs.getLong( position ); @@ -130,7 +130,7 @@ public class UserTypeNonComparableIdTest { PreparedStatement preparedStatement, CustomId customId, int index, - SharedSessionContractImplementor sessionImplementor) throws HibernateException, SQLException { + SharedSessionContractImplementor sessionImplementor) throws SQLException { if ( customId == null ) { preparedStatement.setNull( index, Types.BIGINT ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/QueryParametersValidationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/QueryParametersValidationTest.java index a63d66e5b8..07f4a78e5a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/QueryParametersValidationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/QueryParametersValidationTest.java @@ -133,7 +133,8 @@ public class QueryParametersValidationTest extends BaseEntityManagerFunctionalTe } @Override - public Boolean nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public Boolean nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { return "Y".equals( rs.getString( position ) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/TypedValueParametersTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/TypedValueParametersTest.java index c6bad7a22e..00525b887a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/TypedValueParametersTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/TypedValueParametersTest.java @@ -161,7 +161,8 @@ public class TypedValueParametersTest { } @Override - public List nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public List nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { String string = rs.getString( position ); if (rs.wasNull()) { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/RepeatedMappingUserTypeTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/RepeatedMappingUserTypeTests.java index 79f7dd7261..fc3dec314e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/RepeatedMappingUserTypeTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/RepeatedMappingUserTypeTests.java @@ -129,8 +129,7 @@ public class RepeatedMappingUserTypeTests { public SortedSet nullSafeGet( ResultSet rs, int position, - SharedSessionContractImplementor session, - Object owner) throws SQLException { + SharedSessionContractImplementor session) throws SQLException { return convertToEntityAttribute( rs.getString( position ) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/bitset/BitSetUserType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/bitset/BitSetUserType.java index bdabcbf010..7122a0e783 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/bitset/BitSetUserType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/bitset/BitSetUserType.java @@ -49,7 +49,7 @@ public class BitSetUserType implements UserType { @Override public BitSet nullSafeGet(ResultSet rs, int position, - SharedSessionContractImplementor session, Object owner) + SharedSessionContractImplementor session) throws SQLException { String columnValue = rs.getString(position); if (rs.wasNull()) { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/usertypes/EnumUserType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/usertypes/EnumUserType.java index 0ea2f7f55c..77f7480d2e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/usertypes/EnumUserType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/usertypes/EnumUserType.java @@ -62,7 +62,8 @@ public class EnumUserType> implements UserType, Parameteriz } @Override - public T nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public T nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { final String name = rs.getString( position ); if ( rs.wasNull() ) { return null; @@ -79,7 +80,7 @@ public class EnumUserType> implements UserType, Parameteriz PreparedStatement preparedStatement, T value, int index, - SharedSessionContractImplementor session) throws HibernateException, SQLException { + SharedSessionContractImplementor session) throws SQLException { if ( null == value ) { preparedStatement.setNull( index, Types.VARCHAR ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/usertypes/UserTypeFunctionsTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/usertypes/UserTypeFunctionsTest.java index 83910e9854..e07dd61761 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/usertypes/UserTypeFunctionsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/usertypes/UserTypeFunctionsTest.java @@ -134,7 +134,7 @@ public class UserTypeFunctionsTest { } @Override - public YearMonth nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) + public YearMonth nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) throws SQLException { int intValue = rs.getInt( position ); if ( rs.wasNull() ) { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdType.java index 1c3748520c..b37c2a90ec 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdType.java @@ -41,13 +41,14 @@ public class RowIdType implements UserType{ } @Override - public Object nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public Object nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { return rs.getObject( position ); } @Override public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) - throws HibernateException, SQLException { + throws SQLException { throw new UnsupportedOperationException(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/BasicTypeRegistryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/BasicTypeRegistryTest.java index e8748ebcea..29e57b3290 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/BasicTypeRegistryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/BasicTypeRegistryTest.java @@ -141,7 +141,7 @@ public class BasicTypeRegistryTest extends BaseUnitTestCase { } @Override - public Object nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public Object nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) throws SQLException { return null; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/contributor/ArrayType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/contributor/ArrayType.java index aa481cdf92..1e0087b638 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/contributor/ArrayType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/contributor/ArrayType.java @@ -66,12 +66,14 @@ public class ArrayType implements UserType, BindableType, BasicVal } @Override - public Array nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public Array nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { return jdbcType.getExtractor( javaType ).extract( rs, position, session ); } @Override - public void nullSafeSet(PreparedStatement st, Array value, int index, SharedSessionContractImplementor session) throws SQLException { + public void nullSafeSet(PreparedStatement st, Array value, int index, SharedSessionContractImplementor session) + throws SQLException { jdbcType.getBinder( javaType ).bind( st, value, index, session ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/contributor/usertype/StringWrapperUserType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/contributor/usertype/StringWrapperUserType.java index 772e726853..93a2e37026 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/contributor/usertype/StringWrapperUserType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/contributor/usertype/StringWrapperUserType.java @@ -51,7 +51,8 @@ public class StringWrapperUserType implements UserType { } @Override - public StringWrapper nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public StringWrapper nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { String columnValue = (String) rs.getObject( position ); log.debugv( "Result set column {0} value is {1}", position, columnValue ); return columnValue == null ? null : fromString( columnValue ); @@ -60,7 +61,7 @@ public class StringWrapperUserType implements UserType { @Override public void nullSafeSet( PreparedStatement st, StringWrapper value, int index, SharedSessionContractImplementor session) - throws HibernateException, SQLException { + throws SQLException { if ( value == null ) { log.debugv("Binding null to parameter {0} ",index); st.setNull( index, Types.VARCHAR ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/typeparameters/DefaultValueIntegerType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/typeparameters/DefaultValueIntegerType.java index c90ad62bab..75e4bef242 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/typeparameters/DefaultValueIntegerType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/typeparameters/DefaultValueIntegerType.java @@ -49,14 +49,15 @@ public class DefaultValueIntegerType implements UserType, Parameterized } @Override - public Integer nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public Integer nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { Number result = (Number) rs.getObject( position ); return result == null ? defaultValue : Integer.valueOf( result.intValue() ); } @Override public void nullSafeSet(PreparedStatement st, Integer value, int index, SharedSessionContractImplementor session) - throws HibernateException, SQLException { + throws SQLException { if ( value == null || defaultValue.equals( value ) ) { log.trace( "binding null to parameter: " + index ); st.setNull( index, Types.INTEGER ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/version/UserVersionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/version/UserVersionTest.java index 8fa66a082d..ea266818ae 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/version/UserVersionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/version/UserVersionTest.java @@ -143,8 +143,7 @@ public class UserVersionTest extends BaseSessionFactoryFunctionalTest { public CustomVersion nullSafeGet( ResultSet resultSet, int position, - SharedSessionContractImplementor session, - Object owner) throws HibernateException, SQLException { + SharedSessionContractImplementor session) throws SQLException { return new CustomVersion( resultSet.getLong( position ) ); } @@ -153,7 +152,7 @@ public class UserVersionTest extends BaseSessionFactoryFunctionalTest { PreparedStatement statement, CustomVersion value, int index, - SharedSessionContractImplementor session) throws HibernateException, SQLException { + SharedSessionContractImplementor session) throws SQLException { statement.setLong( index, value.getRev() ); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RevisionTypeType.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RevisionTypeType.java index cbb17cbfac..325497739b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RevisionTypeType.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/RevisionTypeType.java @@ -37,7 +37,8 @@ public class RevisionTypeType implements UserType, Serializable { } @Override - public RevisionType nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public RevisionType nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { byte byteValue = rs.getByte( position ); if ( rs.wasNull() ) { return null; @@ -47,12 +48,12 @@ public class RevisionTypeType implements UserType, Serializable { @Override public void nullSafeSet(PreparedStatement preparedStatement, RevisionType value, int index, SharedSessionContractImplementor session) - throws HibernateException, SQLException { + throws SQLException { if ( value == null ) { preparedStatement.setNull( index, Types.TINYINT ); } else { - preparedStatement.setByte( index, ( (RevisionType) value ).getRepresentation() ); + preparedStatement.setByte( index, value.getRepresentation() ); } } diff --git a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/customtype/ParametrizedTestUserType.java b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/customtype/ParametrizedTestUserType.java index c83d646c44..7db19e0a8a 100644 --- a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/customtype/ParametrizedTestUserType.java +++ b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/customtype/ParametrizedTestUserType.java @@ -38,13 +38,14 @@ public class ParametrizedTestUserType implements UserType, Parameterized } @Override - public String nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public String nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { final String string = rs.getString( position ); return rs.wasNull() ? null : string; } public void nullSafeSet(PreparedStatement st, String value, int index, SharedSessionContractImplementor session) - throws HibernateException, SQLException { + throws SQLException { if ( value != null ) { if ( !value.startsWith( param1 ) ) { value = param1 + value; diff --git a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/ids/CustomEnumUserType.java b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/ids/CustomEnumUserType.java index d431288055..9cf89b5d1e 100644 --- a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/ids/CustomEnumUserType.java +++ b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/ids/CustomEnumUserType.java @@ -45,7 +45,8 @@ public class CustomEnumUserType implements UserType { } @Override - public CustomEnum nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public CustomEnum nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { String name = rs.getString( position ); if ( rs.wasNull() ) { return null; @@ -54,7 +55,7 @@ public class CustomEnumUserType implements UserType { } public void nullSafeSet(PreparedStatement st, CustomEnum value, int index, SharedSessionContractImplementor session) - throws HibernateException, SQLException { + throws SQLException { if ( value == null ) { st.setNull( index, Types.VARCHAR ); } diff --git a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/components/dynamic/AgeType.java b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/components/dynamic/AgeType.java index 073b62f6df..6f745cd2c8 100644 --- a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/components/dynamic/AgeType.java +++ b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/components/dynamic/AgeType.java @@ -39,13 +39,14 @@ public class AgeType implements UserType { } @Override - public Age nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + public Age nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { return new Age( rs.getInt( position ) ); } @Override public void nullSafeSet(PreparedStatement st, Age value, int index, SharedSessionContractImplementor session) - throws HibernateException, SQLException { + throws SQLException { st.setInt( index, value.getAgeInYears() ); } diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/collectionbasictype/CommaDelimitedStringsMapType.java b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/collectionbasictype/CommaDelimitedStringsMapType.java index 8ffd566c98..71f8d68868 100644 --- a/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/collectionbasictype/CommaDelimitedStringsMapType.java +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/collectionbasictype/CommaDelimitedStringsMapType.java @@ -32,11 +32,8 @@ public class CommaDelimitedStringsMapType extends StaticUserTypeSupport nullSafeGet( - ResultSet rs, - int position, - SharedSessionContractImplementor session, - Object owner) throws SQLException { + public Map nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session) + throws SQLException { final Object extracted = getJdbcValueExtractor().extract( rs, position, session ); if ( extracted == null ) { return null; @@ -46,7 +43,8 @@ public class CommaDelimitedStringsMapType extends StaticUserTypeSupport value, int index, SharedSessionContractImplementor session) throws SQLException { + public void nullSafeSet(PreparedStatement st, Map value, int index, SharedSessionContractImplementor session) + throws SQLException { final String stringValue = getJavaType().toString( value ); getJdbcValueBinder().bind( st, stringValue, index, session ); }