Listing 11-50. deleteContact Operation for ContactMapper.xml File
<delete id="deleteContact" parameterType="long">
DELETE FROM CONTACT WHERE ID = #{id}
</delete>
There's just one thing new here, where the <delete> tag was used to indicate a delete operation.
Listings 11-51 and 11-52 show the ContactTelDetailMapper interface (with the new
deleteTelDetailForContact() method) and the ContactTelDetailMapper.xml mapping file, respectively.
Listing 11-51. The ContactTelDetailMapper Interface
package com.apress.prospring3.ch11.persistence;
import java.util.List;
import com.apress.prospring3.ch11.domain.ContactTelDetail;
public interface ContactTelDetailMapper {
public List<ContactTelDetail> selectTelDetailForContact(Long contactId);
public void insertContactTelDetail(ContactTelDetail contactTelDetail);
public void updateContactTelDetail(ContactTelDetail contactTelDetail);
public void deleteOrphanContactTelDetail(List<Long> ids);
void deleteTelDetailForContact(Long contactId);
}
Listing 11-52. The ContactTelDetailMapper.xml Mapping File
<delete id="deleteTelDetailForContact" parameterType="long">
DELETE FROM CONTACT_TEL_DETAIL WHERE CONTACT_ID = #{contactId}
</delete>
For the ContactHobbyDetailMapper interface, we don't need to add new operation, because the
operation for deleting the hobby mappings for a contact was already implemented in the update
operation.
Now we can proceed to implement the delete() method in the ContactServiceImpl class. Listing
11-53 shows the code snippet.
Listing 11-53. Implementing the Delete Operation
// Other codes omitted
public void delete(Contact contact) {
Long contactId = contact.getId();
contactTelDetailMapper.deleteTelDetailForContact(contactId);
contactHobbyDetailMapper.deleteHobbyDetailForContact(contactId);
contactMapper.deleteContact(contactId);
}
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home