68
|
1 package fschmidt.db.postgres;
|
|
2
|
|
3 import java.sql.Connection;
|
|
4 import java.sql.Savepoint;
|
|
5 import java.sql.Statement;
|
|
6 import java.sql.SQLException;
|
|
7
|
|
8
|
|
9 public final class PostgresExceptionHandler {
|
|
10 private boolean inTrans;
|
|
11 private Connection pgCon;
|
|
12 private Savepoint sp;
|
|
13
|
|
14 public PostgresExceptionHandler(Statement stmt) throws SQLException {
|
|
15 pgCon = stmt.getConnection();
|
|
16 inTrans = !pgCon.getAutoCommit();
|
|
17 if( inTrans )
|
|
18 sp = pgCon.setSavepoint();
|
|
19 }
|
|
20
|
|
21 public void handleException() throws SQLException {
|
|
22 if( inTrans )
|
|
23 pgCon.rollback(sp);
|
|
24 }
|
|
25
|
|
26 public void close() throws SQLException {
|
|
27 if( inTrans )
|
|
28 pgCon.releaseSavepoint(sp);
|
|
29 }
|
|
30
|
|
31 }
|