throw new Exception("Cannot open entityManager.");
}
if (etx != null && !etx.isActive()) {
etx.begin();
}
CustomJPAQuery query = jpaQuery.getQuery().clone(em);
if (distinct != null && distinct.equals(Boolean.TRUE)) {
query = query.distinct();
}
Object result;
if (singleResult == null || singleResult.equals(Boolean.FALSE)) {
if (maxRes != 0) {
if (!returnCount) {
result = query.limit(maxRes).list(jpaQuery.getBasePath());
} else {
JPACountQueryResult queryResult = new JPACountQueryResult();
queryResult.setResult(query.limit(maxRes).list(jpaQuery.getBasePath()));
queryResult.setCount(query.count());
result = queryResult;
}
} else {
result = query.list(jpaQuery.getBasePath());
}
} else {
result = query.uniqueResult(jpaQuery.getBasePath());
}
if (etx != null && etx.isActive()) {
etx.commit();
}
return result;