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 @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(); verifyConfigured();
return jdbcType.getExtractor( enumJavaType ).extract( rs, position, session ); return jdbcType.getExtractor( enumJavaType ).extract( rs, position, session );
} }
@ -233,7 +234,8 @@ public class EnumType<T extends Enum<T>>
} }
@Override @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(); verifyConfigured();
jdbcType.getBinder( enumJavaType ).bind( st, value, index, session ); jdbcType.getBinder( enumJavaType ).bind( st, value, index, session );
} }

View File

@ -82,7 +82,7 @@ public abstract class BaseUserTypeSupport<T> implements UserType<T> {
} }
@Override @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(); ensureResolved();
return jdbcValueExtractor.extract( rs, position, session ); return jdbcValueExtractor.extract( rs, position, session );
} }

View File

@ -115,7 +115,8 @@ public class StaticUserTypeSupport<T> implements UserType<T> {
} }
@Override @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 ); final Object extracted = jdbcValueExtractor.extract( rs, position, session );
if ( valueConverter != null ) { if ( valueConverter != null ) {
@ -127,7 +128,8 @@ public class StaticUserTypeSupport<T> implements UserType<T> {
} }
@Override @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; final Object valueToBind;
if ( valueConverter != null ) { if ( valueConverter != null ) {
valueToBind = valueConverter.toRelationalValue( value ); valueToBind = valueConverter.toRelationalValue( value );

View File

@ -10,6 +10,7 @@ import java.io.Serializable;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Objects;
import org.hibernate.Incubating; import org.hibernate.Incubating;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
@ -65,9 +66,9 @@ import org.hibernate.type.spi.TypeConfiguration;
* *
* &#64;Override * &#64;Override
* public Period nullSafeGet(ResultSet rs, int position, * public Period nullSafeGet(ResultSet rs, int position,
* SharedSessionContractImplementor session, Object owner) * SharedSessionContractImplementor session)
* throws SQLException { * throws SQLException {
* String string = rs.getString( position ); * String string = rs.getString(position);
* return rs.wasNull() ? null : Period.parse(string); * return rs.wasNull() ? null : Period.parse(string);
* } * }
* *
@ -171,7 +172,7 @@ import org.hibernate.type.spi.TypeConfiguration;
* *
* &#64;Override * &#64;Override
* public BitSet nullSafeGet(ResultSet rs, int position, * public BitSet nullSafeGet(ResultSet rs, int position,
* SharedSessionContractImplementor session, Object owner) * SharedSessionContractImplementor session)
* throws SQLException { * throws SQLException {
* String string = rs.getString(position); * String string = rs.getString(position);
* return rs.wasNull()? null : parseBitSet(columnValue); * 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 * Compare two instances of the Java class mapped by this custom
* type for persistence "equality", that is, equality of their * type for persistence "equality", that is, equality of their
* persistent state. * 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 * Get a hash code for the given instance of the Java class mapped
* by this custom type, consistent with the definition of * by this custom type, consistent with the definition of
* {@linkplain #equals(Object, Object) persistence "equality"} for * {@linkplain #equals(Object, Object) persistence "equality"} for
* this custom type. * 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 * Read an instance of the Java class mapped by this custom type
* from the given JDBC {@link ResultSet}. Implementors must handle * from the given JDBC {@link ResultSet}. Implementors must handle
* null column values. * 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) @Deprecated(since = "7", forRemoval = true)
throws SQLException; 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 * Write an instance of the Java class mapped by this custom type
* to the given JDBC {@link PreparedStatement}. Implementors must * to the given JDBC {@link PreparedStatement}. Implementors must
* handle null values of the Java class. A multi-column type should * handle null values of the Java class. A multi-column type should
* be written to parameters starting from {@code index}. * 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) default void nullSafeSet(PreparedStatement st, J value, int position, SharedSessionContractImplementor session)
throws SQLException; 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 * Return a clone of the given instance of the Java class mapped
@ -317,7 +359,8 @@ public interface UserType<J> {
* </ul> * </ul>
* *
* @param value the object to be cloned, which may be null * @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); J deepCopy(J value);
@ -344,12 +387,25 @@ public interface UserType<J> {
* This is an optional operation, but, if left unimplemented, * This is an optional operation, but, if left unimplemented,
* this type will not be cacheable in the second-level cache. * 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 * @param value the object to be cached
* @return a cacheable representation of the object * @return a cacheable representation of the object
* @throws UnsupportedOperationException if this type cannot
* be cached in the second-level cache.
* *
* @see org.hibernate.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, * 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 is an optional operation, but, if left unimplemented,
* this type will not be cacheable in the second-level cache. * 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 cached the object to be cached
* @param owner the owner of the cached object * @param owner the owner of the cached object
* @return a reconstructed object from the cacheable representation * @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 * @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 * During merge, replace the existing (target) value in the

View File

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

View File

@ -42,7 +42,8 @@ public class MyDateUserType implements UserType<MyDate> {
} }
@Override @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 ) ); return new MyDate( rs.getDate( position ) );
} }
@ -51,7 +52,7 @@ public class MyDateUserType implements UserType<MyDate> {
PreparedStatement st, PreparedStatement st,
MyDate value, MyDate value,
int index, int index,
SharedSessionContractImplementor session) throws HibernateException, SQLException { SharedSessionContractImplementor session) throws SQLException {
st.setDate(index, new java.sql.Date(value.getDate().getTime())); 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 @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 ); String persistValue = (String) rs.getObject( position );
if ( rs.wasNull() ) { if ( rs.wasNull() ) {
return null; return null;
@ -36,7 +37,7 @@ public class FirstLetterType extends org.hibernate.type.EnumType<FirstLetter> {
@Override @Override
public void nullSafeSet(PreparedStatement st, FirstLetter value, int index, SharedSessionContractImplementor session) public void nullSafeSet(PreparedStatement st, FirstLetter value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException { throws SQLException {
if ( value == null ) { if ( value == null ) {
st.setNull( index, getSqlType() ); st.setNull( index, getSqlType() );
} }

View File

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

View File

@ -41,14 +41,16 @@ public class StateType implements UserType<State> {
} }
@Override @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 ); int result = rs.getInt( position );
if ( rs.wasNull() ) return null; if ( rs.wasNull() ) return null;
return State.values()[result]; return State.values()[result];
} }
@Override @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) { if (value == null) {
st.setNull( index, Types.INTEGER ); st.setNull( index, Types.INTEGER );
} }

View File

@ -51,12 +51,14 @@ public class MyGenericType implements UserType<Object>, DynamicParameterizedType
} }
@Override @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 ); st.setString( index, null );
} }
@Override @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; return null;
} }

View File

@ -98,12 +98,14 @@ public class MyStringType implements UserType<String>, DynamicParameterizedType
} }
@Override @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 ); st.setString( index, this.value );
} }
@Override @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 ); return rs.getString( position );
} }

View File

@ -41,7 +41,7 @@ public class MyUserType implements UserType<UUID> {
} }
@Override @Override
public UUID nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) public UUID nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session)
throws SQLException { throws SQLException {
return null; return null;
} }

View File

@ -93,13 +93,15 @@ public class ExtendedBeanManagerNotAvailableDuringCustomUserTypeInitTest {
} }
@Override @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); String xmldoc = rs.getString(i);
return rs.wasNull() ? null : xmldoc; return rs.wasNull() ? null : xmldoc;
} }
@Override @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) { if (value == null) {
st.setNull(index, Types.OTHER); st.setNull(index, Types.OTHER);
} else { } else {

View File

@ -60,12 +60,14 @@ public class UrlType implements UserType<URL> {
} }
@Override @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" ); throw new UnsupportedOperationException( "Not used" );
} }
@Override @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" ); throw new UnsupportedOperationException( "Not used" );
} }

View File

@ -59,7 +59,8 @@ public class ClassificationType implements EnhancedUserType<Classification>, Val
} }
@Override @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 ); final int intValue = rs.getInt( position );
if ( rs.wasNull() ) { if ( rs.wasNull() ) {
return null; return null;
@ -68,7 +69,8 @@ public class ClassificationType implements EnhancedUserType<Classification>, Val
} }
@Override @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 ) { if ( value == null ) {
st.setNull( index, Types.INTEGER ); st.setNull( index, Types.INTEGER );
} }

View File

@ -131,7 +131,7 @@ public class UserTypeComparableIdTest {
} }
@Override @Override
public CustomId nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) public CustomId nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session)
throws SQLException { throws SQLException {
Long value = rs.getLong( position ); Long value = rs.getLong( position );
@ -143,7 +143,7 @@ public class UserTypeComparableIdTest {
PreparedStatement preparedStatement, PreparedStatement preparedStatement,
CustomId customId, CustomId customId,
int index, int index,
SharedSessionContractImplementor sessionImplementor) throws HibernateException, SQLException { SharedSessionContractImplementor sessionImplementor) throws SQLException {
if ( customId == null ) { if ( customId == null ) {
preparedStatement.setNull( index, Types.BIGINT ); preparedStatement.setNull( index, Types.BIGINT );
} }

View File

@ -118,7 +118,7 @@ public class UserTypeNonComparableIdTest {
} }
@Override @Override
public CustomId nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) public CustomId nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session)
throws SQLException { throws SQLException {
Long value = rs.getLong( position ); Long value = rs.getLong( position );
@ -130,7 +130,7 @@ public class UserTypeNonComparableIdTest {
PreparedStatement preparedStatement, PreparedStatement preparedStatement,
CustomId customId, CustomId customId,
int index, int index,
SharedSessionContractImplementor sessionImplementor) throws HibernateException, SQLException { SharedSessionContractImplementor sessionImplementor) throws SQLException {
if ( customId == null ) { if ( customId == null ) {
preparedStatement.setNull( index, Types.BIGINT ); preparedStatement.setNull( index, Types.BIGINT );
} }

View File

@ -133,7 +133,8 @@ public class QueryParametersValidationTest extends BaseEntityManagerFunctionalTe
} }
@Override @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 ) ); return "Y".equals( rs.getString( position ) );
} }

View File

@ -161,7 +161,8 @@ public class TypedValueParametersTest {
} }
@Override @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 ); String string = rs.getString( position );
if (rs.wasNull()) { if (rs.wasNull()) {

View File

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

View File

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

View File

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

View File

@ -134,7 +134,7 @@ public class UserTypeFunctionsTest {
} }
@Override @Override
public YearMonth nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) public YearMonth nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session)
throws SQLException { throws SQLException {
int intValue = rs.getInt( position ); int intValue = rs.getInt( position );
if ( rs.wasNull() ) { if ( rs.wasNull() ) {

View File

@ -41,13 +41,14 @@ public class RowIdType implements UserType<Object>{
} }
@Override @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 ); return rs.getObject( position );
} }
@Override @Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException { throws SQLException {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@ -141,7 +141,7 @@ public class BasicTypeRegistryTest extends BaseUnitTestCase {
} }
@Override @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; return null;
} }

View File

@ -66,12 +66,14 @@ public class ArrayType implements UserType<Array>, BindableType<Array>, BasicVal
} }
@Override @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 ); return jdbcType.getExtractor( javaType ).extract( rs, position, session );
} }
@Override @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 ); jdbcType.getBinder( javaType ).bind( st, value, index, session );
} }

View File

@ -51,7 +51,8 @@ public class StringWrapperUserType implements UserType<StringWrapper> {
} }
@Override @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 ); String columnValue = (String) rs.getObject( position );
log.debugv( "Result set column {0} value is {1}", position, columnValue ); log.debugv( "Result set column {0} value is {1}", position, columnValue );
return columnValue == null ? null : fromString( columnValue ); return columnValue == null ? null : fromString( columnValue );
@ -60,7 +61,7 @@ public class StringWrapperUserType implements UserType<StringWrapper> {
@Override @Override
public void nullSafeSet( public void nullSafeSet(
PreparedStatement st, StringWrapper value, int index, SharedSessionContractImplementor session) PreparedStatement st, StringWrapper value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException { throws SQLException {
if ( value == null ) { if ( value == null ) {
log.debugv("Binding null to parameter {0} ",index); log.debugv("Binding null to parameter {0} ",index);
st.setNull( index, Types.VARCHAR ); st.setNull( index, Types.VARCHAR );

View File

@ -49,14 +49,15 @@ public class DefaultValueIntegerType implements UserType<Integer>, Parameterized
} }
@Override @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 ); Number result = (Number) rs.getObject( position );
return result == null ? defaultValue : Integer.valueOf( result.intValue() ); return result == null ? defaultValue : Integer.valueOf( result.intValue() );
} }
@Override @Override
public void nullSafeSet(PreparedStatement st, Integer value, int index, SharedSessionContractImplementor session) public void nullSafeSet(PreparedStatement st, Integer value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException { throws SQLException {
if ( value == null || defaultValue.equals( value ) ) { if ( value == null || defaultValue.equals( value ) ) {
log.trace( "binding null to parameter: " + index ); log.trace( "binding null to parameter: " + index );
st.setNull( index, Types.INTEGER ); st.setNull( index, Types.INTEGER );

View File

@ -143,8 +143,7 @@ public class UserVersionTest extends BaseSessionFactoryFunctionalTest {
public CustomVersion nullSafeGet( public CustomVersion nullSafeGet(
ResultSet resultSet, ResultSet resultSet,
int position, int position,
SharedSessionContractImplementor session, SharedSessionContractImplementor session) throws SQLException {
Object owner) throws HibernateException, SQLException {
return new CustomVersion( resultSet.getLong( position ) ); return new CustomVersion( resultSet.getLong( position ) );
} }
@ -153,7 +152,7 @@ public class UserVersionTest extends BaseSessionFactoryFunctionalTest {
PreparedStatement statement, PreparedStatement statement,
CustomVersion value, CustomVersion value,
int index, int index,
SharedSessionContractImplementor session) throws HibernateException, SQLException { SharedSessionContractImplementor session) throws SQLException {
statement.setLong( index, value.getRev() ); statement.setLong( index, value.getRev() );
} }

View File

@ -37,7 +37,8 @@ public class RevisionTypeType implements UserType<RevisionType>, Serializable {
} }
@Override @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 ); byte byteValue = rs.getByte( position );
if ( rs.wasNull() ) { if ( rs.wasNull() ) {
return null; return null;
@ -47,12 +48,12 @@ public class RevisionTypeType implements UserType<RevisionType>, Serializable {
@Override @Override
public void nullSafeSet(PreparedStatement preparedStatement, RevisionType value, int index, SharedSessionContractImplementor session) public void nullSafeSet(PreparedStatement preparedStatement, RevisionType value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException { throws SQLException {
if ( value == null ) { if ( value == null ) {
preparedStatement.setNull( index, Types.TINYINT ); preparedStatement.setNull( index, Types.TINYINT );
} }
else { 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 @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 ); final String string = rs.getString( position );
return rs.wasNull() ? null : string; return rs.wasNull() ? null : string;
} }
public void nullSafeSet(PreparedStatement st, String value, int index, SharedSessionContractImplementor session) public void nullSafeSet(PreparedStatement st, String value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException { throws SQLException {
if ( value != null ) { if ( value != null ) {
if ( !value.startsWith( param1 ) ) { if ( !value.startsWith( param1 ) ) {
value = param1 + value; value = param1 + value;

View File

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

View File

@ -39,13 +39,14 @@ public class AgeType implements UserType<Age> {
} }
@Override @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 ) ); return new Age( rs.getInt( position ) );
} }
@Override @Override
public void nullSafeSet(PreparedStatement st, Age value, int index, SharedSessionContractImplementor session) public void nullSafeSet(PreparedStatement st, Age value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException { throws SQLException {
st.setInt( index, value.getAgeInYears() ); st.setInt( index, value.getAgeInYears() );
} }

View File

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