Mercurial Hosting > nabble
comparison src/fschmidt/db/postgres/PostgresExceptionHandler.java @ 68:00520880ad02
add fschmidt source
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 05 Oct 2025 17:24:15 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:9d0fefce6985 | 68:00520880ad02 |
---|---|
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 } |