Develop the Business Service Tier
Let's see how the business service can be developed for a class table inheritance scenario.
We'll cover the following...
“Find all records” operation
We will proceed with the test for the “find all records” operation.
Press + to interact
@RunWith( SpringJUnit4ClassRunner.class )@ContextConfiguration( locations = { "classpath:context.xml" } )@TransactionConfiguration( defaultRollback = true )@Transactionalpublic class EmployeeServiceImplTest {@Autowiredprivate EmployeeService service;@Testpublic void testFindAll() {Assert.assertEquals(0L, service.findAll().size());}}
Let’s look at how to code the corresponding “find all records” method in the business service.
Press + to interact
@Service@Transactionalpublic class EmployeeServiceImpl implements EmployeeService {@Autowiredprivate EmployeeDao employeeDao;@Autowiredprivate EmployeeMapper employeeMapper;@Overridepublic List<EmployeeDto> findAll() {List<Employee> employees = employeeDao.getAll();List<EmployeeDto> employeeDtos = new ArrayList<EmployeeDto>();for(Employee employee : employees){employeeDtos.add(employeeMapper.mapEntityToDto(employee));}return employeeDtos;}}
Mappers
The mapper has two main operations which are used to convert data access ...