com.vladmihalcea.hibernate.type.basic.internal.Iso8601MonthMonthTypeDescriptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-types-60 Show documentation
Show all versions of hibernate-types-60 Show documentation
Hibernate ORM 6.0 extra Types
package com.vladmihalcea.hibernate.type.basic.internal;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.AbstractClassJavaType;
import java.time.Month;
import java.util.Objects;
/**
* @author Martin Panzer
*/
public class Iso8601MonthMonthTypeDescriptor
extends AbstractClassJavaType {
public static final Iso8601MonthMonthTypeDescriptor INSTANCE = new Iso8601MonthMonthTypeDescriptor();
public Iso8601MonthMonthTypeDescriptor() {
super(Month.class);
}
@Override
public boolean areEqual(Month one, Month another) {
return Objects.equals(one, another);
}
@Override
public String toString(Month value) {
return value.toString();
}
@SuppressWarnings({"unchecked"})
@Override
public X unwrap(Month value, Class type, WrapperOptions options) {
if (value == null) {
return null;
}
if (Number.class.isAssignableFrom(type)) {
return (X) (Number) value.getValue();
}
throw unknownUnwrap(type);
}
@Override
public Month wrap(X value, WrapperOptions options) {
if (value == null) {
return null;
}
if (value instanceof Number) {
int numericValue = ((Number) (value)).intValue();
return Month.of(numericValue);
}
throw unknownWrap(value.getClass());
}
}