...

/

Develop the Business Service Tier

Develop the Business Service Tier

Let's see how the business service can be developed for a class table inheritance scenario.

“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 )
@Transactional
public class EmployeeServiceImplTest {
@Autowired
private EmployeeService service;
@Test
public 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
@Transactional
public class EmployeeServiceImpl implements EmployeeService {
@Autowired
private EmployeeDao employeeDao;
@Autowired
private EmployeeMapper employeeMapper;
@Override
public 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 ...