org.hibernate.type.ZonedDateTimeType 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;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Comparator;
import java.util.Locale;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.ZonedDateTimeComparator;
import org.hibernate.type.descriptor.java.ZonedDateTimeJavaDescriptor;
import org.hibernate.type.descriptor.sql.TimestampTypeDescriptor;
/**
* @author Steve Ebersole
*/
public class ZonedDateTimeType
extends AbstractSingleColumnStandardBasicType
implements VersionType, LiteralType {
/**
* Singleton access
*/
public static final ZonedDateTimeType INSTANCE = new ZonedDateTimeType();
public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern( "yyyy-MM-dd HH:mm:ss.S VV", Locale.ENGLISH );
public ZonedDateTimeType() {
super( TimestampTypeDescriptor.INSTANCE, ZonedDateTimeJavaDescriptor.INSTANCE );
}
@Override
public String objectToSQLString(ZonedDateTime value, Dialect dialect) throws Exception {
return "{ts '" + FORMATTER.format( value ) + "'}";
}
@Override
public ZonedDateTime seed(SharedSessionContractImplementor session) {
return ZonedDateTime.now();
}
@Override
public ZonedDateTime next(ZonedDateTime current, SharedSessionContractImplementor session) {
return ZonedDateTime.now();
}
@Override
@SuppressWarnings("unchecked")
public Comparator getComparator() {
return ZonedDateTimeComparator.INSTANCE;
}
@Override
public String getName() {
return ZonedDateTime.class.getSimpleName();
}
@Override
protected boolean registerUnderJavaType() {
return true;
}
}