Search in sources :

Example 1 with JPQLSerializer

use of com.querydsl.jpa.JPQLSerializer in project querydsl by querydsl.

the class HibernateDeleteClause method toString.

@Override
public String toString() {
    JPQLSerializer serializer = new JPQLSerializer(templates, null);
    serializer.serializeForDelete(queryMixin.getMetadata());
    return serializer.toString();
}
Also used : JPQLSerializer(com.querydsl.jpa.JPQLSerializer)

Example 2 with JPQLSerializer

use of com.querydsl.jpa.JPQLSerializer in project querydsl by querydsl.

the class HibernateUpdateClause method toString.

@Override
public String toString() {
    JPQLSerializer serializer = new JPQLSerializer(templates, null);
    serializer.serializeForUpdate(queryMixin.getMetadata(), updates);
    return serializer.toString();
}
Also used : JPQLSerializer(com.querydsl.jpa.JPQLSerializer)

Example 3 with JPQLSerializer

use of com.querydsl.jpa.JPQLSerializer in project querydsl by querydsl.

the class JPADeleteClause method execute.

@Override
public long execute() {
    JPQLSerializer serializer = new JPQLSerializer(templates, entityManager);
    serializer.serializeForDelete(queryMixin.getMetadata());
    Map<Object, String> constants = serializer.getConstantToLabel();
    Query query = entityManager.createQuery(serializer.toString());
    if (lockMode != null) {
        query.setLockMode(lockMode);
    }
    JPAUtil.setConstants(query, constants, queryMixin.getMetadata().getParams());
    return query.executeUpdate();
}
Also used : Query(javax.persistence.Query) JPQLSerializer(com.querydsl.jpa.JPQLSerializer)

Example 4 with JPQLSerializer

use of com.querydsl.jpa.JPQLSerializer in project querydsl by querydsl.

the class JPAUpdateClause method toString.

@Override
public String toString() {
    JPQLSerializer serializer = new JPQLSerializer(templates, entityManager);
    serializer.serializeForUpdate(queryMixin.getMetadata(), updates);
    return serializer.toString();
}
Also used : JPQLSerializer(com.querydsl.jpa.JPQLSerializer)

Example 5 with JPQLSerializer

use of com.querydsl.jpa.JPQLSerializer in project querydsl by querydsl.

the class AbstractJPAQuery method createQuery.

private Query createQuery(@Nullable QueryModifiers modifiers, boolean forCount) {
    JPQLSerializer serializer = serialize(forCount);
    String queryString = serializer.toString();
    logQuery(queryString, serializer.getConstantToLabel());
    Query query = entityManager.createQuery(queryString);
    JPAUtil.setConstants(query, serializer.getConstantToLabel(), getMetadata().getParams());
    if (modifiers != null && modifiers.isRestricting()) {
        Integer limit = modifiers.getLimitAsInteger();
        Integer offset = modifiers.getOffsetAsInteger();
        if (limit != null) {
            query.setMaxResults(limit);
        }
        if (offset != null) {
            query.setFirstResult(offset);
        }
    }
    if (lockMode != null) {
        query.setLockMode(lockMode);
    }
    if (flushMode != null) {
        query.setFlushMode(flushMode);
    }
    for (Map.Entry<String, Object> entry : hints.entries()) {
        query.setHint(entry.getKey(), entry.getValue());
    }
    // set transformer, if necessary and possible
    Expression<?> projection = getMetadata().getProjection();
    // necessary when query is reused
    this.projection = null;
    if (!forCount && projection instanceof FactoryExpression) {
        if (!queryHandler.transform(query, (FactoryExpression<?>) projection)) {
            this.projection = (FactoryExpression) projection;
        }
    }
    return query;
}
Also used : FactoryExpression(com.querydsl.core.types.FactoryExpression) Query(javax.persistence.Query) JPQLSerializer(com.querydsl.jpa.JPQLSerializer) Map(java.util.Map)

Aggregations

JPQLSerializer (com.querydsl.jpa.JPQLSerializer)9 Map (java.util.Map)3 Query (javax.persistence.Query)3 EntityPath (com.querydsl.core.types.EntityPath)2 Path (com.querydsl.core.types.Path)2 HashMap (java.util.HashMap)2 LockMode (org.hibernate.LockMode)2 Query (org.hibernate.Query)2 FactoryExpression (com.querydsl.core.types.FactoryExpression)1