HHH-15701 deprecate CacheModeType since it is a dupe of CacheMode

improve Javadoc
This commit is contained in:
Gavin King 2022-11-09 23:00:12 +01:00
parent 7bcbfdcc12
commit bd7140eef7
8 changed files with 277 additions and 158 deletions

View File

@ -89,7 +89,7 @@ public enum CacheMode {
* @throws MappingException Indicates the external form was not recognized as a valid enum value.
*/
public static CacheMode interpretExternalSetting(String setting) {
if (setting == null) {
if ( setting == null ) {
return null;
}
@ -115,22 +115,28 @@ public enum CacheMode {
}
switch ( storeMode ) {
case USE: {
switch ( retrieveMode ) {
case USE:
return NORMAL;
case BYPASS:
return PUT;
}
}
case BYPASS: {
return retrieveMode == CacheRetrieveMode.USE
? GET
: IGNORE;
switch ( retrieveMode ) {
case USE:
return GET;
case BYPASS:
return IGNORE;
}
}
case REFRESH: {
// technically should combo `CacheStoreMode#REFRESH` and `CacheRetrieveMode#USE` be illegal?
// technically should combo CacheStoreMode#REFRESH and CacheRetrieveMode#USE be illegal?
return REFRESH;
}
case USE: {
return retrieveMode == CacheRetrieveMode.USE
? NORMAL
: PUT;
}
default: {
throw new UnsupportedOperationException( "Unrecognized CacheStoreMode : " + storeMode );
throw new AssertionFailure( "Unrecognized CacheStoreMode: " + storeMode );
}
}
}

View File

@ -7,14 +7,21 @@
package org.hibernate.annotations;
import org.hibernate.CacheMode;
import org.hibernate.Remove;
/**
* Enumeration for the different interaction modes between the session and
* the Level 2 Cache.
* 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}.
@ -53,7 +60,7 @@ public enum CacheModeType {
private final CacheMode cacheMode;
private CacheModeType(CacheMode cacheMode) {
CacheModeType(CacheMode cacheMode) {
this.cacheMode = cacheMode;
}

View File

@ -10,25 +10,30 @@ import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import org.hibernate.query.NativeQuery;
import jakarta.persistence.CacheRetrieveMode;
import jakarta.persistence.CacheStoreMode;
import org.hibernate.CacheMode;
import org.hibernate.Remove;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Extends {@link jakarta.persistence.NamedNativeQuery} with Hibernate features.
* Declares a named query written in native SQL.
* <p>
* Extends {@link jakarta.persistence.NamedNativeQuery} with additional settings.
*
* @author Emmanuel Bernard
*
* @see NativeQuery
* @see org.hibernate.query.NativeQuery
*/
@Target({TYPE, PACKAGE})
@Retention(RUNTIME)
@Repeatable(NamedNativeQueries.class)
public @interface NamedNativeQuery {
/**
* The registration name.
* The name of this query.
*
* @see org.hibernate.SessionFactory#addNamedQuery
* @see org.hibernate.Session#createNamedQuery
@ -36,72 +41,115 @@ public @interface NamedNativeQuery {
String name();
/**
* The SQL query string.
* The text of the SQL query.
*/
String query();
/**
* The result Class. Should not be used in conjunction with {@link #resultSetMapping()}
* The resulting {@code Class}.
* Should not be used in conjunction with {@link #resultSetMapping()}
*/
Class<?> resultClass() default void.class;
/**
* The name of a SQLResultSetMapping to use. Should not be used in conjunction with {@link #resultClass()}.
* The name of a {@link jakarta.persistence.SqlResultSetMapping}.
* Should not be used in conjunction with {@link #resultClass()}.
*/
String resultSetMapping() default "";
/**
* The flush mode for the query.
*
* @see org.hibernate.query.CommonQueryContract#setFlushMode(jakarta.persistence.FlushModeType)
*/
FlushModeType flushMode() default FlushModeType.PERSISTENCE_CONTEXT;
/**
* Whether the query (results) is cacheable or not. Default is {@code false}, that is not cacheable.
* Whether the query results are cacheable.
* Default is {@code false}, that is, not cacheable.
*
* @see org.hibernate.query.SelectionQuery#setCacheable(boolean)
*/
boolean cacheable() default false;
/**
* If the query results are cacheable, name the query cache region to use.
* If the query results are cacheable, the name of the query cache region.
*
* @see org.hibernate.query.SelectionQuery#setCacheRegion(String)
*/
String cacheRegion() default "";
/**
* The number of rows fetched by the JDBC Driver per trip.
* The number of rows fetched by the JDBC driver per trip.
*
* @see org.hibernate.query.SelectionQuery#setFetchSize(int)
*/
int fetchSize() default -1;
/**
* The query timeout (in seconds). Default is no timeout.
* The query timeout in seconds.
* Default is no timeout.
*
* @see org.hibernate.query.CommonQueryContract#setTimeout(int)
*/
int timeout() default -1;
/**
* A comment added to the SQL query. Useful when engaging with DBA.
* A comment added to the SQL query.
* Useful when engaging with DBA.
*
* @see org.hibernate.query.CommonQueryContract#setComment(String)
*/
String comment() default "";
/**
* The cache mode used for this query. This refers to entities/collections returned from the query.
* The cache storage mode for objects returned by this query.
*
* @see org.hibernate.query.Query#setCacheMode(CacheMode)
*/
CacheStoreMode cacheStoreMode() default CacheStoreMode.USE;
/**
* The cache retrieval mode for objects returned by this query.
*
* @see org.hibernate.query.Query#setCacheMode(CacheMode)
*/
CacheRetrieveMode cacheRetrieveMode() default CacheRetrieveMode.USE;
/**
* The cache interaction mode for this query.
*
* @deprecated use {@link #cacheStoreMode()} and
* {@link #cacheRetrieveMode()} since
* {@link CacheModeType} is deprecated
*/
@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 read-only. Default is {@code false}.
* Whether the query results should be marked read-only.
* Default is {@code false}.
*
* @see org.hibernate.query.SelectionQuery#setReadOnly(boolean)
*/
boolean readOnly() default false;
/**
* The query spaces to apply for the query.
* The query spaces involved in this query.
*
* @see org.hibernate.query.SynchronizeableQuery
*/
String[] querySpaces() default {};
/**
* Does the SQL ({@link #query()}) represent a call to a procedure/function?
* Is the {@linkplain #query() SQL query} a call to a stored procedure
* or function?
*
* @deprecated Calling database procedures and functions through {@link NativeQuery} is
* no longer supported; use {@link jakarta.persistence.NamedStoredProcedureQuery} instead
* @deprecated Calling database procedures and functions through
* {@link org.hibernate.query.NativeQuery} is no longer supported;
* use {@link jakarta.persistence.NamedStoredProcedureQuery} instead.
*/
@Deprecated( since = "6.0" )
boolean callable() default false;

View File

@ -10,18 +10,23 @@ import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import org.hibernate.query.Query;
import jakarta.persistence.CacheRetrieveMode;
import jakarta.persistence.CacheStoreMode;
import org.hibernate.CacheMode;
import org.hibernate.Remove;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Extends {@link jakarta.persistence.NamedQuery} with Hibernate features.
* Declares a named query written in HQL or JPQL.
* <p>
* Extends {@link jakarta.persistence.NamedQuery} with additional settings.
*
* @author Carlos Gonzalez-Cadenas
*
* @see Query
* @see org.hibernate.query.Query
*/
@Target({TYPE, PACKAGE})
@Retention(RUNTIME)
@ -29,52 +34,91 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
public @interface NamedQuery {
/**
* The name of this {@code NamedQuery}.
* The name of this query.
*/
String name();
/**
* The query string for this {@code NamedQuery}.
* The text of the HQL query.
*/
String query();
/**
* The flush mode for this query.
*
* @see org.hibernate.query.CommonQueryContract#setFlushMode(jakarta.persistence.FlushModeType)
*/
FlushModeType flushMode() default FlushModeType.PERSISTENCE_CONTEXT;
/**
* Whether the query (results) is cacheable or not. Default is {@code false}, that is not cacheable.
* Whether the query results are cacheable.
* Default is {@code false}, that is, not cacheable.
*
* @see org.hibernate.query.SelectionQuery#setCacheable(boolean)
*/
boolean cacheable() default false;
/**
* If the query results are cacheable, name the query cache region to use.
* If the query results are cacheable, the name of the query cache region.
*
* @see org.hibernate.query.SelectionQuery#setCacheRegion(String)
*/
String cacheRegion() default "";
/**
* The number of rows fetched by the JDBC Driver per trip.
* The number of rows fetched by the JDBC driver per trip.
*
* @see org.hibernate.query.SelectionQuery#setFetchSize(int)
*/
int fetchSize() default -1;
/**
* The query timeout (in seconds). Default is no timeout.
* The query timeout in seconds.
* Default is no timeout.
*
* @see org.hibernate.query.CommonQueryContract#setTimeout(int)
*/
int timeout() default -1;
/**
* A comment added to the generated SQL query. Useful when engaging with DBA.
* A comment added to the generated SQL query.
* Useful when engaging with DBA.
*
* @see org.hibernate.query.CommonQueryContract#setComment(String)
*/
String comment() default "";
/**
* The cache mode used for this query. This refers to entities/collections returned from the query.
* The cache storage mode for objects returned by this query.
*
* @see org.hibernate.query.Query#setCacheMode(CacheMode)
*/
CacheStoreMode cacheStoreMode() default CacheStoreMode.USE;
/**
* The cache retrieval mode for objects returned by this query.
*
* @see org.hibernate.query.Query#setCacheMode(CacheMode)
*/
CacheRetrieveMode cacheRetrieveMode() default CacheRetrieveMode.USE;
/**
* The cache interaction mode for this query.
*
* @deprecated use {@link #cacheStoreMode()} and
* {@link #cacheRetrieveMode()} since
* {@link CacheModeType} is deprecated
*/
@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 read-only. Default is {@code false}.
* Whether the results should be read-only.
* Default is {@code false}.
*
* @see org.hibernate.query.SelectionQuery#setReadOnly(boolean)
*/
boolean readOnly() default false;
}

View File

@ -25,13 +25,15 @@ public enum OptimisticLockType {
*/
VERSION,
/**
* Perform optimistic locking based on *dirty* fields as part of an expanded WHERE clause restriction for the
* UPDATE/DELETE SQL statement.
* Perform optimistic locking based on <em>dirty</em> fields as
* part of an expanded {@code WHERE} clause restriction for the
* SQL {@code UPDATE} or {@code DELETE} statement.
*/
DIRTY,
/**
* Perform optimistic locking based on *all* fields as part of an expanded WHERE clause restriction for the
* UPDATE/DELETE SQL statement.
* Perform optimistic locking based on <em>all</em> fields as
* part of an expanded {@code WHERE} clause restriction for the
* SQL {@code UPDATE} or {@code DELETE} statement.
*/
ALL
}

View File

@ -14,7 +14,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Used to define the style of optimistic locking to be applied to an entity.
* In an inheritance hierarchy, this annotation may only be applies to the
* In an inheritance hierarchy, this annotation may only be applied to the
* root entity.
*
* @author Steve Ebersole

View File

@ -58,25 +58,25 @@ public abstract class QueryBinder {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, QueryBinder.class.getName());
public static void bindQuery(
NamedQuery queryAnn,
NamedQuery namedQuery,
MetadataBuildingContext context,
boolean isDefault) {
if ( queryAnn == null ) {
if ( namedQuery == null ) {
return;
}
if ( isEmptyAnnotationValue( queryAnn.name() ) ) {
if ( isEmptyAnnotationValue( namedQuery.name() ) ) {
throw new AnnotationException( "Class or package level '@NamedQuery' annotation must specify a 'name'" );
}
final String queryName = queryAnn.name();
final String queryString = queryAnn.query();
final String queryName = namedQuery.name();
final String queryString = namedQuery.query();
if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Binding named query: %s => %s", queryName, queryString );
}
final QueryHintDefinition hints = new QueryHintDefinition( queryName, queryAnn.hints() );
final QueryHintDefinition hints = new QueryHintDefinition( queryName, namedQuery.hints() );
final NamedHqlQueryDefinition queryMapping = new NamedHqlQueryDefinitionImpl.Builder( queryName )
.setHqlString( queryString )
@ -87,7 +87,7 @@ public abstract class QueryBinder {
.setFetchSize( hints.getInteger( HibernateHints.HINT_FETCH_SIZE ) )
.setFlushMode( hints.getFlushMode() )
.setReadOnly( hints.getBoolean( HibernateHints.HINT_READ_ONLY ) )
.setLockOptions( hints.determineLockOptions( queryAnn ) )
.setLockOptions( hints.determineLockOptions( namedQuery ) )
.setComment( hints.getString( HibernateHints.HINT_COMMENT ) )
.build();
@ -101,26 +101,26 @@ public abstract class QueryBinder {
public static void bindNativeQuery(
NamedNativeQuery queryAnn,
NamedNativeQuery namedNativeQuery,
MetadataBuildingContext context,
boolean isDefault) {
if ( queryAnn == null ) {
if ( namedNativeQuery == null ) {
return;
}
if ( isEmptyAnnotationValue( queryAnn.name() ) ) {
if ( isEmptyAnnotationValue( namedNativeQuery.name() ) ) {
throw new AnnotationException( "Class or package level '@NamedNativeQuery' annotation must specify a 'name'" );
}
final String registrationName = queryAnn.name();
final String queryString = queryAnn.query();
final String registrationName = namedNativeQuery.name();
final String queryString = namedNativeQuery.query();
final QueryHintDefinition hints = new QueryHintDefinition( registrationName, queryAnn.hints() );
final QueryHintDefinition hints = new QueryHintDefinition( registrationName, namedNativeQuery.hints() );
final String resultSetMappingName = queryAnn.resultSetMapping();
final String resultSetMappingClassName = void.class.equals( queryAnn.resultClass() )
final String resultSetMappingName = namedNativeQuery.resultSetMapping();
final String resultSetMappingClassName = void.class.equals( namedNativeQuery.resultClass() )
? null
: queryAnn.resultClass().getName();
: namedNativeQuery.resultClass().getName();
final NamedNativeQueryDefinitionBuilder builder = new NamedNativeQueryDefinitionBuilder( registrationName )
.setSqlString( queryString )
@ -153,42 +153,42 @@ public abstract class QueryBinder {
}
public static void bindNativeQuery(
org.hibernate.annotations.NamedNativeQuery queryAnn,
org.hibernate.annotations.NamedNativeQuery namedNativeQuery,
MetadataBuildingContext context) {
if ( queryAnn == null ) {
if ( namedNativeQuery == null ) {
return;
}
final String registrationName = queryAnn.name();
final String registrationName = namedNativeQuery.name();
//ResultSetMappingDefinition mappingDefinition = mappings.getJdbcValuesMappingProducer( queryAnn.resultSetMapping() );
if ( isEmptyAnnotationValue( registrationName ) ) {
throw new AnnotationException( "Class or package level '@NamedNativeQuery' annotation must specify a 'name'" );
}
final String resultSetMappingName = queryAnn.resultSetMapping();
final String resultSetMappingClassName = void.class.equals( queryAnn.resultClass() )
final String resultSetMappingName = namedNativeQuery.resultSetMapping();
final String resultSetMappingClassName = void.class.equals( namedNativeQuery.resultClass() )
? null
: queryAnn.resultClass().getName();
: namedNativeQuery.resultClass().getName();
final NamedNativeQueryDefinitionBuilder builder = new NamedNativeQueryDefinitionBuilder( registrationName )
.setSqlString( queryAnn.query() )
.setSqlString( namedNativeQuery.query() )
.setResultSetMappingName( resultSetMappingName )
.setResultSetMappingClassName( resultSetMappingClassName )
.setQuerySpaces( null )
.setCacheable( queryAnn.cacheable() )
.setCacheRegion( getAnnotationValueStringOrNull( queryAnn.cacheRegion() ) )
.setCacheMode( getCacheMode( queryAnn.cacheMode() ) )
.setTimeout( queryAnn.timeout() < 0 ? null : queryAnn.timeout() )
.setFetchSize( queryAnn.fetchSize() < 0 ? null : queryAnn.fetchSize() )
.setFlushMode( getFlushMode( queryAnn.flushMode() ) )
.setReadOnly( queryAnn.readOnly() )
.setQuerySpaces( setOf( queryAnn.querySpaces() ) )
.setComment( getAnnotationValueStringOrNull( queryAnn.comment() ) );
.setCacheable( namedNativeQuery.cacheable() )
.setCacheRegion( getAnnotationValueStringOrNull( namedNativeQuery.cacheRegion() ) )
.setCacheMode( getCacheMode( namedNativeQuery ) )
.setTimeout( namedNativeQuery.timeout() < 0 ? null : namedNativeQuery.timeout() )
.setFetchSize( namedNativeQuery.fetchSize() < 0 ? null : namedNativeQuery.fetchSize() )
.setFlushMode( getFlushMode( namedNativeQuery.flushMode() ) )
.setReadOnly( namedNativeQuery.readOnly() )
.setQuerySpaces( setOf( namedNativeQuery.querySpaces() ) )
.setComment( getAnnotationValueStringOrNull( namedNativeQuery.comment() ) );
if ( queryAnn.callable() ) {
if ( namedNativeQuery.callable() ) {
final NamedProcedureCallDefinition definition =
createStoredProcedure( builder, context, () -> illegalCallSyntax( queryAnn ) );
createStoredProcedure( builder, context, () -> illegalCallSyntax( namedNativeQuery ) );
context.getMetadataCollector().addNamedProcedureCallDefinition( definition );
DeprecationLogger.DEPRECATION_LOGGER.warn(
"Marking named native queries as callable is no longer supported; use '@jakarta.persistence.NamedStoredProcedureQuery' instead. Ignoring."
@ -290,66 +290,60 @@ public abstract class QueryBinder {
return new NamedProcedureCallDefinitionImpl( AnnotationFactory.create( ann ) );
}
public static void bindQueries(NamedQueries queriesAnn, MetadataBuildingContext context, boolean isDefault) {
if ( queriesAnn == null ) {
return;
}
for (NamedQuery q : queriesAnn.value()) {
bindQuery( q, context, isDefault );
public static void bindQueries(NamedQueries namedQueries, MetadataBuildingContext context, boolean isDefault) {
if ( namedQueries != null ) {
for ( NamedQuery namedQuery : namedQueries.value() ) {
bindQuery( namedQuery, context, isDefault );
}
}
}
public static void bindNativeQueries(
NamedNativeQueries queriesAnn,
NamedNativeQueries namedNativeQueries,
MetadataBuildingContext context,
boolean isDefault) {
if ( queriesAnn == null ) {
return;
}
for (NamedNativeQuery q : queriesAnn.value()) {
bindNativeQuery( q, context, isDefault );
if ( namedNativeQueries != null ) {
for ( NamedNativeQuery namedNativeQuery : namedNativeQueries.value() ) {
bindNativeQuery( namedNativeQuery, context, isDefault );
}
}
}
public static void bindNativeQueries(
org.hibernate.annotations.NamedNativeQueries queriesAnn,
org.hibernate.annotations.NamedNativeQueries namedNativeQueries,
MetadataBuildingContext context) {
if ( queriesAnn == null ) {
return;
}
for (org.hibernate.annotations.NamedNativeQuery q : queriesAnn.value()) {
bindNativeQuery( q, context );
if ( namedNativeQueries != null ) {
for ( org.hibernate.annotations.NamedNativeQuery namedNativeQuery : namedNativeQueries.value() ) {
bindNativeQuery( namedNativeQuery, context );
}
}
}
public static void bindQuery(
org.hibernate.annotations.NamedQuery queryAnn,
org.hibernate.annotations.NamedQuery namedQuery,
MetadataBuildingContext context) {
if ( queryAnn == null ) {
if ( namedQuery == null ) {
return;
}
final String registrationName = queryAnn.name();
final String registrationName = namedQuery.name();
//ResultSetMappingDefinition mappingDefinition = mappings.getJdbcValuesMappingProducer( queryAnn.resultSetMapping() );
//ResultSetMappingDefinition mappingDefinition = mappings.getJdbcValuesMappingProducer( namedQuery.resultSetMapping() );
if ( isEmptyAnnotationValue( registrationName ) ) {
throw new AnnotationException( "Class or package level '@NamedQuery' annotation must specify a 'name'" );
}
final NamedHqlQueryDefinition.Builder builder = new NamedHqlQueryDefinition.Builder( registrationName )
.setHqlString( queryAnn.query() )
.setCacheable( queryAnn.cacheable() )
.setCacheRegion( getAnnotationValueStringOrNull( queryAnn.cacheRegion() ) )
.setCacheMode( getCacheMode( queryAnn.cacheMode() ) )
.setTimeout( queryAnn.timeout() < 0 ? null : queryAnn.timeout() )
.setFetchSize( queryAnn.fetchSize() < 0 ? null : queryAnn.fetchSize() )
.setFlushMode( getFlushMode( queryAnn.flushMode() ) )
.setReadOnly( queryAnn.readOnly() )
.setComment( isEmptyAnnotationValue( queryAnn.comment() ) ? null : queryAnn.comment() );
.setHqlString( namedQuery.query() )
.setCacheable( namedQuery.cacheable() )
.setCacheRegion( getAnnotationValueStringOrNull( namedQuery.cacheRegion() ) )
.setCacheMode( getCacheMode( namedQuery ) )
.setTimeout( namedQuery.timeout() < 0 ? null : namedQuery.timeout() )
.setFetchSize( namedQuery.fetchSize() < 0 ? null : namedQuery.fetchSize() )
.setFlushMode( getFlushMode( namedQuery.flushMode() ) )
.setReadOnly( namedQuery.readOnly() )
.setComment( isEmptyAnnotationValue( namedQuery.comment() ) ? null : namedQuery.comment() );
final NamedHqlQueryDefinitionImpl hqlQueryDefinition = builder.build();
@ -360,6 +354,16 @@ public abstract class QueryBinder {
context.getMetadataCollector().addNamedQuery( hqlQueryDefinition );
}
private static CacheMode getCacheMode(org.hibernate.annotations.NamedQuery namedQuery) {
CacheMode cacheMode = CacheMode.fromJpaModes( namedQuery.cacheRetrieveMode(), namedQuery.cacheStoreMode() );
return cacheMode == null || cacheMode == CacheMode.NORMAL ? getCacheMode( namedQuery.cacheMode() ) : cacheMode;
}
private static CacheMode getCacheMode(org.hibernate.annotations.NamedNativeQuery namedNativeQuery) {
CacheMode cacheMode = CacheMode.fromJpaModes( namedNativeQuery.cacheRetrieveMode(), namedNativeQuery.cacheStoreMode() );
return cacheMode == null || cacheMode == CacheMode.NORMAL ? getCacheMode( namedNativeQuery.cacheMode() ) : cacheMode;
}
private static FlushMode getFlushMode(FlushModeType flushModeType) {
FlushMode flushMode;
switch ( flushModeType ) {

View File

@ -193,32 +193,34 @@ public interface SelectionQuery<R> extends CommonQueryContract {
SelectionQuery<R> setFetchSize(int fetchSize);
/**
* Should entities and proxies loaded by this Query be put in read-only mode? If the
* read-only/modifiable setting was not initialized, then the default
* read-only/modifiable setting for the persistence context is returned instead.
* Should entities and proxies loaded by this Query be put in read-only
* mode? If the read-only/modifiable setting was not initialized, then
* the default read-only/modifiable setting for the persistence context i
* s returned instead.
*
* @see #setReadOnly(boolean)
* @see org.hibernate.engine.spi.PersistenceContext#isDefaultReadOnly()
*
* The read-only/modifiable setting has no impact on entities/proxies returned by the
* query that existed in the session beforeQuery the query was executed.
* The read-only/modifiable setting has no impact on entities/proxies
* returned by the query that existed in the session beforeQuery the
* query was executed.
*
* @return {@code true} if the entities and proxies loaded by the query will be put
* in read-only mode; {@code false} otherwise (they will be modifiable)
* @return {@code true} if the entities and proxies loaded by the query
* will be put in read-only mode; {@code false} otherwise
* (they will be modifiable)
*/
boolean isReadOnly();
/**
* Set the read-only/modifiable mode for entities and proxies
* loaded by this Query. This setting overrides the default setting
* for the persistence context.
* @see org.hibernate.engine.spi.PersistenceContext#isDefaultReadOnly()
*
* To set the default read-only/modifiable setting used for
* entities and proxies that are loaded into the session:
* @see org.hibernate.engine.spi.PersistenceContext#setDefaultReadOnly(boolean)
* @see Session#setDefaultReadOnly(boolean)
*
* Set the read-only/modifiable mode for entities and proxies loaded
* by this {@code Query}. This setting overrides the default setting
* for the persistence context,
* {@link org.hibernate.Session#isDefaultReadOnly()}.
* <p>
* To set the default read-only/modifiable setting used for entities
* and proxies that are loaded into the session, use
* {@link Session#setDefaultReadOnly(boolean)}.
* <p>
* Read-only entities are not dirty-checked and snapshots of persistent
* state are not maintained. Read-only entities can be modified, but
* changes are not persisted.
@ -228,13 +230,15 @@ public interface SelectionQuery<R> extends CommonQueryContract {
* proxy has, regardless of the session's current setting.
* <p>
* The read-only/modifiable setting has no impact on entities/proxies
* returned by the query that existed in the session beforeQuery the query was executed.
* returned by the query that existed in the session beforeQuery the
* query was executed.
*
* @return {@code this}, for method chaining
*
* @param readOnly {@code true} indicates that entities and proxies loaded by the query
* are to be put in read-only mode; {@code false} indicates that entities and proxies
* loaded by the query will be put in modifiable mode
* @param readOnly {@code true} indicates that entities and proxies
* loaded by the query are to be put in read-only mode;
* {@code false} indicates that entities and proxies
* loaded by the query will be put in modifiable mode
*/
SelectionQuery<R> setReadOnly(boolean readOnly);
@ -244,28 +248,29 @@ public interface SelectionQuery<R> extends CommonQueryContract {
int getMaxResults();
/**
* Set the max number of rows requested for the query results. Applied
* Set the max number of rows requested for the query results. Applied
* to the SQL query
*/
SelectionQuery<R> setMaxResults(int maxResult);
/**
* The first row position to return from the query results. Applied
* The first row position to return from the query results. Applied
* to the SQL query
*/
int getFirstResult();
/**
* Set the first row position to return from the query results. Applied
* Set the first row position to return from the query results. Applied
* to the SQL query
*/
SelectionQuery<R> setFirstResult(int startPosition);
/**
* Obtain the CacheMode in effect for this query. By default, the query
* inherits the CacheMode of the Session from which is originates.
* Obtain the {@link CacheMode} in effect for this query. By default,
* the query inherits the {@link CacheMode} of the session from which
* it originates.
* <p/>
* NOTE: The CacheMode here describes reading-from/writing-to the
* NOTE: The {@link CacheMode} here describes reading-from/writing-to the
* entity/collection caches as we process query results. For caching of
* the actual query results, see {@link #isCacheable()} and
* {@link #getCacheRegion()}
@ -279,26 +284,27 @@ public interface SelectionQuery<R> extends CommonQueryContract {
CacheMode getCacheMode();
/**
* Set the current CacheMode in effect for this query.
* Set the current {@link CacheMode} in effect for this query.
*
* @implNote Setting to {@code null} ultimately indicates to use the CacheMode of the Session
* @implNote Setting it to {@code null} ultimately indicates to use the
* {@code CacheMode} of the session.
*
* @see #getCacheMode()
* @see Session#setCacheMode
* @see Session#setCacheMode(CacheMode)
*/
SelectionQuery<R> setCacheMode(CacheMode cacheMode);
/**
* Should the results of the query be stored in the second level cache?
* <p/>
* This is different than second level caching of any returned entities and collections, which
* is controlled by {@link #getCacheMode()}.
* This is different to second level caching of any returned entities and
* collections, which is controlled by {@link #getCacheMode()}.
* <p/>
* NOTE: the query being "eligible" for caching does not necessarily mean its results will be cached. Second level
* query caching still has to be enabled on the {@link SessionFactory} for this to happen. Usually that is
* controlled by the {@code hibernate.cache.use_query_cache} configuration setting.
*
* @see org.hibernate.cfg.AvailableSettings#USE_QUERY_CACHE
* NOTE: the query being "eligible" for caching does not necessarily mean
* its results will be cached. Second-level query caching still has to be
* enabled on the {@link SessionFactory} for this to happen. Usually that
* is controlled by the configuration setting
* {@value org.hibernate.cfg.AvailableSettings#USE_QUERY_CACHE}.
*/
boolean isCacheable();
@ -310,15 +316,17 @@ public interface SelectionQuery<R> extends CommonQueryContract {
SelectionQuery<R> setCacheable(boolean cacheable);
/**
* Obtain the name of the second level query cache region in which query results will be stored (if they are
* cached, see the discussion on {@link #isCacheable()} for more information). {@code null} indicates that the
* default region should be used.
* Obtain the name of the second level query cache region in which query
* results will be stored (if they are cached, see the discussion on
* {@link #isCacheable()} for more information). {@code null} indicates
* that the default region should be used.
*/
String getCacheRegion();
/**
* Set the name of the cache region where query results should be cached
* (assuming {@link #isCacheable}). {@code null} indicates to use the default region.
* (assuming {@link #isCacheable}). {@code null} indicates to use the
* default region.
*
* @see #getCacheRegion()
*/