KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > rentacar > persistance > dao > ContactDAO


1 package org.objectweb.rentacar.persistance.dao;
2
3 import org.objectweb.rentacar.persistance.bo.Address;
4 import org.objectweb.rentacar.persistance.bo.Contact;
5
6 /**
7  *
8  * @author ofabre
9  *
10  */

11 public class ContactDAO extends GenericDAO {
12     
13     private static ContactDAO theInstance;
14     
15     private ContactDAO(){
16         
17     }
18     
19     public static synchronized ContactDAO getInstance() {
20         if (null == theInstance) {
21             theInstance = new ContactDAO();
22         }
23         return theInstance;
24     }
25     
26     /**
27      * Udates the contact address, deleting the old address
28      * @param contactId Id of the contact
29      * @param newAddress New address of the contact
30      * @throws DAOException
31      */

32     public void updateContactAddress(String JavaDoc contactId, Address newAddress) throws DAOException {
33         Contact contact = null;
34         
35         contact = (Contact)retrieveById(Contact.class, contactId);
36         
37         Address oldAddress = contact.getAddress();
38         
39         contact.setAddress(newAddress);
40         
41         update(contact);
42         
43         delete(oldAddress);
44         
45     }
46
47 }
48
Popular Tags