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);
}
}
Aggregations