...

/

Develop the Business Service Tier

Develop the Business Service Tier

Let's see how the business service can be developed for a one-to-one bi-directional relationship scenario.

Find all records operation

To develop the business service tier, first look at the test for the “fetching all records” operation.

Press + to interact
@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath:context.xml" } )
@TransactionConfiguration( defaultRollback = true )
@Transactional
public class CustomerServiceImplTest {
@Autowired
private CustomerService service ;
@Test
public void testFindAll() {
Assert.assertEquals(0L, service.findAll().size());
}
}

Code the identical method in the business service by retrieving all the records using the data access operation and converting the entity to data transfer objects using the mapper.

Press + to interact
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService{
@Autowired
private CustomerDao dao ;
@Autowired
private CustomerMapper mapper ;
@Override
public List<CustomerDto> findAll() {
List<CustomerDto> customerDtos = new ArrayList<CustomerDto>();
List<Customer> customers = dao.getAll();
for(Customer customer:customers){
customerDtos.add(mapper.mapEntityToDto(customer));
}
return customerDtos;
}
}

Mappers

The business service tier uses data access objects, but the data access tier uses ...