FlyBasePostProcess extends PostProcessor { public void postProcess() throws ObjectStoreException { Query q = new Query(); q.setDistinct(false); ConstraintSet cs = new ConstraintSet(ConstraintOp.AND); QueryClass qcGene = new QueryClass(Gene.class); q.addFrom(qcGene); q.addToSelect(qcGene); q.addToOrderBy(qcGene); QueryClass qcTranscript = new QueryClass(Transcript.class); q.addFrom(qcTranscript); q.addToSelect(qcTranscript); q.addToOrderBy(qcTranscript); QueryCollectionReference geneTrans = new QueryCollectionReference(qcGene, "transcripts"); cs.addConstraint(new ContainsConstraint(geneTrans, ConstraintOp.CONTAINS, qcTranscript)); QueryClass qcIntrons = new QueryClass(Intron.class); q.addFrom(qcIntrons); q.addToSelect(qcIntrons); q.addToOrderBy(qcIntrons); QueryCollectionReference introns = new QueryCollectionReference(qcTranscript, "introns"); cs.addConstraint(new ContainsConstraint(introns, ConstraintOp.CONTAINS, qcIntrons)); q.setConstraint(cs); ObjectStore os = osw.getObjectStore(); ((ObjectStoreInterMineImpl) os).precompute(q, Constants.PRECOMPUTE_CATEGORY); Results res = os.execute(q, 500, true, true, true); int count = 0; Gene lastGene = null; Set<Intron> newCollection = new HashSet<Intron>(); osw.beginTransaction(); Iterator<?> resIter = res.iterator(); while (resIter.hasNext()) { ResultsRow<?> rr = (ResultsRow<?>) resIter.next(); Gene thisGene = (Gene) rr.get(0); Intron intron = (Intron) rr.get(2); if (lastGene == null || !thisGene.getId().equals(lastGene.getId())) { if (lastGene != null) { Gene tempGene; try { tempGene = PostProcessUtil.cloneInterMineObject(lastGene); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to clone InterMineObject: " + lastGene, e); } tempGene.setFieldValue("introns", newCollection); osw.store(tempGene); count++; } newCollection = new HashSet<Intron>(); } newCollection.add(intron); lastGene = thisGene; } if (lastGene != null) { Gene tempGene; try { tempGene = PostProcessUtil.cloneInterMineObject(lastGene); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to clone InterMineObject: " + lastGene, e); } tempGene.setFieldValue("introns", newCollection); osw.store(tempGene); count++; } osw.commitTransaction(); } FlyBasePostProcess(ObjectStoreWriter osw); void postProcess();  }
@Test public void testPostProcess() throws Exception { FlyBasePostProcess fb = new FlyBasePostProcess(osw); fb.postProcess(); Gene resGene = (Gene) getFromDb(Gene.class).iterator().next(); assertEquals(2, resGene.getIntrons().size()); }