コード例 #1
0
 // DELETE A EMPLOYEE BANK DETAILS (HARD DELETE)
 public int deleteEmployeeBankHard(int empbankId)
     throws HibernateException, ConstraintViolationException {
   Session session = SessionFactoryUtil.getSessionFactory().openSession();
   int status = 0;
   try {
     session.beginTransaction();
     EmployeeBank employeebank = getEmployeeBankId(empbankId);
     session.delete(employeebank);
     status = 1;
     return status;
   } catch (Exception e) {
     e.printStackTrace();
     return status;
   } finally {
     session.getTransaction().commit();
     session.close();
   }
 }
コード例 #2
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;
  }
コード例 #3
0
 // GET A SINGLE RECORD by employeeId
 @Override
 public List<EmployeeBank> getEmployeeBankById(int employeeId, int organizationId)
     throws HibernateException, ConstraintViolationException {
   Session session = SessionFactoryUtil.getSessionFactory().openSession();
   try {
     session.beginTransaction();
     Criteria criteria = session.createCriteria(EmployeeBank.class);
     criteria.add(Restrictions.eq("employee", new Employee(employeeId)));
     criteria.add(Restrictions.eq("organizationId", organizationId));
     criteria.add(Restrictions.eq("deleteFlag", false));
     return (List<EmployeeBank>) criteria.list();
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   } finally {
     session.getTransaction().commit();
     session.close();
   }
 }
コード例 #4
0
 // GET ALL RECORDS FROM tblempbank
 @SuppressWarnings("unchecked")
 @Override
 public List<EmployeeBank> getAllBankDetails(int organizationId)
     throws HibernateException, ConstraintViolationException {
   Session session = SessionFactoryUtil.getSessionFactory().openSession();
   try {
     session.beginTransaction();
     Criteria criteria = session.createCriteria(EmployeeBank.class);
     criteria.add(Restrictions.eq("organizationId", organizationId));
     criteria.add(Restrictions.eq("deleteFlag", false));
     return criteria.list();
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   } finally {
     session.getTransaction().commit();
     session.close();
   }
 }
コード例 #5
0
 // GET A SINGLE RECORD FROM tblempbank USING empbankId
 public EmployeeBank getEmployeeBankId(int empbankId)
     throws HibernateException, ConstraintViolationException {
   Session session = SessionFactoryUtil.getSessionFactory().openSession();
   try {
     session.beginTransaction();
     EmployeeBank employeebank = (EmployeeBank) session.get(EmployeeBank.class, empbankId);
     if (employeebank != null) {
       if (!employeebank.getDeleteFlag()) {
         return employeebank;
       } else {
         return null;
       }
     } else {
       return null;
     }
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   } finally {
     session.getTransaction().commit();
     session.close();
   }
 }
コード例 #6
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;
  }