@Override public int prepareProductsForShipment(Order order, Customer customer) throws OrderWarhouseException { Connection conn = null; try { conn = source.getConnection(); conn.setAutoCommit(false); if (!dao.checkIfProductsAvailable(order, conn)) { throw new OrderWarhouseException("now products!"); } int totalPrice = dao.calculateProductsTotalPrice(order, conn); if (totalPrice > customer.getBalance()) { throw new OrderWarhouseException("no chash!"); } dao.decreaseProductsAmounts(order, conn); conn.commit(); return totalPrice; } catch (Exception e) { if (conn != null) { try { conn.rollback(); } catch (SQLException e1) { e1.printStackTrace(); } } throw new OrderWarhouseException(e); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
@Override public int prepareProductsForShipment(Order order, Customer customer) throws OrderWarhouseException { try { transaction.begin(); if (!dao.checkIfProductsAvailable(order)) { throw new OrderWarhouseException("now products!"); } int totalPrice = dao.calculateProductsTotalPrice(order); Transaction t = mgr.suspend(); logLocationAndTotalPrice(customer, totalPrice); mgr.resume(t); if (totalPrice > customer.getBalance()) { throw new OrderWarhouseException("no chash!"); } dao.decreaseProductsAmounts(order); transaction.commit(); return totalPrice; } catch (Exception e) { try { transaction.rollback(); } catch (Exception e1) { e1.printStackTrace(); } throw new OrderWarhouseException(e); } }