org.hibernate.type.LongType 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.io.Serializable;
import java.util.Comparator;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.type.descriptor.java.LongTypeDescriptor;
import org.hibernate.type.descriptor.sql.BigIntTypeDescriptor;
/**
* A type that maps between {@link java.sql.Types#BIGINT BIGINT} and {@link Long}
*
* @author Gavin King
* @author Steve Ebersole
*/
public class LongType
extends AbstractSingleColumnStandardBasicType
implements PrimitiveType, DiscriminatorType, VersionType {
public static final LongType INSTANCE = new LongType();
private static final Long ZERO = (long) 0;
public LongType() {
super( BigIntTypeDescriptor.INSTANCE, LongTypeDescriptor.INSTANCE );
}
@Override
public String getName() {
return "long";
}
@Override
public String[] getRegistrationKeys() {
return new String[] { getName(), long.class.getName(), Long.class.getName() };
}
@Override
public Serializable getDefaultValue() {
return ZERO;
}
@Override
public Class getPrimitiveClass() {
return long.class;
}
@Override
public Long stringToObject(String xml) throws Exception {
return Long.valueOf( xml );
}
@Override
public Long next(Long current, SharedSessionContractImplementor session) {
return current + 1L;
}
@Override
public Long seed(SharedSessionContractImplementor session) {
return ZERO;
}
@Override
public Comparator getComparator() {
return getJavaTypeDescriptor().getComparator();
}
@Override
public String objectToSQLString(Long value, Dialect dialect) throws Exception {
return value.toString();
}
}