KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.objectweb.rentacar.persistance.dao;
2
3 import java.util.Set JavaDoc;
4
5 import org.objectweb.rentacar.persistance.bo.Agency;
6 import org.objectweb.rentacar.persistance.bo.CentralOffice;
7
8 /**
9  * @author ofabre
10  */

11 public class CentralOfficeDAO extends GenericDAO {
12
13     private static CentralOfficeDAO theInstance;
14
15     private CentralOfficeDAO() {
16
17     }
18
19     public static synchronized CentralOfficeDAO getInstance() {
20         if (null == theInstance) {
21             theInstance = new CentralOfficeDAO();
22         }
23         return theInstance;
24     }
25
26     /**
27      * Update the agency set of a central office following the best practice given by
28      * Hibernate
29      * @param agencyId
30      * @param newCars
31      * @throws DAOException
32      */

33     public void updateCentralOfficeAgencies(String JavaDoc centralOfficeId, Set JavaDoc<Agency> newAgencies) throws DAOException {
34
35         CentralOffice centralOffice = null;
36
37         centralOffice = (CentralOffice) retrieveById(CentralOffice.class, centralOfficeId);
38
39         centralOffice.getAgencies().clear();
40         centralOffice.getAgencies().addAll(newAgencies);
41
42         update(centralOffice);
43     }
44
45     /**
46      * Return a central office
47      * @param centralOfficeId
48      * @return central office
49      * @throws DAOException
50      */

51     public CentralOffice getCentralOffice(String JavaDoc centralOfficeId) throws DAOException {
52         return (CentralOffice) retrieveById(CentralOffice.class, centralOfficeId);
53     }
54
55 }
56
Popular Tags