// Truy vấn các nhân viên trong 1 phòng ban public static Set<Emp> queryEmployees(int deptNo) { for (Dept dept : DEPARTMENTS) { if (deptNo == dept.getDeptNo()) { return dept.getEmployees(); } } return null; }
public Course insert(int cid, String title, Dept dept) { try { // make sure that the cid is currently unused if (find(cid) != null) return null; String cmd = "insert into COURSE(CId, Title, DeptId) " + "values(?, ?, ?, ?)"; PreparedStatement pstmt = conn.prepareStatement(cmd); pstmt.setInt(1, cid); pstmt.setString(2, title); pstmt.setInt(3, dept.getId()); pstmt.executeUpdate(); return new Course(this, cid, title, dept); } catch (SQLException e) { dbm.cleanup(); throw new RuntimeException("error inserting new course", e); } }
public void testDepartmentService() { DeptService svc = null; try { Context ctx = getInitialContext(); svc = (DeptService) ctx.lookup(sessionBean); } catch (NamingException e) { fail("DeptService lookup failed: " + e); } defineXSD(); Dept dept = svc.getDept(30); if (dept == null) { fail("Department [30] was not returned by the service."); } dept.setDeptno(dept.getDeptno() + 1); dept.setDname(dept.getDname() + "'"); dept.setLoc(dept.getLoc() + "'"); assertTrue("Department [30] update was unsuccessful.", svc.updateDept(dept)); }
public void removeDept(Dept dept) { dept = em.find(Dept.class, dept.getDeptno()); em.remove(dept); }
// Mô phỏng dữ liệu trong database private static void initDate() { Dept accountingDept = new Dept(10, "ACCOUNTING", "NEW YORK"); accountingDept.addEmployee(new Emp(7782, "CLARK", "MANAGER", "6/9/1981", 2450.00F)); accountingDept.addEmployee(new Emp(7839, "KING", "PRESIDENT", "11/17/1981", 5000.00F)); accountingDept.addEmployee(new Emp(7934, "MILLER", "CLERK", "6/9/1981", 1300.00F)); // Dept reseachDept = new Dept(20, "RESEARCH", "DALLAS"); reseachDept.addEmployee(new Emp(7369, "SMITH", "CLERK", "12/17/1980", 800.00f)); reseachDept.addEmployee(new Emp(7788, "SCOTT", "ANALYST", "4/19/1987", 3000.00f)); reseachDept.addEmployee(new Emp(7876, "ADAMS", "CLERK", "5/23/1987", 1100.00f)); reseachDept.addEmployee(new Emp(7876, "FORD", "ANALYST", "12/3/1981", 3000.00f)); reseachDept.addEmployee(new Emp(7566, "JONES", "MANAGER", "4/2/1981", 2975.00f)); // // Dept salesDept = new Dept(30, "SALES", "CHICAGO"); salesDept.addEmployee(new Emp(7654, "MARTIN", "SALESMAN", "9/28/1981", 1250.00f)); salesDept.addEmployee(new Emp(7499, "ALLEN", "SALESMAN", "2/20/1981", 1600.00f)); salesDept.addEmployee(new Emp(7521, "WARD", "SALESMAN", "2/22/1981", 1250.00f)); salesDept.addEmployee(new Emp(7844, "TURNER", "SALESMAN", "9/8/1981", 1500.00f)); salesDept.addEmployee(new Emp(7900, "JAMES", "CLERK", "12/3/1981", 950.00f)); // Dept openrationsDept = new Dept(40, "OPERATIONS", "BOSTON"); // DEPARTMENTS.add(accountingDept); DEPARTMENTS.add(reseachDept); DEPARTMENTS.add(salesDept); DEPARTMENTS.add(openrationsDept); }