Search in sources :

Example 1 with QueryParser

use of com.haulmont.cuba.core.global.QueryParser in project cuba by cuba-platform.

the class PersistenceManager method jpqlLoadList.

@Authenticated
@Override
public String jpqlLoadList(String queryString) {
    try {
        Transaction tx = persistence.createTransaction();
        try {
            EntityManager em = persistence.getEntityManager();
            Query query = em.createQuery(queryString);
            QueryParser parser = QueryTransformerFactory.createParser(queryString);
            Set<String> paramNames = parser.getParamNames();
            for (String paramName : paramNames) {
                security.setQueryParam(query, paramName);
            }
            List resultList = query.getResultList();
            tx.commit();
            StrBuilder sb = new StrBuilder();
            for (Object element : resultList) {
                if (element instanceof Object[]) {
                    sb.appendWithSeparators((Object[]) element, " | ");
                } else {
                    sb.append(element);
                }
                sb.append("\n");
            }
            return sb.toString();
        } finally {
            tx.end();
        }
    } catch (Throwable e) {
        log.error("jpqlLoadList error", e);
        return ExceptionUtils.getStackTrace(e);
    }
}
Also used : QueryParser(com.haulmont.cuba.core.global.QueryParser) List(java.util.List) StrBuilder(org.apache.commons.lang.text.StrBuilder) Authenticated(com.haulmont.cuba.security.app.Authenticated)

Aggregations

QueryParser (com.haulmont.cuba.core.global.QueryParser)1 Authenticated (com.haulmont.cuba.security.app.Authenticated)1 List (java.util.List)1 StrBuilder (org.apache.commons.lang.text.StrBuilder)1