diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java index 53adb45..40a9134 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDao.java @@ -65,7 +65,10 @@ public class EmployeeDatabaseDao implements EmployeeDAO { public long add(Employee employee) throws PersistenceException { // Assumption: the given employee is already validated (from service) + Savepoint savepoint = null; try { + savepoint = connection.setSavepoint(); + connection.setAutoCommit(false); insertEmployeeVersion.setString(1, employee.name()); insertEmployeeVersion.setTimestamp( 2, Timestamp.valueOf(employee.birthday().atStartOfDay())); @@ -82,14 +85,28 @@ public class EmployeeDatabaseDao implements EmployeeDAO { ResultSet resultSetEmployee = insertEmployee.getGeneratedKeys(); if (resultSetEmployee.next()) { + connection.commit(); return resultSetEmployee.getLong(1); } } - throw new PersistenceException("Employee was not created"); + throw new PersistenceException("Employee was not updated"); } catch (SQLException e) { + try { + if (savepoint != null) { + connection.rollback(savepoint); + } + } catch (SQLException e1) { + throw new PersistenceException(e); + } throw new PersistenceException(e); + } finally { + try { + connection.setAutoCommit(true); + } catch (SQLException e) { + throw new PersistenceException(e); + } } } |