2222import org .firebirdsql .gds .ng .AbstractFbTransaction ;
2323import org .firebirdsql .gds .ng .LockCloseable ;
2424import org .firebirdsql .gds .ng .TransactionState ;
25+ import org .firebirdsql .jaybird .xca .FatalErrorHelper ;
2526import org .firebirdsql .jna .fbclient .FbClientLibrary ;
2627import org .firebirdsql .jna .fbclient .ISC_STATUS ;
2728import org .firebirdsql .logging .Logger ;
@@ -78,13 +79,15 @@ public IntByReference getJnaHandle() {
7879 @ Override
7980 public void commit () throws SQLException {
8081 try (LockCloseable ignored = withLock ()) {
81- final JnaDatabase db = getDatabase ();
82- db .checkConnected ();
82+ checkDbAttached ();
8383 switchState (TransactionState .COMMITTING );
8484 clientLibrary .isc_commit_transaction (statusVector , handle );
8585 processStatusVector ();
8686 switchState (TransactionState .COMMITTED );
8787 } catch (SQLException e ) {
88+ if (FatalErrorHelper .isBrokenConnection (e )) {
89+ forceAbortedUnknownState ();
90+ }
8891 exceptionListenerDispatcher .errorOccurred (e );
8992 throw e ;
9093 } finally {
@@ -103,13 +106,15 @@ public void commit() throws SQLException {
103106 @ Override
104107 public void rollback () throws SQLException {
105108 try (LockCloseable ignored = withLock ()) {
106- final JnaDatabase db = getDatabase ();
107- db .checkConnected ();
109+ checkDbAttached ();
108110 switchState (TransactionState .ROLLING_BACK );
109111 clientLibrary .isc_rollback_transaction (statusVector , handle );
110112 processStatusVector ();
111113 switchState (TransactionState .ROLLED_BACK );
112114 } catch (SQLException e ) {
115+ if (FatalErrorHelper .isBrokenConnection (e )) {
116+ forceAbortedUnknownState ();
117+ }
113118 exceptionListenerDispatcher .errorOccurred (e );
114119 throw e ;
115120 } finally {
@@ -129,8 +134,7 @@ public void rollback() throws SQLException {
129134 public void prepare (byte [] recoveryInformation ) throws SQLException {
130135 boolean noRecoveryInfo = recoveryInformation == null || recoveryInformation .length == 0 ;
131136 try (LockCloseable ignored = withLock ()) {
132- final JnaDatabase db = getDatabase ();
133- db .checkConnected ();
137+ checkDbAttached ();
134138 switchState (TransactionState .PREPARING );
135139 if (noRecoveryInfo ) {
136140 clientLibrary .isc_prepare_transaction (statusVector , handle );
@@ -141,6 +145,9 @@ public void prepare(byte[] recoveryInformation) throws SQLException {
141145 processStatusVector ();
142146 switchState (TransactionState .PREPARED );
143147 } catch (SQLException e ) {
148+ if (FatalErrorHelper .isBrokenConnection (e )) {
149+ forceAbortedUnknownState ();
150+ }
144151 exceptionListenerDispatcher .errorOccurred (e );
145152 throw e ;
146153 } finally {
@@ -161,8 +168,7 @@ public byte[] getTransactionInfo(byte[] requestItems, int maxBufferLength) throw
161168 try {
162169 final ByteBuffer responseBuffer = ByteBuffer .allocateDirect (maxBufferLength );
163170 try (LockCloseable ignored = withLock ()) {
164- final JnaDatabase db = getDatabase ();
165- db .checkConnected ();
171+ checkDbAttached ();
166172 clientLibrary .isc_transaction_info (statusVector , handle , (short ) requestItems .length , requestItems ,
167173 (short ) maxBufferLength , responseBuffer );
168174 processStatusVector ();
0 commit comments