Example usage for org.hibernate SharedSessionContract createQuery

List of usage examples for org.hibernate SharedSessionContract createQuery

Introduction

In this page you can find the example usage for org.hibernate SharedSessionContract createQuery.

Prototype

@Override
    org.hibernate.query.Query createQuery(String queryString);

Source Link

Usage

From source file:com.romeikat.datamessie.core.base.dao.impl.StatisticsDao.java

License:Open Source License

public int deleteStatistics(final SharedSessionContract ssc, final Long sourceId, final LocalDate published) {
    if (sourceId == null && published == null) {
        return 0;
    }/*ww w. j a v a2 s .c o m*/

    // Query
    final StringBuilder hql = new StringBuilder();
    hql.append("DELETE Statistics s ");
    hql.append("WHERE ");
    if (sourceId != null) {
        hql.append("s.sourceId = :_sourceId ");
    }
    if (sourceId != null && published != null) {
        hql.append("AND ");
    }
    if (published != null) {
        hql.append("s.published = :_published ");
    }
    final Query<?> query = ssc.createQuery(hql.toString());
    if (sourceId != null) {
        query.setParameter("_sourceId", sourceId);
    }
    if (published != null) {
        query.setParameter("_published", published);
    }

    // Execute
    final int updated = query.executeUpdate();
    return updated;
}