HHH-18184 - Remove CacheModeType and its uses
This commit is contained in:
parent
2b6f4b5ff9
commit
2dde0a7c46
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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}.
|
||||
|
|
|
@ -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}.
|
||||
|
|
|
@ -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<Object>) 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(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue