41 lines
1.0 KiB
Java
41 lines
1.0 KiB
Java
package eu.univento.commons.database;
|
|
|
|
import lombok.Getter;
|
|
|
|
import java.sql.ResultSet;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.function.Consumer;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 1.0
|
|
*/
|
|
public class AsyncMySQL {
|
|
|
|
private ExecutorService executor;
|
|
@Getter
|
|
private MySQL mySQL;
|
|
|
|
public AsyncMySQL(String host, String port, String user, String password, String database) {
|
|
try {
|
|
mySQL = new MySQL(host, port, user, password, database);
|
|
executor = Executors.newCachedThreadPool();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public void update(String update) {
|
|
executor.execute(() -> mySQL.update(update));
|
|
}
|
|
|
|
public void query(String query, Consumer<ResultSet> consumer) {
|
|
executor.execute(() -> {
|
|
ResultSet result;
|
|
result = mySQL.query(query);
|
|
ResultSet finalResult = result;
|
|
consumer.accept(finalResult);
|
|
});
|
|
}
|
|
} |