|
9 | 9 | import java.util.concurrent.TimeUnit; |
10 | 10 |
|
11 | 11 | import org.hibernate.CacheMode; |
| 12 | +import org.hibernate.SharedSessionContract; |
12 | 13 | import org.hibernate.cache.spi.QueryKey; |
13 | 14 | import org.hibernate.cache.spi.QueryResultsCache; |
14 | 15 | import org.hibernate.engine.spi.PersistenceContext; |
15 | 16 | import org.hibernate.engine.spi.SessionFactoryImplementor; |
16 | 17 | import org.hibernate.engine.spi.SharedSessionContractImplementor; |
17 | 18 | import org.hibernate.internal.util.collections.ArrayHelper; |
18 | 19 | import org.hibernate.query.TupleTransformer; |
| 20 | +import org.hibernate.query.spi.QueryOptions; |
19 | 21 | import org.hibernate.sql.exec.SqlExecLogger; |
20 | 22 | import org.hibernate.sql.exec.spi.ExecutionContext; |
21 | 23 | import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect; |
|
45 | 47 | import org.hibernate.type.descriptor.java.JavaType; |
46 | 48 | import org.hibernate.type.spi.TypeConfiguration; |
47 | 49 |
|
| 50 | +import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues; |
| 51 | + |
48 | 52 | /** |
49 | 53 | * Standard JdbcSelectExecutor implementation used by Hibernate, |
50 | 54 | * through {@link JdbcSelectExecutorStandardImpl#INSTANCE} |
@@ -258,18 +262,17 @@ private JdbcValues resolveJdbcValuesSource( |
258 | 262 | final SessionFactoryImplementor factory = session.getFactory(); |
259 | 263 | final boolean queryCacheEnabled = factory.getSessionFactoryOptions().isQueryCacheEnabled(); |
260 | 264 |
|
261 | | - final List<?> cachedResults; |
262 | | - final CacheMode cacheMode = JdbcExecHelper.resolveCacheMode( executionContext ); |
263 | | - |
| 265 | + final CacheMode cacheMode = resolveCacheMode( executionContext ); |
264 | 266 | final JdbcValuesMappingProducer mappingProducer = jdbcSelect.getJdbcValuesMappingProducer(); |
265 | 267 | final boolean cacheable = queryCacheEnabled && canBeCached |
266 | 268 | && executionContext.getQueryOptions().isResultCachingEnabled() == Boolean.TRUE; |
267 | | - final QueryKey queryResultsCacheKey; |
268 | 269 |
|
| 270 | + final QueryKey queryResultsCacheKey; |
| 271 | + final List<?> cachedResults; |
269 | 272 | if ( cacheable && cacheMode.isGetEnabled() ) { |
270 | 273 | SqlExecLogger.SQL_EXEC_LOGGER.debugf( "Reading Query result cache data per CacheMode#isGetEnabled [%s]", cacheMode.name() ); |
271 | 274 | final Set<String> querySpaces = jdbcSelect.getAffectedTableNames(); |
272 | | - if ( querySpaces == null || querySpaces.size() == 0 ) { |
| 275 | + if ( querySpaces == null || querySpaces.isEmpty() ) { |
273 | 276 | SqlExecLogger.SQL_EXEC_LOGGER.tracef( "Unexpected querySpaces is empty" ); |
274 | 277 | } |
275 | 278 | else { |
@@ -368,6 +371,16 @@ private JdbcValues resolveJdbcValuesSource( |
368 | 371 | } |
369 | 372 | } |
370 | 373 |
|
| 374 | + private static CacheMode resolveCacheMode(ExecutionContext executionContext) { |
| 375 | + final QueryOptions queryOptions = executionContext.getQueryOptions(); |
| 376 | + final SharedSessionContract session = executionContext.getSession(); |
| 377 | + return coalesceSuppliedValues( |
| 378 | + () -> queryOptions == null ? null : queryOptions.getCacheMode(), |
| 379 | + session::getCacheMode, |
| 380 | + () -> CacheMode.NORMAL |
| 381 | + ); |
| 382 | + } |
| 383 | + |
371 | 384 | static class CapturingJdbcValuesMetadata implements JdbcValuesMetadata { |
372 | 385 | private final ResultSetAccess resultSetAccess; |
373 | 386 | private String[] columnNames; |
|
0 commit comments