public void create(EventBean newEvent) throws DAOException { try { Transaction.begin(); EventBean dbEvent = factory.create(); factory.copyInto(newEvent, dbEvent); Transaction.commit(); } catch (RollbackException e) { throw new DAOException(e); } finally { if (Transaction.isActive()) Transaction.rollback(); } }
@Override public synchronized Course createCourse(String courseName, String createdBy) throws MyDAOException { try { Transaction.begin(); Course newCourse = factory.create(courseName); newCourse.setCreatedBy(createdBy); Transaction.commit(); return newCourse; } catch (DuplicateKeyException e) { throw new MyDAOException("A course with this name already exists."); } catch (RollbackException e) { throw new MyDAOException(e); } }
public void create(Community community) throws DAOException { try { Transaction.begin(); Community dbcommunity = factory.create(community.getName()); factory.copyInto(community, dbcommunity); Transaction.commit(); } catch (DuplicateKeyException e) { throw new DAOException("Community named " + community.getName() + " already exists."); } catch (RollbackException e) { throw new DAOException(e); } finally { if (Transaction.isActive()) Transaction.rollback(); } }
public void create(UserBean user) throws DAOException { String origID = user.getUserID(); try { Transaction.begin(); user.setUserID(user.getUserID().toLowerCase()); UserBean dBUser = factory.create(user.getUserID()); factory.copyInto(user, dBUser); Transaction.commit(); } catch (DuplicateKeyException e) { throw new DAOException("UserID: " + user.getUserID() + "already exists."); } catch (RollbackException e) { throw new DAOException(e); } finally { if (Transaction.isActive()) Transaction.rollback(); } }