Search⌘ K
AI Features

Develop the Business Service Tier

Explore how to develop the business service tier by implementing key operations such as find, create, edit, and remove records using class table inheritance in Java Spring. Understand how to map data access objects to entities and integrate service methods with the data access tier for effective database management.

“Find all records” operation

We will proceed with the test for the “find all records” operation.

Java
@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.

Java
@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 ...