KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > projectmanagement > business > employee > EmployeeManagerImpl


1 package projectmanagement.business.employee;
2
3 import projectmanagement.business.ProjectManagementBusinessException;
4 import projectmanagement.data.employee.*;
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.employee.*;
13
14 /**
15  * Used to find the instance of Employee.
16  *
17  * @author Sasa Bojanic
18  * @version 1.0
19  */

20 public class EmployeeManagerImpl implements EmployeeManager {
21
22    /**
23     * The getAllEmployees method performs a database query to
24     * return all <CODE>Employee</CODE> objects representing the
25     * row in the <CODE>Employees</CODE> table.
26     * @return all the employees, or null if there are no any.
27     * @exception ProjectManagementBusinessException
28     * if there is a problem retrieving employee information.
29     */

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

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

71    public Employee findEmployeeByID(String JavaDoc id)
72          throws ProjectManagementBusinessException {
73     
74       Employee theEmployee = null;
75
76       try {
77          EmployeeQuery query = new EmployeeQuery();
78          //set query
79
query.setQueryOId(new ObjectId(id));
80          // Throw an exception if more than one user by this name is found
81
query.requireUniqueInstance();
82          EmployeeDO theEmployeeDO = query.getNextDO();
83          theEmployee = new EmployeeImpl(theEmployeeDO);
84          return theEmployee;
85       } catch(Exception JavaDoc ex) {
86          throw new ProjectManagementBusinessException("Exception in findEmployeeByID()", ex);
87       }
88    }
89
90    /**
91     * The findEmployee method performs a database query to
92     * return a <CODE>Employee</CODE> object
93     * representing the row in the <CODE>employees</CODE> table
94     * that matches login name with the username.
95     *
96     * @param username, the login name of the employee.
97     * @return
98     * the employee. null if there isn't a employee associated
99     * the username
100     * @exception ProjectManagementBusinessException
101     * if there is a problem retrieving employee information.
102     */

103     public Employee findEmployee(String JavaDoc username)
104          throws ProjectManagementBusinessException {
105       try {
106        
107          EmployeeQuery query = new EmployeeQuery();
108        
109          // set query.
110
query.setQueryLogin(username);
111          // Throw an exception if more than one user by this name is found
112
query.requireUniqueInstance();
113
114          EmployeeDO[] foundEmployee = query.getDOArray();
115          if(foundEmployee.length != 0) {
116             return new EmployeeImpl(foundEmployee[0]);
117          } else {
118             return null;
119          }
120        } catch(NonUniqueQueryException ex) {
121          Enhydra.getLogChannel().write(Logger.DEBUG,
122             "Non-unique user found in database: " +
123             ex.getMessage());
124          throw new ProjectManagementBusinessException("More than one user found with username: " +
125             username);
126       } catch(DataObjectException ex) {
127          throw new ProjectManagementBusinessException("Database error retrieving user: ", ex);
128       } catch(QueryException ex) {
129          throw new ProjectManagementBusinessException("Query exception retrieving user: ", ex);
130       }
131    }
132
133 public Employee getEmployee()
134          throws ProjectManagementBusinessException
135          {
136           return new EmployeeImpl();
137          }
138 }
139
Popular Tags