001: package projectmanagement.business.employee;
002:
003: import projectmanagement.business.ProjectManagementBusinessException;
004: import projectmanagement.data.employee.*;
005: import com.lutris.appserver.server.sql.DatabaseManagerException;
006: import com.lutris.appserver.server.sql.ObjectId;
007: import com.lutris.appserver.server.sql.ObjectIdException;
008: import com.lutris.dods.builder.generator.query.*;
009: import com.lutris.appserver.server.Enhydra;
010: import com.lutris.logging.*;
011:
012: import projectmanagement.spec.employee.*;
013:
014: /**
015: * Used to find the instance of Employee.
016: *
017: * @author Sasa Bojanic
018: * @version 1.0
019: */
020: public class EmployeeManagerImpl implements EmployeeManager {
021:
022: /**
023: * The getAllEmployees method performs a database query to
024: * return all <CODE>Employee</CODE> objects representing the
025: * row in the <CODE>Employees</CODE> table.
026: * @return all the employees, or null if there are no any.
027: * @exception ProjectManagementBusinessException
028: * if there is a problem retrieving employee information.
029: */
030: public Employee[] getAllEmployees()
031: throws ProjectManagementBusinessException {
032:
033: try {
034: EmployeeQuery query = new EmployeeQuery();
035:
036: EmployeeDO[] foundEmployees = query.getDOArray();
037: if (foundEmployees.length != 0) {
038: EmployeeImpl[] cs = new EmployeeImpl[foundEmployees.length];
039: for (int i = 0; i < foundEmployees.length; i++) {
040: cs[i] = new EmployeeImpl(foundEmployees[i]);
041: }
042: return cs;
043: } else {
044: return null;
045: }
046: } catch (NonUniqueQueryException ex) {
047: Enhydra.getLogChannel().write(
048: Logger.DEBUG,
049: "Non-unique employee found in database: "
050: + ex.getMessage());
051: throw new ProjectManagementBusinessException(
052: "Non unique employee found");
053: } catch (DataObjectException ex) {
054: throw new ProjectManagementBusinessException(
055: "Database error retrieving employees: ", ex);
056: }/*catch(QueryException ex) {
057: throw new ProjectManagementBusinessException("Query exception retrieving employees: ", ex);
058: }*/
059:
060: }
061:
062: /**
063: * The findEmployeeByID method performs a database query to
064: * return a <CODE>Employee</CODE> object
065: * representing the row in the <CODE>employee</CODE> table
066: * that matches the object id.
067: *
068: * @param id, the object id of the employee table.
069: * @return
070: * the employee. null if there isn't a employee associated
071: * the id
072: * @exception ProjectManagementBusinessException
073: * if there is a problem retrieving employee information.
074: */
075: public Employee findEmployeeByID(String id)
076: throws ProjectManagementBusinessException {
077:
078: Employee theEmployee = null;
079:
080: try {
081: EmployeeQuery query = new EmployeeQuery();
082: //set query
083: query.setQueryOId(new ObjectId(id));
084: // Throw an exception if more than one user by this name is found
085: query.requireUniqueInstance();
086: EmployeeDO theEmployeeDO = query.getNextDO();
087: theEmployee = new EmployeeImpl(theEmployeeDO);
088: return theEmployee;
089: } catch (Exception ex) {
090: throw new ProjectManagementBusinessException(
091: "Exception in findEmployeeByID()", ex);
092: }
093: }
094:
095: /**
096: * The findEmployee method performs a database query to
097: * return a <CODE>Employee</CODE> object
098: * representing the row in the <CODE>employees</CODE> table
099: * that matches login name with the username.
100: *
101: * @param username, the login name of the employee.
102: * @return
103: * the employee. null if there isn't a employee associated
104: * the username
105: * @exception ProjectManagementBusinessException
106: * if there is a problem retrieving employee information.
107: */
108: public Employee findEmployee(String username)
109: throws ProjectManagementBusinessException {
110: try {
111:
112: EmployeeQuery query = new EmployeeQuery();
113:
114: // set query.
115: query.setQueryLogin(username);
116: // Throw an exception if more than one user by this name is found
117: query.requireUniqueInstance();
118:
119: EmployeeDO[] foundEmployee = query.getDOArray();
120: if (foundEmployee.length != 0) {
121: return new EmployeeImpl(foundEmployee[0]);
122: } else {
123: return null;
124: }
125: } catch (NonUniqueQueryException ex) {
126: Enhydra.getLogChannel().write(
127: Logger.DEBUG,
128: "Non-unique user found in database: "
129: + ex.getMessage());
130: throw new ProjectManagementBusinessException(
131: "More than one user found with username: "
132: + username);
133: } catch (DataObjectException ex) {
134: throw new ProjectManagementBusinessException(
135: "Database error retrieving user: ", ex);
136: } catch (QueryException ex) {
137: throw new ProjectManagementBusinessException(
138: "Query exception retrieving user: ", ex);
139: }
140: }
141:
142: public Employee getEmployee()
143: throws ProjectManagementBusinessException {
144: return new EmployeeImpl();
145: }
146: }
|