HHH-12463 - Delegate CustomType#equals/hashCode to wrapped UserType

This commit is contained in:
Steve Ebersole 2018-05-12 17:58:40 -05:00
parent 1a4577d1f0
commit 4208ca0a2f
1 changed files with 44 additions and 34 deletions

View File

@ -97,17 +97,17 @@ public class CustomType
@Override @Override
public Class getReturnedClass() { public Class getReturnedClass() {
return userType.returnedClass(); return getUserType().returnedClass();
} }
@Override @Override
public boolean isEqual(Object x, Object y) throws HibernateException { public boolean isEqual(Object x, Object y) throws HibernateException {
return userType.equals( x, y ); return getUserType().equals( x, y );
} }
@Override @Override
public int getHashCode(Object x) { public int getHashCode(Object x) {
return userType.hashCode(x); return getUserType().hashCode( x);
} }
@Override @Override
@ -116,7 +116,7 @@ public class CustomType
String[] names, String[] names,
SharedSessionContractImplementor session, SharedSessionContractImplementor session,
Object owner) throws SQLException { Object owner) throws SQLException {
return userType.nullSafeGet(rs, names, session, owner); return getUserType().nullSafeGet( rs, names, session, owner);
} }
@Override @Override
@ -131,12 +131,12 @@ public class CustomType
@Override @Override
public Object assemble(Serializable cached, SharedSessionContractImplementor session, Object owner) { public Object assemble(Serializable cached, SharedSessionContractImplementor session, Object owner) {
return userType.assemble(cached, owner); return getUserType().assemble( cached, owner);
} }
@Override @Override
public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) { public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) {
return userType.disassemble(value); return getUserType().disassemble( value);
} }
@Override @Override
@ -146,7 +146,7 @@ public class CustomType
SharedSessionContractImplementor session, SharedSessionContractImplementor session,
Object owner, Object owner,
Map copyCache) throws HibernateException { Map copyCache) throws HibernateException {
return userType.replace( original, target, owner ); return getUserType().replace( original, target, owner );
} }
@Override @Override
@ -157,7 +157,7 @@ public class CustomType
boolean[] settable, boolean[] settable,
SharedSessionContractImplementor session) throws SQLException { SharedSessionContractImplementor session) throws SQLException {
if ( settable[0] ) { if ( settable[0] ) {
userType.nullSafeSet( st, value, index, session ); getUserType().nullSafeSet( st, value, index, session );
} }
} }
@ -167,7 +167,7 @@ public class CustomType
Object value, Object value,
int index, int index,
SharedSessionContractImplementor session) throws SQLException { SharedSessionContractImplementor session) throws SQLException {
userType.nullSafeSet( st, value, index, session ); getUserType().nullSafeSet( st, value, index, session );
} }
@SuppressWarnings({ "UnusedDeclaration" }) @SuppressWarnings({ "UnusedDeclaration" })
@ -187,12 +187,12 @@ public class CustomType
@Override @Override
public Object deepCopy(Object value, SessionFactoryImplementor factory) throws HibernateException { public Object deepCopy(Object value, SessionFactoryImplementor factory) throws HibernateException {
return userType.deepCopy(value); return getUserType().deepCopy( value);
} }
@Override @Override
public boolean isMutable() { public boolean isMutable() {
return userType.isMutable(); return getUserType().isMutable();
} }
@Override @Override
@ -202,22 +202,22 @@ public class CustomType
@Override @Override
public String objectToSQLString(Object value, Dialect dialect) throws Exception { public String objectToSQLString(Object value, Dialect dialect) throws Exception {
return ( (EnhancedUserType) userType ).objectToSQLString(value); return ( (EnhancedUserType) getUserType() ).objectToSQLString( value);
} }
@Override @Override
public Comparator getComparator() { public Comparator getComparator() {
return (Comparator) userType; return (Comparator) getUserType();
} }
@Override @Override
public Object next(Object current, SharedSessionContractImplementor session) { public Object next(Object current, SharedSessionContractImplementor session) {
return ( (UserVersionType) userType ).next( current, session ); return ( (UserVersionType) getUserType() ).next( current, session );
} }
@Override @Override
public Object seed(SharedSessionContractImplementor session) { public Object seed(SharedSessionContractImplementor session) {
return ( (UserVersionType) userType ).seed( session ); return ( (UserVersionType) getUserType() ).seed( session );
} }
@Override @Override
@ -227,7 +227,7 @@ public class CustomType
return "null"; return "null";
} }
else if ( customLogging ) { else if ( customLogging ) {
return ( ( LoggableUserType ) userType ).toLoggableString( value, factory ); return ( ( LoggableUserType ) getUserType() ).toLoggableString( value, factory );
} }
else { else {
return toXMLString( value, factory ); return toXMLString( value, factory );
@ -252,27 +252,27 @@ public class CustomType
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public String toString(Object value) throws HibernateException { public String toString(Object value) throws HibernateException {
if ( StringRepresentableType.class.isInstance( userType ) ) { if ( StringRepresentableType.class.isInstance( getUserType() ) ) {
return ( (StringRepresentableType) userType ).toString( value ); return ( (StringRepresentableType) getUserType() ).toString( value );
} }
if ( value == null ) { if ( value == null ) {
return null; return null;
} }
if ( EnhancedUserType.class.isInstance( userType ) ) { if ( EnhancedUserType.class.isInstance( getUserType() ) ) {
//noinspection deprecation //noinspection deprecation
return ( (EnhancedUserType) userType ).toXMLString( value ); return ( (EnhancedUserType) getUserType() ).toXMLString( value );
} }
return value.toString(); return value.toString();
} }
@Override @Override
public Object fromStringValue(String string) throws HibernateException { public Object fromStringValue(String string) throws HibernateException {
if ( StringRepresentableType.class.isInstance( userType ) ) { if ( StringRepresentableType.class.isInstance( getUserType() ) ) {
return ( (StringRepresentableType) userType ).fromStringValue( string ); return ( (StringRepresentableType) getUserType() ).fromStringValue( string );
} }
if ( EnhancedUserType.class.isInstance( userType ) ) { if ( EnhancedUserType.class.isInstance( getUserType() ) ) {
//noinspection deprecation //noinspection deprecation
return ( (EnhancedUserType) userType ).fromXMLString( string ); return ( (EnhancedUserType) getUserType() ).fromXMLString( string );
} }
throw new HibernateException( throw new HibernateException(
String.format( String.format(
@ -286,8 +286,8 @@ public class CustomType
@Override @Override
public boolean canDoSetting() { public boolean canDoSetting() {
if ( ProcedureParameterNamedBinder.class.isInstance( userType ) ) { if ( ProcedureParameterNamedBinder.class.isInstance( getUserType() ) ) {
return ((ProcedureParameterNamedBinder) userType).canDoSetting(); return ((ProcedureParameterNamedBinder) getUserType() ).canDoSetting();
} }
return false; return false;
} }
@ -296,19 +296,19 @@ public class CustomType
public void nullSafeSet( public void nullSafeSet(
CallableStatement statement, Object value, String name, SharedSessionContractImplementor session) throws SQLException { CallableStatement statement, Object value, String name, SharedSessionContractImplementor session) throws SQLException {
if ( canDoSetting() ) { if ( canDoSetting() ) {
((ProcedureParameterNamedBinder) userType).nullSafeSet( statement, value, name, session ); ((ProcedureParameterNamedBinder) getUserType() ).nullSafeSet( statement, value, name, session );
} }
else { else {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Type [" + userType + "] does support parameter binding by name" "Type [" + getUserType() + "] does support parameter binding by name"
); );
} }
} }
@Override @Override
public boolean canDoExtraction() { public boolean canDoExtraction() {
if ( ProcedureParameterExtractionAware.class.isInstance( userType ) ) { if ( ProcedureParameterExtractionAware.class.isInstance( getUserType() ) ) {
return ((ProcedureParameterExtractionAware) userType).canDoExtraction(); return ((ProcedureParameterExtractionAware) getUserType() ).canDoExtraction();
} }
return false; return false;
} }
@ -316,11 +316,11 @@ public class CustomType
@Override @Override
public Object extract(CallableStatement statement, int startIndex, SharedSessionContractImplementor session) throws SQLException { public Object extract(CallableStatement statement, int startIndex, SharedSessionContractImplementor session) throws SQLException {
if ( canDoExtraction() ) { if ( canDoExtraction() ) {
return ((ProcedureParameterExtractionAware) userType).extract( statement, startIndex, session ); return ((ProcedureParameterExtractionAware) getUserType() ).extract( statement, startIndex, session );
} }
else { else {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Type [" + userType + "] does support parameter value extraction" "Type [" + getUserType() + "] does support parameter value extraction"
); );
} }
} }
@ -329,12 +329,22 @@ public class CustomType
public Object extract(CallableStatement statement, String[] paramNames, SharedSessionContractImplementor session) public Object extract(CallableStatement statement, String[] paramNames, SharedSessionContractImplementor session)
throws SQLException { throws SQLException {
if ( canDoExtraction() ) { if ( canDoExtraction() ) {
return ((ProcedureParameterExtractionAware) userType).extract( statement, paramNames, session ); return ((ProcedureParameterExtractionAware) getUserType() ).extract( statement, paramNames, session );
} }
else { else {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Type [" + userType + "] does support parameter value extraction" "Type [" + getUserType() + "] does support parameter value extraction"
); );
} }
} }
@Override
public int hashCode() {
return getUserType().hashCode();
}
@Override
public boolean equals(Object obj) {
return ( obj instanceof CustomType ) && getUserType().equals( ( (CustomType) obj ).getUserType() );
}
} }