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 20 public class EmployeeManagerImpl implements EmployeeManager { 21 22 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 } 55 56 } 57 58 71 public Employee findEmployeeByID(String id) 72 throws ProjectManagementBusinessException { 73 74 Employee theEmployee = null; 75 76 try { 77 EmployeeQuery query = new EmployeeQuery(); 78 query.setQueryOId(new ObjectId(id)); 80 query.requireUniqueInstance(); 82 EmployeeDO theEmployeeDO = query.getNextDO(); 83 theEmployee = new EmployeeImpl(theEmployeeDO); 84 return theEmployee; 85 } catch(Exception ex) { 86 throw new ProjectManagementBusinessException("Exception in findEmployeeByID()", ex); 87 } 88 } 89 90 103 public Employee findEmployee(String username) 104 throws ProjectManagementBusinessException { 105 try { 106 107 EmployeeQuery query = new EmployeeQuery(); 108 109 query.setQueryLogin(username); 111 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 |