Example usage for org.hibernate Query setComment

List of usage examples for org.hibernate Query setComment

Introduction

In this page you can find the example usage for org.hibernate Query setComment.

Prototype

Query<R> setComment(String comment);

Source Link

Document

Set the comment for this query.

Usage

From source file:com.mysema.query.jpa.hibernate.AbstractHibernateQuery.java

License:Apache License

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);//from ww w .  j  av a  2 s .  co m
    }
    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;
}

From source file:com.querydsl.jpa.hibernate.AbstractHibernateQuery.java

License:Apache License

private Query createQuery(@Nullable QueryModifiers modifiers, boolean forCount) {
    JPQLSerializer serializer = serialize(forCount);
    String queryString = serializer.toString();
    logQuery(queryString, serializer.getConstantToLabel());
    Query query = session.createQuery(queryString);
    HibernateUtil.setConstants(query, serializer.getConstantToLabel(), getMetadata().getParams());
    if (fetchSize > 0) {
        query.setFetchSize(fetchSize);/*from w ww .  j  a v  a 2 s  .c  o  m*/
    }
    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()) {
        Integer limit = modifiers.getLimitAsInteger();
        Integer offset = modifiers.getOffsetAsInteger();
        if (limit != null) {
            query.setMaxResults(limit);
        }
        if (offset != null) {
            query.setFirstResult(offset);
        }
    }

    // set transformer, if necessary
    Expression<?> projection = getMetadata().getProjection();
    if (!forCount && projection instanceof FactoryExpression) {
        query.setResultTransformer(new FactoryExpressionTransformer((FactoryExpression<?>) projection));
    }
    return query;
}

From source file:com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskDAS.java

License:Open Source License

public List<PluggableTaskDTO> findAllByEntity(Integer entityId) {
    Query query = getSession().createQuery(findAllByEntitySQL);
    query.setParameter("entity", entityId);
    query.setCacheable(true);/*from  w  w  w .j  a v a2 s. co m*/
    query.setComment("PluggableTaskDAS.findAllByEntity");
    return query.list();
}

From source file:com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskDAS.java

License:Open Source License

public PluggableTaskDTO findByEntityType(Integer entityId, Integer typeId) {
    Query query = getSession().createQuery(findByEntityTypeSQL);
    query.setCacheable(true);//from w ww.ja  v  a 2 s.co  m
    query.setParameter("entity", entityId);
    query.setParameter("type", typeId);
    query.setComment("PluggableTaskDAS.findByEntityType");
    return (PluggableTaskDTO) query.uniqueResult();
}

From source file:com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskDAS.java

License:Open Source License

public PluggableTaskDTO findByEntityCategoryOrder(Integer entityId, Integer categoryId,
        Integer processingOrder) {
    Query query = getSession().createQuery(findByEntityCategoryOrderSQL);
    query.setCacheable(true);/*from  w  w  w  .  j  a v a2s. c o  m*/
    query.setParameter("entity", entityId);
    query.setParameter("category", categoryId);
    query.setParameter("pr_order", processingOrder);
    query.setComment("PluggableTaskDAS.findByEntityTypeOrder");
    return (PluggableTaskDTO) query.uniqueResult();
}

From source file:com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskDAS.java

License:Open Source License

public List<PluggableTaskDTO> findByEntityCategory(Integer entityId, Integer categoryId) {
    List<PluggableTaskDTO> ret = (List<PluggableTaskDTO>) cache
            .getFromCache("PluggableTaskDTO" + entityId + "+" + categoryId, cacheModel);
    if (ret == null) {
        Query query = getSession().createQuery(findByEntityCategorySQL);
        query.setCacheable(true);//  www  . j av  a 2 s .c  om
        query.setParameter("entity", entityId);
        query.setParameter("category", categoryId);
        query.setComment("PluggableTaskDAS.findByEntityCategory");

        ret = query.list();
        cache.putInCache("PluggableTaskDTO" + entityId + "+" + categoryId, cacheModel, ret);
    }
    return ret;
}

From source file:com.sapienter.jbilling.server.pluggableTask.admin.PluggableTaskTypeDAS.java

License:Open Source License

public List<PluggableTaskTypeDTO> findAllByCategory(Integer categoryId) {
    LOG.debug("finding types for category " + categoryId);
    Query query = getSession().createQuery(findByCategorySQL);
    query.setParameter("category", categoryId);
    query.setComment("PluggableTaskTypeDAS.findAllByCategory");
    List<PluggableTaskTypeDTO> ret = query.list();
    LOG.debug("found " + ret.size());

    return ret;/*w  ww . ja v a  2s . c o  m*/
}

From source file:com.sapienter.jbilling.server.user.db.CreditCardDAS.java

License:Open Source License

public List<Integer> findByLastDigits(Integer entityId, String plain) {
    Query query = getSession().createQuery(findByLastDigits);
    query.setParameter("entity", entityId);
    query.setParameter("plain", plain);
    query.setComment("CreditCardDAS.findByLastDigits " + entityId + " " + plain);
    return query.list();
}

From source file:com.sapienter.jbilling.server.user.db.CreditCardDAS.java

License:Open Source License

public List<String> findByNumber(String number) {
    Query query = getSession().createQuery(findByCreditCard);
    query.setParameter("number", number);
    query.setComment("CreditCardDAS.findByCreditCard " + number);
    return query.list();
}

From source file:org.jboss.seam.wiki.plugin.basic.DirTocQuery.java

License:LGPL

public NestedSetNodeWrapper<WikiDirectory> getTocRoot(WikiPluginMacro macro) {

    NestedSetNodeWrapper<WikiDirectory> tocRoot = (NestedSetNodeWrapper<WikiDirectory>) macro.getAttributes()
            .get(MACRO_ATTR_TOCROOT);/*from  w ww  . java  2 s  . c  o m*/
    if (tocRoot == null) {
        DirTocPreferences prefs = Preferences.instance().get(DirTocPreferences.class, macro);

        if (prefs.getRootDocumentLink() != null) {
            Long id = ((WikiLinkResolver) Component.getInstance("wikiLinkResolver"))
                    .resolveWikiDirectoryId(currentDirectory.getAreaNumber(), prefs.getRootDocumentLink());
            WikiDirectory foundDir = WikiNodeDAO.instance().findWikiDirectory(id);
            if (foundDir != null)
                currentDirectory = foundDir;
        }

        // Query the directory tree
        tocRoot = WikiNodeDAO.instance().findWikiDirectoryTree(currentDirectory);

        Set<Long> directoryIds = new HashSet<Long>(tocRoot.getFlatTree().keySet());
        if (prefs.getShowRootDocuments() != null && prefs.getShowRootDocuments()) {
            directoryIds.add(tocRoot.getWrappedNode().getId());
        }
        if (directoryIds.size() == 0)
            return null; // Early exit

        // Now query the documents for the directories in the tree
        StringBuilder queryString = new StringBuilder();
        queryString.append("select d from WikiDocument d ");
        // TODO: Rewrite this query to use a subselect nested set query, this has limits
        queryString.append("where d.parent.id in (:directories) ");
        if (prefs.getWithHeaderMacro() != null)
            queryString.append("and d.headerMacrosString like :headerMacro").append(" ");
        queryString.append("order by d.createdOn asc");

        Query query = getSession().createQuery(queryString.toString());
        query.setParameterList("directories", directoryIds);
        if (prefs.getWithHeaderMacro() != null)
            query.setParameter("headerMacro", "%" + prefs.getWithHeaderMacro() + "%");
        query.setComment("retrieving documents for toc directory tree");

        List<WikiDocument> flatDocs = query.list();

        // Now attach the documents as payloads to the directories in the tree
        for (WikiDocument flatDoc : flatDocs) {

            Long directoryId = flatDoc.getParent().getId();
            NestedSetNodeWrapper<WikiDirectory> dirWrapper;

            if (prefs.getShowRootDocuments() != null && prefs.getShowRootDocuments()
                    && directoryId.equals(tocRoot.getWrappedNode().getId())) {
                dirWrapper = tocRoot;
            } else {
                dirWrapper = tocRoot.getFlatTree().get(directoryId);
            }

            if (dirWrapper.getPayload() == null)
                dirWrapper.setPayload(new ArrayList<WikiDocument>());

            ((Collection) dirWrapper.getPayload()).add(flatDoc);
        }

        macro.getAttributes().put(MACRO_ATTR_TOCROOT, tocRoot);
    }

    return tocRoot;
}