DATAJDBC-490 - Rename .group() to .nest() to avoid confusion with GROUP BY.
Original pull request: #193.
This commit is contained in:
committed by
Jens Schauder
parent
a4bf09e8e8
commit
a184cd9e0e
@@ -44,15 +44,15 @@ public abstract class Conditions {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a grouped {@link Condition} that is enclosed with parentheses. Useful to combine {@code AND} and {@code OR}
|
||||
* Creates a nested {@link Condition} that is enclosed with parentheses. Useful to combine {@code AND} and {@code OR}
|
||||
* statements.
|
||||
*
|
||||
* @param condition the nested condition to be grouped.
|
||||
* @return a {@link GroupedCondition}.
|
||||
* @param condition the nested condition.
|
||||
* @return a {@link NestedCondition}.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static Condition group(Condition condition) {
|
||||
return new GroupedCondition(condition);
|
||||
public static Condition nest(Condition condition) {
|
||||
return new NestedCondition(condition);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,9 +21,9 @@ package org.springframework.data.relational.core.sql;
|
||||
* @author Mark Paluch
|
||||
* @since 2.0
|
||||
*/
|
||||
public class GroupedCondition extends MultipleCondition implements Condition {
|
||||
public class NestedCondition extends MultipleCondition implements Condition {
|
||||
|
||||
GroupedCondition(Condition condition) {
|
||||
NestedCondition(Condition condition) {
|
||||
super("", condition);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.data.relational.core.sql.render;
|
||||
import org.springframework.data.relational.core.sql.AndCondition;
|
||||
import org.springframework.data.relational.core.sql.Comparison;
|
||||
import org.springframework.data.relational.core.sql.Condition;
|
||||
import org.springframework.data.relational.core.sql.GroupedCondition;
|
||||
import org.springframework.data.relational.core.sql.NestedCondition;
|
||||
import org.springframework.data.relational.core.sql.In;
|
||||
import org.springframework.data.relational.core.sql.IsNull;
|
||||
import org.springframework.data.relational.core.sql.Like;
|
||||
@@ -87,7 +87,7 @@ class ConditionVisitor extends TypedSubtreeVisitor<Condition> implements PartRen
|
||||
return new InVisitor(context, builder::append);
|
||||
}
|
||||
|
||||
if (segment instanceof GroupedCondition) {
|
||||
if (segment instanceof NestedCondition) {
|
||||
return new GroupedConditionVisitor(context, builder::append);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,17 +16,17 @@
|
||||
package org.springframework.data.relational.core.sql.render;
|
||||
|
||||
import org.springframework.data.relational.core.sql.Condition;
|
||||
import org.springframework.data.relational.core.sql.GroupedCondition;
|
||||
import org.springframework.data.relational.core.sql.NestedCondition;
|
||||
import org.springframework.data.relational.core.sql.Visitable;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Renderer for {@link GroupedCondition}. Uses a {@link RenderTarget} to call back for render results.
|
||||
* Renderer for {@link NestedCondition}. Uses a {@link RenderTarget} to call back for render results.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @since 2.0
|
||||
*/
|
||||
class GroupedConditionVisitor extends TypedSubtreeVisitor<GroupedCondition> {
|
||||
class GroupedConditionVisitor extends TypedSubtreeVisitor<NestedCondition> {
|
||||
|
||||
private final RenderContext context;
|
||||
private final RenderTarget target;
|
||||
|
||||
@@ -44,19 +44,19 @@ public class ConditionRendererUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-490
|
||||
public void shouldRenderEqualsGroup() {
|
||||
public void shouldRenderEqualsNested() {
|
||||
|
||||
String sql = SqlRenderer
|
||||
.toString(StatementBuilder.select(left).from(table).where(Conditions.group(left.isEqualTo(right))).build());
|
||||
.toString(StatementBuilder.select(left).from(table).where(Conditions.nest(left.isEqualTo(right))).build());
|
||||
|
||||
assertThat(sql).endsWith("WHERE (my_table.left = my_table.right)");
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-490
|
||||
public void shouldRenderAndGroup() {
|
||||
public void shouldRenderAndNest() {
|
||||
|
||||
String sql = SqlRenderer.toString(StatementBuilder.select(left).from(table)
|
||||
.where(Conditions.group(left.isEqualTo(right).and(left.isGreater(right)))).build());
|
||||
.where(Conditions.nest(left.isEqualTo(right).and(left.isGreater(right)))).build());
|
||||
|
||||
assertThat(sql).endsWith("WHERE (my_table.left = my_table.right AND my_table.left > my_table.right)");
|
||||
}
|
||||
@@ -65,18 +65,18 @@ public class ConditionRendererUnitTests {
|
||||
public void shouldRenderAndGroupOr() {
|
||||
|
||||
String sql = SqlRenderer.toString(StatementBuilder.select(left).from(table)
|
||||
.where(Conditions.group(left.isEqualTo(right).and(left.isGreater(right))).or(left.like(right))).build());
|
||||
.where(Conditions.nest(left.isEqualTo(right).and(left.isGreater(right))).or(left.like(right))).build());
|
||||
|
||||
assertThat(sql).endsWith(
|
||||
"WHERE (my_table.left = my_table.right AND my_table.left > my_table.right) OR my_table.left LIKE my_table.right");
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-490
|
||||
public void shouldRenderAndGroupOrAndGroup() {
|
||||
public void shouldRenderAndGroupOrAndNested() {
|
||||
|
||||
String sql = SqlRenderer.toString(StatementBuilder.select(left).from(table)
|
||||
.where(Conditions.group(left.isEqualTo(right).and(left.isGreater(right)))
|
||||
.or(Conditions.group(left.like(right).and(right.like(left)))))
|
||||
.where(Conditions.nest(left.isEqualTo(right).and(left.isGreater(right)))
|
||||
.or(Conditions.nest(left.like(right).and(right.like(left)))))
|
||||
.build());
|
||||
|
||||
assertThat(sql).endsWith(
|
||||
|
||||
Reference in New Issue
Block a user