com.jporm.rx.query.find.CustomResultFindQueryExecutionProvider Maven / Gradle / Ivy
/*******************************************************************************
* Copyright 2013 Francesco Cina'
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.jporm.rx.query.find;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;
import com.jporm.commons.core.exception.JpoException;
import com.jporm.commons.core.exception.JpoNotUniqueResultException;
import com.jporm.commons.core.function.IntBiConsumer;
import com.jporm.commons.core.function.IntBiFunction;
import com.jporm.rx.session.SqlExecutor;
import com.jporm.sql.query.select.SelectCommon;
import com.jporm.types.io.ResultEntry;
import com.jporm.types.io.ResultSet;
/**
*
* @author Francesco Cina
*
* 07/lug/2011
*/
public interface CustomResultFindQueryExecutionProvider extends SelectCommon {
/**
* Execute the query reading the ResultSet with a {@link ResultSetReader}.
*
* @param rse
* object that will extract all rows of results
* @return an arbitrary result object, as returned by the
* {@link ResultSetReader}
*/
default CompletableFuture fetch(Function resultSetReader) {
return getSqlExecutor().query(sqlQuery(), sqlValues(), resultSetReader);
}
/**
* Execute the query reading the ResultSet with a {@link ResultSetReader}.
*
* @param rse
* object that will extract all rows of results
* @return an arbitrary result object, as returned by the
* {@link ResultSetReader}
*/
default CompletableFuture fetch(Consumer resultSetReader) {
return getSqlExecutor().query(sqlQuery(), sqlValues(), resultSetReader);
}
/**
* Execute the query reading the ResultSet with a {@link ResultSetRowReader}
* .
*
* @param rsrr
* object that will extract all rows of results
* @return a List of result objects returned by the
* {@link ResultSetRowReader}
*/
default CompletableFuture> fetch(IntBiFunction resultSetRowReader) {
return getSqlExecutor().query(sqlQuery(), sqlValues(), resultSetRowReader);
}
/**
* Execute the query reading the ResultSet with a {@link ResultSetRowReader}
* .
*
* @param rsrr
* object that will extract all rows of results
* @return a List of result objects returned by the
* {@link ResultSetRowReader}
*/
default CompletableFuture fetch(IntBiConsumer resultSetRowReader) {
return getSqlExecutor().query(sqlQuery(), sqlValues(), resultSetRowReader);
}
/**
* Execute the query and read the result as an {@link BigDecimal} value. If
* more than one rows are returned by the query, the first value is
* returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture fetchBigDecimal() {
return getSqlExecutor().queryForBigDecimal(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link BigDecimal} value. If
* more than one rows are returned by the query, the first value is
* returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture> fetchBigDecimalOptional() {
return fetchBigDecimal().thenApply(value -> Optional.ofNullable(value));
}
/**
* Execute the query and read the result as a BigDecimal value
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @throws JpoNotUniqueResultException
* if the results of the query executions are not exactly 1
* @return
*/
default CompletableFuture fetchBigDecimalUnique() {
return getSqlExecutor().queryForBigDecimalUnique(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link Boolean} value. If
* more than one rows are returned by the query, the first value is
* returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture fetchBoolean() {
return getSqlExecutor().queryForBoolean(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link Boolean} value. If
* more than one rows are returned by the query, the first value is
* returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture> fetchBooleanOptional() {
return fetchBoolean().thenApply(value -> Optional.ofNullable(value));
}
/**
* Execute the query and read the result as a boolean value
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @throws JpoNotUniqueResultException
* if the results of the query executions are not exactly 1
* @return
*/
default CompletableFuture fetchBooleanUnique() {
return getSqlExecutor().queryForBooleanUnique(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link Double} value. If more
* than one rows are returned by the query, the first value is returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture fetchDouble() {
return getSqlExecutor().queryForDouble(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link Double} value. If more
* than one rows are returned by the query, the first value is returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture> fetchDoubleOptional() {
return fetchDouble().thenApply(value -> Optional.ofNullable(value));
}
/**
* Execute the query and read the result as a double value
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @throws JpoNotUniqueResultException
* if the results of the query executions are not exactly 1
* @return
*/
default CompletableFuture fetchDoubleUnique() {
return getSqlExecutor().queryForDoubleUnique(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link Float} value. If more
* than one rows are returned by the query, the first value is returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture fetchFloat() {
return getSqlExecutor().queryForFloat(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link Float} value. If more
* than one rows are returned by the query, the first value is returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture> fetchFloatOptional() {
return fetchFloat().thenApply(value -> Optional.ofNullable(value));
}
/**
* Execute the query and read the result as a float value
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @throws JpoNotUniqueResultException
* if the results of the query executions are not exactly 1
* @return
*/
default CompletableFuture fetchFloatUnique() {
return getSqlExecutor().queryForFloatUnique(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link Integer} value. If
* more than one rows are returned by the query, the first value is
* returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture fetchInt() {
return getSqlExecutor().queryForInt(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link Integer} value. If
* more than one rows are returned by the query, the first value is
* returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture> fetchIntOptional() {
return fetchInt().thenApply(value -> Optional.ofNullable(value));
}
/**
* Execute the query and read the result as an {@link Integer} value
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @throws JpoNotUniqueResultException
* if the results of the query executions are not exactly 1
* @return
*/
default CompletableFuture fetchIntUnique() {
return getSqlExecutor().queryForIntUnique(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link Long} value. If more
* than one rows are returned by the query, the first value is returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture fetchLong() {
return getSqlExecutor().queryForLong(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link Long} value. If more
* than one rows are returned by the query, the first value is returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture> fetchLongOptional() {
return fetchLong().thenApply(value -> Optional.ofNullable(value));
}
/**
* Execute the query and read the result as an {@link Long} value
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @throws JpoNotUniqueResultException
* if the results of the query executions are not exactly 1
* @return
*/
default CompletableFuture fetchLongUnique() {
return getSqlExecutor().queryForLongUnique(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link String} value. If more
* than one rows are returned by the query, the first value is returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture fetchString() {
return getSqlExecutor().queryForString(sqlQuery(), sqlValues());
}
/**
* Execute the query and read the result as an {@link String} value. If more
* than one rows are returned by the query, the first value is returned.
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @return
*/
default CompletableFuture> fetchStringOptional() {
return fetchString().thenApply(value -> Optional.ofNullable(value));
}
/**
* Execute the query and read the result as a String value
*
* @param sql
* SQL query to execute
* @param args
* arguments to bind to the query
* @throws JpoNotUniqueResultException
* if the results of the query executions are not exactly 1
* @return
*/
default CompletableFuture fetchStringUnique() {
return getSqlExecutor().queryForStringUnique(sqlQuery(), sqlValues());
}
/**
* Execute the query reading the ResultSet with a {@link ResultSetRowReader}
* .
*
* @param rsrr
* object that will extract the row of result
* @return
* @throws JpoException
* @throws JpoNotUniqueResultException
* if the results of the query executions are not exactly 1
*/
default CompletableFuture fetchUnique(IntBiFunction resultSetRowReader) {
return getSqlExecutor().queryForUnique(sqlQuery(), sqlValues(), resultSetRowReader);
}
/**
* Execute the query reading the ResultSet with a {@link ResultSetRowReader}. If more
* than one rows are returned by the query, the first value is returned.
*
* @param rsrr
* object that will extract the row of result
* @return
* @throws JpoException
*/
default CompletableFuture> fetchOptional(final IntBiFunction resultSetRowReader) throws JpoException {
return getSqlExecutor().queryForOptional(sqlQuery(), sqlValues(), resultSetRowReader);
}
/**
* Return the count of entities this query should return.
*
* @return
*/
default CompletableFuture fetchRowCount() {
return getSqlExecutor().queryForInt(sqlRowCountQuery(), sqlValues());
}
SqlExecutor getSqlExecutor();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy