org.jooq.Query Maven / Gradle / Ivy
/**
* 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.PreparedStatement;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import org.jooq.conf.ParamType;
import org.jooq.conf.Settings;
import org.jooq.conf.StatementType;
import org.jooq.exception.DataAccessException;
import org.jooq.exception.DataTypeException;
import org.jooq.impl.DSL;
/**
* Any query
*
* @author Lukas Eder
*/
public interface Query extends QueryPart, Attachable {
/**
* Execute the query, if it has been created with a proper configuration.
*
* @return A result value, depending on the concrete implementation of
* {@link Query}:
*
* - {@link Delete} : the number of deleted records
* - {@link Insert} : the number of inserted records
* - {@link Merge} : the result may have no meaning
* - {@link Select} : the number of resulting records
* - {@link Truncate} : the result may have no meaning
* - {@link Update} : the number of updated records
*
* @throws DataAccessException If anything goes wrong in the database
*/
int execute() throws DataAccessException;
/**
* Whether this query is executable in its current state.
*
* DML queries may be incomplete in structure and thus not executable.
* Calling {@link #execute()} on such queries has no effect, but beware that
* {@link #getSQL()} may not render valid SQL!
*/
boolean isExecutable();
/**
* Retrieve the SQL code rendered by this Query.
*
* Use this method, when you want to use jOOQ for object oriented query
* creation, but execute the query with some other technology, such as
*
* - JDBC
* - Spring Templates
* - JPA native queries
* - etc...
*
*
* Note, this is the same as calling {@link #getSQL(boolean)}. The boolean
* parameter will depend on your {@link DSLContext}'s {@link Settings}:
*
*
* StatementType
* boolean parameter
* effect
*
*
* {@link StatementType#PREPARED_STATEMENT}
* false
(default)
* This will render bind variables to be used with a JDBC
* {@link PreparedStatement}. You can extract bind values from this
* Query
using {@link #getBindValues()}
*
*
* {@link StatementType#STATIC_STATEMENT}
* true
* This will inline all bind variables in a statement to be used with a
* JDBC {@link Statement}
*
*
*
* [#1520] Note that the query actually being executed might not contain any
* bind variables, in case the number of bind variables exceeds your SQL
* dialect's maximum number of supported bind variables. This is not
* reflected by this method, which will only use the {@link Settings} to
* decide whether to render bind values.
*
* @see #getSQL(boolean)
*/
String getSQL();
/**
* Retrieve the SQL code rendered by this Query.
*
* [#1520] Note that the query actually being executed might not contain any
* bind variables, in case the number of bind variables exceeds your SQL
* dialect's maximum number of supported bind variables. This is not
* reflected by this method, which will only use inline
* argument to decide whether to render bind values.
*
* See {@link #getSQL()} for more details.
*
* @param inline Whether to inline bind variables. This overrides values in
* {@link Settings#getStatementType()}
* @return The generated SQL
* @deprecated - [#2414] - 3.1.0 - Use {@link #getSQL(ParamType)} instead
*/
@Deprecated
String getSQL(boolean inline);
/**
* Retrieve the SQL code rendered by this Query.
*
* [#1520] Note that the query actually being executed might not contain any
* bind variables, in case the number of bind variables exceeds your SQL
* dialect's maximum number of supported bind variables. This is not
* reflected by this method, which will only use paramType
* argument to decide whether to render bind values.
*
* See {@link #getSQL()} for more details.
*
* @param paramType How to render parameters. This overrides values in
* {@link Settings#getStatementType()}
* @return The generated SQL
*/
String getSQL(ParamType paramType);
/**
* Retrieve the bind values that will be bound by this Query. This
* List
cannot be modified. To modify bind values, use
* {@link #getParams()} instead.
*
* Unlike {@link #getParams()}, which returns also inlined parameters, this
* returns only actual bind values that will render an actual bind value as
* a question mark "?"
*
* @see DSLContext#extractBindValues(QueryPart)
*/
List