[#2049] Add gt() / ge() / lt() / le() to Row[N] types - Factored out
RowSubquery nested class to top-level type
This commit is contained in:
parent
b2df9b7d6d
commit
b76289ea02
@ -874,7 +874,6 @@ class Rows extends Generators {
|
||||
import static org.jooq.SQLDialect.DERBY;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
import static org.jooq.SQLDialect.INGRES;
|
||||
import static org.jooq.SQLDialect.ORACLE;
|
||||
import static org.jooq.SQLDialect.SQLITE;
|
||||
import static org.jooq.SQLDialect.SQLSERVER;
|
||||
import static org.jooq.SQLDialect.SYBASE;
|
||||
@ -1689,7 +1688,7 @@ class Rows extends Generators {
|
||||
|
||||
@Override
|
||||
public final Condition equal(Select select) {
|
||||
return new Subquery(select, SubqueryOperator.EQUALS);
|
||||
return new RowSubquery(this, select, SubqueryOperator.EQUALS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1699,7 +1698,7 @@ class Rows extends Generators {
|
||||
|
||||
@Override
|
||||
public final Condition notEqual(Select select) {
|
||||
return new Subquery(select, SubqueryOperator.NOT_EQUALS);
|
||||
return new RowSubquery(this, select, SubqueryOperator.NOT_EQUALS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1709,7 +1708,7 @@ class Rows extends Generators {
|
||||
|
||||
««« @Override
|
||||
««« public final Condition greaterThan(Select select) {
|
||||
««« return new Subquery(select, SubqueryOperator.GREATER);
|
||||
««« return new RowSubquery(this, select, SubqueryOperator.GREATER);
|
||||
««« }
|
||||
«««
|
||||
««« @Override
|
||||
@ -1719,7 +1718,7 @@ class Rows extends Generators {
|
||||
«««
|
||||
««« @Override
|
||||
««« public final Condition greaterOrEqual(Select select) {
|
||||
««« return new Subquery(select, SubqueryOperator.GREATER_OR_EQUAL);
|
||||
««« return new RowSubquery(this, select, SubqueryOperator.GREATER_OR_EQUAL);
|
||||
««« }
|
||||
«««
|
||||
««« @Override
|
||||
@ -1729,7 +1728,7 @@ class Rows extends Generators {
|
||||
«««
|
||||
««« @Override
|
||||
««« public final Condition lessThan(Select select) {
|
||||
««« return new Subquery(select, SubqueryOperator.LESS);
|
||||
««« return new RowSubquery(this, select, SubqueryOperator.LESS);
|
||||
««« }
|
||||
«««
|
||||
««« @Override
|
||||
@ -1739,7 +1738,7 @@ class Rows extends Generators {
|
||||
«««
|
||||
««« @Override
|
||||
««« public final Condition lessOrEqual(Select select) {
|
||||
««« return new Subquery(select, SubqueryOperator.LESS_OR_EQUAL);
|
||||
««« return new RowSubquery(this, select, SubqueryOperator.LESS_OR_EQUAL);
|
||||
««« }
|
||||
«««
|
||||
««« @Override
|
||||
@ -1749,12 +1748,12 @@ class Rows extends Generators {
|
||||
«««
|
||||
@Override
|
||||
public final Condition in(Select select) {
|
||||
return new Subquery(select, SubqueryOperator.IN);
|
||||
return new RowSubquery(this, select, SubqueryOperator.IN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition notIn(Select select) {
|
||||
return new Subquery(select, SubqueryOperator.NOT_IN);
|
||||
return new RowSubquery(this, select, SubqueryOperator.NOT_IN);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -1849,46 +1848,6 @@ class Rows extends Generators {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Subquery extends AbstractCondition {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -1806139685201770706L;
|
||||
|
||||
private final Select<?> other;
|
||||
private final SubqueryOperator operator;
|
||||
|
||||
Subquery(Select<?> other, SubqueryOperator operator) {
|
||||
this.other = other;
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void toSQL(RenderContext context) {
|
||||
|
||||
// Some databases need extra parentheses around the RHS
|
||||
boolean extraParentheses = asList(ORACLE).contains(context.getDialect());
|
||||
boolean subquery = context.subquery();
|
||||
|
||||
context.sql(RowImpl.this)
|
||||
.sql(" ")
|
||||
.keyword(operator.toSQL())
|
||||
.sql(" (")
|
||||
.sql(extraParentheses ? "(" : "")
|
||||
.subquery(true)
|
||||
.sql(other)
|
||||
.subquery(subquery)
|
||||
.sql(extraParentheses ? ")" : "")
|
||||
.sql(")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void bind(BindContext context) {
|
||||
context.bind(RowImpl.this).bind(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
''');
|
||||
|
||||
|
||||
@ -42,7 +42,6 @@ import static org.jooq.SQLDialect.DB2;
|
||||
import static org.jooq.SQLDialect.DERBY;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
import static org.jooq.SQLDialect.INGRES;
|
||||
import static org.jooq.SQLDialect.ORACLE;
|
||||
import static org.jooq.SQLDialect.SQLITE;
|
||||
import static org.jooq.SQLDialect.SQLSERVER;
|
||||
import static org.jooq.SQLDialect.SYBASE;
|
||||
@ -2937,7 +2936,7 @@ implements
|
||||
|
||||
@Override
|
||||
public final Condition equal(Select select) {
|
||||
return new Subquery(select, SubqueryOperator.EQUALS);
|
||||
return new RowSubquery(this, select, SubqueryOperator.EQUALS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2947,7 +2946,7 @@ implements
|
||||
|
||||
@Override
|
||||
public final Condition notEqual(Select select) {
|
||||
return new Subquery(select, SubqueryOperator.NOT_EQUALS);
|
||||
return new RowSubquery(this, select, SubqueryOperator.NOT_EQUALS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2957,12 +2956,12 @@ implements
|
||||
|
||||
@Override
|
||||
public final Condition in(Select select) {
|
||||
return new Subquery(select, SubqueryOperator.IN);
|
||||
return new RowSubquery(this, select, SubqueryOperator.IN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition notIn(Select select) {
|
||||
return new Subquery(select, SubqueryOperator.NOT_IN);
|
||||
return new RowSubquery(this, select, SubqueryOperator.NOT_IN);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -3057,44 +3056,4 @@ implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Subquery extends AbstractCondition {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -1806139685201770706L;
|
||||
|
||||
private final Select<?> other;
|
||||
private final SubqueryOperator operator;
|
||||
|
||||
Subquery(Select<?> other, SubqueryOperator operator) {
|
||||
this.other = other;
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void toSQL(RenderContext context) {
|
||||
|
||||
// Some databases need extra parentheses around the RHS
|
||||
boolean extraParentheses = asList(ORACLE).contains(context.getDialect());
|
||||
boolean subquery = context.subquery();
|
||||
|
||||
context.sql(RowImpl.this)
|
||||
.sql(" ")
|
||||
.keyword(operator.toSQL())
|
||||
.sql(" (")
|
||||
.sql(extraParentheses ? "(" : "")
|
||||
.subquery(true)
|
||||
.sql(other)
|
||||
.subquery(subquery)
|
||||
.sql(extraParentheses ? ")" : "")
|
||||
.sql(")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void bind(BindContext context) {
|
||||
context.bind(RowImpl.this).bind(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
89
jOOQ/src/main/java/org/jooq/impl/RowSubquery.java
Normal file
89
jOOQ/src/main/java/org/jooq/impl/RowSubquery.java
Normal file
@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed to you under the Apache License, Version 2.0
|
||||
* (the "License"); You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* . Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* . Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* . Neither the name "jOOQ" nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.SQLDialect.ORACLE;
|
||||
|
||||
import org.jooq.BindContext;
|
||||
import org.jooq.RenderContext;
|
||||
import org.jooq.Row;
|
||||
import org.jooq.Select;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
class RowSubquery extends AbstractCondition {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -1806139685201770706L;
|
||||
|
||||
private final Row left;
|
||||
private final Select<?> right;
|
||||
private final SubqueryOperator operator;
|
||||
|
||||
RowSubquery(Row left, Select<?> right, SubqueryOperator operator) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void toSQL(RenderContext context) {
|
||||
|
||||
// Some databases need extra parentheses around the RHS
|
||||
boolean extraParentheses = asList(ORACLE).contains(context.getDialect());
|
||||
boolean subquery = context.subquery();
|
||||
|
||||
context.sql(left)
|
||||
.sql(" ")
|
||||
.keyword(operator.toSQL())
|
||||
.sql(" (")
|
||||
.sql(extraParentheses ? "(" : "")
|
||||
.subquery(true)
|
||||
.sql(right)
|
||||
.subquery(subquery)
|
||||
.sql(extraParentheses ? ")" : "")
|
||||
.sql(")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void bind(BindContext context) {
|
||||
context.bind(left).bind(right);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user