Skip to content

Commit a3ffea4

Browse files
authored
Merge pull request #8 from jeffgbutler/master
General Cleanup and Maintenance
2 parents 0f2567d + 18bc148 commit a3ffea4

17 files changed

+123
-112
lines changed

pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@
108108
<version>${junit.platform.version}</version>
109109
<scope>test</scope>
110110
</dependency>
111-
<dependency>
112-
<groupId>org.junit.jupiter</groupId>
113-
<artifactId>junit-jupiter-engine</artifactId>
114-
<version>${junit.jupiter.version}</version>
115-
<scope>test</scope>
116-
</dependency>
117111
<!-- added to support running JUnit5 tests with JUnit4. Remove when Infinitest catches up. -->
118112
<!-- Note: DO NOT make this the org.junit.vintage support. All the tests are written with JUnit5.
119113
Once Infinitest is ready we can remove this dependency and the corresponding @RunWith annotations

src/main/java/org/mybatis/dynamic/sql/SqlCriterion.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2018 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.
@@ -26,18 +26,18 @@ public class SqlCriterion<T> {
2626

2727
private BindableColumn<T> column;
2828
private VisitableCondition<T> condition;
29-
private Optional<String> connector;
29+
private String connector;
3030
private List<SqlCriterion<?>> subCriteria;
3131

3232
private SqlCriterion(Builder<T> builder) {
33-
connector = Optional.ofNullable(builder.connector);
33+
connector = builder.connector;
3434
column = Objects.requireNonNull(builder.column);
3535
condition = Objects.requireNonNull(builder.condition);
3636
subCriteria = Objects.requireNonNull(builder.subCriteria);
3737
}
3838

3939
public Optional<String> connector() {
40-
return connector;
40+
return Optional.ofNullable(connector);
4141
}
4242

4343
public BindableColumn<T> column() {

src/main/java/org/mybatis/dynamic/sql/delete/DeleteModel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2018 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.
@@ -26,19 +26,19 @@
2626

2727
public class DeleteModel {
2828
private SqlTable table;
29-
private Optional<WhereModel> whereModel;
29+
private WhereModel whereModel;
3030

3131
private DeleteModel(Builder builder) {
3232
table = Objects.requireNonNull(builder.table);
33-
whereModel = Optional.ofNullable(builder.whereModel);
33+
whereModel = builder.whereModel;
3434
}
3535

3636
public SqlTable table() {
3737
return table;
3838
}
3939

4040
public Optional<WhereModel> whereModel() {
41-
return whereModel;
41+
return Optional.ofNullable(whereModel);
4242
}
4343

4444
public DeleteStatementProvider render(RenderingStrategy renderingStrategy) {

src/main/java/org/mybatis/dynamic/sql/delete/render/DeleteStatementProvider.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2018 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.
@@ -17,7 +17,7 @@
1717

1818
import static org.mybatis.dynamic.sql.util.StringUtilities.spaceBefore;
1919

20-
import java.util.Collections;
20+
import java.util.HashMap;
2121
import java.util.Map;
2222
import java.util.Objects;
2323
import java.util.Optional;
@@ -26,22 +26,23 @@
2626

2727
public class DeleteStatementProvider {
2828
private String tableName;
29-
private Optional<WhereClauseProvider> whereClauseProvider;
29+
private Optional<String> whereClause;
30+
private Map<String, Object> parameters;
3031

3132
private DeleteStatementProvider(Builder builder) {
3233
tableName = Objects.requireNonNull(builder.tableName);
33-
whereClauseProvider = Objects.requireNonNull(builder.whereClauseProvider);
34+
whereClause = Optional.ofNullable(builder.whereClause);
35+
parameters = Objects.requireNonNull(builder.parameters);
3436
}
3537

3638
public Map<String, Object> getParameters() {
37-
return whereClauseProvider.map(WhereClauseProvider::getParameters)
38-
.orElse(Collections.emptyMap());
39+
return parameters;
3940
}
4041

4142
public String getDeleteStatement() {
4243
return "delete from" //$NON-NLS-1$
4344
+ spaceBefore(tableName)
44-
+ spaceBefore(whereClauseProvider.map(WhereClauseProvider::getWhereClause));
45+
+ spaceBefore(whereClause);
4546
}
4647

4748
public static Builder withTableName(String tableName) {
@@ -50,15 +51,19 @@ public static Builder withTableName(String tableName) {
5051

5152
public static class Builder {
5253
private String tableName;
53-
private Optional<WhereClauseProvider> whereClauseProvider = Optional.empty();
54+
private String whereClause;
55+
private Map<String, Object> parameters = new HashMap<>();
5456

5557
public Builder withTableName(String tableName) {
5658
this.tableName = tableName;
5759
return this;
5860
}
5961

6062
public Builder withWhereClause(Optional<WhereClauseProvider> whereClauseProvider) {
61-
this.whereClauseProvider = whereClauseProvider;
63+
whereClauseProvider.ifPresent(wcp -> {
64+
whereClause = wcp.getWhereClause();
65+
parameters.putAll(wcp.getParameters());
66+
});
6267
return this;
6368
}
6469

src/main/java/org/mybatis/dynamic/sql/insert/InsertSelectDSL.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2018 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.
@@ -17,6 +17,7 @@
1717

1818
import java.util.Arrays;
1919
import java.util.List;
20+
import java.util.Objects;
2021
import java.util.Optional;
2122

2223
import org.mybatis.dynamic.sql.SqlColumn;
@@ -27,24 +28,22 @@
2728
public class InsertSelectDSL {
2829

2930
private SqlTable table;
30-
private Optional<InsertColumnListModel> columnList;
31+
private InsertColumnListModel columnList;
3132
private SelectModel selectModel;
3233

3334
private InsertSelectDSL(SqlTable table, InsertColumnListModel columnList, SelectModel selectModel) {
34-
this.table = table;
35-
this.columnList = Optional.of(columnList);
36-
this.selectModel = selectModel;
35+
this(table, selectModel);
36+
this.columnList = columnList;
3737
}
3838

3939
private InsertSelectDSL(SqlTable table, SelectModel selectModel) {
40-
this.table = table;
41-
this.columnList = Optional.empty();
42-
this.selectModel = selectModel;
40+
this.table = Objects.requireNonNull(table);
41+
this.selectModel = Objects.requireNonNull(selectModel);
4342
}
4443

4544
public InsertSelectModel build() {
4645
return InsertSelectModel.withTable(table)
47-
.withColumnList(columnList)
46+
.withColumnList(Optional.ofNullable(columnList))
4847
.withSelectModel(selectModel)
4948
.build();
5049
}

src/main/java/org/mybatis/dynamic/sql/select/QueryExpressionModel.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2018 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.
@@ -34,29 +34,29 @@
3434
import org.mybatis.dynamic.sql.where.WhereModel;
3535

3636
public class QueryExpressionModel {
37-
private Optional<String> connector;
37+
private String connector;
3838
private boolean isDistinct;
3939
private List<BasicColumn> selectList;
4040
private SqlTable table;
41-
private Optional<JoinModel> joinModel;
41+
private JoinModel joinModel;
4242
private TableAliasCalculator tableAliasCalculator;
43-
private Optional<WhereModel> whereModel;
44-
private Optional<GroupByModel> groupByModel;
43+
private WhereModel whereModel;
44+
private GroupByModel groupByModel;
4545

4646
private QueryExpressionModel(Builder builder) {
47-
connector = Optional.ofNullable(builder.connector);
47+
connector = builder.connector;
4848
isDistinct = builder.isDistinct;
4949
selectList = Objects.requireNonNull(builder.selectList);
5050
table = Objects.requireNonNull(builder.table);
51-
joinModel = Optional.ofNullable(builder.joinModel);
52-
tableAliasCalculator = joinModel.map(jm -> GuaranteedTableAliasCalculator.of(builder.tableAliases))
51+
joinModel = builder.joinModel;
52+
tableAliasCalculator = joinModel().map(jm -> GuaranteedTableAliasCalculator.of(builder.tableAliases))
5353
.orElse(TableAliasCalculator.of(builder.tableAliases));
54-
whereModel = Optional.ofNullable(builder.whereModel);
55-
groupByModel = Optional.ofNullable(builder.groupByModel);
54+
whereModel = builder.whereModel;
55+
groupByModel = builder.groupByModel;
5656
}
5757

5858
public Optional<String> connector() {
59-
return connector;
59+
return Optional.ofNullable(connector);
6060
}
6161

6262
public boolean isDistinct() {
@@ -76,15 +76,15 @@ public TableAliasCalculator tableAliasCalculator() {
7676
}
7777

7878
public Optional<WhereModel> whereModel() {
79-
return whereModel;
79+
return Optional.ofNullable(whereModel);
8080
}
8181

8282
public Optional<JoinModel> joinModel() {
83-
return joinModel;
83+
return Optional.ofNullable(joinModel);
8484
}
8585

8686
public Optional<GroupByModel> groupByModel() {
87-
return groupByModel;
87+
return Optional.ofNullable(groupByModel);
8888
}
8989

9090
public String calculateTableNameIncludingAlias(SqlTable table) {

src/main/java/org/mybatis/dynamic/sql/select/SelectModel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2018 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.
@@ -28,19 +28,19 @@
2828

2929
public class SelectModel {
3030
private List<QueryExpressionModel> queryExpressions;
31-
private Optional<OrderByModel> orderByModel;
31+
private OrderByModel orderByModel;
3232

3333
private SelectModel(Builder builder) {
3434
queryExpressions = Objects.requireNonNull(builder.queryExpressions);
35-
orderByModel = Optional.ofNullable(builder.orderByModel);
35+
orderByModel = builder.orderByModel;
3636
}
3737

3838
public <R> Stream<R> mapQueryExpressions(Function<QueryExpressionModel, R> mapper) {
3939
return queryExpressions.stream().map(mapper);
4040
}
4141

4242
public Optional<OrderByModel> orderByModel() {
43-
return orderByModel;
43+
return Optional.ofNullable(orderByModel);
4444
}
4545

4646
public SelectStatementProvider render(RenderingStrategy renderingStrategy) {

src/main/java/org/mybatis/dynamic/sql/select/aggregate/CountAll.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2018 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.
@@ -29,7 +29,7 @@
2929
*/
3030
public class CountAll implements BasicColumn {
3131

32-
private Optional<String> alias = Optional.empty();
32+
private String alias;
3333

3434
public CountAll() {
3535
super();
@@ -42,13 +42,13 @@ public String renderWithTableAlias(TableAliasCalculator tableAliasCalculator) {
4242

4343
@Override
4444
public Optional<String> alias() {
45-
return alias;
45+
return Optional.ofNullable(alias);
4646
}
4747

4848
@Override
4949
public CountAll as(String alias) {
5050
CountAll copy = new CountAll();
51-
copy.alias = Optional.of(alias);
51+
copy.alias = alias;
5252
return copy;
5353
}
5454
}

src/main/java/org/mybatis/dynamic/sql/select/function/Add.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2018 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.
@@ -24,7 +24,7 @@
2424

2525
public class Add<T extends Number> implements BindableColumn<T> {
2626

27-
private Optional<String> alias = Optional.empty();
27+
private String alias;
2828
private BindableColumn<T> column1;
2929
private BindableColumn<T> column2;
3030

@@ -35,7 +35,7 @@ private Add(BindableColumn<T> column1, BindableColumn<T> column2) {
3535

3636
@Override
3737
public Optional<String> alias() {
38-
return alias;
38+
return Optional.ofNullable(alias);
3939
}
4040

4141
@Override
@@ -48,7 +48,7 @@ public String renderWithTableAlias(TableAliasCalculator tableAliasCalculator) {
4848
@Override
4949
public BindableColumn<T> as(String alias) {
5050
Add<T> newColumn = new Add<>(column1, column2);
51-
newColumn.alias = Optional.of(alias);
51+
newColumn.alias = alias;
5252
return newColumn;
5353
}
5454

src/main/java/org/mybatis/dynamic/sql/select/join/JoinType.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 the original author or authors.
2+
* Copyright 2016-2018 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.
@@ -23,17 +23,16 @@ public enum JoinType {
2323
RIGHT("right"), //$NON-NLS-1$
2424
FULL("full"); //$NON-NLS-1$
2525

26-
private Optional<String> shortType;
26+
private String shortType;
2727

2828
private JoinType() {
29-
this.shortType = Optional.empty();
3029
}
3130

3231
private JoinType(String shortType) {
33-
this.shortType = Optional.of(shortType);
32+
this.shortType = shortType;
3433
}
3534

3635
public Optional<String> shortType() {
37-
return shortType;
36+
return Optional.ofNullable(shortType);
3837
}
3938
}

0 commit comments

Comments
 (0)