}
@Override
public void save(Mercadoria mercadoria) throws PersistenceException {
if (mercadoria == null) {
throw new PersistenceException("Informe a Mercadoria para salvar!");
}
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = ConnectionManager.getConnection();
if (mercadoria.getId() == null) {
stmt = getStatementInsert(conn, mercadoria);
} else {
stmt = getStatementUpdate(conn, mercadoria);
}
stmt.executeUpdate();
conn.commit();
log.debug("Mercadoria foi salva");
} catch (SQLException e) {
try { conn.rollback(); } catch (Exception sx) {}
String errorMsg = "Erro ao salvar Mercadoria!";
log.error(errorMsg, e);
throw new PersistenceException(errorMsg, e);
} finally {
ConnectionManager.closeAll(conn, stmt);
}
}