Develop the Business Service Tier
Let's see how the business service can be developed for a one-to-one bi-directional relationship with a join attribute scenario.
We'll cover the following...
We will shift 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 ManuscriptAuthorServiceImplTest {@Autowiredprivate ManuscriptService manuscriptService;@Autowiredprivate AuthorService authorService;@Autowiredprivate ManuscriptAuthorService manuscriptAuthorService;@Testpublic void testFindAll() {Assert.assertEquals(0L, manuscriptAuthorService.findAll().size());}}
Let’s review how to code a similar method in the business service.
Press + to interact
@Service@Transactionalpublic class ManuscriptAuthorServiceImpl implements ManuscriptAuthorService {@Autowiredprivate ManuscriptDao manuscriptDao;@Autowiredprivate ManuscriptMapper manuscriptMapper;@Autowiredprivate AuthorDao authorDao;@Autowiredprivate AuthorMapper authorMapper;@Autowiredprivate ManuscriptAuthorDao manuscriptAuthorDao;@Overridepublic List<ManuscriptAuthorDto> findAll() {List<ManuscriptAuthorDto> manuscriptAuthorDtos = new ArrayList<ManuscriptAuthorDto>();List<ManuscriptAuthor> manuscriptList = manuscriptAuthorDao.getAll();for(ManuscriptAuthor manuscriptAuthor : manuscriptList) {ManuscriptAuthorDto manuscriptAuthorDto = new ManuscriptAuthorDto();manuscriptAuthorDto.setManuscriptDto(manuscriptMapper.mapEntityToDto(manuscriptAuthor.getManuscript()));manuscriptAuthorDto.setAuthorDto(authorMapper.mapEntityToDto(manuscriptAuthor.getAuthor()));manuscriptAuthorDto.setPublisher(manuscriptAuthor.getPublisher());manuscriptAuthorDtos.add(manuscriptAuthorDto);}return manuscriptAuthorDtos;}}
Create operation
Let’s move on to the ...