ObjectStoreTranslatingImpl extends ObjectStoreAbstractImpl { @Override public List<ResultsRow<Object>> execute(Query q, int start, int limit, boolean optimise, boolean explain, Map<Object, Integer> sequence) throws ObjectStoreException { long time1 = System.currentTimeMillis(); Query q2 = translateQuery(q); long time2 = System.currentTimeMillis(); timeSpentQuery += time2 - time1; List<ResultsRow<Object>> results = new ArrayList<ResultsRow<Object>>(); List<ResultsRow<Object>> origResults = os.execute(q2, start, limit, optimise, explain, sequence); time1 = System.currentTimeMillis(); timeSpentExecute += time1 - time2; try { for (ResultsRow<Object> origRow : origResults) { ResultsRow<Object> row = new ResultsRow<Object>(); for (Object o : origRow) { if (o instanceof InterMineObject) { Object imo = translator.translateFromDbObject(o); row.add(imo); if (imo instanceof InterMineObject) { cacheObjectById(((InterMineObject) imo).getId(), (InterMineObject) imo); } objectCount++; } else { row.add(o); } } results.add(row); } } catch (MetaDataException e) { throw new ObjectStoreException(e); } time2 = System.currentTimeMillis(); timeSpentTranslate += time2 - time1; queryCount++; if (queryCount % 10000 == 0) { LOG.info("Translated " + queryCount + " queries, " + objectCount + " objects. Time" + " spent: Translate query: " + timeSpentQuery + ", Execute: " + timeSpentExecute + ", Translate objects: " + timeSpentTranslate); } return results; } ObjectStoreTranslatingImpl(Model model, ObjectStore os, Translator translator); static ObjectStoreTranslatingImpl getInstance(String osAlias, Properties props); Translator getTranslator(); @Override List<ResultsRow<Object>> execute(Query q, int start, int limit, boolean optimise,
            boolean explain, Map<Object, Integer> sequence); @Override ResultsInfo estimate(Query q); @Override int count(Query q, Map<Object, Integer> sequence); @Override T getObjectByExample(T o, Set<String> fieldNames); @Override Collection<T> getObjectsByExample(T o, Set<String> fs); @Override boolean isMultiConnection(); @Override Set<Object> getComponentsForQuery(Query q); @Override InterMineObject internalGetObjectById(Integer id,
            Class<? extends InterMineObject> clazz); @Override Integer getSerial();  }
@Test public void testTranslation() throws Exception { ObjectStore os2 = new ObjectStoreTranslatingImpl( Model.getInstanceByName("testmodel"), ObjectStoreFactory.getObjectStore("os.unittest"), new CompanyTranslator()); Query q = new Query(); QueryClass qc = new QueryClass(InterMineObject.class); q.addToSelect(qc); q.addFrom(qc); Results res = os2.execute(q); Assert.assertEquals(2, res.size()); Assert.assertEquals("CompanyA", ((Bank) ((ResultsRow) res.get(0)).get(0)).getName()); Assert.assertEquals("CompanyB", ((Bank) ((ResultsRow) res.get(1)).get(0)).getName()); }