01: package projectmanagement.business.customer;
02:
03: import projectmanagement.business.ProjectManagementBusinessException;
04: import projectmanagement.data.customer.*;
05: import com.lutris.appserver.server.sql.DatabaseManagerException;
06: import com.lutris.appserver.server.sql.ObjectId;
07: import com.lutris.appserver.server.sql.ObjectIdException;
08: import com.lutris.dods.builder.generator.query.*;
09: import com.lutris.appserver.server.Enhydra;
10: import com.lutris.logging.*;
11:
12: import projectmanagement.spec.customer.*;
13:
14: /**
15: * Used to find the instance of Customer.
16: *
17: * @author Sasa Bojanic
18: * @version 1.0
19: */
20: public class CustomerManagerImpl implements CustomerManager {
21:
22: /**
23: * The getAllCustomers method performs a database query to
24: * return all <CODE>Customer</CODE> objects representing the
25: * row in the <CODE>Customers</CODE> table.
26: * @return all the customers, or null if there are no any.
27: * @exception ProjectManagementBusinessException
28: * if there is a problem retrieving customer information.
29: */
30: public Customer[] getAllCustomers()
31: throws ProjectManagementBusinessException {
32: try {
33: CustomerQuery query = new CustomerQuery();
34:
35: CustomerDO[] foundCustomers = query.getDOArray();
36: if (foundCustomers.length != 0) {
37: CustomerImpl[] cs = new CustomerImpl[foundCustomers.length];
38: for (int i = 0; i < foundCustomers.length; i++) {
39: cs[i] = new CustomerImpl(foundCustomers[i]);
40: }
41: return cs;
42: } else {
43: return null;
44: }
45: } catch (NonUniqueQueryException ex) {
46: Enhydra.getLogChannel().write(
47: Logger.DEBUG,
48: "Non-unique customer found in database: "
49: + ex.getMessage());
50: throw new ProjectManagementBusinessException(
51: "Non unique customer found");
52: } catch (DataObjectException ex) {
53: throw new ProjectManagementBusinessException(
54: "Database error retrieving customers: ", ex);
55: } /*catch(QueryException ex) {
56: throw new ProjectManagementBusinessException("Query exception retrieving customers: ", ex);
57: }*/
58: }
59:
60: /**
61: * The findCustomerByID method performs a database query to
62: * return a <CODE>Customer</CODE> object
63: * representing the row in the <CODE>customer</CODE> table
64: * that matches the object id.
65: *
66: * @param id, the object id of the customer table.
67: * @return
68: * the customer. null if there isn't a customer associated
69: * the id
70: * @exception ProjectManagementBusinessException
71: * if there is a problem retrieving customer information.
72: */
73: public Customer findCustomerByID(String id)
74: throws ProjectManagementBusinessException {
75: CustomerImpl theCustomer = null;
76:
77: try {
78: CustomerQuery query = new CustomerQuery();
79: //set query
80: query.setQueryOId(new ObjectId(id));
81: // Throw an exception if more than one user by this name is found
82: query.requireUniqueInstance();
83: CustomerDO theCustomerDO = query.getNextDO();
84: theCustomer = new CustomerImpl(theCustomerDO);
85: return theCustomer;
86: } catch (Exception ex) {
87: throw new ProjectManagementBusinessException(
88: "Exception in findCustomerByID()", ex);
89: }
90: }
91:
92: public Customer getCustomer()
93: throws ProjectManagementBusinessException {
94: return new CustomerImpl();
95: }
96: }
|