Search in sources :

Example 1 with DummyQuery

use of de.invesdwin.context.persistence.jpa.api.query.DummyQuery in project invesdwin-context-persistence by subes.

the class QueryByExampleHelper method deleteByIds.

public Query deleteByIds(final EntityManager em, final Class<E> genericType, final Iterable<Long> ids) {
    if (ids == null || !ids.iterator().hasNext()) {
        return new DummyQuery();
    }
    final StringBuilder sb = new StringBuilder("DELETE FROM ");
    sb.append(extractEntityName(genericType));
    sb.append(" e WHERE ");
    boolean first = true;
    for (final Long id : ids) {
        if (!first) {
            sb.append(" OR ");
        }
        sb.append(IEntity.ID_COLUMN_NAME);
        sb.append(" = ");
        sb.append(id);
        first = false;
    }
    final Query query = em.createQuery(sb.toString());
    return query;
}
Also used : CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TypedQuery(javax.persistence.TypedQuery) DummyQuery(de.invesdwin.context.persistence.jpa.api.query.DummyQuery) Query(javax.persistence.Query) DummyQuery(de.invesdwin.context.persistence.jpa.api.query.DummyQuery)

Aggregations

DummyQuery (de.invesdwin.context.persistence.jpa.api.query.DummyQuery)1 Query (javax.persistence.Query)1 TypedQuery (javax.persistence.TypedQuery)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1