Skip to content

Commit 01620d6

Browse files
committed
Code polishing
1 parent 737126d commit 01620d6

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

src/main/java/org/mybatis/dynamic/sql/insert/render/ValuePhraseVisitor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ public Optional<FieldAndValue> visit(PropertyMapping mapping) {
6666
@Override
6767
public Optional<FieldAndValue> visit(PropertyWhenPresentMapping mapping) {
6868
if (mapping.shouldRender()) {
69-
return FieldAndValue.withFieldName(mapping.mapColumn(SqlColumn::name))
70-
.withValuePhrase(mapping.mapColumn(toJdbcPlaceholder(mapping.property())))
71-
.buildOptional();
69+
return visit((PropertyMapping) mapping);
7270
} else {
7371
return Optional.empty();
7472
}

src/main/java/org/mybatis/dynamic/sql/util/PropertyMapping.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,13 +15,16 @@
1515
*/
1616
package org.mybatis.dynamic.sql.util;
1717

18+
import java.util.Objects;
19+
1820
import org.mybatis.dynamic.sql.SqlColumn;
1921

2022
public class PropertyMapping extends AbstractColumnMapping {
2123
private String property;
2224

23-
private PropertyMapping(SqlColumn<?> column) {
25+
protected PropertyMapping(SqlColumn<?> column, String property) {
2426
super(column);
27+
this.property = Objects.requireNonNull(property);
2528
}
2629

2730
public String property() {
@@ -34,8 +37,6 @@ public <R> R accept(ColumnMappingVisitor<R> visitor) {
3437
}
3538

3639
public static PropertyMapping of(SqlColumn<?> column, String property) {
37-
PropertyMapping mapping = new PropertyMapping(column);
38-
mapping.property = property;
39-
return mapping;
40+
return new PropertyMapping(column, property);
4041
}
4142
}

src/main/java/org/mybatis/dynamic/sql/util/PropertyWhenPresentMapping.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,14 @@
2020

2121
import org.mybatis.dynamic.sql.SqlColumn;
2222

23-
public class PropertyWhenPresentMapping extends AbstractColumnMapping {
24-
private String property;
23+
public class PropertyWhenPresentMapping extends PropertyMapping {
2524
private Supplier<?> valueSupplier;
2625

2726
private PropertyWhenPresentMapping(SqlColumn<?> column, String property, Supplier<?> valueSupplier) {
28-
super(column);
29-
this.property = Objects.requireNonNull(property);
27+
super(column, property);
3028
this.valueSupplier = Objects.requireNonNull(valueSupplier);
3129
}
3230

33-
public String property() {
34-
return property;
35-
}
36-
3731
public boolean shouldRender() {
3832
return valueSupplier.get() != null;
3933
}

src/main/java/org/mybatis/dynamic/sql/util/StringUtilities.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
2222
public interface StringUtilities {
2323

2424
static String spaceAfter(Optional<String> in) {
25-
return in.map(s -> s + " ") //$NON-NLS-1$
25+
return in.map(StringUtilities::spaceAfter)
2626
.orElse(""); //$NON-NLS-1$
2727
}
2828

@@ -31,7 +31,7 @@ static String spaceAfter(String in) {
3131
}
3232

3333
static String spaceBefore(Optional<String> in) {
34-
return in.map(s -> " " + s) //$NON-NLS-1$
34+
return in.map(StringUtilities::spaceBefore)
3535
.orElse(""); //$NON-NLS-1$
3636
}
3737

src/main/java/org/mybatis/dynamic/sql/util/ValueMapping.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616
package org.mybatis.dynamic.sql.util;
1717

18+
import java.util.Objects;
1819
import java.util.function.Supplier;
1920

2021
import org.mybatis.dynamic.sql.SqlColumn;
@@ -25,7 +26,7 @@ public class ValueMapping<T> extends AbstractColumnMapping {
2526

2627
private ValueMapping(SqlColumn<T> column, Supplier<T> valueSupplier) {
2728
super(column);
28-
this.valueSupplier = valueSupplier;
29+
this.valueSupplier = Objects.requireNonNull(valueSupplier);
2930
}
3031

3132
public T value() {

0 commit comments

Comments
 (0)