Java Code Examples for com.atomikos.icatch.jta.UserTransactionImp#commit()
The following examples show how to use
com.atomikos.icatch.jta.UserTransactionImp#commit() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeListener.java From JPPF with Apache License 2.0 | 6 votes |
/** * Terminate the transaction and return an exception if any occurred. * @return Exception if any error occurred. */ @Override public Exception call() { try { final UserTransactionImp utx = new UserTransactionImp(); if (utx.getStatus() == Status.STATUS_NO_TRANSACTION) output("WARNING: endTransaction() called outside a tx"); else { output("INFO: transaction " + (rollback ? "rollback" : "commit")); if (rollback) utx.rollback(); else utx.commit(); } return null; } catch (final Exception e) { return e; } }
Example 2
Source File: ApplicationUnitTest.java From tutorials with MIT License | 6 votes |
private static long getBalance(DataSource inventoryDataSource, String productId) throws Exception { UserTransactionImp utx = new UserTransactionImp(); utx.begin(); Connection inventoryConnection = inventoryDataSource.getConnection(); Statement s1 = inventoryConnection.createStatement(); String q1 = "select balance from Inventory where productId='" + productId + "'"; ResultSet rs1 = s1.executeQuery(q1); if (rs1 == null || !rs1.next()) throw new Exception("Product not found: " + productId); long balance = rs1.getLong(1); inventoryConnection.close(); utx.commit(); return balance; }
Example 3
Source File: Application.java From tutorials with MIT License | 5 votes |
public void placeOrder(String productId, int amount) throws Exception { UserTransactionImp utx = new UserTransactionImp(); String orderId = UUID.randomUUID() .toString(); boolean rollback = false; try { utx.begin(); Connection inventoryConnection = inventoryDataSource.getConnection(); Connection orderConnection = orderDataSource.getConnection(); Statement s1 = inventoryConnection.createStatement(); String q1 = "update Inventory set balance = balance - " + amount + " where productId ='" + productId + "'"; s1.executeUpdate(q1); s1.close(); Statement s2 = orderConnection.createStatement(); String q2 = "insert into Orders values ( '" + orderId + "', '" + productId + "', " + amount + " )"; s2.executeUpdate(q2); s2.close(); inventoryConnection.close(); orderConnection.close(); } catch (Exception e) { System.out.println(e.getMessage()); rollback = true; } finally { if (!rollback) utx.commit(); else utx.rollback(); } }