KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > rentacar > centraloffice > services > update > UpdateCentralDBImpl


1 package org.objectweb.rentacar.centraloffice.services.update;
2
3 import java.util.Date JavaDoc;
4 import java.util.HashSet JavaDoc;
5 import java.util.Set JavaDoc;
6
7 import javax.jws.WebMethod;
8 import javax.jws.WebParam;
9 import javax.jws.WebService;
10
11 import org.apache.log4j.Logger;
12 import org.objectweb.rentacar.centraloffice.services.CentralOfficeException;
13 import org.objectweb.rentacar.persistance.bo.Agency;
14 import org.objectweb.rentacar.persistance.bo.Car;
15 import org.objectweb.rentacar.persistance.bo.Contact;
16 import org.objectweb.rentacar.persistance.bo.Reservation;
17 import org.objectweb.rentacar.persistance.dao.AgencyDAO;
18 import org.objectweb.rentacar.persistance.dao.CarDAO;
19 import org.objectweb.rentacar.persistance.dao.ContactDAO;
20 import org.objectweb.rentacar.persistance.dao.DAOException;
21 import org.objectweb.rentacar.persistance.dao.ReservationDAO;
22
23 /**
24  * Services that allow to update central office database state.
25  * @author ofabre
26  *
27  */

28 @WebService
29 public class UpdateCentralDBImpl {
30     
31     private Logger logger = Logger.getLogger(UpdateCentralDBImpl.class);
32     
33     /**
34      * Create a reservation in central office database.
35      * @param reservation The reservation to create
36      * @throws CentralOfficeException
37      */

38     @WebMethod
39     public void addReservationInCentralDB(
40             @WebParam(name="customerId") String JavaDoc customerId,
41             @WebParam(name="carId") String JavaDoc carId,
42             @WebParam(name="startingDate") Date JavaDoc startingDate,
43             @WebParam(name="endingDate") Date JavaDoc endingDate,
44             @WebParam(name="startingAgencyId") String JavaDoc startingAgencyId,
45             @WebParam(name="endingAgencyId") String JavaDoc endingAgencyId)
46     throws CentralOfficeException{
47         
48         logger.info("Central Office . addReservationInCentralDB : "+ customerId+", "+
49                 carId+", "+startingDate.toString()+", "+endingDate.toString()+", "+
50                 startingAgencyId+", "+endingAgencyId);
51         AgencyDAO agencyDAO = AgencyDAO.getInstance();
52         ContactDAO contactDAO = ContactDAO.getInstance();
53         CarDAO carDAO = CarDAO.getInstance();
54         
55         Car car = null;
56         Contact customer = null;
57         Agency startingAgency = null;
58         Agency endingAgency = null;
59         try {
60             car = (Car) carDAO.retrieveById(Car.class, carId);
61             customer = (Contact) contactDAO.retrieveById(Contact.class, customerId);
62             startingAgency = (Agency) agencyDAO.retrieveById(Agency.class, startingAgencyId);
63             endingAgency = (Agency) agencyDAO.retrieveById(Agency.class, endingAgencyId);
64         } catch (DAOException e) {
65             logger.error("Error when retrieving object in database", e);
66             throw new CentralOfficeException("Error when retrieving object in database", e);
67         }
68         Set JavaDoc<Car> cars = new HashSet JavaDoc<Car>();
69         cars.add(car);
70         Reservation reservationBO = new Reservation(customer, cars, startingDate, endingDate, startingAgency, endingAgency);
71         try {
72             ReservationDAO.getInstance().create(reservationBO);
73         } catch (DAOException e1) {
74             logger.error("Error when creating a reservation in central office DB", e1);
75             throw new CentralOfficeException("Error when creating a reservation in central office DB", e1);
76         }
77         
78     }
79     
80 }
81
Popular Tags