Search in sources :

Example 1 with QueryHint

use of javax.persistence.QueryHint in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method buildQueryHints.

private static void buildQueryHints(List<Element> elements, AnnotationDescriptor ann) {
    List<QueryHint> queryHints = new ArrayList<QueryHint>(elements.size());
    for (Element hint : elements) {
        AnnotationDescriptor hintDescriptor = new AnnotationDescriptor(QueryHint.class);
        String value = hint.attributeValue("name");
        if (value == null) {
            throw new AnnotationException("<hint> without name. " + SCHEMA_VALIDATION);
        }
        hintDescriptor.setValue("name", value);
        value = hint.attributeValue("value");
        if (value == null) {
            throw new AnnotationException("<hint> without value. " + SCHEMA_VALIDATION);
        }
        hintDescriptor.setValue("value", value);
        queryHints.add((QueryHint) AnnotationFactory.create(hintDescriptor));
    }
    ann.setValue("hints", queryHints.toArray(new QueryHint[queryHints.size()]));
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) QueryHint(javax.persistence.QueryHint) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) AnnotationException(org.hibernate.AnnotationException)

Example 2 with QueryHint

use of javax.persistence.QueryHint in project deltaspike by apache.

the class CdiQueryInvocationContext method applyRestrictions.

public Query applyRestrictions(Query query) {
    Parameters params = getParams();
    Method method = getMethod();
    if (params.hasSizeRestriction()) {
        query.setMaxResults(params.getSizeRestriciton());
    }
    if (params.hasFirstResult()) {
        query.setFirstResult(params.getFirstResult());
    }
    if (hasLockMode(method)) {
        query.setLockMode(extractLockMode(method));
    }
    if (hasQueryHints(method)) {
        QueryHint[] hints = extractQueryHints(method);
        for (QueryHint hint : hints) {
            query.setHint(hint.name(), hint.value());
        }
    }
    applyEntityGraph(query, method);
    query = applyJpaQueryPostProcessors(query);
    return query;
}
Also used : Parameters(org.apache.deltaspike.data.impl.param.Parameters) QueryHint(javax.persistence.QueryHint) Method(java.lang.reflect.Method)

Aggregations

QueryHint (javax.persistence.QueryHint)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Parameters (org.apache.deltaspike.data.impl.param.Parameters)1 Element (org.dom4j.Element)1 AnnotationException (org.hibernate.AnnotationException)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1