7
7
import com .github .fernthedev .fernapi .universal .data .chat .ChatColor ;
8
8
import com .github .fernthedev .fernapi .universal .data .database .*;
9
9
import com .github .fernthedev .fernapi .universal .exceptions .database .DatabaseException ;
10
- import lombok .AccessLevel ;
11
- import lombok .Getter ;
12
- import lombok .NonNull ;
13
- import lombok .Setter ;
10
+ import lombok .*;
14
11
import org .intellij .lang .annotations .Language ;
15
12
import org .panteleyev .mysqlapi .MySqlProxy ;
16
13
import org .panteleyev .mysqlapi .annotations .Column ;
@@ -144,7 +141,7 @@ public CompletableFuture<List<DbRow>> getTableRows(String name) {
144
141
@ Language ("SQL" ) String sql = "SELECT * FROM " + name + ";" ;
145
142
Universal .debug (ChatColor .GREEN + "Executing {}" , sql );
146
143
147
- return database .getResultsAsync (sql );
144
+ return database .getResultsAsync (sql ). handle ( this :: handleException ) ;
148
145
}
149
146
150
147
/**
@@ -167,7 +164,7 @@ public <T extends RowData> CompletableFuture<Void> removeRowIfColumnContainsValu
167
164
} catch (SQLException throwables ) {
168
165
throwables .printStackTrace ();
169
166
}
170
- });
167
+ }). handle ( this :: handleException ) ;
171
168
172
169
}
173
170
@@ -200,7 +197,7 @@ public <T extends RowData> CompletableFuture<Integer> insertIntoTable(TableInfo<
200
197
}
201
198
202
199
return dbStatement ;
203
- });
200
+ }). handle ( this :: handleException ) ;
204
201
205
202
}
206
203
@@ -224,7 +221,7 @@ public <T extends RowData> CompletableFuture<Integer> updateRow(TableInfo<T> tab
224
221
Universal .debug (ChatColor .GREEN + "Fully Executed {} {} ({}) {} {}" , sql , tableInfo .getTableName (), columnValues , conditionKey , conditionValue );
225
222
tableInfo .loadFromDB (DatabaseListener .this );
226
223
return integer ;
227
- });
224
+ }). handle ( this :: handleException ) ;
228
225
229
226
230
227
}
@@ -239,7 +236,7 @@ public <T extends RowData> CompletableFuture<Integer> removeTable(TableInfo<T> t
239
236
240
237
Universal .debug ("Executing {}" , sql );
241
238
242
- return database .executeUpdateAsync (sql );
239
+ return database .executeUpdateAsync (sql ). handle ( this :: handleException ) ;
243
240
}
244
241
245
242
/**
@@ -398,7 +395,7 @@ public <T extends RowData> CompletableFuture<Void> createTable(@NonNull TableInf
398
395
}
399
396
400
397
tableDataInfo .loadFromDB (DatabaseListener .this );
401
- });
398
+ }). handle ( this :: handleException ) ;
402
399
403
400
404
401
}
@@ -407,4 +404,14 @@ protected Logger getLogger() {
407
404
return Universal .getMethods ().getAbstractLogger ();
408
405
}
409
406
407
+ @ SneakyThrows
408
+ protected <T > T handleException (T t , Throwable throwable ) {
409
+ if (throwable != null ) {
410
+ Universal .getLogger ().error (throwable .getMessage (), t );
411
+ throw throwable ;
412
+ }
413
+
414
+ return t ;
415
+ }
416
+
410
417
}
0 commit comments