diff options
| author | Dominic Rogetzer <e1627756@student.tuwien.ac.at> | 2018-06-16 14:48:58 +0200 | 
|---|---|---|
| committer | Tharre <tharre3@gmail.com> | 2018-06-16 15:52:37 +0200 | 
| commit | 6aa57486a2e34f76e88d403fe8363c6f45b68130 (patch) | |
| tree | ed51e49c18d35c727dd4724dd5551d8f4f1bde33 /src/main/java/at/ac | |
| parent | ef9ba06432f6c4ab77f09462f672ce84d9f8cfe7 (diff) | |
| download | sepm-groupproject-6aa57486a2e34f76e88d403fe8363c6f45b68130.tar.gz sepm-groupproject-6aa57486a2e34f76e88d403fe8363c6f45b68130.tar.xz sepm-groupproject-6aa57486a2e34f76e88d403fe8363c6f45b68130.zip  | |
Remove finally block, reset autocommit in EmployeeDatabaseDAO [#27305]
Diffstat (limited to 'src/main/java/at/ac')
| -rw-r--r-- | src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDatabaseDAO.java | 31 | 
1 files changed, 10 insertions, 21 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 8c8d8b2..74e407f 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 @@ -85,6 +85,7 @@ public class EmployeeDatabaseDAO implements EmployeeDAO {                      try (ResultSet resultSetEmployee = insertEmployee.getGeneratedKeys()) {                          if (resultSetEmployee.next()) {                              connection.commit(); +                            connection.setAutoCommit(true);                              return resultSetEmployee.getLong(1);                          }                      } @@ -94,20 +95,8 @@ public class EmployeeDatabaseDAO implements EmployeeDAO {              throw new PersistenceException("Employee was not updated");          } catch (SQLException e) { -            try { -                if (savepoint != null) { -                    connection.rollback(savepoint); -                } -            } catch (SQLException e1) { -                throw new PersistenceException(e); -            } +            rollbackAndEnableAutoCommit(savepoint);              throw new PersistenceException(e); -        } finally { -            try { -                connection.setAutoCommit(true); -            } catch (SQLException e) { -                throw new PersistenceException(e); -            }          }      } @@ -137,6 +126,7 @@ public class EmployeeDatabaseDAO implements EmployeeDAO {                      if (affectedRows == 1) {                          connection.commit(); +                        connection.setAutoCommit(true);                      } else {                          throw new ElementNotFoundException(                                  "element not found with id: " + employee.id()); @@ -145,16 +135,15 @@ public class EmployeeDatabaseDAO implements EmployeeDAO {              }          } catch (SQLException e) { -            try { -                if (savepoint != null) { -                    connection.rollback(savepoint); -                } -            } catch (SQLException e1) { -                throw new PersistenceException(e); -            } +            rollbackAndEnableAutoCommit(savepoint);              throw new PersistenceException(e); -        } finally { +        } +    } + +    private void rollbackAndEnableAutoCommit(Savepoint savepoint) throws PersistenceException { +        if (savepoint != null) {              try { +                connection.rollback(savepoint);                  connection.setAutoCommit(true);              } catch (SQLException e) {                  throw new PersistenceException(e);  | 
