EmpireWorkflowMaterialDao extends EmpireDao implements WorkflowMaterialDao { @Override public Job findJob(Material m) { DBCommand cmd = db.createCommand(); cmd.select(db.tableWorkflowJob.getColumns()); cmd.selectDistinct(); cmd.join(db.tableWorkflowMaterialInTask.taskId, db.tableWorkflowTask.id); cmd.join(db.tableWorkflowTask.jobId, db.tableWorkflowJob.id); cmd.where(db.tableWorkflowMaterialInTask.materialId.is(m.getId())); DBReader reader = new DBReader(); try { reader.open(cmd, getConnection()); for (Iterator<DBRecordData> it = reader.iterator(1); it.hasNext();) { DBRecordData rec = it.next(); Job job = new Job(); rec.getBeanProperties(job); return job; } return null; } finally { reader.close(); } } EmpireWorkflowMaterialDao(ProarcDatabase db); @Override T create(MaterialType type); @Override T find(BigDecimal id); @Override Job findJob(Material m); @Override List<MaterialView> view(MaterialFilter filter); @Override void update(Material m); @Override void addTaskReference(Material m, Task t, Way way);  }
@Test public void testFindJob() throws Exception { IDataSet db = database( support.loadFlatXmlDataStream(getClass(), "user.xml"), support.loadFlatXmlDataStream(getClass(), "wf_job.xml"), support.loadFlatXmlDataStream(getClass(), "wf_task.xml"), support.loadFlatXmlDataStream(getClass(), "wf_material.xml") ); support.cleanInsert(support.getConnection(tx), db); tx.commit(); Material m = new Material(); m.setId(BigDecimal.ONE); Job job = dao.findJob(m); assertNotNull(job); assertEquals(BigDecimal.ONE, job.getId()); }