List of usage examples for org.hibernate Query setComment
Query<R> setComment(String comment);
From source file:org.zanata.dao.PersonDAO.java
License:Open Source License
public List<HPerson> findAllContainingName(String name, int maxResult, int firstResult) { if (!StringUtils.isEmpty(name)) { Query query = getSession().createQuery("from HPerson as p " + "where lower(p.account.username) like :name " + "or lower(p.name) like :name"); query.setParameter("name", "%" + name.toLowerCase() + "%"); query.setCacheable(false);//from w w w. ja v a 2s . c om query.setFirstResult(firstResult); if (maxResult != -1) { query.setMaxResults(maxResult); } query.setComment("PersonDAO.findAllContainingName"); return query.list(); } return new ArrayList<HPerson>(); }
From source file:org.zanata.dao.PersonEmailValidationKeyDAO.java
License:Open Source License
public HPersonEmailValidationKey findByKeyHash(String keyHash) { Query query = getSession().createQuery("from HPersonEmailValidationKey as key where key.keyHash= :keyHash"); query.setParameter("keyHash", keyHash); query.setCacheable(false);// www. ja v a 2s. com query.setComment("PersonEmailValidationKeyDAO.findByKeyHash"); return (HPersonEmailValidationKey) query.uniqueResult(); }
From source file:org.zanata.dao.PersonEmailValidationKeyDAO.java
License:Open Source License
public HPersonEmailValidationKey findByPersonId(Long personId) { Query query = getSession() .createQuery("from HPersonEmailValidationKey as key where key.person.id= :personId"); query.setLong("personId", personId); query.setCacheable(false);/*from w w w.ja va 2 s .c o m*/ query.setComment("PersonEmailValidationKeyDAO.findByPersonId"); return (HPersonEmailValidationKey) query.uniqueResult(); }
From source file:org.zanata.dao.ProjectIterationDAO.java
License:Open Source License
public List<HProjectIteration> getByProjectSlug(@Nonnull String projectSlug, EntityStatus... includeStatus) { if (StringUtils.isEmpty(projectSlug)) { return Collections.EMPTY_LIST; }/* ww w . j a v a 2 s. c o m*/ StringBuilder sb = new StringBuilder(); sb.append("from HProjectIteration version where ").append("version.project.slug = :projectSlug "); if (includeStatus != null) { sb.append("and version.status in :includesStatus"); } Query q = getSession().createQuery(sb.toString()); q.setParameter("projectSlug", projectSlug); if (includeStatus != null) { q.setParameterList("includesStatus", Lists.newArrayList(includeStatus)); } q.setComment("ProjectIterationDAO.getByProjectSlug"); List<HProjectIteration> results = q.list(); return results; }
From source file:org.zanata.dao.ProjectIterationDAO.java
License:Open Source License
public List<HProjectIteration> getByGroup(HIterationGroup group) { Query q = getSession().createQuery( "from HProjectIteration as iter where iter.status<>:OBSOLETE AND :group in elements(iter.groups)"); q.setParameter("OBSOLETE", EntityStatus.OBSOLETE); q.setParameter("group", group); q.setComment("ProjectIterationDAO.getByGroup"); @SuppressWarnings("unchecked") List<HProjectIteration> results = q.list(); return results; }
From source file:org.zanata.dao.ProjectIterationDAO.java
License:Open Source License
/** * Retreives translation unit level statistics for a project iteration. * * @param iterationId//from www . j a v a 2s . c o m * The numeric id for a Project iteration. * @return A map of translation unit counts indexed by a locale id string. */ public Map<String, TransUnitCount> getAllStatisticsForContainer(Long iterationId) { Query q = getSession().createQuery("select new map(tft.state as state, " + "count(tft) as count, " + "tft.locale.localeId as locale) " + "from HTextFlowTarget tft " + "where tft.textFlow.document.projectIteration.id = :id " + " and tft.textFlow.obsolete = false" + " and tft.textFlow.document.obsolete = false" + " group by tft.state, tft.locale"); q.setParameter("id", iterationId); q.setComment("ProjectIterationDAO.getAllStatisticsForContainer"); @SuppressWarnings("unchecked") List<Map> stats = q.list(); Map<String, TransUnitCount> retVal = new HashMap<String, TransUnitCount>(); for (Map row : stats) { ContentState state = (ContentState) row.get("state"); Long count = (Long) row.get("count"); LocaleId localeId = (LocaleId) row.get("locale"); TransUnitCount transUnitCount = retVal.get(localeId.getId()); if (transUnitCount == null) { transUnitCount = new TransUnitCount(); retVal.put(localeId.getId(), transUnitCount); } transUnitCount.set(state, count.intValue()); } for (TransUnitCount stat : retVal.values()) { Long totalCount = getTotalMessageCountForIteration(iterationId); stat.set(ContentState.New, StatisticsUtil.calculateUntranslated(totalCount, stat)); } return retVal; }
From source file:org.zanata.dao.TextFlowDAO.java
License:Open Source License
public List<Object[]> getTextFlowAndTarget(List<Long> idList, Long localeId) { StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("from HTextFlow tf ").append("left join tf.targets tft with tft.locale.id =:localeId ") .append("where tf.id in (:idList)"); Query q = getSession().createQuery(queryBuilder.toString()); q.setParameterList("idList", idList); q.setParameter("localeId", localeId); q.setCacheable(true);/*from w ww .ja v a 2s . c om*/ q.setComment("TextFlowTargetDAO.getTextFlowTarget"); return q.list(); }
From source file:org.zanata.dao.TextFlowStreamingDAO.java
License:Open Source License
/** * Returns all HTextFlows in all projects, eagerly fetches targets, * document, iteration and project. Obsolete projects, iterations, documents * and textflows are skipped.//from w w w. j a va 2 s. c o m * <p> * NB: caller must close the iterator, or call next() until the iterator is * exhausted, or else a database connection will be leaked. * * @return */ public @Nonnull CloseableIterator<HTextFlow> findTextFlows() { StreamingEntityIterator<HTextFlow> iter = createIterator(); try { Query q = iter.getSession().createQuery("from HTextFlow tf " + "inner join fetch tf.targets target " + "inner join fetch target.locale " + "inner join fetch tf.document " + "inner join fetch tf.document.locale " + "inner join fetch tf.document.projectIteration " + "inner join fetch tf.document.projectIteration.project " + "where tf.document.projectIteration.project.status<>:OBSOLETE " + "and tf.document.projectIteration.status<>:OBSOLETE " + "and tf.document.obsolete=0 " + "and tf.obsolete=0 "); q.setParameter("OBSOLETE", EntityStatus.OBSOLETE); q.setComment("TextFlowStreamDAO.findTextFlows"); iter.initQuery(q); return iter; } catch (Throwable e) { iter.close(); throw new RuntimeException(e); } }
From source file:org.zanata.dao.TextFlowStreamingDAO.java
License:Open Source License
/** * Returns all HTextFlows in project, eagerly fetches targets, document, * iteration and project. Obsolete iterations, documents and textflows are * skipped.//w w w . j a v a 2s.c o m * <p> * NB: caller must close the iterator, or call next() until the iterator is * exhausted, or else a database connection will be leaked. * * @return */ public @Nonnull CloseableIterator<HTextFlow> findTextFlowsByProject(HProject hProject) { StreamingEntityIterator<HTextFlow> iter = createIterator(); try { Query q = iter.getSession().createQuery("from HTextFlow tf " + "inner join fetch tf.targets target " + "inner join fetch target.locale " + "inner join fetch tf.document " + "inner join fetch tf.document.locale " + "inner join fetch tf.document.projectIteration " + "inner join fetch tf.document.projectIteration.project " + "where tf.document.projectIteration.status<>:OBSOLETE " + "and tf.document.obsolete=0 " + "and tf.obsolete=0" + "and tf.document.projectIteration.project=:proj"); q.setParameter("OBSOLETE", EntityStatus.OBSOLETE); q.setParameter("proj", hProject); q.setComment("TextFlowStreamDAO.findTextFlowsByProject"); iter.initQuery(q); return iter; } catch (Throwable e) { iter.close(); throw new RuntimeException(e); } }
From source file:org.zanata.dao.TextFlowStreamingDAO.java
License:Open Source License
/** * Returns all HTextFlows in project iteration, eagerly fetches targets, * document, iteration and project. Obsolete documents and textflows are * skipped.//from ww w. j a va 2s . c o m * <p> * NB: caller must close the iterator, or call next() until the iterator is * exhausted, or else a database connection will be leaked. * * @return */ public @Nonnull CloseableIterator<HTextFlow> findTextFlowsByProjectIteration( HProjectIteration hProjectIteration) { StreamingEntityIterator<HTextFlow> iter = createIterator(); try { Query q = iter.getSession().createQuery("from HTextFlow tf " + "inner join fetch tf.targets target " + "inner join fetch target.locale " + "inner join fetch tf.document " + "inner join fetch tf.document.locale " + "inner join fetch tf.document.projectIteration " + "inner join fetch tf.document.projectIteration.project " + "where tf.document.obsolete=0 " + "and tf.obsolete=0" + "and tf.document.projectIteration=:iter"); q.setParameter("iter", hProjectIteration); q.setComment("TextFlowStreamDAO.findTextFlowsByProjectIteration"); iter.initQuery(q); return iter; } catch (Throwable e) { iter.close(); throw new RuntimeException(e); } }