![JAR search and dependency download from the Maven repository](/logo.png)
net.redpipe.engine.db.SQLUtil Maven / Gradle / Ivy
package net.redpipe.engine.db;
import io.reactivex.Completable;
import io.reactivex.Single;
import io.vertx.reactivex.ext.sql.SQLConnection;
import net.redpipe.engine.core.AppGlobals;
import rx.functions.Func1;
public class SQLUtil {
public static Single getConnection(){
return AppGlobals.get().getDbConnection();
}
public static Single doInConnection(Func1 super SQLConnection, ? extends Single> func){
return Single.defer(() -> {
Single connection = getConnection();
return connection.flatMap(conn -> {
return func.call(conn).doAfterTerminate(() -> {
conn.close();
});
});
});
}
public static Completable doInConnectionCompletable(Func1 super SQLConnection, ? extends Completable> func){
return Completable.defer(() -> {
Single connection = getConnection();
return connection.flatMapCompletable(conn -> {
return func.call(conn).doAfterTerminate(() -> {
conn.close();
});
});
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy