Skip to content

Commit

Permalink
Close DB in finally block
Browse files Browse the repository at this point in the history
closes #157
  • Loading branch information
ar committed Jun 26, 2020
1 parent dae8fc7 commit 27b0f12
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions modules/txn/src/main/java/org/jpos/transaction/Close.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

import java.io.Serializable;

import static org.jpos.transaction.TxnConstants.*;

public class Close extends TxnSupport implements AbortParticipant {
public int prepare (long id, Serializable o) {
return PREPARED | READONLY;
Expand All @@ -40,16 +38,14 @@ public void abort (long id, Serializable o) {
}
private void closeDB (Serializable o) {
Context ctx = (Context) o;
DB db = (DB) ctx.get (DB);
DB db = ctx.get (DB);
if (db != null) {
// ctx.checkPoint ("Closing");
Transaction tx = (Transaction) ctx.get (TX);
Transaction tx = ctx.get (TX);
try {
if (tx != null) {
try {
tx.commit ();
ctx.remove (TX);
// ctx.checkPoint ("Close-Commit");
} catch (RuntimeException t) {
error (t);
try {
Expand All @@ -59,12 +55,12 @@ private void closeDB (Serializable o) {
}
}
}
db.close ();
} catch (RuntimeException ex) {
error (ex);
} finally {
db.close ();
}
}
checkPoint(ctx);
}
}

0 comments on commit 27b0f12

Please sign in to comment.