/** * Returns a collection of bounds for reactions included in the given's model metabolism. Note * that it has to be a sum of bounds of the parent model (if the given model has a parent) and the * bounds directly associated with current model. * * @param model * @return collection of bounds for the given model */ Collection<EBounds> getBoundsForModel(EModel model, EntityManager em) { if (model.getParent() == null) { return model.getEBoundsCollection(); } else { /* * There are two sources of bounds for each model. * First, we retrieve bounds that have been defined for this model */ List<EBounds> res1 = em.createQuery("SELECT e FROM EBounds e WHERE e.model = :model") .setParameter("model", model) .getResultList(); /* * The remaining bounds are taken from the parent model */ List<EBounds> res2 = em.createQuery( " SELECT b FROM EModel m, EBounds b WHERE " + " m.id = :modelID AND m.parent IS NOT NULL AND " + " b.model = m.parent AND NOT EXISTS (SELECT c " + " FROM EBounds c WHERE c.model = :model AND " + " b.reaction = c.reaction )") .setParameter("modelID", model.getId()) .setParameter("model", model) .getResultList(); res1.addAll(res2); return res1; } }
/** * Returns list of all models from database that are ancestors of a given model (transitive * closure version). * * @return - list of all ancestors of a given model (including that model). */ public List<EModel> getAncestorsModels(EModel start) { EntityManager em = getEntityManager(); try { em.getTransaction().begin(); // List<EModel> allModels = (List<EModel>) em.createQuery("select m from EModel as // m").getResultList(); EModel model = start; List<EModel> result = new LinkedList<EModel>(); // assume that the start model is really a model from the database result.add(model); // transitive closure while (model.getParent() != null) { result.add(model.getParent()); model = model.getParent(); } em.getTransaction().commit(); return result; } finally { em.close(); } }