Omit Transaction.start() in favor of ctx.startTx().
This commit is contained in:
@@ -216,6 +216,21 @@ public class PersistenceContext
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a transaction bound to this persistence context. You <em>must</em> eventually call
|
||||
* {@link Transaction#commit} or {@link Transaction#rollback} on the returned transaction. Also
|
||||
* no other database operations may be performed on other persitence contexts, on the calling
|
||||
* thread, until this transaction is complete.
|
||||
*/
|
||||
public Transaction startTx ()
|
||||
{
|
||||
Transaction tx = Transaction.get();
|
||||
if (tx != null) throw new DatabaseException("Nested transactions not supported.");
|
||||
tx = new Transaction(this);
|
||||
Transaction._activeTx.set(tx);
|
||||
return tx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a snapshot of our current runtime statistics.
|
||||
*/
|
||||
|
||||
@@ -47,19 +47,6 @@ import java.sql.SQLException;
|
||||
*/
|
||||
public class Transaction {
|
||||
|
||||
/**
|
||||
* Starts a transaction using the supplied persistence context. You <em>must</em> eventually
|
||||
* call {@link #commit} or {@link #rollback} on the returned transaction.
|
||||
*/
|
||||
public static Transaction start (PersistenceContext ctx)
|
||||
{
|
||||
Transaction tx = get();
|
||||
if (tx != null) throw new DatabaseException("Nested transactions not supported.");
|
||||
tx = new Transaction(ctx);
|
||||
_activeTx.set(tx);
|
||||
return tx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently active transaction (on the caller's thread), or null.
|
||||
*/
|
||||
@@ -82,7 +69,7 @@ public class Transaction {
|
||||
*/
|
||||
public static void perform (PersistenceContext ctx, Runnable op)
|
||||
{
|
||||
Transaction tx = start(ctx);
|
||||
Transaction tx = ctx.startTx();
|
||||
try {
|
||||
op.run();
|
||||
tx.commit();
|
||||
|
||||
Reference in New Issue
Block a user