Develop the Business Service Tier
Let's see how the business service can be developed for a many-to-many self-referencing relationship with a join-attribute scenario.
We'll cover the following...
In this lesson, we will move to the business service tier.
“Find all records” operation
First, we will review the test to find all records.
Press + to interact
@RunWith( SpringJUnit4ClassRunner.class )@ContextConfiguration( locations = { "classpath:context.xml" } )@TransactionConfiguration( defaultRollback = true )@Transactionalpublic class WorkerWorkerServiceImplTest {@Autowiredprivate WorkerService workerService;@Autowiredprivate WorkerWorkerService workerWorkerService;@Testpublic void testFindAll() {Assert.assertEquals(0L, workerWorkerService.findAll().size());}}
Let’s examine how to program the related method in the business tier.
Press + to interact
@Service@Transactionalpublic class WorkerWorkerServiceImpl implements WorkerWorkerService {@Autowiredprivate WorkerDao workerDao;@Autowiredprivate WorkerMapper workerMapper;@Autowiredprivate WorkerWorkerDao workerWorkerDao;@Overridepublic List<WorkerWorkerDto> findAll() {List<WorkerWorkerDto> workerWorkerDtos = new ArrayList<WorkerWorkerDto>();List<WorkerWorker> workerList = workerWorkerDao.getAll();for(WorkerWorker workerWorker : workerList) {WorkerWorkerDto workerWorkerDto = new WorkerWorkerDto();workerWorkerDto.setWorkerId1(workerMapper.mapEntityToDto(workerWorker.getWorker1()));workerWorkerDto.setWorkerId2(workerMapper.mapEntityToDto(workerWorker.getWorker2()));workerWorkerDto.setRelationshipType(workerWorker.getRelationshipType());workerWorkerDtos.add(workerWorkerDto);}return workerWorkerDtos;}}