Polishing.
Remove unecessary toString calls. Make Cast.create public to align with other factory methods. Fix AbstractSegment.toString See #1066 Original pull request: #1071.
This commit is contained in:
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.relational.core.sql;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -70,7 +68,6 @@ abstract class AbstractSegment implements Segment {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return StringUtils.collectionToDelimitedString(Arrays.asList(children), ", ", getClass().getSimpleName() + "(",
|
||||
")");
|
||||
return getClass().getSimpleName() + "(" + StringUtils.arrayToDelimitedString(children, ", ") + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,6 @@ class AliasedExpression extends AbstractSegment implements Aliased, Expression {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return expression.toString() + " AS " + alias;
|
||||
return expression + " AS " + alias;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.data.relational.core.sql;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Represents a CAST expression like {@code CAST(something AS JSON}.
|
||||
* Represents a {@code CAST} expression like {@code CAST(something AS JSON}.
|
||||
*
|
||||
* @author Jens Schauder
|
||||
* @since 2.3
|
||||
@@ -39,13 +39,13 @@ public class Cast extends AbstractSegment implements Expression {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new CAST expression.
|
||||
* Creates a new {@code CAST} expression.
|
||||
*
|
||||
* @param expression the expression to cast. Must not be {@literal null}.
|
||||
* @param targetType the type to cast to. Must not be {@literal null}.
|
||||
* @return guaranteed to be not {@literal null}.
|
||||
* @return the {@code CAST} for {@code expression} into {@code targetType}.
|
||||
*/
|
||||
static Expression create(Expression expression, String targetType) {
|
||||
public static Expression create(Expression expression, String targetType) {
|
||||
return new Cast(expression, targetType);
|
||||
}
|
||||
|
||||
|
||||
@@ -116,6 +116,6 @@ public class Comparison extends AbstractSegment implements Condition {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return left.toString() + " " + comparator + " " + right.toString();
|
||||
return left + " " + comparator + " " + right;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ public abstract class Expressions {
|
||||
|
||||
/**
|
||||
* @return a new {@link Cast} expression.
|
||||
* @since 2.3
|
||||
*/
|
||||
public static Expression cast(Expression expression, String targetType) {
|
||||
return Cast.create(expression, targetType);
|
||||
|
||||
@@ -45,6 +45,6 @@ public class Not extends AbstractSegment implements Condition {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NOT " + condition.toString();
|
||||
return "NOT " + condition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,6 @@ public class SubselectExpression extends AbstractSegment implements Expression {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + subselect.toString() + ")";
|
||||
return "(" + subselect + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2021 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.
|
||||
*/
|
||||
package org.springframework.data.relational.core.sql;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractSegment}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class AbstractSegmentTests {
|
||||
|
||||
@Test // GH-1066
|
||||
void shouldReportToStringCorrectly() {
|
||||
|
||||
Table table = Table.create("foo");
|
||||
AbstractSegment segment = new AbstractTestSegment(table.column("col1"), table.column("col2"));
|
||||
|
||||
assertThat(segment).hasToString("AbstractTestSegment(foo.col1, foo.col2)");
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ package org.springframework.data.relational.core.sql;
|
||||
*
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
public class AbstractTestSegment extends AbstractSegment{
|
||||
public class AbstractTestSegment extends AbstractSegment {
|
||||
protected AbstractTestSegment(Segment... children) {
|
||||
super(children);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user