com.haulmont.cuba.core.Query.getSingleResult()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(2.9k)|赞(0)|评价(0)|浏览(330)

本文整理了Java中com.haulmont.cuba.core.Query.getSingleResult方法的一些代码示例,展示了Query.getSingleResult的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getSingleResult方法的具体详情如下:
包路径:com.haulmont.cuba.core.Query
类名称:Query
方法名:getSingleResult

Query.getSingleResult介绍

[英]Execute a SELECT query that returns a single result.
[中]执行返回单个结果的SELECT查询。

代码示例

代码示例来源:origin: com.haulmont.cuba/cuba-core

  1. @SuppressWarnings("unchecked")
  2. protected <E extends Entity> List<E> executeQuery(Query query, boolean singleResult) {
  3. List<E> list;
  4. try {
  5. if (singleResult) {
  6. try {
  7. E result = (E) query.getSingleResult();
  8. list = new ArrayList<>(1);
  9. list.add(result);
  10. } catch (NoResultException e) {
  11. list = Collections.emptyList();
  12. }
  13. } else {
  14. list = query.getResultList();
  15. }
  16. } catch (javax.persistence.PersistenceException e) {
  17. if (e.getCause() instanceof org.eclipse.persistence.exceptions.QueryException
  18. && e.getMessage() != null
  19. && e.getMessage().contains("Fetch group cannot be set on report query")) {
  20. throw new DevelopmentException("DataManager cannot execute query for single attributes");
  21. } else {
  22. throw e;
  23. }
  24. }
  25. return list;
  26. }

代码示例来源:origin: com.haulmont.reports/reports-core

  1. protected String generateReportName(String sourceName, int iteration) {
  2. if (iteration == 1) {
  3. iteration++; //like in win 7: duplicate of file 'a.txt' is 'a (2).txt', NOT 'a (1).txt'
  4. }
  5. String reportName = StringUtils.stripEnd(sourceName, null);
  6. if (iteration > 0) {
  7. String newReportName = String.format("%s (%s)", reportName, iteration);
  8. if (newReportName.length() > MAX_REPORT_NAME_LENGTH) {
  9. String abbreviatedReportName = StringUtils.abbreviate(reportName, MAX_REPORT_NAME_LENGTH -
  10. String.valueOf(iteration).length() - 3);// 3 cause it us " ()".length
  11. reportName = String.format("%s (%s)", abbreviatedReportName, iteration);
  12. } else {
  13. reportName = newReportName;
  14. }
  15. }
  16. Transaction tx = persistence.createTransaction();
  17. try {
  18. Long countOfReportsWithSameName = (Long) persistence.getEntityManager()
  19. .createQuery("select count(r) from report$Report r where r.name = :name")
  20. .setParameter("name", reportName)
  21. .getSingleResult();
  22. tx.commit();
  23. if (countOfReportsWithSameName > 0) {
  24. return generateReportName(sourceName, ++iteration);
  25. }
  26. } finally {
  27. tx.end();
  28. }
  29. return reportName;
  30. }

代码示例来源:origin: com.haulmont.cuba/cuba-core

  1. protected boolean referenceExists(String entityName, MetaProperty property) {
  2. String template = property.getRange().getCardinality().isMany() ?
  3. "select count(e) from %s e join e.%s c where c." + primaryKeyName + "= ?1" :
  4. "select count(e) from %s e where e.%s." + primaryKeyName + " = ?1";
  5. String qstr = String.format(template, entityName, property.getName());
  6. Query query = entityManager.createQuery(qstr);
  7. query.setParameter(1, entity.getId());
  8. query.setMaxResults(1);
  9. Long count = (Long) query.getSingleResult();
  10. return count > 0;
  11. }

代码示例来源:origin: com.haulmont.cuba/cuba-core

  1. Long count = (Long) q.getSingleResult();

代码示例来源:origin: com.haulmont.cuba/cuba-core

  1. result = (Number) query.getSingleResult();

相关文章