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

org.jooq.ResultQuery Maven / Gradle / Ivy

There is a newer version: 0.10.0
Show newest version
/**
 * Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com)
 * All rights reserved.
 *
 * This work is dual-licensed
 * - under the Apache Software License 2.0 (the "ASL")
 * - under the jOOQ License and Maintenance Agreement (the "jOOQ License")
 * =============================================================================
 * You may choose which license applies to you:
 *
 * - If you're using this work with Open Source databases, you may choose
 *   either ASL or jOOQ License.
 * - If you're using this work with at least one commercial database, you must
 *   choose jOOQ License
 *
 * For more information, please visit http://www.jooq.org/licenses
 *
 * Apache Software License 2.0:
 * -----------------------------------------------------------------------------
 * 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.
 *
 * jOOQ License and Maintenance Agreement:
 * -----------------------------------------------------------------------------
 * Data Geekery grants the Customer the non-exclusive, timely limited and
 * non-transferable license to install and use the Software under the terms of
 * the jOOQ License and Maintenance Agreement.
 *
 * This library is distributed with a LIMITED WARRANTY. See the jOOQ License
 * and Maintenance Agreement for more details: http://www.jooq.org/licensing
 */

package org.jooq;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;

import org.jooq.conf.Settings;
import org.jooq.exception.DataAccessException;
import org.jooq.exception.DataTypeException;
import org.jooq.exception.InvalidResultException;
import org.jooq.exception.MappingException;
import org.jooq.impl.DefaultRecordMapper;

/**
 * A query that can return results. Mostly, this is a {@link Select} query used
 * for a SELECT statement.
 * 

*

Lifecycle guarantees

Most methods in this type are based on * {@link #fetch()}, which completes the whole {@link ConnectionProvider} and * {@link ExecuteListener} lifecycles, eagerly fetching all results into memory. * Underlying JDBC {@link ResultSet}s are always closed. Underlying JDBC * {@link PreparedStatement}s are closed, unless {@link #keepStatement(boolean)} * is set. *

* In order to keep open {@link ResultSet}s and fetch records lazily, use * {@link #fetchLazy()} instead and then operate on {@link Cursor}. * * @author Lukas Eder */ public interface ResultQuery extends Query, Iterable { /** * Return the result generated by a previous call to execute(). * * @return The result or null if no call to execute() was done * previously. */ Result getResult(); /** * Execute the query and return the generated result. *

* This is the same as calling {@link #execute()} and then * {@link #getResult()} *

* The result and its contained records are attached to the original * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} * to override this behaviour. *

Lifecycle guarantees

This method completes the whole * {@link ConnectionProvider} and {@link ExecuteListener} lifecycles, * eagerly fetching all results into memory. Underlying JDBC * {@link ResultSet}s are always closed. Underlying JDBC * {@link PreparedStatement}s are closed, unless * {@link #keepStatement(boolean)} is set. *

* In order to keep open {@link ResultSet}s and fetch records lazily, use * {@link #fetchLazy()} instead and then operate on {@link Cursor}. * * @return The result. * @throws DataAccessException if something went wrong executing the query */ Result fetch() throws DataAccessException; /** * Execute the query and return the generated result as a JDBC * {@link ResultSet}. *

* This is the same as calling {@link #fetchLazy()}. * {@link Cursor#resultSet() resultSet()} and will return a * {@link ResultSet} wrapping the JDBC driver's ResultSet. * Closing this ResultSet may close the producing * {@link Statement} or {@link PreparedStatement}, depending on your setting * for {@link #keepStatement(boolean)}. *

* You can use this method when you want to use jOOQ for query execution, * but not for result fetching. The returned ResultSet can also * be used with {@link DSLContext#fetch(ResultSet)}. * * @return The result. * @throws DataAccessException if something went wrong executing the query */ ResultSet fetchResultSet() throws DataAccessException; /** * Execute the query and return the generated result. *

* This is essentially the same as {@link #fetch()}, except that being * declared in {@link Iterable}, this method can be used in Java 5 foreach * statements. *

* {@inheritDoc} */ @Override Iterator iterator() throws DataAccessException; /** * Execute the query and "lazily" return the generated result. *

* The returned {@link Cursor} holds a reference to the executed * {@link PreparedStatement} and the associated {@link ResultSet}. Data can * be fetched (or iterated over) lazily, fetching records from the * {@link ResultSet} one by one. *

* Depending on your JDBC driver's default behaviour, this may load the * whole database result into the driver's memory. In order to indicate to * the driver that you may not want to fetch all records at once, use * {@link #fetchLazy(int)} *

* Client code is responsible for closing the cursor after use. * * @return The resulting cursor. * @throws DataAccessException if something went wrong executing the query * @see #fetchLazy(int) */ Cursor fetchLazy() throws DataAccessException; /** * Execute the query and "lazily" return the generated result. *

* The returned {@link Cursor} holds a reference to the executed * {@link PreparedStatement} and the associated {@link ResultSet}. Data can * be fetched (or iterated over) lazily, fetching records from the * {@link ResultSet} one by one. *

* Depending on your JDBC driver's behaviour, this will load only * fetchSize records from the database into memory at once. For * more details, see also {@link Statement#setFetchSize(int)} *

* Client code is responsible for closing the cursor after use. * * @return The resulting cursor. * @throws DataAccessException if something went wrong executing the query * @see #fetchLazy() * @see Statement#setFetchSize(int) * @deprecated - [#2811] - 3.3.0 - Use {@link #fetchSize(int)} and * {@link #fetchLazy()} instead. */ @Deprecated Cursor fetchLazy(int fetchSize) throws DataAccessException; /** * Execute a query, possibly returning several result sets. *

* Example (Sybase ASE): *

*

     * String sql = "sp_help 'my_table'";
*

* The result and its contained records are attached to the original * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} * to override this behaviour. * * @return The resulting records * @throws DataAccessException if something went wrong executing the query */ List> fetchMany() throws DataAccessException; /** * Execute the query and return all values for a field from the generated * result. *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(Field)} * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query */ List fetch(Field field) throws DataAccessException; /** * Execute the query and return all values for a field from the generated * result. *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(Field, Class)} * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Record#getValue(Field, Class) */ List fetch(Field field, Class type) throws DataAccessException; /** * Execute the query and return all values for a field from the generated * result. *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(Field, Converter)} * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Record#getValue(Field, Converter) */ List fetch(Field field, Converter converter) throws DataAccessException; /** * Execute the query and return all values for a field index from the * generated result. *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(int)} * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query */ List fetch(int fieldIndex) throws DataAccessException; /** * Execute the query and return all values for a field index from the * generated result. *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(int, Class)} * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Record#getValue(int, Class) */ List fetch(int fieldIndex, Class type) throws DataAccessException; /** * Execute the query and return all values for a field index from the * generated result. *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(int, Converter)} * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Record#getValue(int, Converter) */ List fetch(int fieldIndex, Converter converter) throws DataAccessException; /** * Execute the query and return all values for a field name from the * generated result. *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(String)} * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query */ List fetch(String fieldName) throws DataAccessException; /** * Execute the query and return all values for a field name from the * generated result. *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(String, Class)} * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Record#getValue(String, Class) */ List fetch(String fieldName, Class type) throws DataAccessException; /** * Execute the query and return all values for a field name from the * generated result. *

* This is the same as calling {@link #fetch()} and then * {@link Result#getValues(String, Converter)} * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Record#getValue(String, Converter) */ List fetch(String fieldName, Converter converter) throws DataAccessException; /** * Execute the query and return return at most one resulting value for a * field from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(Field)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ T fetchOne(Field field) throws DataAccessException, InvalidResultException; /** * Execute the query and return return at most one resulting value for a * field from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(Field, Class)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ T fetchOne(Field field, Class type) throws DataAccessException, InvalidResultException; /** * Execute the query and return return at most one resulting value for a * field from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(Field, Converter)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ U fetchOne(Field field, Converter converter) throws DataAccessException, InvalidResultException; /** * Execute the query and return return at most one resulting value for a * field index from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(int)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ Object fetchOne(int fieldIndex) throws DataAccessException, InvalidResultException; /** * Execute the query and return return at most one resulting value for a * field index from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(int, Class)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ T fetchOne(int fieldIndex, Class type) throws DataAccessException, InvalidResultException; /** * Execute the query and return return at most one resulting value for a * field index from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(int, Converter)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ U fetchOne(int fieldIndex, Converter converter) throws DataAccessException, InvalidResultException; /** * Execute the query and return return at most one resulting value for a * field name from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(int)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ Object fetchOne(String fieldName) throws DataAccessException, InvalidResultException; /** * Execute the query and return return at most one resulting value for a * field name from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(String, Class)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ T fetchOne(String fieldName, Class type) throws DataAccessException, InvalidResultException; /** * Execute the query and return return at most one resulting value for a * field name from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(String, Converter)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ U fetchOne(String fieldName, Converter converter) throws DataAccessException, InvalidResultException; /** * Execute the query and return at most one resulting record. *

* The resulting record is attached to the original {@link Configuration} by * default. Use {@link Settings#isAttachRecords()} to override this * behaviour. * * @return The resulting record or null if the query returns no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ R fetchOne() throws DataAccessException, InvalidResultException; /** * Execute the query and return at most one resulting record as a name/value * map. * * @return The resulting record or null if the query returns no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record * @see Result#intoMaps() * @see Record#intoMap() */ Map fetchOneMap() throws DataAccessException, InvalidResultException; /** * Execute the query and return at most one resulting record as an array *

* You can access data like this *

query.fetchOneArray()[fieldIndex]
* * @return The resulting record or null if the query returns no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ Object[] fetchOneArray() throws DataAccessException, InvalidResultException; /** * Map resulting records onto a custom type. *

* This is the same as calling

     * E result = null;
     * Record r = q.fetchOne();
     *
     * if (r != null)
     *     result = r.into(type);
     * 
. See {@link Record#into(Class)} for more details * * @param The generic entity type. * @param type The entity type. * @return The resulting record or null if the query returns no * records. * @see Record#into(Class) * @see Result#into(Class) * @throws DataAccessException if something went wrong executing the query * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @throws InvalidResultException if the query returned more than one record * @see DefaultRecordMapper */ E fetchOneInto(Class type) throws DataAccessException, MappingException, InvalidResultException; /** * Map resulting records onto a custom record. *

* This is the same as calling

     * Z result = null;
     * Record r = q.fetchOne();
     *
     * if (r != null)
     *     result = r.into(table);
     * 
. See {@link Record#into(Table)} for more details *

* The resulting record is attached to the original {@link Configuration} by * default. Use {@link Settings#isAttachRecords()} to override this * behaviour. * * @param The generic table record type. * @param table The table type. * @return The resulting record or null if the query returns no * records. * @see Record#into(Table) * @see Result#into(Table) * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ Z fetchOneInto(Table table) throws DataAccessException, InvalidResultException; /** * Execute the query and return return at most one resulting value for a * field from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(Field)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ T fetchAny(Field field) throws DataAccessException; /** * Execute the query and return return at most one resulting value for a * field from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(Field, Class)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ T fetchAny(Field field, Class type) throws DataAccessException; /** * Execute the query and return return at most one resulting value for a * field from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(Field, Converter)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ U fetchAny(Field field, Converter converter) throws DataAccessException; /** * Execute the query and return return at most one resulting value for a * field index from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(int)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query */ Object fetchAny(int fieldIndex) throws DataAccessException; /** * Execute the query and return return at most one resulting value for a * field index from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(int, Class)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query */ T fetchAny(int fieldIndex, Class type) throws DataAccessException; /** * Execute the query and return return at most one resulting value for a * field index from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(int, Converter)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ U fetchAny(int fieldIndex, Converter converter) throws DataAccessException; /** * Execute the query and return return at most one resulting value for a * field name from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(int)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query */ Object fetchAny(String fieldName) throws DataAccessException; /** * Execute the query and return return at most one resulting value for a * field name from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(String, Class)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query */ T fetchAny(String fieldName, Class type) throws DataAccessException; /** * Execute the query and return return at most one resulting value for a * field name from the generated result. *

* This is the same as calling {@link #fetchOne()} and then * {@link Record#getValue(String, Converter)} * * @return The resulting value or null if the query returned no * records. * @throws DataAccessException if something went wrong executing the query */ U fetchAny(String fieldName, Converter converter) throws DataAccessException; /** * Execute the query and return at most one resulting record. *

* The resulting record is attached to the original {@link Configuration} by * default. Use {@link Settings#isAttachRecords()} to override this * behaviour. * * @return The first resulting record or null if the query * returns no records. * @throws DataAccessException if something went wrong executing the query */ R fetchAny() throws DataAccessException; /** * Execute the query and return at most one resulting record as a name/value * map. * * @return The resulting record or null if the query returns no * records. * @throws DataAccessException if something went wrong executing the query * @see Result#intoMaps() * @see Record#intoMap() */ Map fetchAnyMap() throws DataAccessException; /** * Execute the query and return at most one resulting record as an array *

* You can access data like this *

query.fetchAnyArray()[fieldIndex]
* * @return The resulting record or null if the query returns no * records. * @throws DataAccessException if something went wrong executing the query */ Object[] fetchAnyArray() throws DataAccessException; /** * Map resulting records onto a custom type. *

* This is the same as calling

     * E result = null;
     * Record r = q.fetchAny();
     *
     * if (r != null)
     *     result = r.into(type);
     * 
. See {@link Record#into(Class)} for more details * * @param The generic entity type. * @param type The entity type. * @return The resulting record or null if the query returns no * records. * @see Record#into(Class) * @see Result#into(Class) * @throws DataAccessException if something went wrong executing the query * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @see DefaultRecordMapper */ E fetchAnyInto(Class type) throws DataAccessException, MappingException; /** * Map resulting records onto a custom record. *

* This is the same as calling

     * Z result = null;
     * Record r = q.fetchOne();
     *
     * if (r != null)
     *     result = r.into(table);
     * 
. See {@link Record#into(Table)} for more details *

* The resulting record is attached to the original {@link Configuration} by * default. Use {@link Settings#isAttachRecords()} to override this * behaviour. * * @param The generic table record type. * @param table The table type. * @return The resulting record or null if the query returns no * records. * @see Record#into(Table) * @see Result#into(Table) * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the query returned more than one record */ Z fetchAnyInto(Table table) throws DataAccessException, InvalidResultException; /** * Execute the query and return the generated result as a list of name/value * maps. * * @return The result. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the key field returned two or more * equal values from the result set. * @see Result#intoMaps() * @see Record#intoMap() */ List> fetchMaps() throws DataAccessException; /** * Execute the query and return a {@link Map} with one of the result's * columns as key and the corresponding records as value. *

* An exception is thrown, if the key turns out to be non-unique in the * result set. Use {@link #fetchGroups(Field)} instead, if your keys are * non-unique *

* The resulting records are attached to the original {@link Configuration} * by default. Use {@link Settings#isAttachRecords()} to override this * behaviour. * * @param The key's generic field type * @param key The key field. Client code must assure that this field is * unique in the result set. * @return A Map containing the results * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the key field returned two or more * equal values from the result set. * @see Result#intoMap(Field) */ Map fetchMap(Field key) throws DataAccessException; /** * Execute the query and return a {@link Map} with one of the result's * columns as key and another one of the result's columns as value *

* An exception is thrown, if the key turns out to be non-unique in the * result set. Use {@link #fetchGroups(Field, Field)} instead, if your keys * are non-unique * * @param The key's generic field type * @param The value's generic field type * @param key The key field. Client code must assure that this field is * unique in the result set. * @param value The value field * @return A Map containing the results * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the key field returned two or more * equal values from the result set. * @see Result#intoMap(Field, Field) */ Map fetchMap(Field key, Field value) throws DataAccessException; /** * Execute the query and return a {@link Map} with keys as a map key and the * corresponding record as value. *

* An exception is thrown, if the keys turn out to be non-unique in the * result set. Use {@link #fetchGroups(Field[])} instead, if your keys are * non-unique. * * @param keys The keys. Client code must assure that keys are unique in the * result set. * @return A Map containing the results. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the key list is non-unique in the * result set. * @see Result#intoMap(Field[]) */ Map fetchMap(Field[] keys) throws DataAccessException; /** * Execute the query and return a {@link Map} with results grouped by the * given keys and mapped into the given entity type. *

* An {@link InvalidResultException} is thrown, if the keys are non-unique * in the result set. Use {@link #fetchGroups(Field[], Class)} instead, if * your keys are non-unique. * * @param keys The keys. Client code must assure that keys are unique in the * result set. If this is null or an empty array, * the resulting map will contain at most one entry. * @param type The entity type. * @return A Map containing the results. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the keys are non-unique in the result * set. * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @see Result#intoMap(Field[], Class) * @see DefaultRecordMapper */ Map, E> fetchMap(Field[] keys, Class type) throws DataAccessException, MappingException; /** * Execute the query and return a {@link Map} with results grouped by the * given keys and mapped by the given mapper. *

* An {@link InvalidResultException} is thrown, if the keys are non-unique * in the result set. Use {@link #fetchGroups(Field[], RecordMapper)} * instead, if your keys are non-unique. * * @param keys The keys. Client code must assure that keys are unique in the * result set. If this is null or an empty array, * the resulting map will contain at most one entry. * @param mapper The mapper callback. * @return A Map containing the results. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the keys are non-unique in the result * set. * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @see Result#intoMap(Field[], Class) * @see DefaultRecordMapper */ Map, E> fetchMap(Field[] keys, RecordMapper mapper) throws DataAccessException, MappingException; /** * Execute the query and return a {@link Map} with table as a map key and the * corresponding record as value. *

* An exception is thrown, if the keys turn out to be non-unique in the * result set. Use {@link #fetchGroups(Table)} instead, if your keys are * non-unique. * * @param table The key table. Client code must assure that keys are unique * in the result set. May not be null. * @return A Map containing the results. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the key list is non-unique in the * result set. * @see Result#intoMap(Table) */ Map fetchMap(Table table) throws DataAccessException; /** * Execute the query and return a {@link Map} with results grouped by the * given table and mapped into the given entity type. *

* An {@link InvalidResultException} is thrown, if the keys are non-unique * in the result set. Use {@link #fetchGroups(Table, Class)} instead, if * your keys are non-unique. * * @param table The key table. Client code must assure that keys are unique * in the result set. May not be null. * @param type The entity type. * @return A Map containing the results. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the keys are non-unique in the result * set. * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @see Result#intoMap(Table, Class) * @see DefaultRecordMapper */ Map fetchMap(Table table, Class type) throws DataAccessException, MappingException; /** * Execute the query and return a {@link Map} with results grouped by the * given table and mapped by the given mapper. *

* An {@link InvalidResultException} is thrown, if the keys are non-unique * in the result set. Use {@link #fetchGroups(Table, RecordMapper)} instead, * if your keys are non-unique. * * @param table The key table. Client code must assure that keys are unique * in the result set. May not be null. * @param mapper The mapper callback. * @return A Map containing the results. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the keys are non-unique in the result * set. * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @see Result#intoMap(Table, Class) * @see DefaultRecordMapper */ Map fetchMap(Table table, RecordMapper mapper) throws DataAccessException, MappingException; /** * Execute the query and return a {@link Map} with results grouped by the * given key and mapped into the given entity type. *

* An exception is thrown, if the key turn out to be non-unique in the * result set. Use {@link #fetchGroups(Field, Class)} instead, if your key * is non-unique. * * @param key The key. Client code must assure that key is unique in the * result set. * @param type The entity type. * @return A Map containing the result. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the key is non-unique in the result * set. * @see Result#intoMap(Field, Class) */ Map fetchMap(Field key, Class type) throws DataAccessException; /** * Execute the query and return a {@link Map} with results grouped by the * given key and mapped by the given mapper. *

* An exception is thrown, if the key turn out to be non-unique in the * result set. Use {@link #fetchGroups(Field, Class)} instead, if your key * is non-unique. * * @param key The key. Client code must assure that key is unique in the * result set. * @param mapper The mapper callback. * @return A Map containing the result. * @throws DataAccessException if something went wrong executing the query * @throws InvalidResultException if the key is non-unique in the result * set. * @see Result#intoMap(Field, Class) */ Map fetchMap(Field key, RecordMapper mapper) throws DataAccessException; /** * Execute the query and return a {@link Map} with one of the result's * columns as key and a list of corresponding records as value. *

* Unlike {@link #fetchMap(Field)}, this method allows for non-unique keys * in the result set. *

* The resulting records are attached to the original {@link Configuration} * by default. Use {@link Settings#isAttachRecords()} to override this * behaviour. * * @param The key's generic field type * @param key The key field. * @return A Map containing the results * @throws DataAccessException if something went wrong executing the query * @see Result#intoGroups(Field) */ Map> fetchGroups(Field key) throws DataAccessException; /** * Execute the query and return a {@link Map} with one of the result's * columns as key and another one of the result's columns as value *

* Unlike {@link #fetchMap(Field, Field)}, this method allows for non-unique * keys in the result set. * * @param The key's generic field type * @param The value's generic field type * @param key The key field. * @param value The value field * @return A Map containing the results * @throws DataAccessException if something went wrong executing the query * @see Result#intoGroups(Field, Field) */ Map> fetchGroups(Field key, Field value) throws DataAccessException; /** * Execute the query and return a {@link Map} with the result grouped by the * given keys. *

* Unlike {@link #fetchMap(Field[])}, this method allows for non-unique keys * in the result set. * * @param keys The keys used for result grouping. If this is * null or an empty array, the resulting map will * contain at most one entry. * @return A Map containing grouped results * @throws DataAccessException if something went wrong executing the query * @see Result#intoGroups(Field[]) */ Map> fetchGroups(Field[] keys) throws DataAccessException; /** * Execute the query and return a {@link Map} with results grouped by the * given keys and mapped into the given entity type. *

* Unlike {@link #fetchMap(Field[], Class)}, this method allows for * non-unique keys in the result set. * * @param keys The keys. If this is null or an empty array, the * resulting map will contain at most one entry. * @param type The entity type. * @return A Map containing grouped results * @throws DataAccessException if something went wrong executing the query * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @see Result#intoGroups(Field[], Class) * @see DefaultRecordMapper */ Map> fetchGroups(Field[] keys, Class type) throws MappingException; /** * Execute the query and return a {@link Map} with results grouped by the * given keys and mapped by the given mapper. *

* Unlike {@link #fetchMap(Field[], RecordMapper)}, this method allows for * non-unique keys in the result set. * * @param keys The keys. If this is null or an empty array, the * resulting map will contain at most one entry. * @param mapper The mapper callback. * @return A Map containing grouped results * @throws DataAccessException if something went wrong executing the query * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @see Result#intoGroups(Field[], Class) * @see DefaultRecordMapper */ Map> fetchGroups(Field[] keys, RecordMapper mapper) throws MappingException; /** * Execute the query and return a {@link Map} with the result grouped by the * given table. *

* Unlike {@link #fetchMap(Table)}, this method allows for non-unique keys * in the result set. * * @param table The key table. May not be null. * @return A Map containing grouped results * @throws DataAccessException if something went wrong executing the query * @see Result#intoGroups(Field[]) */ Map> fetchGroups(Table table) throws DataAccessException; /** * Execute the query and return a {@link Map} with results grouped by the * given table and mapped into the given entity type. *

* Unlike {@link #fetchMap(Table, Class)}, this method allows for non-unique * keys in the result set. * * @param table The key table. May not be null. * @param type The entity type. * @return A Map containing grouped results * @throws DataAccessException if something went wrong executing the query * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @see Result#intoGroups(Table, Class) * @see DefaultRecordMapper */ Map> fetchGroups(Table table, Class type) throws DataAccessException, MappingException; /** * Execute the query and return a {@link Map} with results grouped by the * given table and mapped by the given mapper. *

* Unlike {@link #fetchMap(Table, RecordMapper)}, this method allows for * non-unique keys in the result set. * * @param table The key table. May not be null. * @param mapper The mapper callback. * @return A Map containing grouped results * @throws DataAccessException if something went wrong executing the query * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @see Result#intoGroups(Table, Class) * @see DefaultRecordMapper */ Map> fetchGroups(Table table, RecordMapper mapper) throws DataAccessException, MappingException; /** * Return a {@link Map} with results grouped by the given key and mapped * into the given entity type. * * @param The key's generic field type * @param The generic entity type. * @param key The key field. * @param type The entity type. * @throws DataAccessException if something went wrong executing the query * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @see Result#intoGroups(Field, Class) * @see DefaultRecordMapper */ Map> fetchGroups(Field key, Class type) throws DataAccessException, MappingException; /** * Return a {@link Map} with results grouped by the given key and mapped by * the given mapper. * * @param The key's generic field type * @param The generic entity type. * @param key The key field. * @param mapper The mapper callback. * @throws DataAccessException if something went wrong executing the query * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @see Result#intoGroups(Field, Class) * @see DefaultRecordMapper */ Map> fetchGroups(Field key, RecordMapper mapper) throws DataAccessException, MappingException; /** * Execute the query and return the generated result as an Object matrix *

* You can access data like this *

query.fetchArray()[recordIndex][fieldIndex]
* * @return The result. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray() */ Object[][] fetchArrays() throws DataAccessException; /** * Execute the query and return all values for a field index from the * generated result. *

* You can access data like this *

query.fetchArray(fieldIndex)[recordIndex]
* * @return The resulting values. This may be an array type more concrete * than Object[], depending on whether jOOQ has any * knowledge about fieldIndex's actual type. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(int) */ Object[] fetchArray(int fieldIndex) throws DataAccessException; /** * Execute the query and return all values for a field index from the * generated result. *

* You can access data like this *

query.fetchArray(fieldIndex)[recordIndex]
* * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(int, Class) */ T[] fetchArray(int fieldIndex, Class type) throws DataAccessException; /** * Execute the query and return all values for a field index from the * generated result. *

* You can access data like this *

query.fetchArray(fieldIndex)[recordIndex]
* * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(int, Converter) */ U[] fetchArray(int fieldIndex, Converter converter) throws DataAccessException; /** * Execute the query and return all values for a field name from the * generated result. *

* You can access data like this *

query.fetchArray(fieldName)[recordIndex]
* * @return The resulting values. This may be an array type more concrete * than Object[], depending on whether jOOQ has any * knowledge about fieldName's actual type. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(String) */ Object[] fetchArray(String fieldName) throws DataAccessException; /** * Execute the query and return all values for a field name from the * generated result. *

* You can access data like this *

query.fetchArray(fieldName)[recordIndex]
* * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(String, Converter) */ T[] fetchArray(String fieldName, Class type) throws DataAccessException; /** * Execute the query and return all values for a field name from the * generated result. *

* You can access data like this *

query.fetchArray(fieldName)[recordIndex]
* * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(String, Class) */ U[] fetchArray(String fieldName, Converter converter) throws DataAccessException; /** * Execute the query and return all values for a field from the generated * result. *

* You can access data like this *

query.fetchArray(field)[recordIndex]
* * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(Field) */ T[] fetchArray(Field field) throws DataAccessException; /** * Execute the query and return all values for a field from the generated * result. *

* You can access data like this *

query.fetchArray(field)[recordIndex]
* * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(Field, Class) */ T[] fetchArray(Field field, Class type) throws DataAccessException; /** * Execute the query and return all values for a field from the generated * result. *

* You can access data like this *

query.fetchArray(field)[recordIndex]
* * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(Field, Converter) */ U[] fetchArray(Field field, Converter converter) throws DataAccessException; /** * Execute the query and return all values for a field index from the * generated result. * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(int) */ Set fetchSet(int fieldIndex) throws DataAccessException; /** * Execute the query and return all values for a field index from the * generated result. * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(int, Class) */ Set fetchSet(int fieldIndex, Class type) throws DataAccessException; /** * Execute the query and return all values for a field index from the * generated result. * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(int, Converter) */ Set fetchSet(int fieldIndex, Converter converter) throws DataAccessException; /** * Execute the query and return all values for a field name from the * generated result. * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(String) */ Set fetchSet(String fieldName) throws DataAccessException; /** * Execute the query and return all values for a field name from the * generated result. * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(String, Converter) */ Set fetchSet(String fieldName, Class type) throws DataAccessException; /** * Execute the query and return all values for a field name from the * generated result. * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(String, Class) */ Set fetchSet(String fieldName, Converter converter) throws DataAccessException; /** * Execute the query and return all values for a field from the generated * result. * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(Field) */ Set fetchSet(Field field) throws DataAccessException; /** * Execute the query and return all values for a field from the generated * result. * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(Field, Class) */ Set fetchSet(Field field, Class type) throws DataAccessException; /** * Execute the query and return all values for a field from the generated * result. * * @return The resulting values. * @throws DataAccessException if something went wrong executing the query * @see Result#intoArray(Field, Converter) */ Set fetchSet(Field field, Converter converter) throws DataAccessException; /** * Map resulting records onto a custom type. *

* This is the same as calling fetch().into(type). See * {@link Record#into(Class)} for more details * * @param The generic entity type. * @param type The entity type. * @see Record#into(Class) * @see Result#into(Class) * @throws DataAccessException if something went wrong executing the query * @throws MappingException wrapping any reflection or data type conversion * exception that might have occurred while mapping records * @see DefaultRecordMapper */ List fetchInto(Class type) throws DataAccessException, MappingException; /** * Map resulting records onto a custom record. *

* This is the same as calling fetch().into(table). See * {@link Record#into(Table)} for more details *

* The result and its contained records are attached to the original * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} * to override this behaviour. * * @param The generic table record type. * @param table The table type. * @see Record#into(Table) * @see Result#into(Table) * @throws DataAccessException if something went wrong executing the query */ Result fetchInto(Table table) throws DataAccessException; /** * Fetch results into a custom handler callback. *

* The resulting records are attached to the original {@link Configuration} * by default. Use {@link Settings#isAttachRecords()} to override this * behaviour. * * @param handler The handler callback * @return Convenience result, returning the parameter handler itself * @throws DataAccessException if something went wrong executing the query */ > H fetchInto(H handler) throws DataAccessException; /** * Fetch results into a custom mapper callback. * * @param mapper The mapper callback * @return The custom mapped records * @throws DataAccessException if something went wrong executing the query */ List fetch(RecordMapper mapper) throws DataAccessException; /** * Fetch results asynchronously. *

* This method wraps fetching of records in a * {@link java.util.concurrent.Future}, such that you can access the actual * records at a future instant. This is especially useful when *

    *
  • You want to load heavy data in the background, for instance when the * user logs in and accesses a pre-calculated dashboard screen, before they * access the heavy data.
  • *
  • You want to parallelise several independent OLAP queries before * merging all data into a single report
  • *
  • ...
  • *
*

* This will internally create a "single thread executor", that is shut down * at the end of the {@link FutureResult}'s lifecycle. Use * {@link #fetchLater(ExecutorService)} instead, if you want control over * your executing threads. *

* The result and its contained records are attached to the original * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} * to override this behaviour. * * @return A future result * @throws DataAccessException if something went wrong executing the query * @deprecated - 3.2.0 - [#2581] - This method will be removed in jOOQ 4.0 */ @Deprecated FutureResult fetchLater() throws DataAccessException; /** * Fetch results asynchronously. *

* This method wraps fetching of records in a * {@link java.util.concurrent.Future}, such that you can access the actual * records at a future instant. This is especially useful when *

    *
  • You want to load heavy data in the background, for instance when the * user logs in and accesses a pre-calculated dashboard screen, before they * access the heavy data.
  • *
  • You want to parallelise several independent OLAP queries before * merging all data into a single report
  • *
  • ...
  • *
*

* Use this method rather than {@link #fetchLater()}, in order to keep * control over thread lifecycles, if you manage threads in a J2EE container * or with Spring, for instance. *

* The result and its contained records are attached to the original * {@link Configuration} by default. Use {@link Settings#isAttachRecords()} * to override this behaviour. * * @param executor A custom executor * @return A future result * @throws DataAccessException if something went wrong executing the query * @deprecated - 3.2.0 - [#2581] - This method will be removed in jOOQ 4.0 */ @Deprecated FutureResult fetchLater(ExecutorService executor) throws DataAccessException; /** * The record type produced by this query. */ Class getRecordType(); /** * {@inheritDoc} */ @Override ResultQuery bind(String param, Object value) throws IllegalArgumentException, DataTypeException; /** * {@inheritDoc} */ @Override ResultQuery bind(int index, Object value) throws IllegalArgumentException, DataTypeException; // ------------------------------------------------------------------------ // JDBC methods // ------------------------------------------------------------------------ /** * {@inheritDoc} */ @Override ResultQuery queryTimeout(int timeout); /** * {@inheritDoc} */ @Override ResultQuery keepStatement(boolean keepStatement); /** * Specify the maximum number of rows returned by the underlying * {@link Statement}. *

* This is not the same as setting a LIMIT .. OFFSET clause * onto the statement, where the result set is restricted within the * database. * * @see Statement#setMaxRows(int) */ ResultQuery maxRows(int rows); /** * Specify the fetch size of the underlying {@link Statement}. *

* Regardless of this setting, {@link #fetchLazy()} is the only way in jOOQ * not to fetch all data in memory. However, you may influence how your JDBC * driver interacts with your database through specifying a fetch size. *

* Note that some databases (in particular PostgreSQL) do not like fetch * sizes being combined with * {@link Connection#getAutoCommit()} == true. For more * information, see this page here * * @see Statement#setFetchSize(int) */ ResultQuery fetchSize(int rows); /** * Specify the ResultSet concurrency of ResultSet * objects created by jOOQ. *

* This will affect the way you may perceive ResultSet objects * obtained from any of these methods: *

    *
  • {@link ResultQuery#fetchResultSet()}
  • *
  • {@link Cursor#resultSet()}
  • *
  • {@link ExecuteContext#resultSet()}
  • *
* * @see Statement#getResultSetConcurrency() */ ResultQuery resultSetConcurrency(int resultSetConcurrency); /** * Specify the ResultSet type of ResultSet * objects created by jOOQ. *

* This will affect the way you may perceive ResultSet objects * obtained from any of these methods: *

    *
  • {@link ResultQuery#fetchResultSet()}
  • *
  • {@link Cursor#resultSet()}
  • *
  • {@link ExecuteContext#resultSet()}
  • *
* * @see Statement#getResultSetType() */ ResultQuery resultSetType(int resultSetType); /** * Specify the ResultSet holdability of ResultSet * objects created by jOOQ. *

* This will affect the way you may perceive ResultSet objects * obtained from any of these methods: *

    *
  • {@link ResultQuery#fetchResultSet()}
  • *
  • {@link Cursor#resultSet()}
  • *
  • {@link ExecuteContext#resultSet()}
  • *
* * @see Statement#getResultSetHoldability() */ ResultQuery resultSetHoldability(int resultSetHoldability); /** * Specify a set of fields whose values should be interned. *

* Unlike {@link Result}'s intern() methods, this already * interns values right after fetching them from a JDBC result set. See * {@link Result#intern(int...)} for more details. * * @param fields The fields whose values should be interned * @return The same result query * @see Result#intern(Field...) * @see String#intern() */ ResultQuery intern(Field... fields); /** * Specify a set of field indexes whose values should be interned. *

* Unlike {@link Result}'s intern() methods, this already * interns values right after fetching them from a JDBC result set. See * {@link Result#intern(int...)} for more details. * * @param fieldIndexes The field indexes whose values should be interned * @return The same result query * @see Result#intern(int...) * @see String#intern() */ ResultQuery intern(int... fieldIndexes); /** * Specify a set of field names whose values should be interned. *

* Unlike {@link Result}'s intern() methods, this already * interns values right after fetching them from a JDBC result set. See * {@link Result#intern(int...)} for more details. * * @param fieldNames The field names whose values should be interned * @return The same result query * @see Result#intern(String...) * @see String#intern() */ ResultQuery intern(String... fieldNames); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy