diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fschmidt/db/postgres/PostgresExceptionHandler.java	Sun Oct 05 17:24:15 2025 -0600
@@ -0,0 +1,31 @@
+package fschmidt.db.postgres;
+
+import java.sql.Connection;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.sql.SQLException;
+
+
+public final class PostgresExceptionHandler {
+	private boolean inTrans;
+	private Connection pgCon;
+	private Savepoint sp;
+
+	public PostgresExceptionHandler(Statement stmt) throws SQLException {
+		pgCon = stmt.getConnection();
+		inTrans = !pgCon.getAutoCommit();
+		if( inTrans )
+			sp = pgCon.setSavepoint();
+	}
+
+	public void handleException() throws SQLException {
+		if( inTrans )
+			pgCon.rollback(sp);
+	}
+
+	public void close() throws SQLException {
+		if( inTrans )
+			pgCon.releaseSavepoint(sp);
+	}
+
+}