Made Server Less Error Prone #107

Merged
kske merged 5 commits from f/secure-server into develop 2020-10-31 16:30:45 +01:00
1 changed files with 24 additions and 3 deletions
Showing only changes of commit fccd7e70b1 - Show all commits

View File

@ -341,15 +341,36 @@ public final class PersistenceManager {
}
private void persist(Object obj) {
transaction(() -> entityManager.persist(obj));
try {
transaction(() -> entityManager.persist(obj));
} catch (EntityExistsException e) {
if (transaction.isActive())
transaction.rollback();
EnvoyLog.getLogger(PersistenceManager.class).log(Level.WARNING,
String.format("Could not persist %s: entity exists already.", obj));
}
}
private void merge(Object obj) {
transaction(() -> entityManager.merge(obj));
try {
transaction(() -> entityManager.merge(obj));
} catch (IllegalArgumentException e) {
if (transaction.isActive())
transaction.rollback();
EnvoyLog.getLogger(PersistenceManager.class).log(Level.WARNING,
String.format("Could not merge %s: entity doesn't exist.", obj));
}
}
private void remove(Object obj) {
transaction(() -> entityManager.remove(obj));
try {
transaction(() -> entityManager.remove(obj));
} catch (IllegalArgumentException e) {
if (transaction.isActive())
transaction.rollback();
EnvoyLog.getLogger(PersistenceManager.class).log(Level.WARNING,
String.format("Could not remove %s: entity didn't exist (for the database).", obj));
}
}
/**