/** * Call ObjectStoreInterMineImpl.precompute() with the given Query. * @param query the query to precompute * @param indexes the index QueryNodes * @param name the name of the query we are precomputing (used for documentation is an exception * is thrown * @throws BuildException if the query cannot be precomputed. */ protected void precompute(Query query, Collection<QueryNode> indexes, String name) { long start = System.currentTimeMillis(); try { ObjectStoreInterMineImpl osInterMineImpl = ((ObjectStoreInterMineImpl) os); if (!osInterMineImpl.isPrecomputed(query, PRECOMPUTE_CATEGORY_TEMPLATE)) { osInterMineImpl.precompute(query, indexes, PRECOMPUTE_CATEGORY_TEMPLATE); } else { LOG.info("Skipping template " + name + " - already precomputed."); } } catch (ObjectStoreException e) { LOG.error("Exception while precomputing query: " + name + ", " + query + " with indexes " + indexes, e); } LOG.info("precompute(indexes) of took " + (System.currentTimeMillis() - start) / 1000 + " seconds for: " + query); }
/** * Call ObjectStoreInterMineImpl.precompute() with the given Query. * @param query the query to precompute * @param indexes the index QueryNodes * @param name the name of the query we are precomputing (used for documentation is an exception * is thrown * @throws BuildException if the query cannot be precomputed. */ protected void precompute(Query query, Collection<QueryNode> indexes, String name) { long start = System.currentTimeMillis(); try { ObjectStoreInterMineImpl osInterMineImpl = ((ObjectStoreInterMineImpl) os); if (!osInterMineImpl.isPrecomputed(query, PRECOMPUTE_CATEGORY_TEMPLATE)) { osInterMineImpl.precompute(query, indexes, PRECOMPUTE_CATEGORY_TEMPLATE); } else { LOG.info("Skipping template " + name + " - already precomputed."); } } catch (ObjectStoreException e) { LOG.error("Exception while precomputing query: " + name + ", " + query + " with indexes " + indexes, e); } LOG.info("precompute(indexes) of took " + (System.currentTimeMillis() - start) / 1000 + " seconds for: " + query); }
/** * Precomputes a template query if it is not already precomputed, returning whether precomputing * was necessary. * * @param t the TemplateQuery to precompute * @return true if the template was not already precomputed * @throws ObjectStoreException if there is a problem precomputing */ public boolean precomputeTemplate(TemplateQuery t) throws ObjectStoreException { List<QueryNode> indexes = new ArrayList<QueryNode>(); Query q = TemplatePrecomputeHelper.getPrecomputeQuery(t, indexes); ObjectStoreInterMineImpl osimi = (ObjectStoreInterMineImpl) os; if (!osimi.isPrecomputed(q, "template")) { osimi.precompute(q, indexes, "template"); return true; } return false; }
/** * Precomputes a template query if it is not already precomputed, returning whether precomputing * was necessary. * * @param t the TemplateQuery to precompute * @return true if the template was not already precomputed * @throws ObjectStoreException if there is a problem precomputing */ public boolean precomputeTemplate(TemplateQuery t) throws ObjectStoreException { List<QueryNode> indexes = new ArrayList<QueryNode>(); Query q = TemplatePrecomputeHelper.getPrecomputeQuery(t, indexes); ObjectStoreInterMineImpl osimi = (ObjectStoreInterMineImpl) os; if (!osimi.isPrecomputed(q, "template")) { osimi.precompute(q, indexes, "template"); return true; } return false; }
@Test public void testIsPrecomputed() throws Exception { Query q = new Query(); QueryClass qc = new QueryClass(Employee.class); QueryField qf = new QueryField(qc,"age"); SimpleConstraint sc = new SimpleConstraint(qf,ConstraintOp.GREATER_THAN,new QueryValue(new Integer(20))); q.addToSelect(qc); q.addFrom(qc); q.setConstraint(sc); Assert.assertFalse(((ObjectStoreInterMineImpl)os).isPrecomputed(q,"template")); ((ObjectStoreInterMineImpl)os).precompute(q, "template"); Assert.assertTrue(((ObjectStoreInterMineImpl)os).isPrecomputed(q,"template")); ObjectStoreBag osb = storeDataWriter.createObjectStoreBag(); storeDataWriter.addToBag(osb, new Integer(5)); Assert.assertTrue(((ObjectStoreInterMineImpl)os).isPrecomputed(q,"template")); storeDataWriter.store(data.get("EmployeeA1")); Assert.assertFalse(((ObjectStoreInterMineImpl)os).isPrecomputed(q,"template")); }