All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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> func){
		return Single.defer(() -> {
			Single connection = getConnection();
			return connection.flatMap(conn -> {
				return func.call(conn).doAfterTerminate(() -> {
					conn.close();
				});
			});
		});
	}

	public static Completable doInConnectionCompletable(Func1 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