コード例 #1
0
  // ADD A EMPLOYEE BANK DETAILS IN tblempbank
  @Override
  public int addEmployeeBank(EmployeeBank employeebank)
      throws HibernateException, ConstraintViolationException {
    Session session = SessionFactoryUtil.getSessionFactory().openSession();
    int status = 0;
    try {
      session.beginTransaction();
      java.sql.Timestamp date = new java.sql.Timestamp(new java.util.Date().getTime());

      Criteria criteria = session.createCriteria(EmployeeBank.class);
      criteria.add(Restrictions.eq("organizationId", employeebank.getOrganizationId()));
      criteria.add(
          Restrictions.eq("employee", new Employee(employeebank.getEmployee().getEmployeeId())));
      criteria.add(Restrictions.eq("bank", new Bank(employeebank.getBank().getBankId())));
      if (criteria.list().size() == 0) {
        employeebank.setInsertDate(date.toString());
        employeebank.setUpdateDate(date.toString());
        session.save(employeebank);
        status = 1;
      } else {
        Iterator<EmployeeBank> iterator = criteria.list().iterator();
        while (iterator.hasNext()) {
          EmployeeBank empbank = iterator.next();
          if (empbank.getDeleteFlag() == true) {
            empbank.setDeleteFlag(false);
            empbank.setInsertDate(date.toString());
            empbank.setUpdateDate(date.toString());
            session.update(empbank);
            status = 1;
          } else {
            return 5;
          }
        }
      }

    } catch (Exception e) {
      e.printStackTrace();

    } finally {
      session.getTransaction().commit();
      session.close();
    }
    return status;
  }
コード例 #2
0
  // UPDATE A EMPLOYEE BANK DETAILS IN tblempbank
  @Override
  public int updateEmployeeBank(EmployeeBank employeebank)
      throws HibernateException, ConstraintViolationException {
    Session session = SessionFactoryUtil.getSessionFactory().openSession();
    int status = 0;
    try {
      session.beginTransaction();
      java.sql.Timestamp date = new java.sql.Timestamp(new java.util.Date().getTime());
      EmployeeBank empbank = getEmployeeBankId(employeebank.getEmpbankId());

      Criteria criteria = session.createCriteria(EmployeeBank.class);
      criteria.add(Restrictions.eq("organizationId", employeebank.getOrganizationId()));
      criteria.add(
          Restrictions.eq("employee", new Employee(empbank.getEmployee().getEmployeeId())));
      criteria.add(
          Restrictions.ne("employee", new Employee(employeebank.getEmployee().getEmployeeId())));
      criteria.add(Restrictions.eq("bank", new Bank(employeebank.getBank().getBankId())));

      if ((empbank != null) && (criteria.list().size() == 0)) {
        employeebank.setInsertBy(empbank.getInsertBy());
        employeebank.setInsertDate(empbank.getInsertDate());
        employeebank.setUpdateDate(date.toString());
        session.update(employeebank);
        status = 1;
      } else {
        return 5;
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      session.getTransaction().commit();
      session.close();
    }
    return status;
  }