Search in sources :

Example 1 with EntityGraphImpl

use of org.hibernate.jpa.graph.internal.EntityGraphImpl in project hibernate-orm by hibernate.

the class MetamodelImpl method applyNamedEntityGraphs.

@SuppressWarnings("unchecked")
private void applyNamedEntityGraphs(java.util.Collection<NamedEntityGraphDefinition> namedEntityGraphs) {
    for (NamedEntityGraphDefinition definition : namedEntityGraphs) {
        log.debugf("Applying named entity graph [name=%s, entity-name=%s, jpa-entity-name=%s", definition.getRegisteredName(), definition.getEntityName(), definition.getJpaEntityName());
        final EntityType entityType = entity(definition.getEntityName());
        if (entityType == null) {
            throw new IllegalArgumentException("Attempted to register named entity graph [" + definition.getRegisteredName() + "] for unknown entity [" + definition.getEntityName() + "]");
        }
        final EntityGraphImpl entityGraph = new EntityGraphImpl(definition.getRegisteredName(), entityType, this.getSessionFactory());
        final NamedEntityGraph namedEntityGraph = definition.getAnnotation();
        if (namedEntityGraph.includeAllAttributes()) {
            for (Object attributeObject : entityType.getAttributes()) {
                entityGraph.addAttributeNodes((Attribute) attributeObject);
            }
        }
        if (namedEntityGraph.attributeNodes() != null) {
            applyNamedAttributeNodes(namedEntityGraph.attributeNodes(), namedEntityGraph, entityGraph);
        }
        entityGraphMap.put(definition.getRegisteredName(), entityGraph);
    }
}
Also used : NamedEntityGraphDefinition(org.hibernate.cfg.annotations.NamedEntityGraphDefinition) EntityType(javax.persistence.metamodel.EntityType) EntityGraphImpl(org.hibernate.jpa.graph.internal.EntityGraphImpl) NamedEntityGraph(javax.persistence.NamedEntityGraph)

Example 2 with EntityGraphImpl

use of org.hibernate.jpa.graph.internal.EntityGraphImpl in project hibernate-orm by hibernate.

the class AbstractProducedQuery method setHint.

@Override
@SuppressWarnings("unchecked")
public QueryImplementor setHint(String hintName, Object value) {
    getProducer().checkOpen(true);
    boolean applied = false;
    try {
        if (HINT_TIMEOUT.equals(hintName)) {
            applied = applyTimeoutHint(ConfigurationHelper.getInteger(value));
        } else if (SPEC_HINT_TIMEOUT.equals(hintName)) {
            // convert milliseconds to seconds
            int timeout = (int) Math.round(ConfigurationHelper.getInteger(value).doubleValue() / 1000.0);
            applied = applyTimeoutHint(timeout);
        } else if (JPA_LOCK_TIMEOUT.equals(hintName)) {
            applied = applyLockTimeoutHint(ConfigurationHelper.getInteger(value));
        } else if (HINT_COMMENT.equals(hintName)) {
            applied = applyCommentHint((String) value);
        } else if (HINT_FETCH_SIZE.equals(hintName)) {
            applied = applyFetchSizeHint(ConfigurationHelper.getInteger(value));
        } else if (HINT_CACHEABLE.equals(hintName)) {
            applied = applyCacheableHint(ConfigurationHelper.getBoolean(value));
        } else if (HINT_CACHE_REGION.equals(hintName)) {
            applied = applyCacheRegionHint((String) value);
        } else if (HINT_READONLY.equals(hintName)) {
            applied = applyReadOnlyHint(ConfigurationHelper.getBoolean(value));
        } else if (HINT_FLUSH_MODE.equals(hintName)) {
            applied = applyFlushModeHint(ConfigurationHelper.getFlushMode(value));
        } else if (HINT_CACHE_MODE.equals(hintName)) {
            applied = applyCacheModeHint(ConfigurationHelper.getCacheMode(value));
        } else if (JPA_SHARED_CACHE_RETRIEVE_MODE.equals(hintName)) {
            final CacheRetrieveMode retrieveMode = value != null ? CacheRetrieveMode.valueOf(value.toString()) : null;
            applied = applyJpaCacheRetrieveMode(retrieveMode);
        } else if (JPA_SHARED_CACHE_STORE_MODE.equals(hintName)) {
            final CacheStoreMode storeMode = value != null ? CacheStoreMode.valueOf(value.toString()) : null;
            applied = applyJpaCacheStoreMode(storeMode);
        } else if (QueryHints.HINT_NATIVE_LOCKMODE.equals(hintName)) {
            applied = applyNativeQueryLockMode(value);
        } else if (hintName.startsWith(ALIAS_SPECIFIC_LOCK_MODE)) {
            if (canApplyAliasSpecificLockModeHints()) {
                // extract the alias
                final String alias = hintName.substring(ALIAS_SPECIFIC_LOCK_MODE.length() + 1);
                // determine the LockMode
                try {
                    final LockMode lockMode = LockModeTypeHelper.interpretLockMode(value);
                    applyAliasSpecificLockModeHint(alias, lockMode);
                } catch (Exception e) {
                    MSG_LOGGER.unableToDetermineLockModeValue(hintName, value);
                    applied = false;
                }
            } else {
                applied = false;
            }
        } else if (HINT_FETCHGRAPH.equals(hintName) || HINT_LOADGRAPH.equals(hintName)) {
            if (value instanceof EntityGraphImpl) {
                applyEntityGraphQueryHint(new EntityGraphQueryHint(hintName, (EntityGraphImpl) value));
            } else {
                MSG_LOGGER.warnf("The %s hint was set, but the value was not an EntityGraph!", hintName);
            }
            applied = true;
        } else if (HINT_FOLLOW_ON_LOCKING.equals(hintName)) {
            applied = applyFollowOnLockingHint(ConfigurationHelper.getBoolean(value));
        } else if (QueryHints.HINT_PASS_DISTINCT_THROUGH.equals(hintName)) {
            applied = applyPassDistinctThrough(ConfigurationHelper.getBoolean(value));
        } else {
            MSG_LOGGER.ignoringUnrecognizedQueryHint(hintName);
        }
    } catch (ClassCastException e) {
        throw new IllegalArgumentException("Value for hint");
    }
    if (!applied) {
        MSG_LOGGER.debugf("Skipping unsupported query hint [%s]", hintName);
    }
    return this;
}
Also used : EntityGraphImpl(org.hibernate.jpa.graph.internal.EntityGraphImpl) CacheRetrieveMode(javax.persistence.CacheRetrieveMode) EntityGraphQueryHint(org.hibernate.engine.query.spi.EntityGraphQueryHint) LockMode(org.hibernate.LockMode) CacheStoreMode(javax.persistence.CacheStoreMode) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(org.hibernate.NonUniqueResultException) TransactionRequiredException(javax.persistence.TransactionRequiredException) HibernateException(org.hibernate.HibernateException) TypeMismatchException(org.hibernate.TypeMismatchException) QueryParameterException(org.hibernate.QueryParameterException) PropertyNotFoundException(org.hibernate.PropertyNotFoundException) QueryExecutionRequestException(org.hibernate.hql.internal.QueryExecutionRequestException)

Aggregations

EntityGraphImpl (org.hibernate.jpa.graph.internal.EntityGraphImpl)2 CacheRetrieveMode (javax.persistence.CacheRetrieveMode)1 CacheStoreMode (javax.persistence.CacheStoreMode)1 NamedEntityGraph (javax.persistence.NamedEntityGraph)1 NoResultException (javax.persistence.NoResultException)1 TransactionRequiredException (javax.persistence.TransactionRequiredException)1 EntityType (javax.persistence.metamodel.EntityType)1 HibernateException (org.hibernate.HibernateException)1 LockMode (org.hibernate.LockMode)1 NonUniqueResultException (org.hibernate.NonUniqueResultException)1 PropertyNotFoundException (org.hibernate.PropertyNotFoundException)1 QueryParameterException (org.hibernate.QueryParameterException)1 TypeMismatchException (org.hibernate.TypeMismatchException)1 NamedEntityGraphDefinition (org.hibernate.cfg.annotations.NamedEntityGraphDefinition)1 EntityGraphQueryHint (org.hibernate.engine.query.spi.EntityGraphQueryHint)1 QueryExecutionRequestException (org.hibernate.hql.internal.QueryExecutionRequestException)1