Example usage for org.hibernate Query setComment

List of usage examples for org.hibernate Query setComment

Introduction

In this page you can find the example usage for org.hibernate Query setComment.

Prototype

Query<R> setComment(String comment);

Source Link

Document

Set the comment for this query.

Usage

From source file:org.zanata.dao.TextFlowTargetHistoryDAO.java

License:Open Source License

/**
 * Query to get total wordCount of a person(translated_by_id) from
 * HTextFlowTarget union HTextFlowTargetHistory tables
 * in a project-version, within given date range group by state and locale.
 *
 * HTextFlowTargetHistory:/*from w  w w.  java  2s. co m*/
 * gets latest of all records translated from user in given version,
 * locale and dateRange and its target is not translated by same person.
 *
 * HTextFlowTarget:
 * gets all records translated from user in given version, locale and
 * dateRange.
 *
 * @param versionId HProjectIteration identifier
 * @param personId HPerson identifier
 * @param from start of date range
 * @param to end of date range
 *
 * @return list of Object[wordCount][contentState][localeId]
 */
@NativeQuery
public List<Object[]> getUserTranslationStatisticInVersion(Long versionId, Long personId, Date fromDate,
        Date toDate, boolean automatedEntry) {
    Query query = buildContributionStatisticQuery(true, versionId, personId, fromDate, toDate, automatedEntry);
    query.setComment("textFlowTargetHistoryDAO.getUserTranslationStatisticInVersion");
    return query.list();
}

From source file:org.zanata.dao.TextFlowTargetHistoryDAO.java

License:Open Source License

/**
 * Query to get total wordCount of a person(reviewed_by_id) from
 * HTextFlowTarget union HTextFlowTargetHistory tables
 * in a project-version, within given date range group by state and locale.
 *
 * HTextFlowTargetHistory:/*www .  j av  a  2 s.  c  o m*/
 * gets latest of all records reviewed from user in given version,
 * locale and dateRange and its target is not translated by same person.
 *
 * HTextFlowTarget:
 * gets all records reviewed from user in given version, locale and
 * dateRange.
 *
 * @param versionId HProjectIteration identifier
 * @param personId HPerson identifier
 * @param from start of date range
 * @param to end of date range
 *
 * @return list of Object[wordCount][contentState][localeId]
 */
@NativeQuery
public List<Object[]> getUserReviewStatisticInVersion(Long versionId, Long personId, Date fromDate, Date toDate,
        boolean automatedEntry) {
    Query query = buildContributionStatisticQuery(false, versionId, personId, fromDate, toDate, automatedEntry);
    query.setComment("textFlowTargetHistoryDAO.getUserReviewStatisticInVersion");
    return query.list();
}

From source file:org.zanata.dao.TextFlowTargetHistoryDAO.java

License:Open Source License

public boolean findContentInHistory(HTextFlowTarget target, List<String> contents) {
    // Ordinal parameters can't be used in NamedQueries due to the following
    // bug://from ww w.  jav a2s.  co m
    // https://hibernate.onjira.com/browse/HHH-5653
    Query query;

    // use named queries for the smaller more common cases
    if (contents.size() <= 6) {
        query = getSession().getNamedQuery(HTextFlowTargetHistory.getQueryNameMatchingHistory(contents.size()));
    } else {
        StringBuilder queryStr = new StringBuilder(
                "select count(*) from HTextFlowTargetHistory t where t.textFlowTarget = :tft and size(t.contents) = :contentCount");
        for (int i = 0; i < contents.size(); i++) {
            queryStr.append(" and contents[" + i + "] = :content" + i);
        }
        query = getSession().createQuery(queryStr.toString());
    }
    query.setParameter("tft", target);
    query.setParameter("contentCount", contents.size());
    int paramPos = 0;
    for (String c : contents) {
        query.setParameter("content" + paramPos++, c);
    }
    query.setComment("TextFlowTargetHistoryDAO.findContentInHistory-" + contents.size());
    return (Long) query.uniqueResult() != 0;
}

From source file:org.zanata.dao.TextFlowTargetHistoryDAO.java

License:Open Source License

public boolean findConflictInHistory(HTextFlowTarget target, Integer verNum, String username) {
    Query query = getSession().createQuery(
            "select count(*) from HTextFlowTargetHistory t where t.textFlowTarget.id =:id and t.textFlowRevision > :ver and t.lastModifiedBy.account.username != :username");
    query.setParameter("id", target.getId());
    query.setParameter("ver", verNum);
    query.setParameter("username", username);
    query.setComment("TextFlowTargetHistoryDAO.findConflictInHistory");
    Long count = (Long) query.uniqueResult();
    return count != 0;
}

From source file:org.zanata.dao.TextFlowTargetReviewCommentsDAO.java

License:Open Source License

public List<HTextFlowTargetReviewComment> getReviewComments(TransUnitId textFlowId, LocaleId localeId) {
    Query query = getSession().createQuery(
            "select c from HTextFlowTargetReviewComment c join fetch c.commenter where c.textFlowTarget.textFlow.id = :textFlowId and c.textFlowTarget.locale.localeId = :localeId");
    query.setParameter("textFlowId", textFlowId.getValue());
    query.setParameter("localeId", localeId);
    query.setComment("TextFlowTargetReviewCommentsDAO.getReviewComments");
    query.setCacheable(true);//from   w w  w .j  a  v  a 2  s.  c  o m
    return query.list();
}

From source file:org.zanata.dao.TransMemoryStreamingDAO.java

License:Open Source License

/**
 * Finds all the TransMemoryUnits for a given TransMemory.
 * <p>//from w  w  w. j a  va 2  s  .c  o m
 * NB: caller must close the iterator, or call next() until the iterator is
 * exhausted, or else a database connection will be leaked.
 *
 * @param transMemory
 * @return
 */
public CloseableIterator<TransMemoryUnit> findTransUnitsByTM(TransMemory transMemory) {
    StreamingEntityIterator<TransMemoryUnit> iter = createIterator();
    try {
        Query q = iter.getSession()
                .createQuery("FROM TransMemoryUnit tu FETCH ALL PROPERTIES "
                        + "JOIN FETCH tu.transUnitVariants tuv FETCH ALL PROPERTIES "
                        + "WHERE tu.translationMemory = :transMemory " + "");
        q.setParameter("transMemory", transMemory);
        q.setComment("TransMemoryStreamingDAO.findTransUnitsByTM");

        iter.initQuery(q);
        return iter;
    } catch (Throwable e) {
        iter.close();
        throw new RuntimeException(e);
    }

}

From source file:org.zanata.dao.TransMemoryStreamingDAO.java

License:Open Source License

/**
 * Finds all TransMemoryUnits.//from   w w w.j av  a  2s  .  c  om
 * <p>
 * NB: caller must close the iterator, or call next() until the iterator is
 * exhausted, or else a database connection will be leaked.
 *
 * @param transMemory
 * @return
 */
public CloseableIterator<TransMemoryUnit> findAllTransUnits() {
    StreamingEntityIterator<TransMemoryUnit> iter = createIterator();
    try {
        Query q = iter.getSession().createQuery("FROM TransMemoryUnit tu FETCH ALL PROPERTIES "
                + "JOIN FETCH tu.transUnitVariants tuv FETCH ALL PROPERTIES " + "");
        q.setComment("TransMemoryStreamingDAO.findAllTransUnits");
        iter.initQuery(q);
        return iter;
    } catch (Throwable e) {
        iter.close();
        throw new RuntimeException(e);
    }
}

From source file:org.zanata.dao.VersionGroupDAO.java

License:Open Source License

public List<HIterationGroup> getAllGroups(int maxResult, int firstResult, EntityStatus... statuses) {
    StringBuilder sb = new StringBuilder();
    sb.append("from HIterationGroup ");
    if (statuses != null && statuses.length >= 1) {
        sb.append("where status in :statuses ");
    }/* www  . ja  v a 2s .  c  o  m*/

    sb.append("order by name asc");
    Query query = getSession().createQuery(sb.toString());

    if (statuses != null && statuses.length >= 1) {
        query.setParameterList("statuses", Lists.newArrayList(statuses));
    }

    query.setFirstResult(firstResult);
    if (maxResult != -1) {
        query.setMaxResults(maxResult);
    }
    query.setComment("VersionGroupDAO.getAllGroups");
    query.setCacheable(true);
    return query.list();
}

From source file:org.zanata.dao.VersionGroupDAO.java

License:Open Source License

public List<HPerson> getMaintainersBySlug(String slug) {
    Query q = getSession().createQuery("select g.maintainers from HIterationGroup as g where g.slug = :slug");
    q.setParameter("slug", slug);
    q.setComment("VersionGroupDAO.getMaintainersBySlug");
    return q.list();
}

From source file:org.zanata.dao.VersionGroupDAO.java

License:Open Source License

public List<HIterationGroup> searchGroupBySlugAndName(String searchTerm, int maxResult, int firstResult,
        EntityStatus... statuses) {/*from   w  w w  .j av a 2  s  .com*/
    if (StringUtils.isEmpty(searchTerm)) {
        return new ArrayList<HIterationGroup>();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("from HIterationGroup ")
            .append("where (lower(slug) LIKE :searchTerm OR lower(name) LIKE :searchTerm) ");
    if (statuses != null && statuses.length >= 1) {
        sb.append("AND status in :statuses ");
    }
    sb.append("order by name asc");
    Query query = getSession().createQuery(sb.toString());
    query.setParameter("searchTerm", "%" + searchTerm.toLowerCase() + "%");
    query.setFirstResult(firstResult);
    if (maxResult != -1) {
        query.setMaxResults(maxResult);
    }
    if (statuses != null && statuses.length >= 1) {
        query.setParameterList("statuses", Lists.newArrayList(statuses));
    }
    query.setComment("VersionGroupDAO.searchGroupBySlugAndName");
    query.setCacheable(true);
    return query.list();
}