예제 #1
0
  @Override
  public boolean approveElective(int[] electiveIds) {

    try {
      for (int id : electiveIds) {
        Elective elective = entityManager.find(Elective.class, id);
        if (elective == null) {
          return false;
        }
        elective.setProposed("1");
        entityManager.persist(elective);
      }
    } catch (EntityExistsException e) {
      e.printStackTrace();
      entityManager.getTransaction().rollback();
      return false;
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
      entityManager.getTransaction().rollback();
      return false;
    } catch (TransactionRequiredException e) {
      e.printStackTrace();
      entityManager.getTransaction().rollback();
      return false;
    }
    return true;
  }
예제 #2
0
  @Override
  public boolean setTaughtElectives(int[] electiveId) {

    // entityManager.getTransaction().begin();
    for (int i : electiveId) {
      Elective ele = entityManager.find(Elective.class, i);
      ele.setTaught((short) 1);
      try {
        entityManager.persist(ele);
      } catch (EntityExistsException e) {
        e.printStackTrace();
        return false;
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
        return false;
      } catch (TransactionRequiredException e) {
        e.printStackTrace();
        return false;
      }
    }

    //        try {
    //            entityManager.getTransaction().commit();
    //        } catch (RollbackException e) {
    //            e.printStackTrace();
    //            return false;
    //        }
    return true;
  }
예제 #3
0
 public <T extends BaseDto> void delete(T entity) throws DaoException {
   startTxn();
   try {
     getEntityManager().remove(entity);
     getEntityManager().getTransaction().commit();
   } catch (IllegalArgumentException e) {
     getEntityManager().getTransaction().rollback();
     e.printStackTrace();
     throw new DaoException("Create Failed: " + e.getMessage());
   } catch (TransactionRequiredException e) {
     getEntityManager().getTransaction().rollback();
     e.printStackTrace();
     throw new DaoException("Update Failed: " + e.getMessage());
   }
 }
예제 #4
0
 public <T extends BaseDto> void delete(Class<T> entityClass, Object[] entityids)
     throws DaoException {
   for (Object id : entityids) {
     startTxn();
     //	        getEntityManager().remove(getEntityManager().find(entityClass, id));
     try {
       getEntityManager().remove(getEntityManager().find(entityClass, id));
       getEntityManager().getTransaction().commit();
     } catch (IllegalArgumentException e) {
       getEntityManager().getTransaction().rollback();
       e.printStackTrace();
       throw new DaoException("Create Failed: " + e.getMessage());
     } catch (TransactionRequiredException e) {
       getEntityManager().getTransaction().rollback();
       e.printStackTrace();
       throw new DaoException("Update Failed: " + e.getMessage());
     }
   }
 }
예제 #5
0
 public <T extends BaseDto> void update(T entity) throws DaoException {
   startTxn();
   try {
     getEntityManager().merge(entity);
     //        	getEntityManager().flush();
     getEntityManager().getTransaction().commit();
   } catch (TransactionRequiredException e) {
     getEntityManager().getTransaction().rollback();
     e.printStackTrace();
     throw new DaoException("Update Failed: " + e.getMessage());
   } catch (PersistenceException e) {
     getEntityManager().getTransaction().rollback();
     e.printStackTrace();
     throw new DaoException("Update Failed: " + e.getMessage());
   } catch (Exception e) {
     getEntityManager().getTransaction().rollback();
     e.printStackTrace();
     throw new DaoException("Update Failed: " + e.getMessage());
   }
 }
예제 #6
0
  @Override
  public boolean removeElective(int electiveId) {

    try {
      Elective elective = entityManager.find(Elective.class, electiveId);

      if (elective != null) {
        entityManager.remove(elective);
        entityManager.flush();

        return true;
      }
    } catch (IllegalArgumentException ex) {
      ex.printStackTrace();
      return false;
    } catch (TransactionRequiredException ex) {
      ex.printStackTrace();
      return false;
    }
    return false;
  }
예제 #7
0
  @Override
  public boolean addElective(ElectiveDTO e) {

    Elective el =
        new Elective(
            e.getElectiveID(), e.getTitle(), e.getDescription(), new Date(), e.getProposed());

    try {
      entityManager.persist(el);
    } catch (EntityExistsException ex) {
      ex.printStackTrace();
      return false;
    } catch (IllegalArgumentException ex) {
      ex.printStackTrace();
      return false;
    } catch (TransactionRequiredException ex) {
      ex.printStackTrace();
      return false;
    }
    return true;
  }