Search in sources :

Example 1 with AppliedGraph

use of org.hibernate.graph.spi.AppliedGraph in project hibernate-orm by hibernate.

the class AbstractSelectionQuery method collectHints.

protected void collectHints(Map<String, Object> hints) {
    super.collectHints(hints);
    if (isReadOnly()) {
        hints.put(HINT_READONLY, true);
    }
    putIfNotNull(hints, HINT_FETCH_SIZE, getFetchSize());
    if (isCacheable()) {
        hints.put(HINT_CACHEABLE, true);
        putIfNotNull(hints, HINT_CACHE_REGION, getCacheRegion());
        putIfNotNull(hints, HINT_CACHE_MODE, getCacheMode());
        putIfNotNull(hints, JAKARTA_SHARED_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode());
        putIfNotNull(hints, JAKARTA_SHARED_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode());
        // noinspection deprecation
        putIfNotNull(hints, JPA_SHARED_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode());
        // noinspection deprecation
        putIfNotNull(hints, JPA_SHARED_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode());
    }
    final AppliedGraph appliedGraph = getQueryOptions().getAppliedGraph();
    if (appliedGraph != null && appliedGraph.getSemantic() != null) {
        hints.put(appliedGraph.getSemantic().getJakartaHintName(), appliedGraph);
        hints.put(appliedGraph.getSemantic().getJpaHintName(), appliedGraph);
    }
    putIfNotNull(hints, HINT_FOLLOW_ON_LOCKING, getQueryOptions().getLockOptions().getFollowOnLocking());
}
Also used : AppliedGraph(org.hibernate.graph.spi.AppliedGraph)

Example 2 with AppliedGraph

use of org.hibernate.graph.spi.AppliedGraph 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 3 with AppliedGraph

use of org.hibernate.graph.spi.AppliedGraph in project hibernate-orm by hibernate.

the class SqmSelectionQueryImpl method collectHints.

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// hints
protected void collectHints(Map<String, Object> hints) {
    super.collectHints(hints);
    if (isReadOnly()) {
        hints.put(HINT_READ_ONLY, true);
    }
    putIfNotNull(hints, HINT_FETCH_SIZE, getFetchSize());
    if (isCacheable()) {
        hints.put(HINT_CACHEABLE, true);
        putIfNotNull(hints, HINT_CACHE_REGION, getCacheRegion());
        putIfNotNull(hints, HINT_CACHE_MODE, getCacheMode());
        putIfNotNull(hints, HINT_SPEC_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode());
        putIfNotNull(hints, HINT_SPEC_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode());
        putIfNotNull(hints, HINT_JAVAEE_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode());
        putIfNotNull(hints, HINT_JAVAEE_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode());
    }
    final AppliedGraph appliedGraph = getQueryOptions().getAppliedGraph();
    if (appliedGraph != null && appliedGraph.getSemantic() != null) {
        hints.put(appliedGraph.getSemantic().getJakartaHintName(), appliedGraph);
        hints.put(appliedGraph.getSemantic().getJpaHintName(), appliedGraph);
    }
    putIfNotNull(hints, HINT_FOLLOW_ON_LOCKING, getQueryOptions().getLockOptions().getFollowOnLocking());
}
Also used : AppliedGraph(org.hibernate.graph.spi.AppliedGraph)

Example 4 with AppliedGraph

use of org.hibernate.graph.spi.AppliedGraph in project hibernate-orm by hibernate.

the class QuerySqmImpl method collectHints.

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// hints
protected void collectHints(Map<String, Object> hints) {
    super.collectHints(hints);
    if (isReadOnly()) {
        hints.put(HINT_READ_ONLY, true);
    }
    putIfNotNull(hints, HINT_FETCH_SIZE, getFetchSize());
    if (isCacheable()) {
        hints.put(HINT_CACHEABLE, true);
        putIfNotNull(hints, HINT_CACHE_REGION, getCacheRegion());
        putIfNotNull(hints, HINT_CACHE_MODE, getCacheMode());
        putIfNotNull(hints, HINT_SPEC_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode());
        putIfNotNull(hints, HINT_SPEC_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode());
        putIfNotNull(hints, HINT_JAVAEE_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode());
        putIfNotNull(hints, HINT_JAVAEE_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode());
    }
    final AppliedGraph appliedGraph = getQueryOptions().getAppliedGraph();
    if (appliedGraph != null && appliedGraph.getSemantic() != null) {
        hints.put(appliedGraph.getSemantic().getJakartaHintName(), appliedGraph);
        hints.put(appliedGraph.getSemantic().getJpaHintName(), appliedGraph);
    }
    putIfNotNull(hints, HINT_FOLLOW_ON_LOCKING, getQueryOptions().getLockOptions().getFollowOnLocking());
}
Also used : AppliedGraph(org.hibernate.graph.spi.AppliedGraph)

Example 5 with AppliedGraph

use of org.hibernate.graph.spi.AppliedGraph in project hibernate-orm by hibernate.

the class AbstractCommonQueryContract method collectHints.

@SuppressWarnings("deprecation")
protected void collectHints(Map<String, Object> hints) {
    if (getQueryOptions().getTimeout() != null) {
        hints.put(HINT_TIMEOUT, getQueryOptions().getTimeout());
        hints.put(HINT_SPEC_QUERY_TIMEOUT, getQueryOptions().getTimeout() * 1000);
    }
    putIfNotNull(hints, HINT_COMMENT, getComment());
    putIfNotNull(hints, HINT_FLUSH_MODE, getHibernateFlushMode());
    putIfNotNull(hints, HINT_READONLY, getQueryOptions().isReadOnly());
    putIfNotNull(hints, HINT_FETCH_SIZE, getQueryOptions().getFetchSize());
    putIfNotNull(hints, HINT_CACHEABLE, getQueryOptions().isResultCachingEnabled());
    putIfNotNull(hints, HINT_CACHE_REGION, getQueryOptions().getResultCacheRegionName());
    putIfNotNull(hints, HINT_CACHE_MODE, getQueryOptions().getCacheMode());
    putIfNotNull(hints, HINT_SPEC_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode());
    putIfNotNull(hints, HINT_JAVAEE_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode());
    putIfNotNull(hints, HINT_SPEC_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode());
    putIfNotNull(hints, HINT_JAVAEE_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode());
    final AppliedGraph appliedGraph = getQueryOptions().getAppliedGraph();
    if (appliedGraph != null && appliedGraph.getSemantic() != null) {
        hints.put(appliedGraph.getSemantic().getJakartaHintName(), appliedGraph.getGraph());
        hints.put(appliedGraph.getSemantic().getJpaHintName(), appliedGraph.getGraph());
    }
    final LockOptions lockOptions = getQueryOptions().getLockOptions();
    if (!lockOptions.isEmpty()) {
        final LockMode lockMode = lockOptions.getLockMode();
        if (lockMode != null && lockMode != LockMode.NONE) {
            hints.put(HINT_NATIVE_LOCKMODE, lockMode);
        }
        if (lockOptions.hasAliasSpecificLockModes()) {
            for (Map.Entry<String, LockMode> entry : lockOptions.getAliasSpecificLocks()) {
                hints.put(HINT_NATIVE_LOCKMODE + "." + entry.getKey(), entry.getValue());
            }
        }
        if (lockOptions.getFollowOnLocking() == TRUE) {
            hints.put(HINT_FOLLOW_ON_LOCKING, TRUE);
        }
        if (lockOptions.getTimeOut() != WAIT_FOREVER) {
            hints.put(HINT_SPEC_LOCK_TIMEOUT, lockOptions.getTimeOut());
            hints.put(HINT_JAVAEE_LOCK_TIMEOUT, lockOptions.getTimeOut());
        }
    }
}
Also used : LockOptions(org.hibernate.LockOptions) LockMode(org.hibernate.LockMode) AppliedGraph(org.hibernate.graph.spi.AppliedGraph) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

AppliedGraph (org.hibernate.graph.spi.AppliedGraph)5 LockOptions (org.hibernate.LockOptions)2 CacheRetrieveMode (jakarta.persistence.CacheRetrieveMode)1 CacheStoreMode (jakarta.persistence.CacheStoreMode)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FlushMode (org.hibernate.FlushMode)1 LockMode (org.hibernate.LockMode)1 Limit (org.hibernate.query.spi.Limit)1 QueryOptions (org.hibernate.query.spi.QueryOptions)1 ExecutionContext (org.hibernate.sql.exec.spi.ExecutionContext)1