Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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.impl;
import static java.lang.Boolean.TRUE;
import static java.util.Arrays.asList;
import static org.jooq.Clause.SELECT;
import static org.jooq.Clause.SELECT_CONNECT_BY;
import static org.jooq.Clause.SELECT_FROM;
import static org.jooq.Clause.SELECT_GROUP_BY;
import static org.jooq.Clause.SELECT_HAVING;
import static org.jooq.Clause.SELECT_ORDER_BY;
import static org.jooq.Clause.SELECT_SELECT;
import static org.jooq.Clause.SELECT_START_WITH;
import static org.jooq.Clause.SELECT_WHERE;
import static org.jooq.Clause.SELECT_WINDOW;
import static org.jooq.Operator.OR;
// ...
// ...
// ...
import static org.jooq.SQLDialect.CUBRID;
import static org.jooq.SQLDialect.DERBY;
import static org.jooq.SQLDialect.FIREBIRD;
import static org.jooq.SQLDialect.H2;
import static org.jooq.SQLDialect.HSQLDB;
// ...
import static org.jooq.SQLDialect.MARIADB;
import static org.jooq.SQLDialect.MYSQL;
import static org.jooq.SQLDialect.POSTGRES;
import static org.jooq.SQLDialect.SQLITE;
// ...
// ...
// ...
// ...
import static org.jooq.SortOrder.ASC;
import static org.jooq.conf.ParamType.INLINED;
import static org.jooq.impl.DSL.denseRank;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.one;
import static org.jooq.impl.DSL.row;
import static org.jooq.impl.DSL.rowNumber;
import static org.jooq.impl.Dual.DUAL_ACCESS;
import static org.jooq.impl.Utils.DATA_LOCALLY_SCOPED_DATA_MAP;
import static org.jooq.impl.Utils.DATA_RENDERING_DB2_FINAL_TABLE_CLAUSE;
import static org.jooq.impl.Utils.DATA_ROW_VALUE_EXPRESSION_PREDICATE_SUBQUERY;
import static org.jooq.impl.Utils.DATA_WINDOW_DEFINITIONS;
import static org.jooq.impl.Utils.DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.jooq.BindContext;
import org.jooq.Clause;
import org.jooq.Condition;
import org.jooq.Configuration;
import org.jooq.Context;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.GroupField;
import org.jooq.JoinType;
import org.jooq.Operator;
import org.jooq.Param;
import org.jooq.QueryPart;
import org.jooq.Record;
import org.jooq.RenderContext;
import org.jooq.SQLDialect;
import org.jooq.SelectQuery;
import org.jooq.SortField;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableLike;
import org.jooq.TableOnStep;
import org.jooq.TablePartitionByStep;
import org.jooq.WindowDefinition;
import org.jooq.conf.ParamType;
import org.jooq.exception.DataAccessException;
import org.jooq.tools.StringUtils;
/**
* A sub-select is a SELECT statement that can be combined with
* other SELECT statement in UNIONs and similar
* operations.
*
* @author Lukas Eder
*/
class SelectQueryImpl extends AbstractSelect implements SelectQuery {
/**
* Generated UID
*/
private static final long serialVersionUID = 1646393178384872967L;
private static final Clause[] CLAUSES = { SELECT };
private final SelectFieldList select;
private String hint;
private String option;
private boolean distinct;
private boolean forUpdate;
private final QueryPartList> forUpdateOf;
private final TableList forUpdateOfTables;
private ForUpdateMode forUpdateMode;
private int forUpdateWait;
private boolean forShare;
private final TableList from;
private final ConditionProviderImpl condition;
private final ConditionProviderImpl connectBy;
private boolean connectByNoCycle;
private final ConditionProviderImpl connectByStartWith;
private boolean grouping;
private final QueryPartList groupBy;
private final ConditionProviderImpl having;
private final WindowList window;
private final SortFieldList orderBy;
private boolean orderBySiblings;
private final QueryPartList> seek;
private boolean seekBefore;
private final Limit limit;
SelectQueryImpl(Configuration configuration) {
this(configuration, null);
}
SelectQueryImpl(Configuration configuration, boolean distinct) {
this(configuration, null, distinct);
}
SelectQueryImpl(Configuration configuration, TableLike extends R> from) {
this(configuration, from, false);
}
SelectQueryImpl(Configuration configuration, TableLike extends R> from, boolean distinct) {
super(configuration);
this.distinct = distinct;
this.select = new SelectFieldList();
this.from = new TableList();
this.condition = new ConditionProviderImpl();
this.connectBy = new ConditionProviderImpl();
this.connectByStartWith = new ConditionProviderImpl();
this.groupBy = new QueryPartList();
this.having = new ConditionProviderImpl();
this.window = new WindowList();
this.orderBy = new SortFieldList();
this.seek = new QueryPartList>();
this.limit = new Limit();
if (from != null) {
this.from.add(from.asTable());
}
this.forUpdateOf = new QueryPartList>();
this.forUpdateOfTables = new TableList();
}
@Override
public final Clause[] clauses(Context> ctx) {
return CLAUSES;
}
@Override
public final void bind(BindContext context) {
pushWindow(context);
context.declareFields(true)
.visit(getSelect0())
.declareFields(false)
.declareTables(true)
.visit(getFrom())
.declareTables(false)
.visit(getWhere())
.visit(getConnectByStartWith())
.visit(getConnectBy())
.visit(getGroupBy())
.visit(getHaving());
if (asList(POSTGRES).contains(context.configuration().dialect().family())) {
context.declareWindows(true)
.visit(getWindow())
.declareWindows(false);
}
context.visit(getOrderBy());
// TOP clauses never bind values. So this can be safely applied at the
// end for LIMIT .. OFFSET clauses, or ROW_NUMBER() filtering
if (getLimit().isApplicable()) {
context.visit(getLimit());
}
context.visit(forUpdateOf)
.visit(forUpdateOfTables);
}
@Override
public final void toSQL(RenderContext context) {
pushWindow(context);
Boolean wrapDerivedTables = (Boolean) context.data(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES);
if (TRUE.equals(wrapDerivedTables)) {
context.sql("(")
.data(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES, null);
}
// If a limit applies
if (getLimit().isApplicable()) {
switch (context.configuration().dialect()) {
/* [pro] xx
xx xxxxxx xxxxx xxx xxxxxx xxxxxxxxxxxxxx xxxx xxxxx xxxxxx xxxxxx
xxxx xxxxxxx
xxxx xxxxxxxxxx
xxxx xxxxxxxxxx
xxxx xxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxx
xx xxxx xxxx xxxxx xxx xxx xxxxxxxxxxxxx
xxxx xxxx
xxxx xxxxxx
xxxx xxxxxxx x
xx xxx xxxxxxxx xxxxxxxx x xxxxxx xxxxx xxxxxxx xxxxxxx
xx xxxxxx xxx xxxxxxx xxxx xxxxxx
xx xxxxxxxxxxxxxxxxxxxxxxxx xx xxxxxxxxxxxxxxxxxxxxxxxxxxxx x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x
xx xxxxxxxx xxx xx xx xxxxxxxxx
xxxx x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x
xxxxxx
x
xx xxxxxx xxx xxx xxx xxxxxx xxxxxxx x xxx xxxxxx xxxxxxx xxxxxx
xx xxxxxx xxx xx xxxxxxxxx xx xxx xxxxxxx xxx xx xxx
xxxx xxxxxxx
xxxx xxxxxxxxxxx
xxxx xxxx
xxxx xxxxxxxxxxxxxx x
xx xxxxxx xxx xxxxxxxx xxxxxxx xxxxxx xxx xxxxxxx xxxx xxxxxx
xx xxxxxxxxxxxxxxxxxxxxxxxx xx xxxxxxxxxxxxxxxxxxxxxxxxxxxx x
xxxxxxxxxxxxxxxxxxxxxxxxx
x
xx xxxxxx xxxxxxxxxx
xxxx x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x
xxxxxx
x
xx xxxxxx xxx xxx xx xxxxx xx xxxxxxx xxx xxxx xxxxxxx
xx xxxxxxxx xxx xxxxx xx xxxx xxxxxxx xxx xxxx xxxxxxx
xxxx xxxxxxx x
xx xxxxxx xxx xxxxxxxx xxxxxxx xxxxxx xxx xxxxxxx xxxx xxxxxx
xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx x
xxxxxxxxxxxxxxxxxxxxxxxxx
x
xx xxxxxx xxxxxxxxxx
xxxx x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x
xxxxxx
x
xx [/pro] */
// By default, render the dialect's limit clause
default: {
toSQLReferenceLimitDefault(context);
break;
}
}
}
// If no limit applies, just render the rest of the query
else {
toSQLReference0(context);
}
// [#1296] FOR UPDATE is simulated in some dialects using ResultSet.CONCUR_UPDATABLE
if (forUpdate && !asList(CUBRID).contains(context.configuration().dialect().family())) {
context.formatSeparator()
.keyword("for update");
if (!forUpdateOf.isEmpty()) {
context.sql(" ").keyword("of").sql(" ");
Utils.fieldNames(context, forUpdateOf);
}
else if (!forUpdateOfTables.isEmpty()) {
context.sql(" ").keyword("of").sql(" ");
switch (context.configuration().dialect().family()) {
// Some dialects don't allow for an OF [table-names] clause
// It can be simulated by listing the table's fields, though
/* [pro] xx
xxxx xxxx
xxxx xxxxxxx
xxxx xxxxxxx
xx [/pro] */
case DERBY: {
forUpdateOfTables.toSQLFieldNames(context);
break;
}
// Render the OF [table-names] clause
default:
Utils.tableNames(context, forUpdateOfTables);
break;
}
}
if (forUpdateMode != null) {
context.sql(" ");
context.keyword(forUpdateMode.toSQL());
if (forUpdateMode == ForUpdateMode.WAIT) {
context.sql(" ");
context.sql(forUpdateWait);
}
}
}
else if (forShare) {
switch (context.configuration().dialect()) {
// MySQL has a non-standard implementation for the "FOR SHARE" clause
case MARIADB:
case MYSQL:
context.formatSeparator()
.keyword("lock in share mode");
break;
// Postgres is known to implement the "FOR SHARE" clause like this
default:
context.formatSeparator()
.keyword("for share");
break;
}
}
// [#1952] SQL Server OPTION() clauses as well as many other optional
// end-of-query clauses are appended to the end of a query
if (!StringUtils.isBlank(option)) {
context.formatSeparator()
.sql(option);
}
if (TRUE.equals(wrapDerivedTables)) {
context.sql(")")
.data(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES, true);
}
}
@SuppressWarnings("unchecked")
private final void pushWindow(Context> context) {
// [#531] [#2790] Make the WINDOW clause available to the SELECT clause
// to be able to inline window definitions if the WINDOW clause is not
// supported.
if (!getWindow().isEmpty()) {
((Map