org.hibernate.type.descriptor.java.AbstractTypeDescriptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-core Show documentation
Show all versions of hibernate-core Show documentation
JPMS Module-Info's for a few of the Jakarta Libraries just until they add them in themselves
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.type.descriptor.java;
import java.io.Serializable;
import java.util.Comparator;
import java.util.Objects;
import org.hibernate.HibernateException;
import org.hibernate.internal.util.compare.ComparableComparator;
/**
* Abstract adapter for Java type descriptors.
*
* @apiNote This abstract descriptor implements BasicJavaDescriptor
* because we currently only categorize "basic" JavaTypeDescriptors,
* as in the {@link jakarta.persistence.metamodel.Type.PersistenceType#BASIC}
* sense
*
* @author Steve Ebersole
*/
public abstract class AbstractTypeDescriptor implements BasicJavaDescriptor, Serializable {
private final Class type;
private final MutabilityPlan mutabilityPlan;
private final Comparator comparator;
/**
* Initialize a type descriptor for the given type. Assumed immutable.
*
* @param type The Java type.
*
* @see #AbstractTypeDescriptor(Class, MutabilityPlan)
*/
@SuppressWarnings({ "unchecked" })
protected AbstractTypeDescriptor(Class type) {
this( type, (MutabilityPlan) ImmutableMutabilityPlan.INSTANCE );
}
/**
* Initialize a type descriptor for the given type. Assumed immutable.
*
* @param type The Java type.
* @param mutabilityPlan The plan for handling mutability aspects of the java type.
*/
@SuppressWarnings({ "unchecked" })
protected AbstractTypeDescriptor(Class type, MutabilityPlan mutabilityPlan) {
this.type = type;
this.mutabilityPlan = mutabilityPlan;
this.comparator = Comparable.class.isAssignableFrom( type )
? (Comparator) ComparableComparator.INSTANCE
: null;
}
@Override
public MutabilityPlan getMutabilityPlan() {
return mutabilityPlan;
}
public Class getJavaType() {
return type;
}
/**
* @deprecated Use {@link #getJavaType()} instead
*/
@Override
@Deprecated
public Class getJavaTypeClass() {
return getJavaType();
}
@Override
public int extractHashCode(T value) {
return value.hashCode();
}
@Override
public boolean areEqual(T one, T another) {
return Objects.equals( one, another );
}
@Override
public Comparator getComparator() {
return comparator;
}
@Override
public String extractLoggableRepresentation(T value) {
return (value == null) ? "null" : value.toString();
}
protected HibernateException unknownUnwrap(Class conversionType) {
throw new HibernateException(
"Unknown unwrap conversion requested: " + type.getName() + " to " + conversionType.getName()
);
}
protected HibernateException unknownWrap(Class conversionType) {
throw new HibernateException(
"Unknown wrap conversion requested: " + conversionType.getName() + " to " + type.getName()
);
}
}