Delete
As part of HW5 it is left to you to write tests for Sql2oCourseDao.delete
method!
Here is the implementation of Sql2oCourseDao.delete
:
@Override
public Course delete(String offeringName) throws DaoException {
String sql = "WITH deleted AS ("
+ "DELETE FROM courses WHERE offeringName = :name RETURNING *"
+ ") SELECT * FROM deleted;";
try (Connection conn = sql2o.open()) {
return conn.createQuery(sql)
.addParameter("name", offeringName)
.executeAndFetchFirst(Course.class);
} catch (Sql2oException ex) {
throw new DaoException("Unable to delete the course", ex);
}
}