com.rapleaf.jack.queries.AbstractExecution Maven / Gradle / Ivy
package com.rapleaf.jack.queries;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import com.rapleaf.jack.BaseDatabaseConnection;
import com.rapleaf.jack.exception.BulkOperationException;
import com.rapleaf.jack.exception.JackRuntimeException;
public abstract class AbstractExecution {
protected static int MAX_CONNECTION_RETRIES = 1;
final BaseDatabaseConnection dbConnection;
AbstractExecution(BaseDatabaseConnection dbConnection) {
this.dbConnection = dbConnection;
}
/**
* @return fully prepared SQL statement
*/
public String getSqlStatement() {
return this.getPreparedStatement(Optional.empty()).toString();
}
protected PreparedStatement getPreparedStatementStreaming() {
PreparedStatement preparedStatement = dbConnection.getPreparedStatement(getQueryStatement(),
java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY);
setStatementParameters(preparedStatement, getParameters());
return preparedStatement;
}
protected PreparedStatement getPreparedStatement(Optional options) {
PreparedStatement preparedStatement;
preparedStatement = options
.map(integer -> dbConnection.getPreparedStatement(getQueryStatement(), integer))
.orElseGet(() -> dbConnection.getPreparedStatement(getQueryStatement()));
setStatementParameters(preparedStatement, getParameters());
return preparedStatement;
}
protected void checkBulkOperation(boolean allowBulkOperation, Collection whereConstraints) {
if (!allowBulkOperation && whereConstraints.isEmpty()) {
throw new BulkOperationException("Bulk operation is not allowed; either enable it, or specify at least one where constraint");
}
}
private void setStatementParameters(PreparedStatement preparedStatement, Collection
© 2015 - 2024 Weber Informatics LLC | Privacy Policy