File loader loads data into a list from SQL database.
File loader must extend AbstractSqlDataBaseLoader.
First of all, get the current SQL database, you can do it thanks to T-DataBasesAPI.
The prefix of the table will be added automatically.
public class MyDatabaseLoader extends AbstractSqlDataBaseLoader<MyUser> {
/**
* Loads data from the database
*/
@Override
public void load(String tableName) {
QueryBuilder queryBuilder = new QueryBuilder();
String query = queryBuilder.selectAll(tableName).build();
try (ResultSet resultSet = currentSqlDataBase.getAsyncQuery().query(query)) {
while (resultSet.next()) {
MyUser user = new MyUser(
UUID.fromString(resultSet.getString("uuid")),
resultSet.getInt("coins")
);
getData().add(user);
}
} catch (ExecutionException | InterruptedException | SQLException e) {
throw new RuntimeException(e);
}
}
protected String getTableName(){
return MyUser.TABLE_NAME;
}
}