HHH-5941 : remove deprecated set(), nullSafeSet(), get(), nullSafeGet() methods and add SessionImplementer argument to UserType.nullSafeGet()/nullSafeSet()

This commit is contained in:
Gail Badner 2011-02-25 16:29:09 -08:00
parent 89eabb920d
commit 7243d04541
21 changed files with 87 additions and 147 deletions

View File

@ -48,38 +48,10 @@ public abstract class AbstractSingleColumnStandardBasicType<T>
super( sqlTypeDescriptor, javaTypeDescriptor );
}
private static WrapperOptions NO_OPTIONS = new WrapperOptions() {
public boolean useStreamForLobBinding() {
return false;
}
public LobCreator getLobCreator() {
return NonContextualLobCreator.INSTANCE;
}
public SqlTypeDescriptor resolveSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
return sqlTypeDescriptor;
}
};
public final int sqlType() {
return getSqlTypeDescriptor().getSqlType();
}
/**
* {@inheritDoc}
*/
public T nullSafeGet(ResultSet rs, String name) throws HibernateException, SQLException {
return nullSafeGet( rs, name, NO_OPTIONS );
}
/**
* {@inheritDoc}
*/
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
return nullSafeGet( rs, name );
}
/**
* {@inheritDoc}
*/
@ -89,19 +61,4 @@ public abstract class AbstractSingleColumnStandardBasicType<T>
nullSafeSet( st, value, index, session );
}
}
/**
* {@inheritDoc}
*/
public void nullSafeSet(PreparedStatement st, T value, int index) throws HibernateException, SQLException {
nullSafeSet( st, value, index, NO_OPTIONS );
}
/**
* {@inheritDoc}
*/
public void set(PreparedStatement st, T value, int index) throws HibernateException, SQLException {
nullSafeSet( st, value, index );
}
}

View File

@ -106,7 +106,7 @@ public class CustomType extends AbstractType implements IdentifierType, Discrimi
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
throws HibernateException, SQLException {
return userType.nullSafeGet(rs, names, owner);
return userType.nullSafeGet(rs, names, session, owner);
}
public Object nullSafeGet(ResultSet rs, String columnName, SessionImplementor session, Object owner)
@ -137,13 +137,13 @@ public class CustomType extends AbstractType implements IdentifierType, Discrimi
public void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SessionImplementor session)
throws HibernateException, SQLException {
if ( settable[0] ) {
userType.nullSafeSet( st, value, index );
userType.nullSafeSet( st, value, index, session );
}
}
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
throws HibernateException, SQLException {
userType.nullSafeSet( st, value, index );
userType.nullSafeSet( st, value, index, session );
}
@SuppressWarnings({ "UnusedDeclaration" })

View File

@ -34,6 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.usertype.EnhancedUserType;
import org.hibernate.usertype.ParameterizedType;
import org.hibernate.util.ReflectHelper;
@ -97,7 +98,7 @@ public class EnumType implements EnhancedUserType, ParameterizedType, Serializab
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
Object object = rs.getObject( names[0] );
if ( rs.wasNull() ) {
if ( IS_VALUE_TRACING_ENABLED ) {
@ -130,7 +131,7 @@ public class EnumType implements EnhancedUserType, ParameterizedType, Serializab
}
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if ( value == null ) {
if ( IS_VALUE_TRACING_ENABLED ) {
log().debug( "Binding null to parameter: {}", index );

View File

@ -46,12 +46,6 @@ public interface SingleColumnType<T> extends Type {
public T fromStringValue(String xml) throws HibernateException;
/**
* @deprecated Use {@link #nullSafeGet(ResultSet, String, SessionImplementor)} instead
*/
@SuppressWarnings({ "JavaDoc" })
public T nullSafeGet(ResultSet rs, String name) throws HibernateException, SQLException;
/**
* Get a column value from a result set by name.
*
@ -66,14 +60,6 @@ public interface SingleColumnType<T> extends Type {
*/
public T nullSafeGet(ResultSet rs, String name, SessionImplementor session) throws HibernateException, SQLException;
/**
* DO NOT USER THIS FORM!
*
* @deprecated Use {@link #get(ResultSet, String, SessionImplementor)} instead.
*/
@SuppressWarnings({ "JavaDoc" })
public Object get(ResultSet rs, String name) throws HibernateException, SQLException;
/**
* Get a column value from a result set, without worrying about the possibility of null values.
*
@ -88,22 +74,6 @@ public interface SingleColumnType<T> extends Type {
*/
public Object get(ResultSet rs, String name, SessionImplementor session) throws HibernateException, SQLException;
/**
* DO NOT USE THIS FORM!
*
* @deprecated Use {@link #nullSafeSet(PreparedStatement, Object, int, SessionImplementor)} instead.
*/
@SuppressWarnings({ "JavaDoc" })
public void nullSafeSet(PreparedStatement st, T value, int index) throws HibernateException, SQLException;
/**
* DO NOT USE THIS FORM!
*
* @deprecated Use {@link #set(PreparedStatement, Object, int, SessionImplementor)} instead.
*/
@SuppressWarnings({ "JavaDoc" })
public void set(PreparedStatement st, T value, int index) throws HibernateException, SQLException;
/**
* Set a parameter value without worrying about the possibility of null
* values. Called from {@link #nullSafeSet} after nullness checks have

View File

@ -33,6 +33,7 @@ import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.usertype.UserType;
/**
@ -59,7 +60,7 @@ public class StringClobType implements UserType, Serializable {
return x.hashCode();
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
Reader reader = rs.getCharacterStream( names[0] );
if ( reader == null ) return null;
StringBuilder result = new StringBuilder( 4096 );
@ -75,7 +76,7 @@ public class StringClobType implements UserType, Serializable {
return result.toString();
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if ( value != null ) {
String string = (String) value;
StringReader reader = new StringReader( string );

View File

@ -30,6 +30,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
/**
* This interface should be implemented by user-defined "types".
@ -100,27 +101,30 @@ public interface UserType {
* Retrieve an instance of the mapped class from a JDBC resultset. Implementors
* should handle possibility of null values.
*
*
* @param rs a JDBC result set
* @param names the column names
* @param owner the containing entity
* @return Object
* @param session
*@param owner the containing entity @return Object
* @throws HibernateException
* @throws SQLException
*/
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException;
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException;
/**
* Write an instance of the mapped class to a prepared statement. Implementors
* should handle possibility of null values. A multi-column type should be written
* to parameters starting from <tt>index</tt>.
*
*
* @param st a JDBC prepared statement
* @param value the object to write
* @param index statement parameter index
* @param session
* @throws HibernateException
* @throws SQLException
*/
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException;
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException;
/**
* Return a deep copy of the persistent state, stopping at entities and at

View File

@ -9,6 +9,7 @@ import java.sql.Types;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.usertype.ParameterizedType;
import org.hibernate.usertype.UserType;
@ -37,7 +38,7 @@ public class CasterStringType implements UserType, ParameterizedType {
return x.hashCode();
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
String result = rs.getString( names[0] );
if ( rs.wasNull() ) return null;
if ( parameters.getProperty( CAST ).equals( "lower" ) ) {
@ -48,7 +49,7 @@ public class CasterStringType implements UserType, ParameterizedType {
}
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if ( value == null ) {
st.setNull( index, sqlTypes()[0] );
}

View File

@ -62,8 +62,8 @@ public class MonetaryAmountUserType implements CompositeUserType {
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
throws HibernateException, SQLException {
BigDecimal amt = (BigDecimal) Hibernate.BIG_DECIMAL.nullSafeGet( rs, names[0] );
Currency cur = (Currency) Hibernate.CURRENCY.nullSafeGet( rs, names[1] );
BigDecimal amt = (BigDecimal) Hibernate.BIG_DECIMAL.nullSafeGet( rs, names[0], session);
Currency cur = (Currency) Hibernate.CURRENCY.nullSafeGet( rs, names[1], session );
if ( amt == null ) return null;
return new MonetaryAmount( amt, cur );
}
@ -75,8 +75,8 @@ public class MonetaryAmountUserType implements CompositeUserType {
MonetaryAmount ma = (MonetaryAmount) value;
BigDecimal amt = ma == null ? null : ma.getAmount();
Currency cur = ma == null ? null : ma.getCurrency();
Hibernate.BIG_DECIMAL.nullSafeSet( st, amt, index );
Hibernate.CURRENCY.nullSafeSet( st, cur, index + 1 );
Hibernate.BIG_DECIMAL.nullSafeSet( st, amt, index, session );
Hibernate.CURRENCY.nullSafeSet( st, cur, index + 1, session );
}
public Object deepCopy(Object value) throws HibernateException {

View File

@ -29,6 +29,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.usertype.UserType;
/**
@ -54,7 +55,7 @@ public class PhoneNumberType implements UserType {
return x.hashCode();
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
String result = rs.getString( names[0] );
if ( rs.wasNull() ) return null;
@ -66,7 +67,7 @@ public class PhoneNumberType implements UserType {
}
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if ( value == null ) {
st.setNull( index, sqlTypes()[0] );
return;

View File

@ -7,6 +7,7 @@ import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.Types;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.usertype.UserType;
import org.hibernate.HibernateException;
@ -32,13 +33,13 @@ public class StateType implements UserType {
return x.hashCode();
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
int result = rs.getInt( names[0] );
if ( rs.wasNull() ) return null;
return State.values()[result];
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if (value == null) {
st.setNull( index, Types.INTEGER );
}

View File

@ -93,10 +93,10 @@ public class MyOidType implements CompositeUserType {
public Object nullSafeGet(
ResultSet aResultSet, String[] names, SessionImplementor aSessionImplementor, Object aObject
) throws HibernateException, SQLException {
Integer highval = (Integer) Hibernate.INTEGER.nullSafeGet( aResultSet, names[0] );
Integer midval = (Integer) Hibernate.INTEGER.nullSafeGet( aResultSet, names[1] );
Integer lowval = (Integer) Hibernate.INTEGER.nullSafeGet( aResultSet, names[2] );
Integer other = (Integer) Hibernate.INTEGER.nullSafeGet( aResultSet, names[3] );
Integer highval = (Integer) Hibernate.INTEGER.nullSafeGet( aResultSet, names[0], aSessionImplementor );
Integer midval = (Integer) Hibernate.INTEGER.nullSafeGet( aResultSet, names[1], aSessionImplementor );
Integer lowval = (Integer) Hibernate.INTEGER.nullSafeGet( aResultSet, names[2], aSessionImplementor );
Integer other = (Integer) Hibernate.INTEGER.nullSafeGet( aResultSet, names[3], aSessionImplementor );
return new MyOid( highval, midval, lowval, other );
}
@ -113,10 +113,10 @@ public class MyOidType implements CompositeUserType {
c = (MyOid) value;
}
Hibernate.INTEGER.nullSafeSet( aPreparedStatement, c.getHigh(), index );
Hibernate.INTEGER.nullSafeSet( aPreparedStatement, c.getMiddle(), index + 1 );
Hibernate.INTEGER.nullSafeSet( aPreparedStatement, c.getLow(), index + 2 );
Hibernate.INTEGER.nullSafeSet( aPreparedStatement, c.getOther(), index + 3 );
Hibernate.INTEGER.nullSafeSet( aPreparedStatement, c.getHigh(), index, aSessionImplementor );
Hibernate.INTEGER.nullSafeSet( aPreparedStatement, c.getMiddle(), index + 1, aSessionImplementor );
Hibernate.INTEGER.nullSafeSet( aPreparedStatement, c.getLow(), index + 2, aSessionImplementor );
Hibernate.INTEGER.nullSafeSet( aPreparedStatement, c.getOther(), index + 3, aSessionImplementor );
}
public Object deepCopy(Object aObject) throws HibernateException {

View File

@ -62,8 +62,8 @@ public class MonetoryAmountUserType implements CompositeUserType {
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
throws HibernateException, SQLException {
BigDecimal amt = (BigDecimal) Hibernate.BIG_DECIMAL.nullSafeGet( rs, names[0] );
Currency cur = (Currency) Hibernate.CURRENCY.nullSafeGet( rs, names[1] );
BigDecimal amt = (BigDecimal) Hibernate.BIG_DECIMAL.nullSafeGet( rs, names[0], session );
Currency cur = (Currency) Hibernate.CURRENCY.nullSafeGet( rs, names[1], session );
if (amt==null) return null;
return new MonetoryAmount(amt, cur);
}
@ -73,8 +73,8 @@ public class MonetoryAmountUserType implements CompositeUserType {
MonetoryAmount ma = (MonetoryAmount) value;
BigDecimal amt = ma == null ? null : ma.getAmount();
Currency cur = ma == null ? null : ma.getCurrency();
Hibernate.BIG_DECIMAL.nullSafeSet(st, amt, index);
Hibernate.CURRENCY.nullSafeSet(st, cur, index+1);
Hibernate.BIG_DECIMAL.nullSafeSet(st, amt, index, session);
Hibernate.CURRENCY.nullSafeSet(st, cur, index+1, session);
}
public Object deepCopy(Object value) throws HibernateException {

View File

@ -1,5 +1,6 @@
package org.hibernate.test.hql;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.type.IntegerType;
import org.hibernate.usertype.EnhancedUserType;
import org.hibernate.HibernateException;
@ -46,14 +47,14 @@ public class ClassificationType implements EnhancedUserType {
return x.hashCode();
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
Integer ordinal = ( Integer ) IntegerType.INSTANCE.nullSafeGet( rs, names[0] );
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
Integer ordinal = ( Integer ) IntegerType.INSTANCE.nullSafeGet( rs, names[0], session );
return Classification.valueOf( ordinal );
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
Integer ordinal = value == null ? null : new Integer( ( ( Classification ) value ).ordinal() );
Hibernate.INTEGER.nullSafeSet( st, ordinal, index );
Hibernate.INTEGER.nullSafeSet( st, ordinal, index, session );
}
public Object deepCopy(Object value) throws HibernateException {

View File

@ -9,6 +9,7 @@ import java.util.Arrays;
import org.hibernate.HibernateException;
import org.hibernate.Hibernate;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.usertype.UserType;
/**
@ -18,17 +19,17 @@ public class CustomBlobType implements UserType {
/**
* {@inheritDoc}
*/
public Object nullSafeGet(ResultSet rs, String names[], Object owner) throws SQLException {
public Object nullSafeGet(ResultSet rs, String names[], SessionImplementor session, Object owner) throws SQLException {
// cast just to make sure...
return ( byte[] ) Hibernate.BINARY.nullSafeGet( rs, names[0] );
return ( byte[] ) Hibernate.BINARY.nullSafeGet( rs, names[0], session );
}
/**
* {@inheritDoc}
*/
public void nullSafeSet(PreparedStatement ps, Object value, int index) throws SQLException, HibernateException {
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException {
// cast just to make sure...
Hibernate.BINARY.nullSafeSet( ps, ( byte[] ) value, index );
Hibernate.BINARY.nullSafeSet( ps, ( byte[] ) value, index, session );
}
/**

View File

@ -8,6 +8,7 @@ import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.usertype.UserType;
/**
@ -31,12 +32,12 @@ public class RowIdType implements UserType {
return x.hashCode();
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
throws HibernateException, SQLException {
return rs.getObject( names[0] );
}
public void nullSafeSet(PreparedStatement st, Object value, int index)
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
throws HibernateException, SQLException {
throw new UnsupportedOperationException();
}

View File

@ -9,6 +9,7 @@ import java.sql.Types;
import java.util.Currency;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.usertype.UserType;
/**
@ -40,7 +41,7 @@ public class MonetaryAmountUserType
public Object nullSafeGet(ResultSet resultSet,
String[] names,
Object owner)
SessionImplementor session, Object owner)
throws HibernateException, SQLException {
BigDecimal value = resultSet.getBigDecimal(names[0]);
@ -53,7 +54,7 @@ public class MonetaryAmountUserType
public void nullSafeSet(PreparedStatement statement,
Object value,
int index)
int index, SessionImplementor session)
throws HibernateException, SQLException {
if (value == null) {

View File

@ -9,6 +9,7 @@ import java.util.Properties;
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.usertype.ParameterizedType;
import org.hibernate.usertype.UserType;
@ -34,12 +35,12 @@ public class DefaultValueIntegerType implements UserType, ParameterizedType, Ser
return x.equals(y);
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
Number result = (Number) rs.getObject(names[0]);
return result==null ? defaultValue : new Integer(result.intValue());
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if (value == null || defaultValue.equals(value) ) {
LoggerFactory.getLogger( getClass() ).trace("binding null to parameter: " + index);
st.setNull(index, Types.INTEGER);

View File

@ -24,7 +24,6 @@
package org.hibernate.type;
import java.io.Serializable;
import java.net.Socket;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -35,7 +34,6 @@ import junit.framework.TestCase;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.type.descriptor.java.StringTypeDescriptor;
import org.hibernate.type.descriptor.java.UrlTypeDescriptor;
import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.UserType;
@ -132,11 +130,11 @@ public class BasicTypeRegistryTest extends TestCase {
return 0;
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
return null;
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
}
public Object deepCopy(Object value) throws HibernateException {

View File

@ -29,9 +29,11 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.envers.RevisionType;
import org.hibernate.HibernateException;
import org.hibernate.type.IntegerType;
import org.hibernate.usertype.UserType;
/**
@ -49,23 +51,20 @@ public class RevisionTypeType implements UserType {
return RevisionType.class;
}
public RevisionType nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException {
byte representation = (byte) resultSet.getInt(names[0]);
RevisionType result = null;
if (!resultSet.wasNull()) {
result = RevisionType.fromRepresentation(representation);
}
return result;
public RevisionType nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
Integer representationInt = IntegerType.INSTANCE.nullSafeGet( resultSet, names[0], session );
return representationInt == null ?
null :
RevisionType.fromRepresentation( representationInt.byteValue() );
}
public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException {
if (null == value) {
preparedStatement.setNull(index, Types.TINYINT);
} else {
preparedStatement.setInt(index, ((RevisionType) value).getRepresentation());
}
public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
IntegerType.INSTANCE.nullSafeSet(
preparedStatement,
( value == null ? null : ((RevisionType) value).getRepresentation().intValue() ),
index,
session
);
}
public Object deepCopy(Object value) throws HibernateException{

View File

@ -30,8 +30,8 @@ import java.sql.SQLException;
import java.sql.Types;
import java.util.Properties;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.type.StringType;
import org.hibernate.usertype.ParameterizedType;
import org.hibernate.usertype.UserType;
@ -54,11 +54,11 @@ public class ParametrizedTestUserType implements UserType, ParameterizedType {
return String.class;
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
return StringType.INSTANCE.nullSafeGet( rs, names[0] );
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
return StringType.INSTANCE.nullSafeGet( rs, names[0], session );
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if (value != null) {
String v = (String) value;
if (!v.startsWith(param1)) {
@ -67,10 +67,10 @@ public class ParametrizedTestUserType implements UserType, ParameterizedType {
if (!v.endsWith(param2)) {
v = v + param2;
}
StringType.INSTANCE.nullSafeSet(st, v, index);
StringType.INSTANCE.nullSafeSet(st, v, index, session);
}
else {
StringType.INSTANCE.nullSafeSet( st, null, index );
StringType.INSTANCE.nullSafeSet( st, null, index, session );
}
}

View File

@ -30,6 +30,8 @@ import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.type.StringType;
import org.hibernate.usertype.UserType;
/**
@ -60,7 +62,7 @@ public class CustomEnumUserType implements UserType {
return (x == null) ? 0 : x.hashCode();
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
String name = rs.getString(names[0]);
if (rs.wasNull()) {
return null;
@ -68,7 +70,7 @@ public class CustomEnumUserType implements UserType {
return CustomEnum.fromYesNo(name);
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
CustomEnum val = (CustomEnum) value;
if (val == null) {
st.setNull(index, Types.VARCHAR);