Ejemplo n.º 1
0
  @Override
  public Query createQuery(NamedQueryDefinition namedQueryDefinition) {
    errorIfClosed();
    checkTransactionSynchStatus();

    String queryString = namedQueryDefinition.getQueryString();
    Query query = createQuery(queryString);
    query.setComment("named HQL/JP-QL query " + namedQueryDefinition.getName());
    query.setFlushMode(namedQueryDefinition.getFlushMode());
    return query;
  }
  private Query createQuery(
      String queryString, @Nullable QueryModifiers modifiers, boolean forCount) {
    Query query = session.createQuery(queryString);
    HibernateUtil.setConstants(query, getConstants(), getMetadata().getParams());
    if (fetchSize > 0) {
      query.setFetchSize(fetchSize);
    }
    if (timeout > 0) {
      query.setTimeout(timeout);
    }
    if (cacheable != null) {
      query.setCacheable(cacheable);
    }
    if (cacheRegion != null) {
      query.setCacheRegion(cacheRegion);
    }
    if (comment != null) {
      query.setComment(comment);
    }
    if (readOnly != null) {
      query.setReadOnly(readOnly);
    }
    for (Map.Entry<Path<?>, LockMode> entry : lockModes.entrySet()) {
      query.setLockMode(entry.getKey().toString(), entry.getValue());
    }
    if (flushMode != null) {
      query.setFlushMode(flushMode);
    }

    if (modifiers != null && modifiers.isRestricting()) {
      if (modifiers.getLimit() != null) {
        query.setMaxResults(modifiers.getLimit().intValue());
      }
      if (modifiers.getOffset() != null) {
        query.setFirstResult(modifiers.getOffset().intValue());
      }
    }

    // set transformer, if necessary
    List<? extends Expression<?>> projection = getMetadata().getProjection();
    if (projection.size() == 1 && !forCount) {
      Expression<?> expr = projection.get(0);
      if (expr instanceof FactoryExpression<?>) {
        query.setResultTransformer(
            new FactoryExpressionTransformer((FactoryExpression<?>) projection.get(0)));
      }
    } else if (!forCount) {
      FactoryExpression<?> proj = FactoryExpressionUtils.wrap(projection);
      if (proj != null) {
        query.setResultTransformer(new FactoryExpressionTransformer(proj));
      }
    }
    return query;
  }
Ejemplo n.º 3
0
  @Override
  public Query getNamedSQLQuery(String queryName) {
    errorIfClosed();
    checkTransactionSynchStatus();

    NamedSQLQueryDefinition nsqlqd = findNamedNativeQuery(queryName);
    Query query =
        new NoSQLQueryImpl(
            nsqlqd, this, factory.getQueryPlanCache().getSQLParameterMetadata(nsqlqd.getQuery()));
    query.setComment("named native query " + queryName);
    return query;
  }
Ejemplo n.º 4
0
  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);
    q.setComment("TextFlowTargetDAO.getTextFlowTarget");

    return q.list();
  }
Ejemplo n.º 5
0
 protected void applyComment(String comment) {
   query.setComment(comment);
 }