HHH-18547, HHH-17114 add default implementations to UserType

and deprecate the wrong-signature nullSafeGet() method

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-08-29 22:13:29 +02:00
parent 519ffb7c78
commit 1d12dc0499
34 changed files with 174 additions and 78 deletions

View File

@ -221,7 +221,8 @@ public class EnumType<T extends Enum<T>>
}
@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<T extends Enum<T>>
}
@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 );
}

View File

@ -82,7 +82,7 @@ public abstract class BaseUserTypeSupport<T> implements UserType<T> {
}
@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 );
}

View File

@ -115,7 +115,8 @@ public class StaticUserTypeSupport<T> implements UserType<T> {
}
@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<T> implements UserType<T> {
}
@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 );

View File

@ -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;
*
* &#64;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;
*
* &#64;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<J> {
* 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<J> {
* </ul>
*
* @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<J> {
* 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<J> {
* 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

View File

@ -42,7 +42,8 @@ public class DollarValueUserType implements UserType<DollarValue> {
}
@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<DollarValue> {
PreparedStatement st,
DollarValue value,
int index,
SharedSessionContractImplementor session) throws HibernateException, SQLException {
SharedSessionContractImplementor session) throws SQLException {
st.setBigDecimal(index, value.getAmount());
}

View File

@ -42,7 +42,8 @@ public class MyDateUserType implements UserType<MyDate> {
}
@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<MyDate> {
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()));
}

View File

@ -26,7 +26,8 @@ public class FirstLetterType extends org.hibernate.type.EnumType<FirstLetter> {
}
@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<FirstLetter> {
@Override
public void nullSafeSet(PreparedStatement st, FirstLetter value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException {
throws SQLException {
if ( value == null ) {
st.setNull( index, getSqlType() );
}

View File

@ -26,7 +26,8 @@ public class LastNumberType extends org.hibernate.type.EnumType<LastNumber> {
}
@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<LastNumber> {
@Override
public void nullSafeSet(PreparedStatement st, LastNumber value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException {
throws SQLException {
if ( value == null ) {
st.setNull( index, getSqlType() );
}

View File

@ -41,14 +41,16 @@ public class StateType implements UserType<State> {
}
@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 );
}

View File

@ -51,12 +51,14 @@ public class MyGenericType implements UserType<Object>, 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;
}

View File

@ -98,12 +98,14 @@ public class MyStringType implements UserType<String>, 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 );
}

View File

@ -41,7 +41,7 @@ public class MyUserType implements UserType<UUID> {
}
@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;
}

View File

@ -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 {

View File

@ -60,12 +60,14 @@ public class UrlType implements UserType<URL> {
}
@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" );
}

View File

@ -59,7 +59,8 @@ public class ClassificationType implements EnhancedUserType<Classification>, 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<Classification>, 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 );
}

View File

@ -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 );
}

View File

@ -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 );
}

View File

@ -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 ) );
}

View File

@ -161,7 +161,8 @@ public class TypedValueParametersTest {
}
@Override
public List<String> nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException {
public List<String> nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session)
throws SQLException {
String string = rs.getString( position );
if (rs.wasNull()) {

View File

@ -129,8 +129,7 @@ public class RepeatedMappingUserTypeTests {
public SortedSet<Integer> nullSafeGet(
ResultSet rs,
int position,
SharedSessionContractImplementor session,
Object owner) throws SQLException {
SharedSessionContractImplementor session) throws SQLException {
return convertToEntityAttribute( rs.getString( position ) );
}

View File

@ -49,7 +49,7 @@ public class BitSetUserType implements UserType<BitSet> {
@Override
public BitSet nullSafeGet(ResultSet rs, int position,
SharedSessionContractImplementor session, Object owner)
SharedSessionContractImplementor session)
throws SQLException {
String columnValue = rs.getString(position);
if (rs.wasNull()) {

View File

@ -62,7 +62,8 @@ public class EnumUserType<T extends Enum<T>> implements UserType<T>, 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<T extends Enum<T>> implements UserType<T>, Parameteriz
PreparedStatement preparedStatement,
T value,
int index,
SharedSessionContractImplementor session) throws HibernateException, SQLException {
SharedSessionContractImplementor session) throws SQLException {
if ( null == value ) {
preparedStatement.setNull( index, Types.VARCHAR );
}

View File

@ -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() ) {

View File

@ -41,13 +41,14 @@ public class RowIdType implements UserType<Object>{
}
@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();
}

View File

@ -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;
}

View File

@ -66,12 +66,14 @@ public class ArrayType implements UserType<Array>, BindableType<Array>, 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 );
}

View File

@ -51,7 +51,8 @@ public class StringWrapperUserType implements UserType<StringWrapper> {
}
@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<StringWrapper> {
@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 );

View File

@ -49,14 +49,15 @@ public class DefaultValueIntegerType implements UserType<Integer>, 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 );

View File

@ -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() );
}

View File

@ -37,7 +37,8 @@ public class RevisionTypeType implements UserType<RevisionType>, 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<RevisionType>, 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() );
}
}

View File

@ -38,13 +38,14 @@ public class ParametrizedTestUserType implements UserType<String>, 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;

View File

@ -45,7 +45,8 @@ public class CustomEnumUserType implements UserType<CustomEnum> {
}
@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<CustomEnum> {
}
public void nullSafeSet(PreparedStatement st, CustomEnum value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException {
throws SQLException {
if ( value == null ) {
st.setNull( index, Types.VARCHAR );
}

View File

@ -39,13 +39,14 @@ public class AgeType implements UserType<Age> {
}
@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() );
}

View File

@ -32,11 +32,8 @@ public class CommaDelimitedStringsMapType extends StaticUserTypeSupport<Map<Stri
}
@Override
public Map<String,String> nullSafeGet(
ResultSet rs,
int position,
SharedSessionContractImplementor session,
Object owner) throws SQLException {
public Map<String,String> 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<Map<Stri
}
@Override
public void nullSafeSet(PreparedStatement st, Map<String,String> value, int index, SharedSessionContractImplementor session) throws SQLException {
public void nullSafeSet(PreparedStatement st, Map<String,String> value, int index, SharedSessionContractImplementor session)
throws SQLException {
final String stringValue = getJavaType().toString( value );
getJdbcValueBinder().bind( st, stringValue, index, session );
}