List of usage examples for org.hibernate Query setComment
Query<R> setComment(String comment);
From source file:org.zanata.dao.ActivityDAO.java
License:Open Source License
public int getActivityCountByActor(Long personId) { Query q = getSession().createQuery("select count(*) from Activity a where a.actor.id = :personId"); q.setParameter("personId", personId); q.setCacheable(true);/*from ww w. j av a 2s.c o m*/ q.setComment("activityDAO.getActivityCountByActor"); Long totalCount = (Long) q.uniqueResult(); if (totalCount == null) { return 0; } return totalCount.intValue(); }
From source file:org.zanata.dao.ActivityDAO.java
License:Open Source License
/** * Return int[0]: Words, int[1]: Messages, int[2]: Documents * * @param personId/*from ww w . j a va2s . c o m*/ * @param startDate * @param endDate */ private int[] getTranslationStatistic(Long personId, Date startDate, Date endDate, STATS_BY statsBy) { StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("select sum(tft.textFlow.wordCount),").append("count(tft.textFlow),") .append("count(distinct tft.textFlow.document)").append("from HTextFlowTarget tft "); if (statsBy == STATS_BY.REVIEWER) { queryBuilder.append("where tft.reviewer.id = :personId "); } else { queryBuilder.append("where tft.translator.id = :personId "); } queryBuilder.append("and tft.lastChanged BETWEEN :startDate AND :endDate "); Query q = getSession().createQuery(queryBuilder.toString()); q.setParameter("personId", personId); q.setParameter("startDate", startDate); q.setParameter("endDate", endDate); if (statsBy == STATS_BY.REVIEWER) { q.setComment("activityDAO.getReviewedStats"); } else { q.setComment("activityDAO.getTranslatedStats"); } q.setCacheable(true); Object[] objects = (Object[]) q.uniqueResult(); int[] results = new int[] { 0, 0, 0 }; if (objects == null || objects.length == 0) { return results; } for (int i = 0; i < results.length; i++) { if (objects.length >= i) { Long count = (Long) objects[i]; results[i] = count == null ? 0 : count.intValue(); } } return results; }
From source file:org.zanata.dao.GlossaryDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<HGlossaryEntry> getEntries() { Query query = getSession().createQuery("from HGlossaryEntry"); query.setComment("GlossaryDAO.getEntries"); return query.list(); }
From source file:org.zanata.dao.GlossaryDAO.java
License:Open Source License
public HGlossaryTerm getTermByEntryAndLocale(Long glossaryEntryId, LocaleId locale) { Query query = getSession().createQuery( "from HGlossaryTerm as t WHERE t.locale.localeId= :locale AND glossaryEntry.id= :glossaryEntryId"); query.setParameter("locale", locale); query.setParameter("glossaryEntryId", glossaryEntryId); query.setComment("GlossaryDAO.getTermByEntryAndLocale"); return (HGlossaryTerm) query.uniqueResult(); }
From source file:org.zanata.dao.GlossaryDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<HGlossaryTerm> getTermByGlossaryEntryId(Long glossaryEntryId) { Query query = getSession() .createQuery("from HGlossaryTerm as t WHERE t.glossaryEntry.id= :glossaryEntryId"); query.setParameter("glossaryEntryId", glossaryEntryId); query.setComment("GlossaryDAO.getTermByGlossaryEntryId"); return query.list(); }
From source file:org.zanata.dao.GlossaryDAO.java
License:Open Source License
public HGlossaryEntry getEntryByContentHash(String contentHash) { Query query = getSession().createQuery("from HGlossaryEntry as e WHERE e.contentHash = :contentHash "); query.setParameter("contentHash", contentHash); query.setComment("GlossaryDAO.getEntryByContentHash"); return (HGlossaryEntry) query.uniqueResult(); }
From source file:org.zanata.dao.GlossaryDAO.java
License:Open Source License
public Map<HLocale, Integer> getGlossaryTermCountByLocale() { Map<HLocale, Integer> result = new HashMap<HLocale, Integer>(); Query query = getSession() .createQuery("select term.locale, count(*) from HGlossaryTerm term GROUP BY term.locale.localeId"); query.setComment("GlossaryDAO.getGlossaryTermCountByLocale"); @SuppressWarnings("unchecked") List<Object[]> list = query.list(); for (Object[] obj : list) { HLocale locale = (HLocale) obj[0]; Long count = (Long) obj[1]; int countInt = count == null ? 0 : count.intValue(); result.put(locale, countInt);/*from w w w . j a v a 2s. com*/ } return result; }
From source file:org.zanata.dao.GlossaryDAO.java
License:Open Source License
public int deleteAllEntries() { Query query2 = getSession().createQuery("Delete HGlossaryTerm"); query2.setComment("GlossaryDAO.deleteAllEntries-terms"); int rowCount = query2.executeUpdate(); Query query3 = getSession().createQuery("Delete HGlossaryEntry"); query3.setComment("GlossaryDAO.deleteAllEntries-entries"); query3.executeUpdate();/* w ww . jav a 2 s . co m*/ return rowCount; }
From source file:org.zanata.dao.GlossaryDAO.java
License:Open Source License
public int deleteAllEntries(LocaleId targetLocale) { Query query2 = getSession().createQuery( "Delete HGlossaryTerm t WHERE t.locale IN (SELECT l FROM HLocale l WHERE localeId= :locale)"); query2.setParameter("locale", targetLocale); query2.setComment("GlossaryDAO.deleteLocaleEntries-terms"); int rowCount = query2.executeUpdate(); Query query3 = getSession().createQuery("Delete HGlossaryEntry e WHERE size(e.glossaryTerms) = 0"); query3.setComment("GlossaryDAO.deleteLocaleEntries-entries"); query3.executeUpdate();/*from ww w . j a va 2s . c o m*/ return rowCount; }
From source file:org.zanata.dao.LocaleDAO.java
License:Open Source License
public List<HLocale> searchByName(String query, int maxResult, int firstResult) { Query q = getSession() .createQuery("from HLocale l where " + "lower(l.localeId) like :query " + "or lower(l.displayName) like :query " + "or lower(l.nativeName) like :query") .setString("query", "%" + query.toLowerCase() + "%").setFirstResult(firstResult); if (maxResult != -1) { q.setMaxResults(maxResult);//from ww w . j ava2 s .c om } q.setComment("LocaleDAO.searchByName"); return q.list(); }