HHH-18184 - Remove CacheModeType and its uses

This commit is contained in:
Steve Ebersole 2024-07-23 09:44:08 -05:00
parent 2b6f4b5ff9
commit 2dde0a7c46
6 changed files with 18 additions and 206 deletions

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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 );
}
}
}

View File

@ -132,20 +132,6 @@ public @interface NamedNativeQuery {
*/ */
CacheRetrieveMode cacheRetrieveMode() default CacheRetrieveMode.USE; 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. * Whether the results should be loaded in read-only mode.
* Default is {@code false}. * Default is {@code false}.

View File

@ -126,20 +126,6 @@ public @interface NamedQuery {
*/ */
CacheRetrieveMode cacheRetrieveMode() default CacheRetrieveMode.USE; 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. * Whether the results should be loaded in read-only mode.
* Default is {@code false}. * Default is {@code false}.

View File

@ -13,10 +13,8 @@ import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.hibernate.AnnotationException; import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.CacheMode; import org.hibernate.CacheMode;
import org.hibernate.FlushMode; import org.hibernate.FlushMode;
import org.hibernate.annotations.CacheModeType;
import org.hibernate.annotations.FlushModeType; import org.hibernate.annotations.FlushModeType;
import org.hibernate.annotations.HQLSelect; import org.hibernate.annotations.HQLSelect;
import org.hibernate.annotations.SQLSelect; import org.hibernate.annotations.SQLSelect;
@ -236,7 +234,7 @@ public abstract class QueryBinder {
.setResultClass( resultClass ) .setResultClass( resultClass )
.setCacheable( namedNativeQuery.cacheable() ) .setCacheable( namedNativeQuery.cacheable() )
.setCacheRegion( nullIfEmpty( namedNativeQuery.cacheRegion() ) ) .setCacheRegion( nullIfEmpty( namedNativeQuery.cacheRegion() ) )
.setCacheMode( getCacheMode( namedNativeQuery.cacheRetrieveMode(), namedNativeQuery.cacheStoreMode(), namedNativeQuery.cacheMode() ) ) .setCacheMode( getCacheMode( namedNativeQuery.cacheRetrieveMode(), namedNativeQuery.cacheStoreMode() ) )
.setTimeout( timeout < 0 ? null : timeout ) .setTimeout( timeout < 0 ? null : timeout )
.setFetchSize( fetchSize < 0 ? null : fetchSize ) .setFetchSize( fetchSize < 0 ? null : fetchSize )
.setFlushMode( getFlushMode( namedNativeQuery.flushMode() ) ) .setFlushMode( getFlushMode( namedNativeQuery.flushMode() ) )
@ -380,7 +378,7 @@ public abstract class QueryBinder {
.setResultClass( (Class<Object>) namedQuery.resultClass() ) .setResultClass( (Class<Object>) namedQuery.resultClass() )
.setCacheable( namedQuery.cacheable() ) .setCacheable( namedQuery.cacheable() )
.setCacheRegion( nullIfEmpty( namedQuery.cacheRegion() ) ) .setCacheRegion( nullIfEmpty( namedQuery.cacheRegion() ) )
.setCacheMode( getCacheMode( namedQuery.cacheRetrieveMode(), namedQuery.cacheStoreMode(), namedQuery.cacheMode() ) ) .setCacheMode( getCacheMode( namedQuery.cacheRetrieveMode(), namedQuery.cacheStoreMode() ) )
.setTimeout( timeout < 0 ? null : timeout ) .setTimeout( timeout < 0 ? null : timeout )
.setFetchSize( fetchSize < 0 ? null : fetchSize ) .setFetchSize( fetchSize < 0 ? null : fetchSize )
.setFlushMode( getFlushMode( namedQuery.flushMode() ) ) .setFlushMode( getFlushMode( namedQuery.flushMode() ) )
@ -396,45 +394,19 @@ public abstract class QueryBinder {
context.getMetadataCollector().addNamedQuery( hqlQueryDefinition ); 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 ); final CacheMode cacheMode = CacheMode.fromJpaModes( cacheRetrieveMode, cacheStoreMode );
return cacheMode == null || cacheMode == CacheMode.NORMAL return cacheMode == null ? CacheMode.NORMAL : cacheMode;
? interpretCacheMode( cacheModeType )
: cacheMode;
} }
private static FlushMode getFlushMode(FlushModeType flushModeType) { private static FlushMode getFlushMode(FlushModeType flushModeType) {
switch ( flushModeType ) { return switch ( flushModeType ) {
case ALWAYS: case ALWAYS -> FlushMode.ALWAYS;
return FlushMode.ALWAYS; case AUTO -> FlushMode.AUTO;
case AUTO: case COMMIT -> FlushMode.COMMIT;
return FlushMode.AUTO; case MANUAL -> FlushMode.MANUAL;
case COMMIT: case PERSISTENCE_CONTEXT -> null;
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 );
}
} }
public static void bindNamedStoredProcedureQuery( public static void bindNamedStoredProcedureQuery(

View File

@ -10,7 +10,6 @@ import java.lang.annotation.Annotation;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.hibernate.annotations.CacheModeType;
import org.hibernate.annotations.FlushModeType; import org.hibernate.annotations.FlushModeType;
import org.hibernate.annotations.NamedNativeQuery; import org.hibernate.annotations.NamedNativeQuery;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl;
@ -44,7 +43,6 @@ public class NamedNativeQueryAnnotation implements NamedNativeQuery {
String comment; String comment;
CacheStoreMode cacheStoreMode; CacheStoreMode cacheStoreMode;
CacheRetrieveMode cacheRetrieveMode; CacheRetrieveMode cacheRetrieveMode;
CacheModeType cacheMode;
boolean readOnly; boolean readOnly;
String[] querySpaces; String[] querySpaces;
boolean callable; boolean callable;
@ -60,7 +58,6 @@ public class NamedNativeQueryAnnotation implements NamedNativeQuery {
comment = ""; comment = "";
cacheStoreMode = CacheStoreMode.USE; cacheStoreMode = CacheStoreMode.USE;
cacheRetrieveMode = CacheRetrieveMode.USE; cacheRetrieveMode = CacheRetrieveMode.USE;
cacheMode = CacheModeType.NORMAL;
readOnly = false; readOnly = false;
querySpaces = new String[0]; querySpaces = new String[0];
callable = false; callable = false;
@ -79,7 +76,6 @@ public class NamedNativeQueryAnnotation implements NamedNativeQuery {
this.comment = annotation.comment(); this.comment = annotation.comment();
this.cacheStoreMode = annotation.cacheStoreMode(); this.cacheStoreMode = annotation.cacheStoreMode();
this.cacheRetrieveMode = annotation.cacheRetrieveMode(); this.cacheRetrieveMode = annotation.cacheRetrieveMode();
this.cacheMode = annotation.cacheMode();
this.readOnly = annotation.readOnly(); this.readOnly = annotation.readOnly();
this.querySpaces = annotation.querySpaces(); this.querySpaces = annotation.querySpaces();
this.callable = annotation.callable(); this.callable = annotation.callable();
@ -98,7 +94,6 @@ public class NamedNativeQueryAnnotation implements NamedNativeQuery {
this.comment = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "comment", modelContext ); this.comment = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "comment", modelContext );
this.cacheStoreMode = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "cacheStoreMode", modelContext ); this.cacheStoreMode = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "cacheStoreMode", modelContext );
this.cacheRetrieveMode = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "cacheRetrieveMode", 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.readOnly = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "readOnly", modelContext );
this.querySpaces = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "querySpaces", modelContext ); this.querySpaces = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "querySpaces", modelContext );
this.callable = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "callable", modelContext ); this.callable = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "callable", modelContext );
@ -219,15 +214,6 @@ public class NamedNativeQueryAnnotation implements NamedNativeQuery {
this.cacheRetrieveMode = value; this.cacheRetrieveMode = value;
} }
@Override
public CacheModeType cacheMode() {
return cacheMode;
}
public void cacheMode(CacheModeType value) {
this.cacheMode = value;
}
@Override @Override
public boolean readOnly() { public boolean readOnly() {
return readOnly; return readOnly;

View File

@ -8,8 +8,6 @@ package org.hibernate.boot.models.annotations.internal;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import org.hibernate.CacheMode;
import org.hibernate.annotations.CacheModeType;
import org.hibernate.annotations.FlushModeType; import org.hibernate.annotations.FlushModeType;
import org.hibernate.annotations.NamedQuery; import org.hibernate.annotations.NamedQuery;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl;
@ -40,7 +38,6 @@ public class NamedQueryAnnotation implements NamedQuery {
String comment; String comment;
CacheStoreMode cacheStoreMode; CacheStoreMode cacheStoreMode;
CacheRetrieveMode cacheRetrieveMode; CacheRetrieveMode cacheRetrieveMode;
CacheModeType cacheMode;
boolean readOnly; boolean readOnly;
public NamedQueryAnnotation(SourceModelBuildingContext modelContext) { public NamedQueryAnnotation(SourceModelBuildingContext modelContext) {
@ -53,7 +50,6 @@ public class NamedQueryAnnotation implements NamedQuery {
comment = ""; comment = "";
cacheStoreMode = CacheStoreMode.USE; cacheStoreMode = CacheStoreMode.USE;
cacheRetrieveMode = CacheRetrieveMode.USE; cacheRetrieveMode = CacheRetrieveMode.USE;
cacheMode = CacheModeType.NORMAL;
readOnly = false; readOnly = false;
} }
@ -69,7 +65,6 @@ public class NamedQueryAnnotation implements NamedQuery {
this.comment = annotation.comment(); this.comment = annotation.comment();
this.cacheStoreMode = annotation.cacheStoreMode(); this.cacheStoreMode = annotation.cacheStoreMode();
this.cacheRetrieveMode = annotation.cacheRetrieveMode(); this.cacheRetrieveMode = annotation.cacheRetrieveMode();
this.cacheMode = annotation.cacheMode();
this.readOnly = annotation.readOnly(); this.readOnly = annotation.readOnly();
} }
@ -85,7 +80,6 @@ public class NamedQueryAnnotation implements NamedQuery {
this.comment = extractJandexValue( annotation, NAMED_QUERY, "comment", modelContext ); this.comment = extractJandexValue( annotation, NAMED_QUERY, "comment", modelContext );
this.cacheStoreMode = extractJandexValue( annotation, NAMED_QUERY, "cacheStoreMode", modelContext ); this.cacheStoreMode = extractJandexValue( annotation, NAMED_QUERY, "cacheStoreMode", modelContext );
this.cacheRetrieveMode = extractJandexValue( annotation, NAMED_QUERY, "cacheRetrieveMode", 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 ); this.readOnly = extractJandexValue( annotation, NAMED_QUERY, "readOnly", modelContext );
} }
@ -195,15 +189,6 @@ public class NamedQueryAnnotation implements NamedQuery {
this.cacheRetrieveMode = value; this.cacheRetrieveMode = value;
} }
@Override
public CacheModeType cacheMode() {
return cacheMode;
}
public void cacheMode(CacheModeType value) {
this.cacheMode = value;
}
@Override @Override
public boolean readOnly() { public boolean readOnly() {
return readOnly; return readOnly;
@ -226,9 +211,13 @@ public class NamedQueryAnnotation implements NamedQuery {
cacheRegion( jaxbNamedQuery.getCacheRegion() ); cacheRegion( jaxbNamedQuery.getCacheRegion() );
} }
final CacheMode cacheMode = jaxbNamedQuery.getCacheMode(); if ( jaxbNamedQuery.getCacheMode() != null ) {
if ( cacheMode != null && cacheMode != CacheMode.IGNORE ) { if ( jaxbNamedQuery.getCacheMode().isGetEnabled() ) {
cacheMode( CacheModeType.fromCacheMode( cacheMode ) ); cacheRetrieveMode( CacheRetrieveMode.USE );
}
if ( jaxbNamedQuery.getCacheMode().isPutEnabled() ) {
cacheStoreMode( CacheStoreMode.USE );
}
} }
} }
} }