org.hibernate.type.RowVersionType 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
The core O/RM functionality as provided by Hibernate
/*
* 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.util.Comparator;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.compare.RowVersionComparator;
import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor;
import org.hibernate.type.descriptor.java.RowVersionTypeDescriptor;
import org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor;
/**
* A type that maps between a {@link java.sql.Types#VARBINARY VARBINARY} and {@code byte[]}
* specifically for entity versions/timestamps.
*
* @author Gavin King
* @author Steve Ebersole
* @author Gail Badner
*/
public class RowVersionType
extends AbstractSingleColumnStandardBasicType
implements VersionType {
public static final RowVersionType INSTANCE = new RowVersionType();
public String getName() {
return "row_version";
}
public RowVersionType() {
super( VarbinaryTypeDescriptor.INSTANCE, RowVersionTypeDescriptor.INSTANCE );
}
@Override
public String[] getRegistrationKeys() {
return new String[] { getName() };
}
@Override
public byte[] seed(SharedSessionContractImplementor session) {
// Note : simply returns null for seed() and next() as the only known
// application of binary types for versioning is for use with the
// TIMESTAMP datatype supported by Sybase and SQL Server, which
// are completely db-generated values...
return null;
}
@Override
public byte[] next(byte[] current, SharedSessionContractImplementor session) {
return current;
}
@Override
public Comparator getComparator() {
return getJavaTypeDescriptor().getComparator();
}
}