Develop the Business Service Tier
Let's see how the business service can be developed for a one-to-many unidirectional relationship scenario.
We'll cover the following...
We will now jump to the business service tier.
Find all records operation
First, examine the test for the “fetch all records” operation.
Press + to interact
@RunWith( SpringJUnit4ClassRunner.class )@ContextConfiguration( locations = { "classpath:context.xml" } )@TransactionConfiguration( defaultRollback = true )@Transactionalpublic class PersonServiceImplTest {@Autowiredprivate PersonService service;@Testpublic void testFindAll(){Assert.assertEquals(0L, service.findAll().size());}}
Then, look at how to program the equivalent method in the business service.
Press + to interact
@Service@Transactionalpublic class PersonServiceImpl implements PersonService{@Autowiredprivate PersonDao dao;@Autowiredprivate PersonMapper mapper;@Overridepublic List<PersonDto> findAll() {List<Person> persons = dao.getAll();List<PersonDto> personDtos = new ArrayList<PersonDto>();if(null !=persons){for(Person person : persons){personDtos.add(mapper.mapEntityToDto(person));}}return personDtos;}}
Mappers
As shown previously, we have a mapper for converting data access objects into entities and vice-versa. This has two operations displayed in the following code. Note that the Phone
identifier is generated every ...