se.fortnox.reactivewizard.db.ReactiveStatementFactory Maven / Gradle / Ivy
package se.fortnox.reactivewizard.db;
import org.reactivestreams.Publisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.FluxSink;
import reactor.core.publisher.Mono;
import se.fortnox.reactivewizard.db.config.DatabaseConfig;
import se.fortnox.reactivewizard.db.paging.PagingOutput;
import se.fortnox.reactivewizard.db.statement.DbStatementFactory;
import se.fortnox.reactivewizard.db.statement.Statement;
import se.fortnox.reactivewizard.db.transactions.ConnectionScheduler;
import se.fortnox.reactivewizard.db.transactions.StatementContext;
import se.fortnox.reactivewizard.metrics.Metrics;
import se.fortnox.reactivewizard.util.DebugUtil;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.function.Function;
import static java.lang.String.format;
import static se.fortnox.reactivewizard.util.ReactiveDecorator.decorated;
public class ReactiveStatementFactory {
private static final int RECORD_BUFFER_SIZE = 100000;
private static final Logger LOG = LoggerFactory.getLogger("Dao");
private static final String QUERY_FAILED = "Query failed";
private final DbStatementFactory statementFactory;
private final PagingOutput pagingOutput;
private final Function resultConverter;
private final Metrics metrics;
private final DatabaseConfig config;
private final boolean isReturnTypeMono;
public ReactiveStatementFactory(
DbStatementFactory statementFactory,
PagingOutput pagingOutput,
Metrics metrics,
DatabaseConfig config,
Function resultConverter,
Method method) {
this.statementFactory = statementFactory;
this.pagingOutput = pagingOutput;
this.metrics = metrics;
this.config = config;
this.resultConverter = resultConverter;
isReturnTypeMono = Mono.class.isAssignableFrom(method.getReturnType());
}
private static void closeSilently(Connection connection) {
try {
connection.close();
} catch (SQLException sqlException) {
LOG.warn("Failed to close connection", sqlException);
}
}
private Flux
© 2015 - 2025 Weber Informatics LLC | Privacy Policy