Commit 05643b60 authored by Niels Erik G. Nielsen's avatar Niels Erik G. Nielsen
Browse files

Support queries for transformation step associations (tsas)

  i.e. query=transformation.id=1234 or query=step.id=1234
parent 403816f1
......@@ -69,11 +69,12 @@ public class TransformationStepAssociationsResource {
public TransformationStepAssociationsConverter get(
@QueryParam("start") @DefaultValue("0") int start,
@QueryParam("max") @DefaultValue("100") int max) {
@QueryParam("max") @DefaultValue("100") int max,
@QueryParam("query") @DefaultValue("") String query) {
List<TransformationStepAssociation> entities;
EntityQuery qry = new EntityQuery();
EntityQuery qry = new EntityQuery().withQuery( query );
if (max <= 0)
entities = new ArrayList();
entities = new ArrayList<>();
else
entities = dao.retrieve(start, max, qry);
return new TransformationStepAssociationsConverter(entities, context.getAbsolutePath(), start,
......
......@@ -111,20 +111,22 @@ public class TransformationStepAssociationsDAOJPA implements TransformationStepA
EntityManager em = getEntityManager();
EntityTransaction tx = em.getTransaction();
// HACK: Hides database errors but does not crash the Scheduler
List<TransformationStepAssociation> hables = new LinkedList<TransformationStepAssociation>();
List<TransformationStepAssociation> hables = new LinkedList<>();
try {
tx.begin();
String queryString = "select object(o) from TransformationStepAssociation as o" + query.asWhereClause("o");
Query q = em.createQuery("select object(o) from TransformationStepAssociation as o" + query.asWhereClause("o"));
logger.info("Query is: " + queryString);
q.setMaxResults(max);
q.setFirstResult(start);
hables = q.getResultList();
tx.commit();
} catch (Exception ex) {
logger.log(Level.DEBUG, ex);
logger.log(Level.INFO, ex);
try {
tx.rollback();
} catch (Exception e) {
logger.log(Level.DEBUG, e);
logger.log(Level.INFO, e);
}
} finally {
em.close();
......@@ -188,8 +190,7 @@ public class TransformationStepAssociationsDAOJPA implements TransformationStepA
try {
Query query = em.createQuery("select count(o) from TransformationStepAssociation o where o.transformation.id = :id");
query.setParameter("id", id);
int count = ((Long) query.getSingleResult()).intValue();
return count;
return ((Long) query.getSingleResult()).intValue();
} finally {
em.close();
}
......@@ -201,8 +202,7 @@ public class TransformationStepAssociationsDAOJPA implements TransformationStepA
try {
Query query = em.createQuery("select count(o) from TransformationStepAssociation o where o.step.id = :id");
query.setParameter("id", id);
int count = ((Long) query.getSingleResult()).intValue();
return count;
return ((Long) query.getSingleResult()).intValue();
} finally {
em.close();
}
......@@ -210,7 +210,7 @@ public class TransformationStepAssociationsDAOJPA implements TransformationStepA
@Override
public List<TransformationStepAssociationBrief> retrieveBriefs(int start, int max, EntityQuery query) {
List<TransformationStepAssociationBrief> hrefs = new ArrayList<TransformationStepAssociationBrief>();
List<TransformationStepAssociationBrief> hrefs = new ArrayList<>();
for (TransformationStepAssociation hable : retrieve(start, max, query)) {
TransformationStepAssociationBrief href = new TransformationStepAssociationBrief(hable);
hrefs.add(href);
......@@ -228,9 +228,8 @@ public class TransformationStepAssociationsDAOJPA implements TransformationStepA
public int getCount(EntityQuery entityQuery) {
EntityManager em = getEntityManager();
try {
Query query = em.createQuery("select count(o) from TransformationStepAssociation o");
int count = ((Long) query.getSingleResult()).intValue();
return count;
Query query = em.createQuery("select count(o) from TransformationStepAssociation o " + entityQuery.asWhereClause("o"));
return ((Long) query.getSingleResult()).intValue();
} finally {
em.close();
}
......@@ -245,7 +244,7 @@ public class TransformationStepAssociationsDAOJPA implements TransformationStepA
@Override
public List<TransformationStepAssociationBrief> retrieveBriefs(int start,
int max, String sortKey, boolean asc, EntityQuery query) {
return retrieveBriefs(start, max, sortKey, asc, query);
return retrieveBriefs(start, max, query);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment