To use Spring Data JPA's repository abstraction, we also need to define the ContactRepository
interface, which extends Spring Data Common's CrudRepository<T,ID extends Serializable> interface.
Listing 13-7 shows the ContactRepository interface.
Listing 13-7. The ContactRepository Class
package com.apress.prospring3.ch13.repository;
import org.springframework.data.repository.CrudRepository;
import com.apress.prospring3.ch13.domain.Contact;
public interface ContactRepository extends CrudRepository<Contact, Long> {
}
As shown in Listing 13-7, no additional method is required, because those methods provided by the
CrudRepositoy interface already are sufficient for the examples in this chapter.
Finally, let's take a look at the ContactService interface, which defines all the business logic in
relation to the Contact entity class. Listing 13-8 shows the ContactService interface.
Listing 13-8. The ContactService Interface
package com.apress.prospring3.ch13.service;
import java.util.List;
import com.apress.prospring3.ch13.domain.Contact;
public interface ContactService {
public List<Contact> findAll();
public Contact findById(Long id);
public Contact save(Contact contact);
public long countAll();
}
All methods are self-explanatory. In the next section, we will discuss how to implement transaction
management in various ways by implementing the ContactService interface.
Declarative and Programmatic Transactions with Spring
In Spring, there are three options for transaction management. Two of them are for declarative
transaction management, with one using Java annotations and the other using XML configuration. The
third option is managing transactions programmatically. We will go through the three of them one by
one in the following sections.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home