File tree Expand file tree Collapse file tree
asql-core/src/main/java/me/zort/sqllib Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package me .zort .sqllib ;
22
33import lombok .AllArgsConstructor ;
4- import lombok .Data ;
54import lombok .Getter ;
65import me .zort .sqllib .api .Query ;
76import me .zort .sqllib .api .SQLConnection ;
@@ -376,7 +375,10 @@ protected void logSqlError(Exception e) {
376375
377376 @ SuppressWarnings ("all" )
378377 protected void notifyHandlers (int code ) {
379- errorCount ++;
378+ if (code >= 100 ) {
379+ // Code is higher than 99, so it's an error
380+ errorCount ++;
381+ }
380382 this .codeHandlers .forEach (handler -> runCatching (() -> handler .onNotified (code )));
381383 }
382384
@@ -398,9 +400,11 @@ protected static class DefsVals {
398400 }
399401
400402 public static final class Code {
401- public static final int QUERY_FATAL = 0 ;
402403 public static final int CONNECTED = 1 ;
403404 public static final int CLOSED = 2 ;
404405 public static final int CLEARING = 3 ;
406+
407+ // Error codes start on 100
408+ public static final int QUERY_FATAL = 100 ;
405409 }
406410}
Original file line number Diff line number Diff line change @@ -130,18 +130,28 @@ private PooledSQLDatabaseConnection establishObject() throws SQLException {
130130 if (error != null ) throw error ;
131131
132132 if (polled instanceof SQLDatabaseConnectionImpl )
133- ((SQLDatabaseConnectionImpl ) polled ).addCodeHandler (code -> handleConnectionError (polled ));
133+ ((SQLDatabaseConnectionImpl ) polled ).addCodeHandler (code -> handleConnectionCode (polled , code ));
134134
135135 return polled ;
136136 }
137137
138- synchronized void handleConnectionError (PooledSQLDatabaseConnection polled ) {
139- errorCount ++;
138+ synchronized void handleConnectionCode (PooledSQLDatabaseConnection polled , int code ) {
139+ if (code == SQLDatabaseConnection .Code .CONNECTED ) {
140+ return ;
141+ }
142+
143+ if (code >= 100 ) {
144+ errorCount ++;
145+ }
140146 // Remove the connection from the pool and disconnect
141147 // on fatal errors.
142148 freeConnections .remove (polled );
143149 usedConnections .remove (polled );
144- polled .disconnect ();
150+ if (code != SQLDatabaseConnection .Code .CLOSED ) {
151+ // I prevent stack overflow by closing only connections
152+ // that are not already closed.
153+ polled .disconnect ();
154+ }
145155 }
146156
147157 void releaseObject (PooledSQLDatabaseConnection connection ) {
You can’t perform that action at this time.
0 commit comments