Search in sources :

Example 1 with CacheRetrieveMode

use of jakarta.persistence.CacheRetrieveMode in project hibernate-orm by hibernate.

the class JdbcSelectExecutorStandardImpl method getScrollContext.

/*
		When `Query#scroll()` is call the query is not executed immediately, a new ExecutionContext with the values of the `persistenceContext.isDefaultReadOnly()` and of the `queryOptions.isReadOnly()`
		set at the moment of the Query#scroll() call is created in order to use it when the query will be executed.
	 */
private ExecutionContext getScrollContext(ExecutionContext context, PersistenceContext persistenceContext) {
    final QueryOptions queryOptions = context.getQueryOptions();
    final Boolean readOnly;
    if (queryOptions.isReadOnly() == null) {
        readOnly = persistenceContext.isDefaultReadOnly();
    } else {
        readOnly = queryOptions.isReadOnly();
    }
    final Integer timeout = queryOptions.getTimeout();
    final FlushMode flushMode = queryOptions.getFlushMode();
    final AppliedGraph appliedGraph = queryOptions.getAppliedGraph();
    final TupleTransformer<?> tupleTransformer = queryOptions.getTupleTransformer();
    final ResultListTransformer<?> resultListTransformer = queryOptions.getResultListTransformer();
    final Boolean resultCachingEnabled = queryOptions.isResultCachingEnabled();
    final CacheRetrieveMode cacheRetrieveMode = queryOptions.getCacheRetrieveMode();
    final CacheStoreMode cacheStoreMode = queryOptions.getCacheStoreMode();
    final String resultCacheRegionName = queryOptions.getResultCacheRegionName();
    final LockOptions lockOptions = queryOptions.getLockOptions();
    final String comment = queryOptions.getComment();
    final List<String> databaseHints = queryOptions.getDatabaseHints();
    final Integer fetchSize = queryOptions.getFetchSize();
    final Limit limit = queryOptions.getLimit();
    return new ExecutionContext() {

        @Override
        public QueryOptions getQueryOptions() {
            return new QueryOptions() {

                @Override
                public Integer getTimeout() {
                    return timeout;
                }

                @Override
                public FlushMode getFlushMode() {
                    return flushMode;
                }

                @Override
                public Boolean isReadOnly() {
                    return readOnly;
                }

                @Override
                public AppliedGraph getAppliedGraph() {
                    return appliedGraph;
                }

                @Override
                public TupleTransformer<?> getTupleTransformer() {
                    return tupleTransformer;
                }

                @Override
                public ResultListTransformer<?> getResultListTransformer() {
                    return resultListTransformer;
                }

                @Override
                public Boolean isResultCachingEnabled() {
                    return resultCachingEnabled;
                }

                @Override
                public CacheRetrieveMode getCacheRetrieveMode() {
                    return cacheRetrieveMode;
                }

                @Override
                public CacheStoreMode getCacheStoreMode() {
                    return cacheStoreMode;
                }

                @Override
                public String getResultCacheRegionName() {
                    return resultCacheRegionName;
                }

                @Override
                public LockOptions getLockOptions() {
                    return lockOptions;
                }

                @Override
                public String getComment() {
                    return comment;
                }

                @Override
                public List<String> getDatabaseHints() {
                    return databaseHints;
                }

                @Override
                public Integer getFetchSize() {
                    return fetchSize;
                }

                @Override
                public Limit getLimit() {
                    return limit;
                }
            };
        }

        @Override
        public QueryParameterBindings getQueryParameterBindings() {
            return context.getQueryParameterBindings();
        }

        @Override
        public Callback getCallback() {
            return context.getCallback();
        }

        @Override
        public SharedSessionContractImplementor getSession() {
            return context.getSession();
        }
    };
}
Also used : CacheRetrieveMode(jakarta.persistence.CacheRetrieveMode) LockOptions(org.hibernate.LockOptions) CacheStoreMode(jakarta.persistence.CacheStoreMode) QueryOptions(org.hibernate.query.spi.QueryOptions) AppliedGraph(org.hibernate.graph.spi.AppliedGraph) FlushMode(org.hibernate.FlushMode) ExecutionContext(org.hibernate.sql.exec.spi.ExecutionContext) Limit(org.hibernate.query.spi.Limit)

Example 2 with CacheRetrieveMode

use of jakarta.persistence.CacheRetrieveMode in project hibernate-orm by hibernate.

the class SessionImpl method determineAppropriateLocalCacheMode.

protected CacheMode determineAppropriateLocalCacheMode(Map<String, Object> localProperties) {
    CacheRetrieveMode retrieveMode = null;
    CacheStoreMode storeMode = null;
    if (localProperties != null) {
        retrieveMode = determineCacheRetrieveMode(localProperties);
        storeMode = determineCacheStoreMode(localProperties);
    }
    if (retrieveMode == null) {
        // use the EM setting
        retrieveMode = fastSessionServices.getCacheRetrieveMode(this.properties);
    }
    if (storeMode == null) {
        // use the EM setting
        storeMode = fastSessionServices.getCacheStoreMode(this.properties);
    }
    return CacheModeHelper.interpretCacheMode(storeMode, retrieveMode);
}
Also used : CacheRetrieveMode(jakarta.persistence.CacheRetrieveMode) CacheStoreMode(jakarta.persistence.CacheStoreMode)

Example 3 with CacheRetrieveMode

use of jakarta.persistence.CacheRetrieveMode in project hibernate-orm by hibernate.

the class AbstractCommonQueryContract method applySelectionHint.

protected final boolean applySelectionHint(String hintName, Object value) {
    final boolean lockingHintApplied = applyLockingHint(hintName, value);
    if (lockingHintApplied) {
        return true;
    }
    if (HINT_READONLY.equals(hintName)) {
        applyReadOnlyHint(ConfigurationHelper.getBoolean(value));
        return true;
    }
    if (HINT_FETCH_SIZE.equals(hintName)) {
        applyFetchSizeHint(ConfigurationHelper.getInteger(value));
        return true;
    }
    if (HINT_CACHEABLE.equals(hintName)) {
        applyCacheableHint(ConfigurationHelper.getBoolean(value));
        return true;
    }
    if (HINT_CACHE_REGION.equals(hintName)) {
        applyCacheRegionHint((String) value);
        return true;
    }
    if (HINT_CACHE_MODE.equals(hintName)) {
        applyCacheModeHint(ConfigurationHelper.getCacheMode(value));
        return true;
    }
    if (HINT_SPEC_CACHE_RETRIEVE_MODE.equals(hintName)) {
        final CacheRetrieveMode retrieveMode = value != null ? CacheRetrieveMode.valueOf(value.toString()) : null;
        applyJpaCacheRetrieveModeHint(retrieveMode);
        return true;
    }
    if (HINT_SPEC_CACHE_STORE_MODE.equals(hintName)) {
        final CacheStoreMode storeMode = value != null ? CacheStoreMode.valueOf(value.toString()) : null;
        applyJpaCacheStoreModeHint(storeMode);
        return true;
    }
    if (HINT_JAVAEE_CACHE_RETRIEVE_MODE.equals(hintName)) {
        DEPRECATION_LOGGER.deprecatedSetting(HINT_JAVAEE_CACHE_RETRIEVE_MODE, HINT_SPEC_CACHE_RETRIEVE_MODE);
        final CacheRetrieveMode retrieveMode = value != null ? CacheRetrieveMode.valueOf(value.toString()) : null;
        applyJpaCacheRetrieveModeHint(retrieveMode);
        return true;
    }
    if (HINT_JAVAEE_CACHE_STORE_MODE.equals(hintName)) {
        DEPRECATION_LOGGER.deprecatedSetting(HINT_JAVAEE_CACHE_STORE_MODE, HINT_SPEC_CACHE_STORE_MODE);
        final CacheStoreMode storeMode = value != null ? CacheStoreMode.valueOf(value.toString()) : null;
        applyJpaCacheStoreModeHint(storeMode);
        return true;
    }
    if (HINT_SPEC_FETCH_GRAPH.equals(hintName) || HINT_SPEC_LOAD_GRAPH.equals(hintName)) {
        applyEntityGraphHint(hintName, value);
        return true;
    }
    if (HINT_JAVAEE_FETCH_GRAPH.equals(hintName) || HINT_JAVAEE_LOAD_GRAPH.equals(hintName)) {
        if (HINT_JAVAEE_FETCH_GRAPH.equals(hintName)) {
            DEPRECATION_LOGGER.deprecatedSetting(HINT_JAVAEE_FETCH_GRAPH, HINT_SPEC_FETCH_GRAPH);
        } else {
            DEPRECATION_LOGGER.deprecatedSetting(HINT_JAVAEE_LOAD_GRAPH, HINT_SPEC_LOAD_GRAPH);
        }
        applyEntityGraphHint(hintName, value);
        return true;
    }
    return false;
}
Also used : CacheRetrieveMode(jakarta.persistence.CacheRetrieveMode) CacheStoreMode(jakarta.persistence.CacheStoreMode)

Aggregations

CacheRetrieveMode (jakarta.persistence.CacheRetrieveMode)3 CacheStoreMode (jakarta.persistence.CacheStoreMode)3 FlushMode (org.hibernate.FlushMode)1 LockOptions (org.hibernate.LockOptions)1 AppliedGraph (org.hibernate.graph.spi.AppliedGraph)1 Limit (org.hibernate.query.spi.Limit)1 QueryOptions (org.hibernate.query.spi.QueryOptions)1 ExecutionContext (org.hibernate.sql.exec.spi.ExecutionContext)1