...

/

Develop the Business Service Tier

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.

@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath:context.xml" } )
@TransactionConfiguration( defaultRollback = true )
@Transactional
public class WorkerWorkerServiceImplTest {
@Autowired
private WorkerService workerService;
@Autowired
private WorkerWorkerService workerWorkerService;
@Test
public void testFindAll() {
Assert.assertEquals(0L, workerWorkerService.findAll().size());
}
}

Let’s examine how to program the related method in the business tier.

@Service
@Transactional
public class WorkerWorkerServiceImpl implements WorkerWorkerService {
@Autowired
private WorkerDao workerDao;
@Autowired
private WorkerMapper workerMapper;
@Autowired
private WorkerWorkerDao workerWorkerDao;
@Override
public 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;
}
}

Create operation

Let’s move on to the ...