-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceOrder.java
More file actions
66 lines (53 loc) · 1.62 KB
/
Copy pathServiceOrder.java
File metadata and controls
66 lines (53 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package Utils;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import daoLibrary.DBConnection;
import daoLibrary.OrderDAO;
import daoLibrary.OrderItemDAO;
import daoLibrary.OrderPaymentDAO;
import modelsLibrary.Order;
import modelsLibrary.OrderItem;
import modelsLibrary.OrderPayment;
public class ServiceOrder {
private OrderDAO orderDAO;
private OrderItemDAO orderItemDAO;
private OrderPaymentDAO orderPaymentDAO;
public ServiceOrder() {
this.orderDAO = new OrderDAO();
this.orderItemDAO = new OrderItemDAO();
this.orderPaymentDAO = new OrderPaymentDAO();
}
public int finalizarPedido(Order pedido, List<OrderItem> itens, List<OrderPayment> pagamentos) {
int idPedido = 0;
Connection conn = null;
try {
conn = DBConnection.getConnection();
conn.setAutoCommit(false);
idPedido = orderDAO.insertPedido(conn, pedido);
if (itens != null && !itens.isEmpty()) {
for (OrderItem item : itens) {
item.setIdPedido(idPedido);
}
orderItemDAO.insertItemPedido(conn, idPedido, itens);
}
if (pagamentos != null && !pagamentos.isEmpty()) {
orderPaymentDAO.insertPedidoPagamento(conn, idPedido, pagamentos);
}
conn.commit();
} catch (SQLException ex) {
if (conn != null) {
try {
conn.rollback();
MessageBox.messageShow("Transação revertida devido a erro: "+ex.getMessage());
} catch (SQLException rollbackEX) {
rollbackEX.printStackTrace();
}
}
throw new RuntimeException("Erro ao finalizar pedido: "+ex.getMessage(), ex);
}finally {
DBConnection.CloseConnection(conn);
}
return idPedido;
}
}