From 2dde0a7c469e180cc0510dac1d38ea8ab5b9f0ff Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 23 Jul 2024 09:44:08 -0500 Subject: [PATCH] HHH-18184 - Remove CacheModeType and its uses --- .../hibernate/annotations/CacheModeType.java | 107 ------------------ .../annotations/NamedNativeQuery.java | 14 --- .../org/hibernate/annotations/NamedQuery.java | 14 --- .../boot/model/internal/QueryBinder.java | 50 ++------ .../internal/NamedNativeQueryAnnotation.java | 14 --- .../internal/NamedQueryAnnotation.java | 25 ++-- 6 files changed, 18 insertions(+), 206 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/annotations/CacheModeType.java diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/CacheModeType.java b/hibernate-core/src/main/java/org/hibernate/annotations/CacheModeType.java deleted file mode 100644 index 3ea1775114..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/annotations/CacheModeType.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.annotations; - -import org.hibernate.AssertionFailure; -import org.hibernate.CacheMode; -import org.hibernate.Remove; - -/** - * Enumerates the different interaction modes between the session - * and the second-level Cache. This enumeration is isomorphic to - * {@link CacheMode} and exists only for historical reasons. - * - * @author Emmanuel Bernard - * @author Carlos Gonzalez-Cadenas - * - * @deprecated use {@link CacheMode} or - * {@link jakarta.persistence.CacheStoreMode} and - * {@link jakarta.persistence.CacheRetrieveMode}. - */ -@Deprecated(since = "6.2") @Remove -public enum CacheModeType { - /** - * Corresponds to {@link CacheMode#GET}. - * - * @see CacheMode#GET - */ - GET, - - /** - * Corresponds to {@link CacheMode#IGNORE}. - * - * @see CacheMode#IGNORE - */ - IGNORE, - - /** - * Corresponds to {@link CacheMode#NORMAL}. - * - * @see CacheMode#NORMAL - */ - NORMAL, - - /** - * Corresponds to {@link CacheMode#PUT}. - * - * @see CacheMode#PUT - */ - PUT, - - /** - * Corresponds to {@link CacheMode#REFRESH}. - * - * @see CacheMode#REFRESH - */ - REFRESH; - - public CacheMode getCacheMode() { - switch (this) { - case GET: - return CacheMode.GET; - case IGNORE: - return CacheMode.IGNORE; - case NORMAL: - return CacheMode.NORMAL; - case PUT: - return CacheMode.PUT; - case REFRESH: - return CacheMode.REFRESH; - default: - throw new AssertionFailure( "Unknown CacheModeType" ); - } - } - - /** - * Conversion from {@link CacheMode} to {@link CacheModeType}. - * - * @param cacheMode The cache mode to convert - * - * @return The corresponding enum value. - * Will be {@code null} if the given {@code accessType} is {@code null}. - */ - public static CacheModeType fromCacheMode(CacheMode cacheMode) { - if ( null == cacheMode ) { - return null; - } - - switch ( cacheMode ) { - case NORMAL: - return NORMAL; - case GET: - return GET; - case PUT: - return PUT; - case REFRESH: - return REFRESH; - case IGNORE: - return IGNORE; - default: - throw new IllegalArgumentException( "Unrecognized CacheMode : " + cacheMode ); - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/NamedNativeQuery.java b/hibernate-core/src/main/java/org/hibernate/annotations/NamedNativeQuery.java index 43db60fc94..4e1538de9a 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/NamedNativeQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/NamedNativeQuery.java @@ -132,20 +132,6 @@ public @interface NamedNativeQuery { */ CacheRetrieveMode cacheRetrieveMode() default CacheRetrieveMode.USE; - /** - * The cache interaction mode for this query. - * - * @deprecated use {@link #cacheStoreMode()} and - * {@link #cacheRetrieveMode()} since - * {@link CacheModeType} is deprecated - * - * @see org.hibernate.jpa.HibernateHints#HINT_CACHE_MODE - */ - @Deprecated(since = "6.2") @Remove - //TODO: actually, we won't remove it, we'll change its - // type to CacheMode and then un-deprecate it - CacheModeType cacheMode() default CacheModeType.NORMAL; - /** * Whether the results should be loaded in read-only mode. * Default is {@code false}. diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/NamedQuery.java b/hibernate-core/src/main/java/org/hibernate/annotations/NamedQuery.java index c524746715..09d841fa6a 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/NamedQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/NamedQuery.java @@ -126,20 +126,6 @@ public @interface NamedQuery { */ CacheRetrieveMode cacheRetrieveMode() default CacheRetrieveMode.USE; - /** - * The cache interaction mode for this query. - * - * @deprecated use {@link #cacheStoreMode()} and - * {@link #cacheRetrieveMode()} since - * {@link CacheModeType} is deprecated - * - * @see org.hibernate.jpa.HibernateHints#HINT_CACHE_MODE - */ - @Deprecated(since = "6.2") @Remove - //TODO: actually, we won't remove it, we'll change its - // type to CacheMode and then un-deprecate it - CacheModeType cacheMode() default CacheModeType.NORMAL; - /** * Whether the results should be loaded in read-only mode. * Default is {@code false}. diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java index 315a5da68f..ee32a98ec0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java @@ -13,10 +13,8 @@ import java.util.List; import java.util.function.Supplier; import org.hibernate.AnnotationException; -import org.hibernate.AssertionFailure; import org.hibernate.CacheMode; import org.hibernate.FlushMode; -import org.hibernate.annotations.CacheModeType; import org.hibernate.annotations.FlushModeType; import org.hibernate.annotations.HQLSelect; import org.hibernate.annotations.SQLSelect; @@ -236,7 +234,7 @@ public abstract class QueryBinder { .setResultClass( resultClass ) .setCacheable( namedNativeQuery.cacheable() ) .setCacheRegion( nullIfEmpty( namedNativeQuery.cacheRegion() ) ) - .setCacheMode( getCacheMode( namedNativeQuery.cacheRetrieveMode(), namedNativeQuery.cacheStoreMode(), namedNativeQuery.cacheMode() ) ) + .setCacheMode( getCacheMode( namedNativeQuery.cacheRetrieveMode(), namedNativeQuery.cacheStoreMode() ) ) .setTimeout( timeout < 0 ? null : timeout ) .setFetchSize( fetchSize < 0 ? null : fetchSize ) .setFlushMode( getFlushMode( namedNativeQuery.flushMode() ) ) @@ -380,7 +378,7 @@ public abstract class QueryBinder { .setResultClass( (Class) namedQuery.resultClass() ) .setCacheable( namedQuery.cacheable() ) .setCacheRegion( nullIfEmpty( namedQuery.cacheRegion() ) ) - .setCacheMode( getCacheMode( namedQuery.cacheRetrieveMode(), namedQuery.cacheStoreMode(), namedQuery.cacheMode() ) ) + .setCacheMode( getCacheMode( namedQuery.cacheRetrieveMode(), namedQuery.cacheStoreMode() ) ) .setTimeout( timeout < 0 ? null : timeout ) .setFetchSize( fetchSize < 0 ? null : fetchSize ) .setFlushMode( getFlushMode( namedQuery.flushMode() ) ) @@ -396,45 +394,19 @@ public abstract class QueryBinder { context.getMetadataCollector().addNamedQuery( hqlQueryDefinition ); } - private static CacheMode getCacheMode(CacheRetrieveMode cacheRetrieveMode, CacheStoreMode cacheStoreMode, CacheModeType cacheModeType) { + private static CacheMode getCacheMode(CacheRetrieveMode cacheRetrieveMode, CacheStoreMode cacheStoreMode) { final CacheMode cacheMode = CacheMode.fromJpaModes( cacheRetrieveMode, cacheStoreMode ); - return cacheMode == null || cacheMode == CacheMode.NORMAL - ? interpretCacheMode( cacheModeType ) - : cacheMode; + return cacheMode == null ? CacheMode.NORMAL : cacheMode; } private static FlushMode getFlushMode(FlushModeType flushModeType) { - switch ( flushModeType ) { - case ALWAYS: - return FlushMode.ALWAYS; - case AUTO: - return FlushMode.AUTO; - case COMMIT: - return FlushMode.COMMIT; - case MANUAL: - return FlushMode.MANUAL; - case PERSISTENCE_CONTEXT: - return null; - default: - throw new AssertionFailure( "Unknown FlushModeType: " + flushModeType ); - } - } - - private static CacheMode interpretCacheMode(CacheModeType cacheModeType) { - switch ( cacheModeType ) { - case GET: - return CacheMode.GET; - case IGNORE: - return CacheMode.IGNORE; - case NORMAL: - return CacheMode.NORMAL; - case PUT: - return CacheMode.PUT; - case REFRESH: - return CacheMode.REFRESH; - default: - throw new AssertionFailure( "Unknown cacheModeType: " + cacheModeType ); - } + return switch ( flushModeType ) { + case ALWAYS -> FlushMode.ALWAYS; + case AUTO -> FlushMode.AUTO; + case COMMIT -> FlushMode.COMMIT; + case MANUAL -> FlushMode.MANUAL; + case PERSISTENCE_CONTEXT -> null; + }; } public static void bindNamedStoredProcedureQuery( diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueryAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueryAnnotation.java index 3b4174f167..e2bdd94561 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueryAnnotation.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueryAnnotation.java @@ -10,7 +10,6 @@ import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.List; -import org.hibernate.annotations.CacheModeType; import org.hibernate.annotations.FlushModeType; import org.hibernate.annotations.NamedNativeQuery; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl; @@ -44,7 +43,6 @@ public class NamedNativeQueryAnnotation implements NamedNativeQuery { String comment; CacheStoreMode cacheStoreMode; CacheRetrieveMode cacheRetrieveMode; - CacheModeType cacheMode; boolean readOnly; String[] querySpaces; boolean callable; @@ -60,7 +58,6 @@ public class NamedNativeQueryAnnotation implements NamedNativeQuery { comment = ""; cacheStoreMode = CacheStoreMode.USE; cacheRetrieveMode = CacheRetrieveMode.USE; - cacheMode = CacheModeType.NORMAL; readOnly = false; querySpaces = new String[0]; callable = false; @@ -79,7 +76,6 @@ public class NamedNativeQueryAnnotation implements NamedNativeQuery { this.comment = annotation.comment(); this.cacheStoreMode = annotation.cacheStoreMode(); this.cacheRetrieveMode = annotation.cacheRetrieveMode(); - this.cacheMode = annotation.cacheMode(); this.readOnly = annotation.readOnly(); this.querySpaces = annotation.querySpaces(); this.callable = annotation.callable(); @@ -98,7 +94,6 @@ public class NamedNativeQueryAnnotation implements NamedNativeQuery { this.comment = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "comment", modelContext ); this.cacheStoreMode = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "cacheStoreMode", modelContext ); this.cacheRetrieveMode = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "cacheRetrieveMode", modelContext ); - this.cacheMode = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "cacheMode", modelContext ); this.readOnly = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "readOnly", modelContext ); this.querySpaces = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "querySpaces", modelContext ); this.callable = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "callable", modelContext ); @@ -219,15 +214,6 @@ public class NamedNativeQueryAnnotation implements NamedNativeQuery { this.cacheRetrieveMode = value; } - @Override - public CacheModeType cacheMode() { - return cacheMode; - } - - public void cacheMode(CacheModeType value) { - this.cacheMode = value; - } - @Override public boolean readOnly() { return readOnly; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueryAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueryAnnotation.java index ae1e3d8b35..8e4dd43ae8 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueryAnnotation.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueryAnnotation.java @@ -8,8 +8,6 @@ package org.hibernate.boot.models.annotations.internal; import java.lang.annotation.Annotation; -import org.hibernate.CacheMode; -import org.hibernate.annotations.CacheModeType; import org.hibernate.annotations.FlushModeType; import org.hibernate.annotations.NamedQuery; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl; @@ -40,7 +38,6 @@ public class NamedQueryAnnotation implements NamedQuery { String comment; CacheStoreMode cacheStoreMode; CacheRetrieveMode cacheRetrieveMode; - CacheModeType cacheMode; boolean readOnly; public NamedQueryAnnotation(SourceModelBuildingContext modelContext) { @@ -53,7 +50,6 @@ public class NamedQueryAnnotation implements NamedQuery { comment = ""; cacheStoreMode = CacheStoreMode.USE; cacheRetrieveMode = CacheRetrieveMode.USE; - cacheMode = CacheModeType.NORMAL; readOnly = false; } @@ -69,7 +65,6 @@ public class NamedQueryAnnotation implements NamedQuery { this.comment = annotation.comment(); this.cacheStoreMode = annotation.cacheStoreMode(); this.cacheRetrieveMode = annotation.cacheRetrieveMode(); - this.cacheMode = annotation.cacheMode(); this.readOnly = annotation.readOnly(); } @@ -85,7 +80,6 @@ public class NamedQueryAnnotation implements NamedQuery { this.comment = extractJandexValue( annotation, NAMED_QUERY, "comment", modelContext ); this.cacheStoreMode = extractJandexValue( annotation, NAMED_QUERY, "cacheStoreMode", modelContext ); this.cacheRetrieveMode = extractJandexValue( annotation, NAMED_QUERY, "cacheRetrieveMode", modelContext ); - this.cacheMode = extractJandexValue( annotation, NAMED_QUERY, "cacheMode", modelContext ); this.readOnly = extractJandexValue( annotation, NAMED_QUERY, "readOnly", modelContext ); } @@ -195,15 +189,6 @@ public class NamedQueryAnnotation implements NamedQuery { this.cacheRetrieveMode = value; } - @Override - public CacheModeType cacheMode() { - return cacheMode; - } - - public void cacheMode(CacheModeType value) { - this.cacheMode = value; - } - @Override public boolean readOnly() { return readOnly; @@ -226,9 +211,13 @@ public class NamedQueryAnnotation implements NamedQuery { cacheRegion( jaxbNamedQuery.getCacheRegion() ); } - final CacheMode cacheMode = jaxbNamedQuery.getCacheMode(); - if ( cacheMode != null && cacheMode != CacheMode.IGNORE ) { - cacheMode( CacheModeType.fromCacheMode( cacheMode ) ); + if ( jaxbNamedQuery.getCacheMode() != null ) { + if ( jaxbNamedQuery.getCacheMode().isGetEnabled() ) { + cacheRetrieveMode( CacheRetrieveMode.USE ); + } + if ( jaxbNamedQuery.getCacheMode().isPutEnabled() ) { + cacheStoreMode( CacheStoreMode.USE ); + } } } }