Make use of type variable for a few CompositeUserType methods

This commit is contained in:
Christian Beikov 2022-03-22 15:49:50 +01:00
parent 4b48dd31f6
commit ce298a1566
4 changed files with 31 additions and 31 deletions

View File

@ -59,13 +59,12 @@ public class MonetaryAmountUserType implements CompositeUserType<MonetaryAmount>
}
@Override
public Object deepCopy(Object value) {
MonetaryAmount ma = (MonetaryAmount) value;
return new MonetaryAmount( ma.getAmount(), ma.getCurrency() );
public MonetaryAmount deepCopy(MonetaryAmount value) {
return new MonetaryAmount( value.getAmount(), value.getCurrency() );
}
@Override
public boolean equals(Object x, Object y) {
public boolean equals(MonetaryAmount x, MonetaryAmount y) {
if ( x == y ) {
return true;
}
@ -76,22 +75,22 @@ public class MonetaryAmountUserType implements CompositeUserType<MonetaryAmount>
}
@Override
public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) deepCopy( value );
public Serializable disassemble(MonetaryAmount value) throws HibernateException {
return deepCopy( value );
}
@Override
public Object assemble(Serializable cached, Object owner) throws HibernateException {
return deepCopy( cached );
public MonetaryAmount assemble(Serializable cached, Object owner) throws HibernateException {
return deepCopy( (MonetaryAmount) cached );
}
@Override
public Object replace(Object original, Object target, Object owner) throws HibernateException {
public MonetaryAmount replace(MonetaryAmount original, MonetaryAmount target, Object owner) throws HibernateException {
return deepCopy( original ); //TODO: improve
}
@Override
public int hashCode(Object x) throws HibernateException {
public int hashCode(MonetaryAmount x) throws HibernateException {
return x.hashCode();
}

View File

@ -71,12 +71,12 @@ public interface CompositeUserType<J> extends EmbeddableInstantiator {
* Compare two instances of the class mapped by this type for persistence "equality".
* Equality of the persistent state.
*/
boolean equals(Object x, Object y);
boolean equals(J x, J y);
/**
* Get a hashcode for the instance, consistent with persistence "equality"
*/
int hashCode(Object x);
int hashCode(J x);
/**
* Return a deep copy of the persistent state, stopping at entities and at
@ -86,7 +86,7 @@ public interface CompositeUserType<J> extends EmbeddableInstantiator {
* @param value the object to be cloned, which may be null
* @return Object a copy
*/
Object deepCopy(Object value);
J deepCopy(J value);
/**
* Are objects of this type mutable?
@ -104,7 +104,7 @@ public interface CompositeUserType<J> extends EmbeddableInstantiator {
* @param value the object to be cached
* @return a cacheable representation of the object
*/
Serializable disassemble(Object value);
Serializable disassemble(J value);
/**
* Reconstruct an object from the cacheable representation. At the very least this
@ -114,7 +114,7 @@ public interface CompositeUserType<J> extends EmbeddableInstantiator {
* @param owner the owner of the cached object
* @return a reconstructed object from the cacheable representation
*/
Object assemble(Serializable cached, Object owner);
J assemble(Serializable cached, Object owner);
/**
* During merge, replace the existing (target) value in the entity we are merging to
@ -128,7 +128,7 @@ public interface CompositeUserType<J> extends EmbeddableInstantiator {
*
* @return the value to be merged
*/
Object replace(Object detached, Object managed, Object owner);
J replace(J detached, J managed, Object owner);
@Override
default boolean isInstance(Object object, SessionFactoryImplementor sessionFactory) {

View File

@ -19,17 +19,17 @@ public abstract class AbstractTimeZoneStorageCompositeUserType<T> implements Com
public static final String ZONE_OFFSET_NAME = "zoneOffset";
@Override
public boolean equals(Object x, Object y) {
public boolean equals(T x, T y) {
return x.equals( y );
}
@Override
public int hashCode(Object x) {
public int hashCode(T x) {
return x.hashCode();
}
@Override
public Object deepCopy(Object value) {
public T deepCopy(T value) {
return value;
}
@ -39,17 +39,18 @@ public abstract class AbstractTimeZoneStorageCompositeUserType<T> implements Com
}
@Override
public Serializable disassemble(Object value) {
public Serializable disassemble(T value) {
return (Serializable) value;
}
@Override
public Object assemble(Serializable cached, Object owner) {
return cached;
public T assemble(Serializable cached, Object owner) {
//noinspection unchecked
return (T) cached;
}
@Override
public Object replace(Object detached, Object managed, Object owner) {
public T replace(T detached, T managed, Object owner) {
return detached;
}

View File

@ -61,12 +61,12 @@ public class MonetaryAmountUserType implements CompositeUserType<MonetaryAmount>
}
@Override
public Object deepCopy(Object value) {
public MonetaryAmount deepCopy(MonetaryAmount value) {
return value; // MonetaryAmount is immutable
}
@Override
public boolean equals(Object x, Object y) {
public boolean equals(MonetaryAmount x, MonetaryAmount y) {
if ( x == y ) {
return true;
}
@ -77,22 +77,22 @@ public class MonetaryAmountUserType implements CompositeUserType<MonetaryAmount>
}
@Override
public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) value;
public Serializable disassemble(MonetaryAmount value) throws HibernateException {
return value;
}
@Override
public Object assemble(Serializable cached, Object owner) throws HibernateException {
return cached;
public MonetaryAmount assemble(Serializable cached, Object owner) throws HibernateException {
return (MonetaryAmount) cached;
}
@Override
public Object replace(Object original, Object target, Object owner) throws HibernateException {
public MonetaryAmount replace(MonetaryAmount original, MonetaryAmount target, Object owner) throws HibernateException {
return original;
}
@Override
public int hashCode(Object x) throws HibernateException {
public int hashCode(MonetaryAmount x) throws HibernateException {
return x.hashCode();
}