[jOOQ/jOOQ#12425] Seal the UnmodifiableCollection hierarchy
This commit is contained in:
parent
1b801537be
commit
855cbff9bf
@ -214,12 +214,25 @@ public final class QOM {
|
||||
/**
|
||||
* An unmodifiable {@link Collection} of {@link QueryPart} elements.
|
||||
*/
|
||||
public interface UnmodifiableCollection<Q extends org.jooq.QueryPart> extends org.jooq.QueryPart, java.util.Collection<Q> {}
|
||||
public /* sealed */ interface UnmodifiableCollection<Q extends org.jooq.QueryPart>
|
||||
extends
|
||||
org.jooq.QueryPart,
|
||||
java.util.Collection<Q>
|
||||
/* permits
|
||||
UnmodifiableList,
|
||||
QueryPartCollectionView */
|
||||
{}
|
||||
|
||||
/**
|
||||
* An unmodifiable {@link List} of {@link QueryPart} elements.
|
||||
*/
|
||||
public interface UnmodifiableList<Q extends org.jooq.QueryPart> extends UnmodifiableCollection<Q>, java.util.List<Q> {}
|
||||
public /* sealed */ interface UnmodifiableList<Q extends org.jooq.QueryPart>
|
||||
extends
|
||||
UnmodifiableCollection<Q>,
|
||||
java.util.List<Q>
|
||||
/* permits
|
||||
QueryPartListView */
|
||||
{}
|
||||
|
||||
public /*sealed*/ interface With
|
||||
extends
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import org.jooq.Context;
|
||||
import org.jooq.SelectFieldOrAsterisk;
|
||||
import org.jooq.Table;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class QualifiedSelectFieldList extends QueryPartList<SelectFieldOrAsterisk> {
|
||||
|
||||
private final Table<?> table;
|
||||
|
||||
QualifiedSelectFieldList(Table<?> table, Iterable<SelectFieldOrAsterisk> fields) {
|
||||
this.table = table;
|
||||
|
||||
for (SelectFieldOrAsterisk field : fields)
|
||||
add(Tools.qualify(table, field));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean rendersContent(Context<?> ctx) {
|
||||
return super.rendersContent(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void toSQLEmptyList(Context<?> context) {
|
||||
table.asterisk();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean declaresFields() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -69,7 +69,19 @@ import org.jooq.impl.QOM.UnmodifiableCollection;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
class QueryPartCollectionView<T extends QueryPart> extends AbstractQueryPart implements UnmodifiableCollection<T>, SimpleQueryPart, SeparatedQueryPart {
|
||||
/* sealed */ class QueryPartCollectionView<T extends QueryPart>
|
||||
extends
|
||||
AbstractQueryPart
|
||||
implements
|
||||
UnmodifiableCollection<T>,
|
||||
SimpleQueryPart,
|
||||
SeparatedQueryPart
|
||||
/* permits
|
||||
|
||||
|
||||
|
||||
QueryPartListView */
|
||||
{
|
||||
|
||||
final Collection<T> wrapped;
|
||||
Boolean qualify;
|
||||
|
||||
@ -49,7 +49,19 @@ import org.jooq.QueryPart;
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
class QueryPartList<T extends QueryPart> extends QueryPartListView<T> {
|
||||
/* sealed */ class QueryPartList<T extends QueryPart>
|
||||
extends
|
||||
QueryPartListView<T>
|
||||
/* permits
|
||||
CommonTableExpressionList,
|
||||
GroupFieldList,
|
||||
SelectFieldList,
|
||||
SortFieldList,
|
||||
TableList,
|
||||
TopLevelCte,
|
||||
WindowList,
|
||||
QualifiedSelectFieldList */
|
||||
{
|
||||
|
||||
QueryPartList() {
|
||||
this((Collection<T>) null);
|
||||
|
||||
@ -55,7 +55,14 @@ import org.jooq.impl.QOM.UnmodifiableList;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
class QueryPartListView<T extends QueryPart> extends QueryPartCollectionView<T> implements UnmodifiableList<T> {
|
||||
/* sealed */ class QueryPartListView<T extends QueryPart>
|
||||
extends
|
||||
QueryPartCollectionView<T>
|
||||
implements
|
||||
UnmodifiableList<T>
|
||||
/* permits
|
||||
QueryPartList */
|
||||
{
|
||||
|
||||
@SafeVarargs
|
||||
static final <T extends QueryPart> QueryPartListView<T> wrap(T... wrappedList) {
|
||||
|
||||
@ -1238,7 +1238,7 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
|
||||
copy.limit.clear();
|
||||
|
||||
SelectLimitStep<?> s1 =
|
||||
DSL.select(qualify(table(name("t")), select))
|
||||
DSL.select(new QualifiedSelectFieldList(table(name("t")), select))
|
||||
.from(copy.asTable("t"))
|
||||
.where(rn.eq(one()))
|
||||
.orderBy(map(orderBy, o -> unqualified(o)));
|
||||
|
||||
@ -5671,30 +5671,6 @@ final class Tools {
|
||||
return anyMatch(fields, f -> !names.add(f.getName()));
|
||||
}
|
||||
|
||||
static final QueryPartList<SelectFieldOrAsterisk> qualify(final Table<?> table, Iterable<SelectFieldOrAsterisk> fields) {
|
||||
QueryPartList<SelectFieldOrAsterisk> result = new QueryPartList<SelectFieldOrAsterisk>() {
|
||||
@Override
|
||||
public final boolean rendersContent(Context<?> ctx) {
|
||||
return super.rendersContent(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void toSQLEmptyList(Context<?> context) {
|
||||
table.asterisk();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean declaresFields() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
for (SelectFieldOrAsterisk field : fields)
|
||||
result.add(qualify(table, field));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static final SelectFieldOrAsterisk qualify(Table<?> table, SelectFieldOrAsterisk field) {
|
||||
if (field instanceof Field)
|
||||
return qualify(table, (Field<?>) field);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user