diff --git a/documentation/src/test/java/org/hibernate/userguide/collections/type/TimestampEpochType.java b/documentation/src/test/java/org/hibernate/userguide/collections/type/TimestampEpochType.java index 52cd0eb9a8..9554a43309 100644 --- a/documentation/src/test/java/org/hibernate/userguide/collections/type/TimestampEpochType.java +++ b/documentation/src/test/java/org/hibernate/userguide/collections/type/TimestampEpochType.java @@ -6,14 +6,10 @@ */ package org.hibernate.userguide.collections.type; -import java.sql.Timestamp; -import java.util.Comparator; import java.util.Date; import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.VersionType; import org.hibernate.type.descriptor.java.JdbcTimestampTypeDescriptor; import org.hibernate.type.descriptor.jdbc.BigIntTypeDescriptor; @@ -22,9 +18,7 @@ import org.hibernate.type.descriptor.jdbc.BigIntTypeDescriptor; */ //tag::collections-map-custom-key-type-mapping-example[] -public class TimestampEpochType - extends AbstractSingleColumnStandardBasicType - implements VersionType { +public class TimestampEpochType extends AbstractSingleColumnStandardBasicType { public static final TimestampEpochType INSTANCE = new TimestampEpochType(); @@ -41,26 +35,7 @@ public class TimestampEpochType } @Override - public Date next( - Date current, - SharedSessionContractImplementor session) { - return seed( session ); - } - - @Override - public Date seed( - SharedSessionContractImplementor session) { - return new Timestamp( System.currentTimeMillis() ); - } - - @Override - public Comparator getComparator() { - return getJavaTypeDescriptor().getComparator(); - } - - @Override - public Date fromStringValue( - CharSequence xml) throws HibernateException { + public Date fromStringValue(CharSequence xml) throws HibernateException { return fromString( xml ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/ReplicationMode.java b/hibernate-core/src/main/java/org/hibernate/ReplicationMode.java index 9ffeede61d..0a1bf6e427 100644 --- a/hibernate-core/src/main/java/org/hibernate/ReplicationMode.java +++ b/hibernate-core/src/main/java/org/hibernate/ReplicationMode.java @@ -6,7 +6,7 @@ */ package org.hibernate; -import org.hibernate.type.VersionType; +import org.hibernate.type.BasicType; /** * Represents a replication strategy. @@ -20,7 +20,7 @@ public enum ReplicationMode { */ EXCEPTION { @Override - public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType) { + public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, BasicType versionType) { throw new AssertionFailure( "should not be called" ); } }, @@ -29,7 +29,7 @@ public enum ReplicationMode { */ IGNORE { @Override - public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType) { + public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, BasicType versionType) { return false; } }, @@ -38,7 +38,7 @@ public enum ReplicationMode { */ OVERWRITE { @Override - public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType) { + public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, BasicType versionType) { return true; } }, @@ -48,9 +48,9 @@ public enum ReplicationMode { LATEST_VERSION { @Override @SuppressWarnings("unchecked") - public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType) { + public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, BasicType versionType) { // always overwrite non-versioned data (because we don't know which is newer) - return versionType == null || versionType.getComparator().compare( currentVersion, newVersion ) <= 0; + return versionType == null || versionType.getJavaTypeDescriptor().getComparator().compare( currentVersion, newVersion ) <= 0; } }; @@ -64,6 +64,6 @@ public enum ReplicationMode { * * @return {@code true} indicates the data should be overwritten; {@code false} indicates it should not. */ - public abstract boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType); + public abstract boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, BasicType versionType); } diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/SourceType.java b/hibernate-core/src/main/java/org/hibernate/annotations/SourceType.java index cfd0c153c7..40f04cf5cd 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/SourceType.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/SourceType.java @@ -29,7 +29,7 @@ public enum SourceType { } /** - * Get the corresponding Hibernate {@link org.hibernate.type.VersionType} name. + * Get the corresponding Hibernate {@link org.hibernate.type.BasicType} name. * * @return The corresponding type name. */ diff --git a/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/CollectionDataCachingConfigImpl.java b/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/CollectionDataCachingConfigImpl.java index 30a15aae9a..a00451d634 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/CollectionDataCachingConfigImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/CollectionDataCachingConfigImpl.java @@ -12,7 +12,7 @@ import org.hibernate.cache.cfg.spi.CollectionDataCachingConfig; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.mapping.Collection; import org.hibernate.metamodel.model.domain.NavigableRole; -import org.hibernate.type.VersionType; +import org.hibernate.type.BasicType; /** * @author Steve Ebersole @@ -46,7 +46,7 @@ public class CollectionDataCachingConfigImpl if ( !isVersioned() ) { return null; } - return ( (VersionType) collectionDescriptor.getOwner().getVersion().getType() ).getComparator(); + return ( (BasicType) collectionDescriptor.getOwner().getVersion().getType() ).getJavaTypeDescriptor().getComparator(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/DomainDataRegionConfigImpl.java b/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/DomainDataRegionConfigImpl.java index 1020c6c63f..512c0c5272 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/DomainDataRegionConfigImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/DomainDataRegionConfigImpl.java @@ -24,7 +24,7 @@ import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.RootClass; import org.hibernate.metamodel.model.domain.NavigableRole; -import org.hibernate.type.VersionType; +import org.hibernate.type.BasicType; /** * DomainDataRegionConfig implementation @@ -99,7 +99,7 @@ public class DomainDataRegionConfigImpl implements DomainDataRegionConfig { x -> new EntityDataCachingConfigImpl( rootEntityName, bootEntityDescriptor.isVersioned() - ? (Supplier) () -> ( (VersionType) bootEntityDescriptor.getVersion().getType() ).getComparator() + ? (Supplier) () -> ( (BasicType) bootEntityDescriptor.getVersion().getType() ).getJavaTypeDescriptor().getComparator() : null, bootEntityDescriptor.isMutable(), accessType diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/lock/UpdateLockingStrategy.java b/hibernate-core/src/main/java/org/hibernate/dialect/lock/UpdateLockingStrategy.java index 9914a1f162..0cce1ce2cc 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/lock/UpdateLockingStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/lock/UpdateLockingStrategy.java @@ -21,8 +21,8 @@ import org.hibernate.persister.entity.Lockable; import org.hibernate.pretty.MessageHelper; import org.hibernate.sql.Update; import org.hibernate.stat.spi.StatisticsImplementor; +import org.hibernate.type.BasicType; import org.hibernate.type.Type; -import org.hibernate.type.VersionType; import org.jboss.logging.Logger; @@ -84,7 +84,7 @@ public class UpdateLockingStrategy implements LockingStrategy { final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator(); final PreparedStatement st = jdbcCoordinator.getStatementPreparer().prepareStatement( sql ); try { - final VersionType lockableVersionType = lockable.getVersionType(); + final BasicType lockableVersionType = lockable.getVersionType(); lockableVersionType.nullSafeSet( st, version, 1, session ); int offset = 2; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/UnsavedValueFactory.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/UnsavedValueFactory.java index 7c6fa38f5d..0a23f7e826 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/UnsavedValueFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/UnsavedValueFactory.java @@ -17,7 +17,7 @@ import org.hibernate.property.access.spi.Getter; import org.hibernate.type.IdentifierType; import org.hibernate.type.PrimitiveType; import org.hibernate.type.Type; -import org.hibernate.type.VersionType; +import org.hibernate.type.descriptor.java.VersionJavaTypeDescriptor; /** * Helper for dealing with unsaved value handling @@ -114,18 +114,19 @@ public class UnsavedValueFactory { * * @return The appropriate VersionValue */ - public static VersionValue getUnsavedVersionValue( - String versionUnsavedValue, + public static VersionValue getUnsavedVersionValue( + String versionUnsavedValue, Getter versionGetter, - VersionType versionType, + VersionJavaTypeDescriptor versionType, Constructor constructor) { if ( versionUnsavedValue == null ) { if ( constructor!=null ) { - final Object defaultValue = versionGetter.get( instantiate( constructor ) ); + @SuppressWarnings("unchecked") + final X defaultValue = (X) versionGetter.get( instantiate( constructor ) ); // if the version of a newly instantiated object is not the same // as the version seed value, use that as the unsaved-value - return versionType.isEqual( versionType.seed( null ), defaultValue ) + return versionType.areEqual( versionType.seed( null ), defaultValue ) ? VersionValue.UNDEFINED : new VersionValue( defaultValue ); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/Versioning.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/Versioning.java index 6265dfdf30..380adf3b2a 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/Versioning.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/Versioning.java @@ -9,7 +9,7 @@ package org.hibernate.engine.internal; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.type.VersionType; +import org.hibernate.type.descriptor.java.VersionJavaTypeDescriptor; import org.jboss.logging.Logger; @@ -31,21 +31,21 @@ public final class Versioning { } /** - * Create an initial optimistic locking value according the {@link VersionType} + * Create an initial optimistic locking value according the {@link VersionJavaTypeDescriptor} * contract for the version property. * * @param versionType The version type. * @param session The originating session * @return The initial optimistic locking value */ - private static Object seed(VersionType versionType, SharedSessionContractImplementor session) { + private static Object seed(VersionJavaTypeDescriptor versionType, SharedSessionContractImplementor session) { final Object seed = versionType.seed( session ); LOG.tracef( "Seeding: %s", seed ); return seed; } /** - * Create an initial optimistic locking value according the {@link VersionType} + * Create an initial optimistic locking value according the {@link VersionJavaTypeDescriptor} * contract for the version property if required and inject it into * the snapshot state. * @@ -59,7 +59,7 @@ public final class Versioning { public static boolean seedVersion( Object[] fields, int versionProperty, - VersionType versionType, + VersionJavaTypeDescriptor versionType, SharedSessionContractImplementor session) { final Object initialVersion = fields[versionProperty]; if ( @@ -80,21 +80,20 @@ public final class Versioning { /** * Generate the next increment in the optimistic locking value according - * the {@link VersionType} contract for the version property. + * the {@link VersionJavaTypeDescriptor} contract for the version property. * * @param version The current version * @param versionType The version type * @param session The originating session * @return The incremented optimistic locking value. */ - @SuppressWarnings("unchecked") - public static Object increment(Object version, VersionType versionType, SharedSessionContractImplementor session) { + public static Object increment(Object version, VersionJavaTypeDescriptor versionType, SharedSessionContractImplementor session) { final Object next = versionType.next( version, session ); if ( LOG.isTraceEnabled() ) { LOG.tracef( "Incrementing: %s to %s", - versionType.toLoggableString( version, session.getFactory() ), - versionType.toLoggableString( next, session.getFactory() ) + versionType.toString( version ), + versionType.toString( next ) ); } return next; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java index e139034a86..7fd4a45ca7 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java @@ -55,6 +55,7 @@ import org.hibernate.query.spi.QueryEngine; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.type.Type; +import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.spi.TypeConfiguration; /** @@ -444,4 +445,9 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor, public AllowableParameterType resolveParameterBindType(Class clazz) { return delegate.resolveParameterBindType( clazz ); } + + @Override + public WrapperOptions getWrapperOptions() { + return delegate.getWrapperOptions(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java index 19bcb885e4..dfd78e91dc 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java @@ -410,7 +410,7 @@ public abstract class AbstractSaveEventListener substitute = Versioning.seedVersion( values, persister.getVersionProperty(), - persister.getVersionType(), + persister.getVersionJavaTypeDescriptor(), source ) || substitute; } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java index 0437f2f6e7..c7381e2dd8 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java @@ -394,7 +394,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener ); final Object nextVersion = isVersionIncrementRequired ? - Versioning.increment( entry.getVersion(), persister.getVersionType(), event.getSession() ) : + Versioning.increment( entry.getVersion(), persister.getVersionJavaTypeDescriptor(), event.getSession() ) : entry.getVersion(); //use the current version Versioning.setVersion( values, nextVersion, persister ); diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultReplicateEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultReplicateEventListener.java index 2c40578203..33a0acf424 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultReplicateEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultReplicateEventListener.java @@ -25,6 +25,7 @@ import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.pretty.MessageHelper; +import org.hibernate.type.BasicType; import org.hibernate.type.Type; /** @@ -96,11 +97,12 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp /// HHH-2378 final Object realOldVersion = persister.isVersioned() ? oldVersion : null; + @SuppressWarnings("unchecked") boolean canReplicate = replicationMode.shouldOverwriteCurrentVersion( entity, realOldVersion, persister.getVersion( entity ), - persister.getVersionType() + (BasicType) persister.getVersionType() ); // if can replicate, will result in a SQL UPDATE diff --git a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java index d57a0a6a15..af6b593198 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java @@ -85,7 +85,7 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen boolean substitute = Versioning.seedVersion( state, persister.getVersionProperty(), - persister.getVersionType(), + persister.getVersionJavaTypeDescriptor(), this ); if ( substitute ) { @@ -138,7 +138,7 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen Object oldVersion; if ( persister.isVersioned() ) { oldVersion = persister.getVersion( entity ); - Object newVersion = Versioning.increment( oldVersion, persister.getVersionType(), this ); + Object newVersion = Versioning.increment( oldVersion, persister.getVersionJavaTypeDescriptor(), this ); Versioning.setVersion( state, newVersion, persister ); persister.setPropertyValues( entity, state ); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index ee2a232972..6040c29e37 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -258,7 +258,6 @@ import org.hibernate.type.CompositeType; import org.hibernate.type.EntityType; import org.hibernate.type.Type; import org.hibernate.type.TypeHelper; -import org.hibernate.type.VersionType; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.MutabilityPlan; import org.hibernate.type.spi.TypeConfiguration; @@ -2070,6 +2069,7 @@ public abstract class AbstractEntityPersister boolean includeProperty(int propertyNumber); } + @Override public Object forceVersionIncrement(Object id, Object currentVersion, SharedSessionContractImplementor session) { if ( !isVersioned() ) { throw new AssertionFailure( "cannot force version increment on non-versioned entity" ); @@ -2081,7 +2081,7 @@ public abstract class AbstractEntityPersister throw new HibernateException( "LockMode.FORCE is currently not supported for generated version properties" ); } - Object nextVersion = ((VersionType) getVersionType()).next( currentVersion, session ); + Object nextVersion = getVersionJavaTypeDescriptor().next( currentVersion, session ); if ( LOG.isTraceEnabled() ) { LOG.trace( "Forcing version increment [" + MessageHelper.infoString( this, id, getFactory() ) + "; " @@ -4494,7 +4494,7 @@ public abstract class AbstractEntityPersister } public Comparator getVersionComparator() { - return isVersioned() ? getVersionType().getComparator() : null; + return isVersioned() ? getVersionType().getJavaTypeDescriptor().getComparator() : null; } // temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -4522,10 +4522,10 @@ public abstract class AbstractEntityPersister return !entityMetamodel.getIdentifierProperty().isVirtual(); } - public VersionType getVersionType() { + public BasicType getVersionType() { return entityMetamodel.getVersionProperty() == null ? null - : (VersionType) entityMetamodel.getVersionProperty().getType(); + : (BasicType) entityMetamodel.getVersionProperty().getType(); } public int getVersionProperty() { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java index 3d316694bb..dcec5233dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java @@ -48,8 +48,9 @@ import org.hibernate.sql.ast.tree.from.RootTableGroupProducer; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityTuplizer; +import org.hibernate.type.BasicType; import org.hibernate.type.Type; -import org.hibernate.type.VersionType; +import org.hibernate.type.descriptor.java.VersionJavaTypeDescriptor; /** * Contract describing mapping information and persistence logic for a particular strategy of entity mapping. A given @@ -364,7 +365,15 @@ public interface EntityPersister * * @return The type of the version property; or null, if not versioned. */ - VersionType getVersionType(); + BasicType getVersionType(); + + default VersionJavaTypeDescriptor getVersionJavaTypeDescriptor() { + final BasicType versionType = getVersionType(); + //noinspection unchecked + return versionType == null + ? null + : (VersionJavaTypeDescriptor) versionType.getJavaTypeDescriptor(); + } /** * If {@link #isVersioned()}, then what is the index of the property diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 13b05647a8..04f0018670 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -314,7 +314,6 @@ import org.hibernate.sql.results.internal.SqlSelectionImpl; import org.hibernate.sql.results.internal.StandardEntityGraphTraversalStateImpl; import org.hibernate.type.BasicType; import org.hibernate.type.JavaObjectType; -import org.hibernate.type.VersionType; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators; import org.hibernate.type.spi.TypeConfiguration; @@ -711,7 +710,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base throw new SemanticException( "increment option specified for update of non-versioned entity" ); } - final VersionType versionType = persister.getVersionType(); + final BasicType versionType = persister.getVersionType(); if ( versionType instanceof UserVersionType ) { throw new SemanticException( "user-defined version types not supported for increment option" ); } @@ -728,30 +727,20 @@ public abstract class BaseSqmToSqlAstConverter extends Base final ColumnReference versionColumn = targetColumnReferences.get( 0 ); final Expression value; - if ( isTimestampBasedVersion( versionType ) ) { - value = new VersionTypeSeedParameterSpecification( versionType ); + if ( versionMapping.getJdbcMapping().getJdbcTypeDescriptor().isTemporal() ) { + value = new VersionTypeSeedParameterSpecification( versionType, persister.getVersionJavaTypeDescriptor() ); } else { - final BasicValuedMapping basicValuedMapping = (BasicValuedMapping) versionType; value = new BinaryArithmeticExpression( versionColumn, ADD, - new QueryLiteral<>( 1, basicValuedMapping ), - basicValuedMapping + new QueryLiteral<>( 1, versionType ), + versionType ); } assignmentConsumer.accept( new Assignment( versionColumn, value ) ); } - private boolean isTimestampBasedVersion(VersionType versionType) { - if ( versionType instanceof BasicType ) { - return ( (BasicType) versionType ).getJdbcTypeDescriptor().isTemporal(); - } - final Class javaType = versionType.getReturnedClass(); - return java.util.Date.class.isAssignableFrom( javaType ) - || Calendar.class.isAssignableFrom( javaType ); - } - @Override public List visitSetClause(SqmSetClause setClause) { final List assignments = new ArrayList<>( setClause.getAssignments().size() ); @@ -1024,8 +1013,10 @@ public abstract class BaseSqmToSqlAstConverter extends Base ); if ( needsVersionInsert ) { - final VersionType versionType = entityDescriptor.getVersionType(); - final Expression expression = new VersionTypeSeedParameterSpecification( versionType ); + final Expression expression = new VersionTypeSeedParameterSpecification( + entityDescriptor.getVersionMapping().getJdbcMapping(), + entityDescriptor.getVersionJavaTypeDescriptor() + ); insertStatement.getSourceSelectStatement().forEachQuerySpec( querySpec -> { querySpec.getSelectClause().addSqlSelection( diff --git a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/VersionTypeSeedParameterSpecification.java b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/VersionTypeSeedParameterSpecification.java index 7c55774171..498611ee68 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/VersionTypeSeedParameterSpecification.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/VersionTypeSeedParameterSpecification.java @@ -12,7 +12,7 @@ import java.sql.SQLException; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.sql.exec.spi.ExecutionContext; import org.hibernate.sql.exec.spi.JdbcParameterBindings; -import org.hibernate.type.VersionType; +import org.hibernate.type.descriptor.java.VersionJavaTypeDescriptor; /** * Parameter bind specification used for optimistic lock version seeding (from insert statements). @@ -20,15 +20,15 @@ import org.hibernate.type.VersionType; * @author Steve Ebersole */ public class VersionTypeSeedParameterSpecification extends JdbcParameterImpl { - private final VersionType type; + private final VersionJavaTypeDescriptor type; /** * Constructs a version seed parameter bind specification. * * @param type The version type. */ - public VersionTypeSeedParameterSpecification(VersionType type) { - super( (JdbcMapping) type ); + public VersionTypeSeedParameterSpecification(JdbcMapping jdbcMapping, VersionJavaTypeDescriptor type) { + super( jdbcMapping ); this.type = type; } @@ -38,6 +38,12 @@ public class VersionTypeSeedParameterSpecification extends JdbcParameterImpl { int startPosition, JdbcParameterBindings jdbcParamBindings, ExecutionContext executionContext) throws SQLException { - type.nullSafeSet( statement, type.seed( executionContext.getSession() ), startPosition, executionContext.getSession() ); + //noinspection unchecked + getJdbcMapping().getJdbcValueBinder().bind( + statement, + type.seed( executionContext.getSession() ), + startPosition, + executionContext.getSession() + ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java index d56ca35aaa..bc10372358 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java @@ -51,8 +51,8 @@ import org.hibernate.sql.results.internal.NullValueAssembler; import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingState; import org.hibernate.sql.results.jdbc.spi.RowProcessingState; import org.hibernate.stat.spi.StatisticsImplementor; +import org.hibernate.type.BasicType; import org.hibernate.type.TypeHelper; -import org.hibernate.type.VersionType; import static org.hibernate.internal.log.LoggingHelper.toLoggableString; @@ -517,7 +517,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces if ( version != null ) { // null version means the object is in the process of being loaded somewhere else in the ResultSet - final VersionType versionType = concreteDescriptor.getVersionType(); + final BasicType versionType = concreteDescriptor.getVersionType(); final Object currentVersion = versionAssembler.assemble( rowProcessingState ); if ( !versionType.isEqual( version, currentVersion ) ) { final StatisticsImplementor statistics = rowProcessingState.getSession().getFactory().getStatistics(); diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java b/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java index 48fac277ce..00ec50757e 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java @@ -33,9 +33,10 @@ import org.hibernate.tuple.entity.EntityBasedBasicAttribute; import org.hibernate.tuple.entity.EntityBasedCompositionAttribute; import org.hibernate.tuple.entity.VersionProperty; import org.hibernate.type.AssociationType; +import org.hibernate.type.BasicType; import org.hibernate.type.CompositeType; import org.hibernate.type.Type; -import org.hibernate.type.VersionType; +import org.hibernate.type.descriptor.java.VersionJavaTypeDescriptor; /** * Responsible for generation of runtime metamodel {@link Property} representations. @@ -107,10 +108,11 @@ public final class PropertyFactory { boolean lazyAvailable) { String mappedUnsavedValue = ( (KeyValue) property.getValue() ).getNullValue(); + //noinspection unchecked VersionValue unsavedValue = UnsavedValueFactory.getUnsavedVersionValue( mappedUnsavedValue, getGetter( property ), - (VersionType) property.getType(), + ( VersionJavaTypeDescriptor) ((BasicType) property.getType()).getJavaTypeDescriptor(), getConstructor( property.getPersistentClass() ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/BinaryType.java b/hibernate-core/src/main/java/org/hibernate/type/BinaryType.java index 2d21ac6486..9b235ca059 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/BinaryType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/BinaryType.java @@ -7,29 +7,19 @@ package org.hibernate.type; import java.sql.Types; -import java.util.Comparator; -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor; -import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; -import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators; import org.hibernate.type.descriptor.jdbc.VarbinaryTypeDescriptor; -import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry; -import org.hibernate.type.spi.TypeConfiguration; /** * A type that maps between a {@link Types#VARBINARY VARBINARY} and {@code byte[]} * - * Implementation of the {@link VersionType} interface should be considered deprecated. - * For binary entity versions/timestamps, {@link RowVersionType} should be used instead. - * * @author Gavin King * @author Steve Ebersole */ public class BinaryType extends AbstractSingleColumnStandardBasicType - implements VersionType, AdjustableBasicType { + implements AdjustableBasicType { public static final BinaryType INSTANCE = new BinaryType(); @@ -46,47 +36,4 @@ public class BinaryType return new String[] { getName(), "byte[]", byte[].class.getName() }; } - /** - * Generate an initial version. - * - * @param session The session from which this request originates. - * @return an instance of the type - * @deprecated use {@link RowVersionType} for binary entity versions/timestamps - */ - @Override - @Deprecated - 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; - } - - /** - * Increment the version. - * - * @param session The session from which this request originates. - * @param current the current version - * @return an instance of the type - * @deprecated use {@link RowVersionType} for binary entity versions/timestamps - */ - @Override - @Deprecated - public byte[] next(byte[] current, SharedSessionContractImplementor session) { - return current; - } - - /** - * Get a comparator for version values. - * - * @return The comparator to use to compare different version values. - * @deprecated use {@link RowVersionType} for binary entity versions/timestamps - */ - @Override - @Deprecated - public Comparator getComparator() { - return PrimitiveByteArrayTypeDescriptor.INSTANCE.getComparator(); - } - } diff --git a/hibernate-core/src/main/java/org/hibernate/type/ByteType.java b/hibernate-core/src/main/java/org/hibernate/type/ByteType.java index d8ca6b2729..b0301c6f99 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ByteType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ByteType.java @@ -7,9 +7,7 @@ package org.hibernate.type; import java.io.Serializable; -import java.util.Comparator; -import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.java.ByteTypeDescriptor; import org.hibernate.type.descriptor.jdbc.TinyIntTypeDescriptor; @@ -21,7 +19,7 @@ import org.hibernate.type.descriptor.jdbc.TinyIntTypeDescriptor; */ public class ByteType extends AbstractSingleColumnStandardBasicType - implements PrimitiveType, DiscriminatorType, VersionType { + implements PrimitiveType, DiscriminatorType { public static final ByteType INSTANCE = new ByteType(); @@ -60,19 +58,4 @@ public class ByteType public Byte fromStringValue(CharSequence xml) { return fromString( xml ); } - - @Override - public Byte next(Byte current, SharedSessionContractImplementor session) { - return (byte) ( current + 1 ); - } - - @Override - public Byte seed(SharedSessionContractImplementor session) { - return ZERO; - } - - @Override - public Comparator getComparator() { - return getJavaTypeDescriptor().getComparator(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/CalendarType.java b/hibernate-core/src/main/java/org/hibernate/type/CalendarType.java index 24f843deeb..f03938f8d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CalendarType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CalendarType.java @@ -7,18 +7,16 @@ package org.hibernate.type; import java.util.Calendar; -import java.util.Comparator; import java.util.GregorianCalendar; -import jakarta.persistence.TemporalType; - import org.hibernate.QueryException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.metamodel.model.domain.AllowableTemporalParameterType; import org.hibernate.type.descriptor.java.CalendarTypeDescriptor; import org.hibernate.type.descriptor.jdbc.TimestampTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; +import jakarta.persistence.TemporalType; + /** * A type that maps between {@link java.sql.Types#TIMESTAMP TIMESTAMP} and {@link Calendar} * @@ -27,7 +25,7 @@ import org.hibernate.type.spi.TypeConfiguration; */ public class CalendarType extends AbstractSingleColumnStandardBasicType - implements VersionType, AllowableTemporalParameterType { + implements AllowableTemporalParameterType { public static final CalendarType INSTANCE = new CalendarType(); @@ -45,21 +43,6 @@ public class CalendarType return new String[] { getName(), Calendar.class.getName(), GregorianCalendar.class.getName() }; } - @Override - public Calendar next(Calendar current, SharedSessionContractImplementor session) { - return seed( session ); - } - - @Override - public Calendar seed(SharedSessionContractImplementor session) { - return Calendar.getInstance(); - } - - @Override - public Comparator getComparator() { - return getJavaTypeDescriptor().getComparator(); - } - @Override public AllowableTemporalParameterType resolveTemporalPrecision( TemporalType temporalPrecision, diff --git a/hibernate-core/src/main/java/org/hibernate/type/CustomType.java b/hibernate-core/src/main/java/org/hibernate/type/CustomType.java index 7261a6a190..a67de1374b 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CustomType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CustomType.java @@ -12,7 +12,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Arrays; -import java.util.Comparator; import java.util.Map; import org.hibernate.HibernateException; @@ -30,6 +29,7 @@ import org.hibernate.type.descriptor.java.JavaTypedExpressable; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.internal.UserTypeJavaTypeWrapper; import org.hibernate.type.internal.UserTypeSqlTypeAdapter; +import org.hibernate.type.internal.UserTypeVersionJavaTypeWrapper; import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.usertype.EnhancedUserType; import org.hibernate.usertype.Sized; @@ -52,7 +52,7 @@ import org.hibernate.usertype.UserVersionType; */ public class CustomType extends AbstractType - implements BasicType, IdentifierType, DiscriminatorType, VersionType, StringRepresentableType, ProcedureParameterNamedBinder, ProcedureParameterExtractionAware { + implements BasicType, IdentifierType, DiscriminatorType, StringRepresentableType, ProcedureParameterNamedBinder, ProcedureParameterExtractionAware { private final UserType userType; private final String[] registrationKeys; @@ -84,6 +84,9 @@ public class CustomType //noinspection rawtypes this.mappedJavaTypeDescriptor = (BasicJavaDescriptor) ( (JavaTypedExpressable) userType ).getExpressableJavaTypeDescriptor(); } + else if ( userType instanceof UserVersionType ) { + this.mappedJavaTypeDescriptor = new UserTypeVersionJavaTypeWrapper<>( (UserVersionType) userType ); + } else { this.mappedJavaTypeDescriptor = new UserTypeJavaTypeWrapper<>( userType ); } @@ -255,21 +258,6 @@ public class CustomType return fromStringValue( sequence ); } - @Override - public Comparator getComparator() { - return (Comparator) getUserType(); - } - - @Override - public Object next(Object current, SharedSessionContractImplementor session) { - return ( (UserVersionType) getUserType() ).next( current, session ); - } - - @Override - public Object seed(SharedSessionContractImplementor session) { - return ( (UserVersionType) getUserType() ).seed( session ); - } - @Override public String toLoggableString(Object value, SessionFactoryImplementor factory) { if ( value == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/DbTimestampType.java b/hibernate-core/src/main/java/org/hibernate/type/DbTimestampType.java index a80ed1577a..0b6b62ff79 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/DbTimestampType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/DbTimestampType.java @@ -6,16 +6,15 @@ */ package org.hibernate.type; -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; import java.util.Date; -import org.hibernate.dialect.Dialect; -import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.type.descriptor.java.DbTimestampJavaTypeDescriptor; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; +import org.hibernate.type.descriptor.java.JdbcTimestampTypeDescriptor; +import org.hibernate.type.descriptor.java.TemporalJavaTypeDescriptor; +import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; +import org.hibernate.type.descriptor.jdbc.TimestampTypeDescriptor; import org.jboss.logging.Logger; @@ -38,6 +37,14 @@ public class DbTimestampType extends TimestampType { DbTimestampType.class.getName() ); + public DbTimestampType() { + this( TimestampTypeDescriptor.INSTANCE, JdbcTimestampTypeDescriptor.INSTANCE ); + } + + public DbTimestampType(JdbcTypeDescriptor jdbcTypeDescriptor, JavaTypeDescriptor javaTypeDescriptor) { + super( jdbcTypeDescriptor, new DbTimestampJavaTypeDescriptor<>( (TemporalJavaTypeDescriptor) javaTypeDescriptor ) ); + } + @Override public String getName() { return "dbtimestamp"; @@ -48,97 +55,4 @@ public class DbTimestampType extends TimestampType { return new String[] {getName()}; } - @Override - public Date seed(SharedSessionContractImplementor session) { - if ( session == null ) { - LOG.trace( "Incoming session was null; using current jvm time" ); - return super.seed( null ); - } - else if ( !session.getJdbcServices().getJdbcEnvironment().getDialect().supportsCurrentTimestampSelection() ) { - LOG.debug( "Falling back to vm-based timestamp, as dialect does not support current timestamp selection" ); - return super.seed( session ); - } - else { - return getCurrentTimestamp( session ); - } - } - - private Date getCurrentTimestamp(SharedSessionContractImplementor session) { - Dialect dialect = session.getJdbcServices().getJdbcEnvironment().getDialect(); - String timestampSelectString = dialect.getCurrentTimestampSelectString(); - if ( dialect.isCurrentTimestampSelectStringCallable() ) { - return useCallableStatement( timestampSelectString, session ); - } - return usePreparedStatement( timestampSelectString, session ); - } - - private Timestamp usePreparedStatement(String timestampSelectString, SharedSessionContractImplementor session) { - PreparedStatement ps = null; - try { - ps = session - .getJdbcCoordinator() - .getStatementPreparer() - .prepareStatement( timestampSelectString, false ); - ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract( ps ); - rs.next(); - Timestamp ts = rs.getTimestamp( 1 ); - if ( LOG.isTraceEnabled() ) { - LOG.tracev( - "Current timestamp retrieved from db : {0} (nanos={1}, time={2})", - ts, - ts.getNanos(), - ts.getTime() - ); - } - return ts; - } - catch (SQLException e) { - throw session.getJdbcServices().getSqlExceptionHelper().convert( - e, - "could not select current db timestamp", - timestampSelectString - ); - } - finally { - if ( ps != null ) { - session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( ps ); - session.getJdbcCoordinator().afterStatementExecution(); - } - } - } - - private Timestamp useCallableStatement(String callString, SharedSessionContractImplementor session) { - CallableStatement cs = null; - try { - cs = (CallableStatement) session - .getJdbcCoordinator() - .getStatementPreparer() - .prepareStatement( callString, true ); - cs.registerOutParameter( 1, java.sql.Types.TIMESTAMP ); - session.getJdbcCoordinator().getResultSetReturn().execute( cs ); - Timestamp ts = cs.getTimestamp( 1 ); - if ( LOG.isTraceEnabled() ) { - LOG.tracev( - "Current timestamp retrieved from db : {0} (nanos={1}, time={2})", - ts, - ts.getNanos(), - ts.getTime() - ); - } - return ts; - } - catch (SQLException e) { - throw session.getJdbcServices().getSqlExceptionHelper().convert( - e, - "could not call current db timestamp function", - callString - ); - } - finally { - if ( cs != null ) { - session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( cs ); - session.getJdbcCoordinator().afterStatementExecution(); - } - } - } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/InstantType.java b/hibernate-core/src/main/java/org/hibernate/type/InstantType.java index bd6201af29..d2ae8133f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/InstantType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/InstantType.java @@ -8,18 +8,16 @@ package org.hibernate.type; import java.time.Instant; import java.time.format.DateTimeFormatter; -import java.util.Comparator; import java.util.Locale; -import jakarta.persistence.TemporalType; import org.hibernate.QueryException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.internal.util.compare.ComparableComparator; import org.hibernate.metamodel.model.domain.AllowableTemporalParameterType; import org.hibernate.type.descriptor.java.InstantJavaDescriptor; import org.hibernate.type.descriptor.jdbc.TimestampTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; +import jakarta.persistence.TemporalType; + /** * A type that maps between {@link java.sql.Types#TIMESTAMP TIMESTAMP} and {@link java.time.LocalDateTime}. * @@ -27,7 +25,7 @@ import org.hibernate.type.spi.TypeConfiguration; */ public class InstantType extends AbstractSingleColumnStandardBasicType - implements VersionType, AllowableTemporalParameterType { + implements AllowableTemporalParameterType { /** * Singleton access */ @@ -39,22 +37,6 @@ public class InstantType super( TimestampTypeDescriptor.INSTANCE, InstantJavaDescriptor.INSTANCE ); } - @Override - public Instant seed(SharedSessionContractImplementor session) { - return Instant.now(); - } - - @Override - public Instant next(Instant current, SharedSessionContractImplementor session) { - return Instant.now(); - } - - @Override - @SuppressWarnings("unchecked") - public Comparator getComparator() { - return ComparableComparator.INSTANCE; - } - @Override public String getName() { return "instant"; diff --git a/hibernate-core/src/main/java/org/hibernate/type/IntegerType.java b/hibernate-core/src/main/java/org/hibernate/type/IntegerType.java index 396eaa9c11..0700189db3 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/IntegerType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/IntegerType.java @@ -7,9 +7,7 @@ package org.hibernate.type; import java.io.Serializable; -import java.util.Comparator; -import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.java.IntegerTypeDescriptor; /** @@ -19,7 +17,7 @@ import org.hibernate.type.descriptor.java.IntegerTypeDescriptor; * @author Steve Ebersole */ public class IntegerType extends AbstractSingleColumnStandardBasicType - implements PrimitiveType, DiscriminatorType, VersionType { + implements PrimitiveType, DiscriminatorType { public static final IntegerType INSTANCE = new IntegerType(); @@ -53,19 +51,4 @@ public class IntegerType extends AbstractSingleColumnStandardBasicType public Integer stringToObject(CharSequence sequence) { return fromString( sequence ); } - - @Override - public Integer seed(SharedSessionContractImplementor session) { - return ZERO; - } - - @Override - public Integer next(Integer current, SharedSessionContractImplementor session) { - return current + 1; - } - - @Override - public Comparator getComparator() { - return getJavaTypeDescriptor().getComparator(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/LocalDateTimeType.java b/hibernate-core/src/main/java/org/hibernate/type/LocalDateTimeType.java index 3286ad84d4..97878a5fc8 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/LocalDateTimeType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/LocalDateTimeType.java @@ -7,17 +7,15 @@ package org.hibernate.type; import java.time.LocalDateTime; -import java.util.Comparator; -import jakarta.persistence.TemporalType; import org.hibernate.QueryException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.internal.util.compare.ComparableComparator; import org.hibernate.metamodel.model.domain.AllowableTemporalParameterType; import org.hibernate.type.descriptor.java.LocalDateTimeJavaDescriptor; import org.hibernate.type.descriptor.jdbc.TimestampTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; +import jakarta.persistence.TemporalType; + /** * A type that maps between {@link java.sql.Types#TIMESTAMP TIMESTAMP} and {@link LocalDateTime}. * @@ -25,7 +23,7 @@ import org.hibernate.type.spi.TypeConfiguration; */ public class LocalDateTimeType extends AbstractSingleColumnStandardBasicType - implements VersionType, AllowableTemporalParameterType { + implements AllowableTemporalParameterType { /** * Singleton access */ @@ -45,22 +43,6 @@ public class LocalDateTimeType return true; } - @Override - public LocalDateTime seed(SharedSessionContractImplementor session) { - return LocalDateTime.now(); - } - - @Override - public LocalDateTime next(LocalDateTime current, SharedSessionContractImplementor session) { - return LocalDateTime.now(); - } - - @Override - @SuppressWarnings("unchecked") - public Comparator getComparator() { - return ComparableComparator.INSTANCE; - } - @Override public AllowableTemporalParameterType resolveTemporalPrecision( TemporalType temporalPrecision, diff --git a/hibernate-core/src/main/java/org/hibernate/type/LongType.java b/hibernate-core/src/main/java/org/hibernate/type/LongType.java index 8375325fb4..547add21eb 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/LongType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/LongType.java @@ -7,9 +7,7 @@ package org.hibernate.type; import java.io.Serializable; -import java.util.Comparator; -import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.java.LongTypeDescriptor; import org.hibernate.type.descriptor.jdbc.BigIntTypeDescriptor; @@ -21,7 +19,7 @@ import org.hibernate.type.descriptor.jdbc.BigIntTypeDescriptor; */ public class LongType extends AbstractSingleColumnStandardBasicType - implements PrimitiveType, DiscriminatorType, VersionType { + implements PrimitiveType, DiscriminatorType { public static final LongType INSTANCE = new LongType(); @@ -56,19 +54,4 @@ public class LongType return Long.valueOf( sequence.toString() ); } - @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(); - } - } diff --git a/hibernate-core/src/main/java/org/hibernate/type/OffsetDateTimeType.java b/hibernate-core/src/main/java/org/hibernate/type/OffsetDateTimeType.java index 4134bcdb8f..5f5d369ec3 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/OffsetDateTimeType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/OffsetDateTimeType.java @@ -7,24 +7,22 @@ package org.hibernate.type; import java.time.OffsetDateTime; -import java.util.Comparator; - -import jakarta.persistence.TemporalType; import org.hibernate.QueryException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.metamodel.model.domain.AllowableTemporalParameterType; import org.hibernate.query.CastType; import org.hibernate.type.descriptor.java.OffsetDateTimeJavaDescriptor; import org.hibernate.type.descriptor.jdbc.TimestampWithTimeZoneDescriptor; import org.hibernate.type.spi.TypeConfiguration; +import jakarta.persistence.TemporalType; + /** * @author Steve Ebersole */ public class OffsetDateTimeType extends AbstractSingleColumnStandardBasicType - implements VersionType, AllowableTemporalParameterType { + implements AllowableTemporalParameterType { /** * Singleton access @@ -35,21 +33,6 @@ public class OffsetDateTimeType super( TimestampWithTimeZoneDescriptor.INSTANCE, OffsetDateTimeJavaDescriptor.INSTANCE ); } - @Override - public OffsetDateTime seed(SharedSessionContractImplementor session) { - return OffsetDateTime.now(); - } - - @Override - public OffsetDateTime next(OffsetDateTime current, SharedSessionContractImplementor session) { - return OffsetDateTime.now(); - } - - @Override - public Comparator getComparator() { - return OffsetDateTime.timeLineOrder(); - } - @Override public String getName() { return OffsetDateTime.class.getSimpleName(); diff --git a/hibernate-core/src/main/java/org/hibernate/type/RowVersionType.java b/hibernate-core/src/main/java/org/hibernate/type/RowVersionType.java index e1c4595d29..c118350b3e 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/RowVersionType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/RowVersionType.java @@ -6,9 +6,6 @@ */ package org.hibernate.type; -import java.util.Comparator; - -import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.java.RowVersionTypeDescriptor; import org.hibernate.type.descriptor.jdbc.VarbinaryTypeDescriptor; @@ -21,8 +18,7 @@ import org.hibernate.type.descriptor.jdbc.VarbinaryTypeDescriptor; * @author Gail Badner */ public class RowVersionType - extends AbstractSingleColumnStandardBasicType - implements VersionType { + extends AbstractSingleColumnStandardBasicType { public static final RowVersionType INSTANCE = new RowVersionType(); @@ -39,22 +35,4 @@ public class RowVersionType 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(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/ShortType.java b/hibernate-core/src/main/java/org/hibernate/type/ShortType.java index b02f79b6d6..76312054b0 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ShortType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ShortType.java @@ -7,9 +7,7 @@ package org.hibernate.type; import java.io.Serializable; -import java.util.Comparator; -import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.java.ShortTypeDescriptor; import org.hibernate.type.descriptor.jdbc.SmallIntTypeDescriptor; @@ -21,7 +19,7 @@ import org.hibernate.type.descriptor.jdbc.SmallIntTypeDescriptor; */ public class ShortType extends AbstractSingleColumnStandardBasicType - implements PrimitiveType, DiscriminatorType, VersionType { + implements PrimitiveType, DiscriminatorType { public static final ShortType INSTANCE = new ShortType(); @@ -56,19 +54,4 @@ public class ShortType return Short.valueOf( sequence.toString() ); } - @Override - public Short seed(SharedSessionContractImplementor session) { - return ZERO; - } - - @Override - public Short next(Short current, SharedSessionContractImplementor session) { - return (short) ( current + 1 ); - } - - @Override - public Comparator getComparator() { - return getJavaTypeDescriptor().getComparator(); - } - } diff --git a/hibernate-core/src/main/java/org/hibernate/type/TimestampType.java b/hibernate-core/src/main/java/org/hibernate/type/TimestampType.java index d191c5e4a4..4b1a3fa9e1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/TimestampType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/TimestampType.java @@ -7,18 +7,19 @@ package org.hibernate.type; import java.sql.Timestamp; -import java.util.Comparator; import java.util.Date; -import jakarta.persistence.TemporalType; import org.hibernate.HibernateException; import org.hibernate.QueryException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.metamodel.model.domain.AllowableTemporalParameterType; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JdbcTimestampTypeDescriptor; +import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.TimestampTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; +import jakarta.persistence.TemporalType; + /** * A type that maps between {@link java.sql.Types#TIMESTAMP TIMESTAMP} and {@link Timestamp} * @@ -27,7 +28,7 @@ import org.hibernate.type.spi.TypeConfiguration; */ public class TimestampType extends AbstractSingleColumnStandardBasicType - implements VersionType, AllowableTemporalParameterType { + implements AllowableTemporalParameterType { public static final TimestampType INSTANCE = new TimestampType(); @@ -35,6 +36,10 @@ public class TimestampType super( TimestampTypeDescriptor.INSTANCE, JdbcTimestampTypeDescriptor.INSTANCE ); } + protected TimestampType(JdbcTypeDescriptor jdbcTypeDescriptor, JavaTypeDescriptor javaTypeDescriptor) { + super( jdbcTypeDescriptor, javaTypeDescriptor ); + } + @Override public String getName() { return "timestamp"; @@ -45,21 +50,6 @@ public class TimestampType return new String[] { getName(), Timestamp.class.getName(), Date.class.getName() }; } - @Override - public Date next(Date current, SharedSessionContractImplementor session) { - return seed( session ); - } - - @Override - public Date seed(SharedSessionContractImplementor session) { - return new Timestamp( System.currentTimeMillis() ); - } - - @Override - public Comparator getComparator() { - return getJavaTypeDescriptor().getComparator(); - } - @Override public Date fromStringValue(CharSequence xml) throws HibernateException { return fromString( xml ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/ZonedDateTimeType.java b/hibernate-core/src/main/java/org/hibernate/type/ZonedDateTimeType.java index 72bb02361a..c73becd1dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ZonedDateTimeType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ZonedDateTimeType.java @@ -7,24 +7,22 @@ package org.hibernate.type; import java.time.ZonedDateTime; -import java.util.Comparator; -import jakarta.persistence.TemporalType; import org.hibernate.QueryException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.internal.util.ZonedDateTimeComparator; import org.hibernate.metamodel.model.domain.AllowableTemporalParameterType; import org.hibernate.query.CastType; -import org.hibernate.type.descriptor.java.ZonedDateTimeJavaDescriptor; +import org.hibernate.type.descriptor.java.ZonedDateTimeJavaTypeDescriptor; import org.hibernate.type.descriptor.jdbc.TimestampWithTimeZoneDescriptor; import org.hibernate.type.spi.TypeConfiguration; +import jakarta.persistence.TemporalType; + /** * @author Steve Ebersole */ public class ZonedDateTimeType extends AbstractSingleColumnStandardBasicType - implements VersionType, AllowableTemporalParameterType { + implements AllowableTemporalParameterType { /** * Singleton access @@ -32,23 +30,7 @@ public class ZonedDateTimeType public static final ZonedDateTimeType INSTANCE = new ZonedDateTimeType(); public ZonedDateTimeType() { - super( TimestampWithTimeZoneDescriptor.INSTANCE, ZonedDateTimeJavaDescriptor.INSTANCE ); - } - - @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; + super( TimestampWithTimeZoneDescriptor.INSTANCE, ZonedDateTimeJavaTypeDescriptor.INSTANCE ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteTypeDescriptor.java index fa0b233573..7b7e84c231 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteTypeDescriptor.java @@ -10,6 +10,7 @@ import java.math.BigInteger; import java.util.Locale; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.spi.Primitive; @@ -19,7 +20,9 @@ import org.hibernate.type.descriptor.java.spi.Primitive; * @author Steve Ebersole * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ -public class ByteTypeDescriptor extends AbstractClassTypeDescriptor implements Primitive { +public class ByteTypeDescriptor extends AbstractClassTypeDescriptor implements Primitive, VersionJavaTypeDescriptor{ + + private static final Byte ZERO = (byte) 0; public static final ByteTypeDescriptor INSTANCE = new ByteTypeDescriptor(); public ByteTypeDescriptor() { @@ -170,4 +173,13 @@ public class ByteTypeDescriptor extends AbstractClassTypeDescriptor implem ) ); } + @Override + public Byte next(Byte current, SharedSessionContractImplementor session) { + return (byte) ( current + 1 ); + } + + @Override + public Byte seed(SharedSessionContractImplementor session) { + return ZERO; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTypeDescriptor.java index 2b52ca3a76..90020a7f40 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTypeDescriptor.java @@ -13,6 +13,7 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.util.compare.CalendarComparator; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; @@ -25,7 +26,7 @@ import org.hibernate.type.spi.TypeConfiguration; * * @author Steve Ebersole */ -public class CalendarTypeDescriptor extends AbstractTemporalTypeDescriptor { +public class CalendarTypeDescriptor extends AbstractTemporalTypeDescriptor implements VersionJavaTypeDescriptor { public static final CalendarTypeDescriptor INSTANCE = new CalendarTypeDescriptor(); public static class CalendarMutabilityPlan extends MutableMutabilityPlan { @@ -158,4 +159,14 @@ public class CalendarTypeDescriptor extends AbstractTemporalTypeDescriptor. + */ +package org.hibernate.type.descriptor.java; + +import java.lang.reflect.Type; +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.Comparator; + +import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.type.descriptor.WrapperOptions; +import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; +import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators; +import org.hibernate.type.spi.TypeConfiguration; + +import org.jboss.logging.Logger; + +import jakarta.persistence.TemporalType; + +/** + * Wrapper Java type descriptor for that uses the database timestamp as seed value for versions. + * + * @author Christian Beikov + */ +public class DbTimestampJavaTypeDescriptor implements VersionJavaTypeDescriptor, TemporalJavaTypeDescriptor { + + private static final CoreMessageLogger LOG = Logger.getMessageLogger( + CoreMessageLogger.class, + DbTimestampJavaTypeDescriptor.class.getName() + ); + + private final TemporalJavaTypeDescriptor delegate; + + public DbTimestampJavaTypeDescriptor(TemporalJavaTypeDescriptor delegate) { + this.delegate = delegate; + } + + @Override + public T next(T current, SharedSessionContractImplementor session) { + return seed( session ); + } + + @Override + @SuppressWarnings("unchecked") + public T seed(SharedSessionContractImplementor session) { + if ( session == null ) { + LOG.trace( "Incoming session was null; using current jvm time" ); + return ((VersionJavaTypeDescriptor) delegate).seed( null ); + } + else if ( !session.getJdbcServices().getJdbcEnvironment().getDialect().supportsCurrentTimestampSelection() ) { + LOG.debug( "Falling back to vm-based timestamp, as dialect does not support current timestamp selection" ); + return ((VersionJavaTypeDescriptor) delegate).seed( session ); + } + else { + return getCurrentTimestamp( session ); + } + } + + private T getCurrentTimestamp(SharedSessionContractImplementor session) { + Dialect dialect = session.getJdbcServices().getJdbcEnvironment().getDialect(); + String timestampSelectString = dialect.getCurrentTimestampSelectString(); + if ( dialect.isCurrentTimestampSelectStringCallable() ) { + return useCallableStatement( timestampSelectString, session ); + } + return usePreparedStatement( timestampSelectString, session ); + } + + private T usePreparedStatement(String timestampSelectString, SharedSessionContractImplementor session) { + PreparedStatement ps = null; + try { + ps = session + .getJdbcCoordinator() + .getStatementPreparer() + .prepareStatement( timestampSelectString, false ); + ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract( ps ); + rs.next(); + Timestamp ts = rs.getTimestamp( 1 ); + if ( LOG.isTraceEnabled() ) { + LOG.tracev( + "Current timestamp retrieved from db : {0} (nanos={1}, time={2})", + ts, + ts.getNanos(), + ts.getTime() + ); + } + return delegate.wrap( ts, session ); + } + catch (SQLException e) { + throw session.getJdbcServices().getSqlExceptionHelper().convert( + e, + "could not select current db timestamp", + timestampSelectString + ); + } + finally { + if ( ps != null ) { + session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( ps ); + session.getJdbcCoordinator().afterStatementExecution(); + } + } + } + + private T useCallableStatement(String callString, SharedSessionContractImplementor session) { + CallableStatement cs = null; + try { + cs = (CallableStatement) session + .getJdbcCoordinator() + .getStatementPreparer() + .prepareStatement( callString, true ); + cs.registerOutParameter( 1, java.sql.Types.TIMESTAMP ); + session.getJdbcCoordinator().getResultSetReturn().execute( cs ); + Timestamp ts = cs.getTimestamp( 1 ); + if ( LOG.isTraceEnabled() ) { + LOG.tracev( + "Current timestamp retrieved from db : {0} (nanos={1}, time={2})", + ts, + ts.getNanos(), + ts.getTime() + ); + } + return delegate.wrap( ts, session ); + } + catch (SQLException e) { + throw session.getJdbcServices().getSqlExceptionHelper().convert( + e, + "could not call current db timestamp function", + callString + ); + } + finally { + if ( cs != null ) { + session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( cs ); + session.getJdbcCoordinator().afterStatementExecution(); + } + } + } + + @Override + public JdbcTypeDescriptor getRecommendedJdbcType(JdbcTypeDescriptorIndicators indicators) { + return delegate.getRecommendedJdbcType( indicators ); + } + + @Override + public T fromString(CharSequence string) { + return delegate.fromString( string ); + } + + @Override + public Type getJavaType() { + return delegate.getJavaType(); + } + + @Override + public MutabilityPlan getMutabilityPlan() { + return delegate.getMutabilityPlan(); + } + + @Override + public long getDefaultSqlLength(Dialect dialect) { + return delegate.getDefaultSqlLength( dialect ); + } + + @Override + public long getLongSqlLength() { + return delegate.getLongSqlLength(); + } + + @Override + public int getDefaultSqlPrecision(Dialect dialect) { + return delegate.getDefaultSqlPrecision( dialect ); + } + + @Override + public int getDefaultSqlScale() { + return delegate.getDefaultSqlScale(); + } + + @Override + public Comparator getComparator() { + return delegate.getComparator(); + } + + @Override + public int extractHashCode(T value) { + return delegate.extractHashCode( value ); + } + + @Override + public boolean areEqual(T one, T another) { + return delegate.areEqual( one, another ); + } + + @Override + public String extractLoggableRepresentation(T value) { + return delegate.extractLoggableRepresentation( value ); + } + + @Override + public String toString(T value) { + return delegate.toString( value ); + } + + @Override + public X unwrap(T value, Class type, WrapperOptions options) { + return delegate.unwrap( value, type, options ); + } + + @Override + public T wrap(X value, WrapperOptions options) { + return delegate.wrap( value, options ); + } + + @Override + public T coerce(X value, CoercionContext coercionContext) { + return delegate.coerce( value, coercionContext ); + } + + @Override + public Class getJavaTypeClass() { + return delegate.getJavaTypeClass(); + } + + @Override + public String getCheckCondition(String columnName, JdbcTypeDescriptor sqlType, Dialect dialect) { + return delegate.getCheckCondition( columnName, sqlType, dialect ); + } + + @Override + public TemporalType getPrecision() { + return delegate.getPrecision(); + } + + @Override + public TemporalJavaTypeDescriptor resolveTypeForPrecision( + TemporalType precision, + TypeConfiguration typeConfiguration) { + return delegate.resolveTypeForPrecision( precision, typeConfiguration ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaDescriptor.java index df88a2a3a4..35e4a8af29 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaDescriptor.java @@ -19,6 +19,7 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators; @@ -30,7 +31,8 @@ import org.hibernate.type.spi.TypeConfiguration; * * @author Steve Ebersole */ -public class InstantJavaDescriptor extends AbstractTemporalTypeDescriptor { +public class InstantJavaDescriptor extends AbstractTemporalTypeDescriptor + implements VersionJavaTypeDescriptor { /** * Singleton access */ @@ -185,4 +187,15 @@ public class InstantJavaDescriptor extends AbstractTemporalTypeDescriptor implements Primitive { +public class IntegerTypeDescriptor extends AbstractClassTypeDescriptor + implements Primitive, VersionJavaTypeDescriptor { + + public static final Integer ZERO = 0; public static final IntegerTypeDescriptor INSTANCE = new IntegerTypeDescriptor(); public IntegerTypeDescriptor() { @@ -175,4 +179,15 @@ public class IntegerTypeDescriptor extends AbstractClassTypeDescriptor ) ); } + + @Override + public Integer seed(SharedSessionContractImplementor session) { + return ZERO; + } + + @Override + public Integer next(Integer current, SharedSessionContractImplementor session) { + return current + 1; + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampTypeDescriptor.java index 0619caa4ab..d0356aaabf 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampTypeDescriptor.java @@ -21,6 +21,7 @@ import jakarta.persistence.TemporalType; import org.hibernate.HibernateException; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators; @@ -32,7 +33,7 @@ import org.hibernate.type.spi.TypeConfiguration; * * @author Steve Ebersole */ -public class JdbcTimestampTypeDescriptor extends AbstractTemporalTypeDescriptor { +public class JdbcTimestampTypeDescriptor extends AbstractTemporalTypeDescriptor implements VersionJavaTypeDescriptor { public static final JdbcTimestampTypeDescriptor INSTANCE = new JdbcTimestampTypeDescriptor(); @SuppressWarnings("WeakerAccess") @@ -208,4 +209,15 @@ public class JdbcTimestampTypeDescriptor extends AbstractTemporalTypeDescriptor< public int getDefaultSqlPrecision(Dialect dialect) { return dialect.getDefaultTimestampPrecision(); } + + @Override + public Date next(Date current, SharedSessionContractImplementor session) { + return seed( session ); + } + + @Override + public Date seed(SharedSessionContractImplementor session) { + return new Timestamp( System.currentTimeMillis() ); + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaDescriptor.java index 9cb2cb4f12..4d56629cec 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaDescriptor.java @@ -18,6 +18,7 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators; @@ -29,7 +30,8 @@ import org.hibernate.type.spi.TypeConfiguration; * * @author Steve Ebersole */ -public class LocalDateTimeJavaDescriptor extends AbstractTemporalTypeDescriptor { +public class LocalDateTimeJavaDescriptor extends AbstractTemporalTypeDescriptor + implements VersionJavaTypeDescriptor { /** * Singleton access */ @@ -160,4 +162,14 @@ public class LocalDateTimeJavaDescriptor extends AbstractTemporalTypeDescriptor< public int getDefaultSqlPrecision(Dialect dialect) { return dialect.getDefaultTimestampPrecision(); } + + @Override + public LocalDateTime seed(SharedSessionContractImplementor session) { + return LocalDateTime.now(); + } + + @Override + public LocalDateTime next(LocalDateTime current, SharedSessionContractImplementor session) { + return LocalDateTime.now(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongTypeDescriptor.java index c25fab7caf..44eb440441 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongTypeDescriptor.java @@ -11,6 +11,7 @@ import java.math.BigInteger; import java.util.Locale; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.spi.Primitive; @@ -19,7 +20,10 @@ import org.hibernate.type.descriptor.java.spi.Primitive; * * @author Steve Ebersole */ -public class LongTypeDescriptor extends AbstractClassTypeDescriptor implements Primitive { +public class LongTypeDescriptor extends AbstractClassTypeDescriptor + implements Primitive, VersionJavaTypeDescriptor { + + private static final Long ZERO = (long) 0; public static final LongTypeDescriptor INSTANCE = new LongTypeDescriptor(); public LongTypeDescriptor() { @@ -175,4 +179,14 @@ public class LongTypeDescriptor extends AbstractClassTypeDescriptor implem public int getDefaultSqlScale() { return 0; } + + @Override + public Long next(Long current, SharedSessionContractImplementor session) { + return current + 1L; + } + + @Override + public Long seed(SharedSessionContractImplementor session) { + return ZERO; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaDescriptor.java index 8050ee8807..16fc999036 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaDescriptor.java @@ -13,12 +13,14 @@ import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Calendar; +import java.util.Comparator; import java.util.Date; import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.DateTypeDescriptor; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; @@ -32,7 +34,8 @@ import org.hibernate.type.spi.TypeConfiguration; * * @author Steve Ebersole */ -public class OffsetDateTimeJavaDescriptor extends AbstractTemporalTypeDescriptor { +public class OffsetDateTimeJavaDescriptor extends AbstractTemporalTypeDescriptor + implements VersionJavaTypeDescriptor { /** * Singleton access */ @@ -200,4 +203,19 @@ public class OffsetDateTimeJavaDescriptor extends AbstractTemporalTypeDescriptor public int getDefaultSqlPrecision(Dialect dialect) { return dialect.getDefaultTimestampPrecision(); } + + @Override + public OffsetDateTime seed(SharedSessionContractImplementor session) { + return OffsetDateTime.now(); + } + + @Override + public OffsetDateTime next(OffsetDateTime current, SharedSessionContractImplementor session) { + return OffsetDateTime.now(); + } + + @Override + public Comparator getComparator() { + return OffsetDateTime.timeLineOrder(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveByteArrayTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveByteArrayTypeDescriptor.java index 82c033ab42..189bc6eb37 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveByteArrayTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveByteArrayTypeDescriptor.java @@ -16,6 +16,7 @@ import java.util.Comparator; import org.hibernate.HibernateException; import org.hibernate.engine.jdbc.BinaryStream; import org.hibernate.engine.jdbc.internal.BinaryStreamImpl; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.type.descriptor.WrapperOptions; @@ -24,7 +25,8 @@ import org.hibernate.type.descriptor.WrapperOptions; * * @author Steve Ebersole */ -public class PrimitiveByteArrayTypeDescriptor extends AbstractClassTypeDescriptor { +public class PrimitiveByteArrayTypeDescriptor extends AbstractClassTypeDescriptor + implements VersionJavaTypeDescriptor { public static final PrimitiveByteArrayTypeDescriptor INSTANCE = new PrimitiveByteArrayTypeDescriptor(); @SuppressWarnings({ "unchecked" }) @@ -132,4 +134,18 @@ public class PrimitiveByteArrayTypeDescriptor extends AbstractClassTypeDescripto throw unknownWrap( value.getClass() ); } + + @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; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/RowVersionTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/RowVersionTypeDescriptor.java index a0eff44a92..91e8969745 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/RowVersionTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/RowVersionTypeDescriptor.java @@ -16,6 +16,7 @@ import java.util.Comparator; import org.hibernate.HibernateException; import org.hibernate.engine.jdbc.BinaryStream; import org.hibernate.engine.jdbc.internal.BinaryStreamImpl; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.util.compare.RowVersionComparator; import org.hibernate.type.descriptor.WrapperOptions; @@ -25,7 +26,8 @@ import org.hibernate.type.descriptor.WrapperOptions; * @author Steve Ebersole * @author Gail Badner */ -public class RowVersionTypeDescriptor extends AbstractClassTypeDescriptor { +public class RowVersionTypeDescriptor extends AbstractClassTypeDescriptor + implements VersionJavaTypeDescriptor { public static final RowVersionTypeDescriptor INSTANCE = new RowVersionTypeDescriptor(); @SuppressWarnings({ "unchecked" }) @@ -128,4 +130,18 @@ public class RowVersionTypeDescriptor extends AbstractClassTypeDescriptor implements Primitive { +public class ShortTypeDescriptor extends AbstractClassTypeDescriptor + implements Primitive, VersionJavaTypeDescriptor { + + private static final Short ZERO = (short) 0; public static final ShortTypeDescriptor INSTANCE = new ShortTypeDescriptor(); public ShortTypeDescriptor() { @@ -167,4 +171,13 @@ public class ShortTypeDescriptor extends AbstractClassTypeDescriptor impl ) ); } + @Override + public Short seed(SharedSessionContractImplementor session) { + return ZERO; + } + + @Override + public Short next(Short current, SharedSessionContractImplementor session) { + return (short) ( current + 1 ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/VersionType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/VersionJavaTypeDescriptor.java similarity index 73% rename from hibernate-core/src/main/java/org/hibernate/type/VersionType.java rename to hibernate-core/src/main/java/org/hibernate/type/descriptor/java/VersionJavaTypeDescriptor.java index 26f741a6ae..941a4578cf 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/VersionType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/VersionJavaTypeDescriptor.java @@ -4,19 +4,16 @@ * 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; +package org.hibernate.type.descriptor.java; import org.hibernate.engine.spi.SharedSessionContractImplementor; /** * Additional contract for types which may be used to version (and optimistic lock) data. * - * @author Gavin King - * @author Steve Ebersole + * @author Christian Beikov */ -public interface VersionType extends Type { +public interface VersionJavaTypeDescriptor extends JavaTypeDescriptor { /** * Generate an initial version. * @@ -34,10 +31,4 @@ public interface VersionType extends Type { */ T next(T current, SharedSessionContractImplementor session); - /** - * Get a comparator for version values. - * - * @return The comparator to use to compare different version values. - */ - Comparator getComparator(); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaTypeDescriptor.java similarity index 88% rename from hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaDescriptor.java rename to hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaTypeDescriptor.java index 7d0b318f99..5791841552 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaTypeDescriptor.java @@ -13,12 +13,15 @@ import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Calendar; +import java.util.Comparator; import java.util.Date; import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.internal.util.ZonedDateTimeComparator; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.DateTypeDescriptor; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; @@ -32,14 +35,14 @@ import org.hibernate.type.spi.TypeConfiguration; * * @author Steve Ebersole */ -public class ZonedDateTimeJavaDescriptor extends AbstractTemporalTypeDescriptor { +public class ZonedDateTimeJavaTypeDescriptor extends AbstractTemporalTypeDescriptor implements VersionJavaTypeDescriptor { /** * Singleton access */ - public static final ZonedDateTimeJavaDescriptor INSTANCE = new ZonedDateTimeJavaDescriptor(); + public static final ZonedDateTimeJavaTypeDescriptor INSTANCE = new ZonedDateTimeJavaTypeDescriptor(); @SuppressWarnings("unchecked") - public ZonedDateTimeJavaDescriptor() { + public ZonedDateTimeJavaTypeDescriptor() { super( ZonedDateTime.class, ImmutableMutabilityPlan.INSTANCE ); } @@ -199,4 +202,19 @@ public class ZonedDateTimeJavaDescriptor extends AbstractTemporalTypeDescriptor< public int getDefaultSqlPrecision(Dialect dialect) { return dialect.getDefaultTimestampPrecision(); } + + @Override + public ZonedDateTime seed(SharedSessionContractImplementor session) { + return ZonedDateTime.now(); + } + + @Override + public ZonedDateTime next(ZonedDateTime current, SharedSessionContractImplementor session) { + return ZonedDateTime.now(); + } + + @Override + public Comparator getComparator() { + return ZonedDateTimeComparator.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/JavaTypeDescriptorBaseline.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/JavaTypeDescriptorBaseline.java index b814c1f8ca..3359f87133 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/JavaTypeDescriptorBaseline.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/JavaTypeDescriptorBaseline.java @@ -69,7 +69,7 @@ import org.hibernate.type.descriptor.java.TimeZoneTypeDescriptor; import org.hibernate.type.descriptor.java.UUIDTypeDescriptor; import org.hibernate.type.descriptor.java.UrlTypeDescriptor; import org.hibernate.type.descriptor.java.ZoneOffsetJavaDescriptor; -import org.hibernate.type.descriptor.java.ZonedDateTimeJavaDescriptor; +import org.hibernate.type.descriptor.java.ZonedDateTimeJavaTypeDescriptor; /** * @@ -115,7 +115,7 @@ public class JavaTypeDescriptorBaseline { target.addBaselineDescriptor( LocalTimeJavaDescriptor.INSTANCE ); target.addBaselineDescriptor( OffsetDateTimeJavaDescriptor.INSTANCE ); target.addBaselineDescriptor( OffsetTimeJavaDescriptor.INSTANCE ); - target.addBaselineDescriptor( ZonedDateTimeJavaDescriptor.INSTANCE ); + target.addBaselineDescriptor( ZonedDateTimeJavaTypeDescriptor.INSTANCE ); target.addBaselineDescriptor( CalendarTypeDescriptor.INSTANCE ); target.addBaselineDescriptor( DateTypeDescriptor.INSTANCE ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeJavaTypeWrapper.java b/hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeJavaTypeWrapper.java index 20c849e714..774acdff0a 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeJavaTypeWrapper.java +++ b/hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeJavaTypeWrapper.java @@ -28,7 +28,7 @@ import org.hibernate.usertype.UserType; * @author Steve Ebersole */ public class UserTypeJavaTypeWrapper implements BasicJavaDescriptor { - private final UserType userType; + protected final UserType userType; private final MutabilityPlan mutabilityPlan; private final Comparator comparator; diff --git a/hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeVersionJavaTypeWrapper.java b/hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeVersionJavaTypeWrapper.java new file mode 100644 index 0000000000..df057b31b9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeVersionJavaTypeWrapper.java @@ -0,0 +1,32 @@ +/* + * 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 http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.type.internal; + +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.type.descriptor.java.VersionJavaTypeDescriptor; +import org.hibernate.usertype.UserVersionType; + +/** + * + * @author Christian Beikov + */ +public class UserTypeVersionJavaTypeWrapper extends UserTypeJavaTypeWrapper implements VersionJavaTypeDescriptor { + + public UserTypeVersionJavaTypeWrapper(UserVersionType userType) { + super( userType ); + } + + @Override + public J seed(SharedSessionContractImplementor session) { + return ( (UserVersionType) userType ).seed( session ); + } + + @Override + public J next(J current, SharedSessionContractImplementor session) { + return ( (UserVersionType) userType ).next( current, session ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/usertype/UserVersionType.java b/hibernate-core/src/main/java/org/hibernate/usertype/UserVersionType.java index abd55a59ef..5183153f1d 100644 --- a/hibernate-core/src/main/java/org/hibernate/usertype/UserVersionType.java +++ b/hibernate-core/src/main/java/org/hibernate/usertype/UserVersionType.java @@ -15,7 +15,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; * * @author Gavin King */ -public interface UserVersionType extends UserType, Comparator { +public interface UserVersionType extends UserType, Comparator { /** * Generate an initial version. * @@ -24,7 +24,7 @@ public interface UserVersionType extends UserType, Comparator { * the "unsaved value" of entities. * @return an instance of the type */ - Object seed(SharedSessionContractImplementor session); + T seed(SharedSessionContractImplementor session); /** * Increment the version. @@ -33,5 +33,5 @@ public interface UserVersionType extends UserType, Comparator { * @param current the current version * @return an instance of the type */ - Object next(Object current, SharedSessionContractImplementor session); + T next(T current, SharedSessionContractImplementor session); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cfg/persister/GoofyPersisterClassProvider.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cfg/persister/GoofyPersisterClassProvider.java index fc8b49026b..1eda35dae6 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/cfg/persister/GoofyPersisterClassProvider.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cfg/persister/GoofyPersisterClassProvider.java @@ -64,9 +64,9 @@ import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.tuple.entity.BytecodeEnhancementMetadataNonPojoImpl; import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityTuplizer; +import org.hibernate.type.BasicType; import org.hibernate.type.CollectionType; import org.hibernate.type.Type; -import org.hibernate.type.VersionType; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; /** @@ -237,7 +237,7 @@ public class GoofyPersisterClassProvider implements PersisterClassResolver { } @Override - public VersionType getVersionType() { + public BasicType getVersionType() { return null; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/PersisterClassProviderTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/PersisterClassProviderTest.java index dddea236dc..cc78ab2df6 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/PersisterClassProviderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/PersisterClassProviderTest.java @@ -62,8 +62,8 @@ import org.hibernate.persister.walking.spi.EntityIdentifierDefinition; import org.hibernate.tuple.entity.BytecodeEnhancementMetadataNonPojoImpl; import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityTuplizer; +import org.hibernate.type.BasicType; import org.hibernate.type.Type; -import org.hibernate.type.VersionType; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.junit.jupiter.api.Assertions; @@ -262,7 +262,7 @@ public class PersisterClassProviderTest { } @Override - public VersionType getVersionType() { + public BasicType getVersionType() { return null; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/CustomPersister.java b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/CustomPersister.java index b04ea859d1..41f0e4e8c3 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/CustomPersister.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/legacy/CustomPersister.java @@ -63,9 +63,9 @@ import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.tuple.entity.BytecodeEnhancementMetadataNonPojoImpl; import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityTuplizer; +import org.hibernate.type.BasicType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.Type; -import org.hibernate.type.VersionType; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; public class CustomPersister implements EntityPersister { @@ -295,7 +295,7 @@ public class CustomPersister implements EntityPersister { /** * @see EntityPersister#getVersionType() */ - public VersionType getVersionType() { + public BasicType getVersionType() { return null; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/ZonedDateTimeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/ZonedDateTimeDescriptorTest.java index 4ff35bc281..9952faacd8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/ZonedDateTimeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/ZonedDateTimeDescriptorTest.java @@ -9,7 +9,7 @@ package org.hibernate.orm.test.mapping.type.java; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; -import org.hibernate.type.descriptor.java.ZonedDateTimeJavaDescriptor; +import org.hibernate.type.descriptor.java.ZonedDateTimeJavaTypeDescriptor; /** * @author Jordan Gigov @@ -20,7 +20,7 @@ public class ZonedDateTimeDescriptorTest extends AbstractDescriptorTest versionType = sessionFactory().getEntityPersister( Thing.class.getName() ).getVersionType(); assertSame( RowVersionType.INSTANCE, versionType ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/version/sybase/SybaseTimestampVersioningTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/version/sybase/SybaseTimestampVersioningTest.java index d853164d83..08d55342cc 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/version/sybase/SybaseTimestampVersioningTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/version/sybase/SybaseTimestampVersioningTest.java @@ -16,9 +16,10 @@ import org.hibernate.dialect.SybaseASE15Dialect; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; + +import org.hibernate.type.BasicType; import org.hibernate.type.BinaryType; import org.hibernate.type.RowVersionType; -import org.hibernate.type.VersionType; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; @@ -225,7 +226,7 @@ public class SybaseTimestampVersioningTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue( jiraKey = "HHH-10413" ) public void testComparableTimestamps() { - final VersionType versionType = + final BasicType versionType = sessionFactory().getEntityPersister( User.class.getName() ).getVersionType(); assertSame( RowVersionType.INSTANCE, versionType );