FlowRepositoryImpl extends HibernateDaoSupport implements FlowRepository { @Override public Flow lock(Long id) { try { return (Flow) getHibernateTemplate().load(Flow.class, id, LockMode.UPGRADE); } catch (HibernateObjectRetrievalFailureException e) { throw new FlowException("no flow with id " + id); } } FlowRepositoryImpl(); @Override void initDao(); @Override void persist(Flow flow); @Override void merge(Flow flow); @Override void remove(Flow flow); @Override Flow find(Long id); @Override Flow lock(Long id); @Override int purgeFlows(FlowPurgeCriteria purgeCriteria); @Override @SuppressWarnings("unchecked") List<Flow> findFlows(final FlowFinderCriteria finderCriteria); @Override @SuppressWarnings("unchecked") List<Flow> findErrorFlows(final FlowFinderCriteria finderCriteria); @Override @SuppressWarnings("unchecked") List<Flow> findUnackFlows(final FlowFinderCriteria finderCriteria); @Override @SuppressWarnings("unchecked") List<Long> findFlowIds(final FlowFinderCriteria finderCriteria); @Override @SuppressWarnings("unchecked") List<Long> findErrorFlowIds(final FlowFinderCriteria finderCriteria); @Override @SuppressWarnings("unchecked") List<Long> findUnackFlowIds(final FlowFinderCriteria finderCriteria);  }
@Test public void testLock() throws Exception { Flow flow = createFlow("blah"); flowRepository.persist(flow); Long id = flow.getIdentifier(); testTransactionManager.commitTransaction(); testTransactionManager.beginTransaction(); try { flowRepository.lock(0L); fail("found non-existing flow"); } catch (FlowException e) { } flow = flowRepository.lock(id); flow.setAckCountExpected(111); testTransactionManager.commitTransaction(); testTransactionManager.beginTransaction(); flow = flowRepository.find(id); assertEquals(111, flow.getAckCountExpected()); }