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

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

本文整理了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

@SuppressWarnings("unchecked")
protected <E extends Entity> List<E> executeQuery(Query query, boolean singleResult) {
  List<E> list;
  try {
    if (singleResult) {
      try {
        E result = (E) query.getSingleResult();
        list = new ArrayList<>(1);
        list.add(result);
      } catch (NoResultException e) {
        list = Collections.emptyList();
      }
    } else {
      list = query.getResultList();
    }
  } catch (javax.persistence.PersistenceException e) {
    if (e.getCause() instanceof org.eclipse.persistence.exceptions.QueryException
        && e.getMessage() != null
        && e.getMessage().contains("Fetch group cannot be set on report query")) {
      throw new DevelopmentException("DataManager cannot execute query for single attributes");
    } else {
      throw e;
    }
  }
  return list;
}

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

protected String generateReportName(String sourceName, int iteration) {
  if (iteration == 1) {
    iteration++; //like in win 7: duplicate of file 'a.txt' is 'a (2).txt', NOT 'a (1).txt'
  }
  String reportName = StringUtils.stripEnd(sourceName, null);
  if (iteration > 0) {
    String newReportName = String.format("%s (%s)", reportName, iteration);
    if (newReportName.length() > MAX_REPORT_NAME_LENGTH) {
      String abbreviatedReportName = StringUtils.abbreviate(reportName, MAX_REPORT_NAME_LENGTH -
          String.valueOf(iteration).length() - 3);// 3 cause it us " ()".length
      reportName = String.format("%s (%s)", abbreviatedReportName, iteration);
    } else {
      reportName = newReportName;
    }
  }
  Transaction tx = persistence.createTransaction();
  try {
    Long countOfReportsWithSameName = (Long) persistence.getEntityManager()
        .createQuery("select count(r) from report$Report r where r.name = :name")
        .setParameter("name", reportName)
        .getSingleResult();
    tx.commit();
    if (countOfReportsWithSameName > 0) {
      return generateReportName(sourceName, ++iteration);
    }
  } finally {
    tx.end();
  }
  return reportName;
}

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

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

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

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

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

result = (Number) query.getSingleResult();

相关文章