Esempio n. 1
0
  /**
   * Method called by the Form panel to delete existing data.
   *
   * @param persistentObject value object to delete
   * @return an ErrorResponse value object in case of errors, VOResponse if the operation is
   *     successfully completed
   */
  public Response deleteRecord(ValueObject persistentObject) throws Exception {
    PreparedStatement stmt = null;
    try {
      EmpVO vo = (EmpVO) persistentObject;

      // delete from WORKING_DAYS...
      stmt = conn.prepareStatement("delete from WORKING_DAYS where EMP_CODE=?");
      stmt.setString(1, vo.getEmpCode());
      stmt.execute();
      stmt.close();

      // delete from EMP...
      stmt = conn.prepareStatement("delete from EMP where EMP_CODE=?");
      stmt.setString(1, vo.getEmpCode());
      stmt.execute();
      gridFrame.reloadData();

      frame.getGrid().clearData();

      return new VOResponse(vo);
    } catch (SQLException ex) {
      ex.printStackTrace();
      return new ErrorResponse(ex.getMessage());
    } finally {
      try {
        stmt.close();
        conn.commit();
      } catch (SQLException ex1) {
      }
    }
  }
Esempio n. 2
0
  /**
   * This method must be overridden by the subclass to retrieve data and return the valorized value
   * object.
   *
   * @param valueObjectClass value object class
   * @return a VOResponse object if data loading is successfully completed, or an ErrorResponse
   *     object if an error occours
   */
  public Response loadData(Class valueObjectClass) {
    try {
      // since this method could be invoked also when selecting another row on the linked grid,
      // the pk attribute must be recalculated from the grid...
      int row = gridFrame.getGrid().getSelectedRow();
      if (row != -1) {
        GridEmpVO gridVO =
            (GridEmpVO) gridFrame.getGrid().getVOListTableModel().getObjectForRow(row);
        pk = gridVO.getEmpCode();
      }

      String sql =
          "select EMP.EMP_CODE,EMP.FIRST_NAME, EMP.LAST_NAME,EMP.DEPT_CODE,DEPT.DESCRIPTION,EMP.TASK_CODE,TASKS.DESCRIPTION,EMP.SEX,EMP.HIRE_DATE,EMP.SALARY,EMP.NOTE "
              + "from EMP,DEPT,TASKS where EMP.DEPT_CODE=DEPT.DEPT_CODE and EMP.TASK_CODE=TASKS.TASK_CODE and EMP.EMP_CODE='"
              + pk
              + "'";

      // mapping between attributes and database fields...
      Map attribute2dbField = new HashMap();
      attribute2dbField.put("empCode", "EMP.EMP_CODE");
      attribute2dbField.put("firstName", "EMP.FIRST_NAME");
      attribute2dbField.put("lastName", "EMP.LAST_NAME");
      attribute2dbField.put("deptCode", "EMP.DEPT_CODE");
      attribute2dbField.put("deptDescription", "DEPT.DESCRIPTION");
      attribute2dbField.put("taskCode", "EMP.TASK_CODE");
      attribute2dbField.put("taskDescription", "TASKS.DESCRIPTION");
      attribute2dbField.put("sex", "EMP.SEX");
      attribute2dbField.put("hireDate", "EMP.HIRE_DATE");
      attribute2dbField.put("salary", "EMP.SALARY");
      attribute2dbField.put("note", "EMP.NOTE");

      return QueryUtil.getQuery(
          conn,
          sql,
          new ArrayList(), // list of values linked to "?" parameters in sql
          attribute2dbField,
          EmpVO.class, // v.o. to dinamically create for each row...
          "Y",
          "N",
          true // log query...
          );
    } catch (Exception ex) {
      ex.printStackTrace();
      return new ErrorResponse(ex.getMessage());
    }

    /*
        // an alternative way: you can define your own business logic to retrieve data and adding filtering/sorting conditions at hand...
        Statement stmt = null;
        try {
          stmt = conn.createStatement();
          ResultSet rset = stmt.executeQuery(
            "select EMP.EMP_CODE,EMP.FIRST_NAME, EMP.LAST_NAME,EMP.DEPT_CODE,DEPT.DESCRIPTION,EMP.TASK_CODE,TASKS.DESCRIPTION,EMP.SEX,EMP.HIRE_DATE,EMP.SALARY,EMP.NOTE "+
            "from EMP,DEPT,TASKS where EMP.DEPT_CODE=DEPT.DEPT_CODE and EMP.TASK_CODE=TASKS.TASK_CODE and EMP.EMP_CODE='"+pk+"'"
          );
          if (rset.next()) {
            EmpVO vo = new EmpVO();
            vo.setEmpCode(rset.getString(1));
            vo.setFirstName(rset.getString(2));
            vo.setLastName(rset.getString(3));
            vo.setDeptCode(rset.getString(4));
            vo.setDeptDescription(rset.getString(5));
            vo.setTaskCode(rset.getString(6));
            vo.setTaskDescription(rset.getString(7));
            vo.setSex(rset.getString(8));
            vo.setHireDate(rset.getDate(9));
            vo.setSalary(rset.getBigDecimal(10));
            vo.setNote(rset.getString(11));
            return new VOResponse(vo);
          }
          else
            return new ErrorResponse("No data found.");
        }
        catch (SQLException ex) {
          ex.printStackTrace();
          return new ErrorResponse(ex.getMessage());
        }
        finally {
          try {
            stmt.close();
          }
          catch (SQLException ex1) {
          }
        }
    */
  }
Esempio n. 3
0
 public void actionPerformed(ActionEvent e) {
   adaptee.insertButton_actionPerformed(e);
 }