Made Server Less Error Prone #107
@ -341,15 +341,36 @@ public final class PersistenceManager {
|
||||
}
|
||||
|
||||
private void persist(Object 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) {
|
||||
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) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user