Skip to content

Commit

Permalink
[#5127] Remove the DATA_LOCALLY_SCOPED_DATA_MAP in SelectQueryImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Oct 12, 2017
1 parent e85a1e0 commit 1f22474
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
5 changes: 1 addition & 4 deletions jOOQ/src/main/java/org/jooq/impl/Function.java
Expand Up @@ -66,14 +66,12 @@
import static org.jooq.impl.Term.LIST_AGG;
import static org.jooq.impl.Term.MEDIAN;
import static org.jooq.impl.Term.ROW_NUMBER;
import static org.jooq.impl.Tools.DataKey.DATA_LOCALLY_SCOPED_DATA_MAP;
import static org.jooq.impl.Tools.DataKey.DATA_WINDOW_DEFINITIONS;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Map;

import org.jooq.AggregateFilterStep;
import org.jooq.AggregateFunction;
Expand Down Expand Up @@ -371,8 +369,7 @@ final QueryPart window(Context<?> ctx) {
if (SUPPORT_WINDOW_CLAUSE.contains(ctx.family()))
return windowName;

Map<Object, Object> map = (Map<Object, Object>) ctx.data(DATA_LOCALLY_SCOPED_DATA_MAP);
QueryPartList<WindowDefinition> windows = (QueryPartList<WindowDefinition>) map.get(DATA_WINDOW_DEFINITIONS);
QueryPartList<WindowDefinition> windows = (QueryPartList<WindowDefinition>) ctx.data(DATA_WINDOW_DEFINITIONS);

if (windows != null) {
for (WindowDefinition window : windows)
Expand Down
18 changes: 8 additions & 10 deletions jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java
Expand Up @@ -121,7 +121,6 @@
import static org.jooq.impl.Tools.DataKey.DATA_COLLECTED_SEMI_ANTI_JOIN;
import static org.jooq.impl.Tools.DataKey.DATA_COLLECT_SEMI_ANTI_JOIN;
import static org.jooq.impl.Tools.DataKey.DATA_INSERT_SELECT_WITHOUT_INSERT_COLUMN_LIST;
import static org.jooq.impl.Tools.DataKey.DATA_LOCALLY_SCOPED_DATA_MAP;
import static org.jooq.impl.Tools.DataKey.DATA_OMIT_INTO_CLAUSE;
import static org.jooq.impl.Tools.DataKey.DATA_OVERRIDE_ALIASES_IN_ORDER_BY;
import static org.jooq.impl.Tools.DataKey.DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE;
Expand All @@ -136,9 +135,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Stream;
Expand Down Expand Up @@ -461,11 +458,14 @@ public final void accept(Context<?> context) {
// [#2791] TODO: Instead of explicitly manipulating these data() objects, future versions
// of jOOQ should implement a push / pop semantics to clearly delimit such scope.
Object renderTrailingLimit = context.data(DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE);
Object localDataMap = context.data(DATA_LOCALLY_SCOPED_DATA_MAP);
Object localWindowDefinitions = context.data(DATA_WINDOW_DEFINITIONS);
try {
if (renderTrailingLimit != null)
context.data().remove(DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE);
context.data(DATA_LOCALLY_SCOPED_DATA_MAP, new HashMap<Object, Object>());

// [#5127] Lazy initialise this map
if (localWindowDefinitions != null)
context.data(DATA_WINDOW_DEFINITIONS, null);

if (into != null
&& context.data(DATA_OMIT_INTO_CLAUSE) == null
Expand Down Expand Up @@ -759,20 +759,18 @@ else if (forShare) {

}
finally {
context.data(DATA_LOCALLY_SCOPED_DATA_MAP, localDataMap);
context.data(DATA_WINDOW_DEFINITIONS, localWindowDefinitions);
if (renderTrailingLimit != null)
context.data(DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE, renderTrailingLimit);
}
}

@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<Object, Object>) context.data(DATA_LOCALLY_SCOPED_DATA_MAP)).put(DATA_WINDOW_DEFINITIONS, getWindow());
}
if (!getWindow().isEmpty())
context.data(DATA_WINDOW_DEFINITIONS, getWindow());
}

/**
Expand Down
10 changes: 0 additions & 10 deletions jOOQ/src/main/java/org/jooq/impl/Tools.java
Expand Up @@ -335,16 +335,6 @@ enum DataKey {
*/
DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES,

/**
* [#2790] A locally scoped data map.
* <p>
* Sometimes, it is useful to have some information only available while
* visiting QueryParts in the same context of the current subquery, e.g.
* when communicating between SELECT and WINDOW clauses, as is required to
* emulate #531.
*/
DATA_LOCALLY_SCOPED_DATA_MAP,

/**
* [#531] The local window definitions.
* <p>
Expand Down

0 comments on commit 1f22474

Please sign in to comment.