KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > projectmanagement > business > customer > CustomerManagerImpl


1 package projectmanagement.business.customer;
2
3 import projectmanagement.business.ProjectManagementBusinessException;
4 import projectmanagement.data.customer.*;
5 import com.lutris.appserver.server.sql.DatabaseManagerException;
6 import com.lutris.appserver.server.sql.ObjectId;
7 import com.lutris.appserver.server.sql.ObjectIdException;
8 import com.lutris.dods.builder.generator.query.*;
9 import com.lutris.appserver.server.Enhydra;
10 import com.lutris.logging.*;
11
12 import projectmanagement.spec.customer.*;
13 /**
14  * Used to find the instance of Customer.
15  *
16  * @author Sasa Bojanic
17  * @version 1.0
18  */

19 public class CustomerManagerImpl implements CustomerManager {
20
21    /**
22     * The getAllCustomers method performs a database query to
23     * return all <CODE>Customer</CODE> objects representing the
24     * row in the <CODE>Customers</CODE> table.
25     * @return all the customers, or null if there are no any.
26     * @exception ProjectManagementBusinessException
27     * if there is a problem retrieving customer information.
28     */

29     public Customer[] getAllCustomers()
30          throws ProjectManagementBusinessException {
31       try {
32          CustomerQuery query = new CustomerQuery();
33
34          CustomerDO[] foundCustomers = query.getDOArray();
35          if(foundCustomers.length != 0) {
36             CustomerImpl[] cs=new CustomerImpl[foundCustomers.length];
37             for (int i=0; i<foundCustomers.length; i++) {
38                cs[i]=new CustomerImpl(foundCustomers[i]);
39             }
40             return cs;
41          } else {
42             return null;
43          }
44       } catch(NonUniqueQueryException ex) {
45          Enhydra.getLogChannel().write(Logger.DEBUG,
46             "Non-unique customer found in database: "+ex.getMessage());
47          throw new ProjectManagementBusinessException("Non unique customer found");
48       } catch(DataObjectException ex) {
49          throw new ProjectManagementBusinessException("Database error retrieving customers: ", ex);
50       } /*catch(QueryException ex) {
51          throw new ProjectManagementBusinessException("Query exception retrieving customers: ", ex);
52       }*/

53    }
54
55    /**
56     * The findCustomerByID method performs a database query to
57     * return a <CODE>Customer</CODE> object
58     * representing the row in the <CODE>customer</CODE> table
59     * that matches the object id.
60     *
61     * @param id, the object id of the customer table.
62     * @return
63     * the customer. null if there isn't a customer associated
64     * the id
65     * @exception ProjectManagementBusinessException
66     * if there is a problem retrieving customer information.
67     */

68    public Customer findCustomerByID(String JavaDoc id)
69          throws ProjectManagementBusinessException {
70       CustomerImpl theCustomer = null;
71
72       try {
73          CustomerQuery query = new CustomerQuery();
74          //set query
75
query.setQueryOId(new ObjectId(id));
76          // Throw an exception if more than one user by this name is found
77
query.requireUniqueInstance();
78          CustomerDO theCustomerDO = query.getNextDO();
79          theCustomer = new CustomerImpl(theCustomerDO);
80          return theCustomer;
81       } catch(Exception JavaDoc ex) {
82          throw new ProjectManagementBusinessException("Exception in findCustomerByID()", ex);
83       }
84    }
85    
86    public Customer getCustomer()
87          throws ProjectManagementBusinessException{
88     return new CustomerImpl();
89    }
90 }
91
92
Popular Tags