File tree Expand file tree Collapse file tree 16 files changed +279
-14
lines changed
main/java/org/mybatis/dynamic/sql
test/java/org/mybatis/dynamic/sql Expand file tree Collapse file tree 16 files changed +279
-14
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2016-2022 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org .mybatis .dynamic .sql .exception ;
17
+
18
+ public class InvalidSqlException extends RuntimeException {
19
+ public InvalidSqlException (String message ) {
20
+ super (message );
21
+ }
22
+ }
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2020 the original author or authors.
2
+ * Copyright 2016-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
29
29
public abstract class AbstractMultiRowInsertModel <T > {
30
30
private final SqlTable table ;
31
31
private final List <T > records ;
32
- private final List <AbstractColumnMapping > columnMappings ;
32
+ protected final List <AbstractColumnMapping > columnMappings ;
33
33
34
34
protected AbstractMultiRowInsertModel (AbstractBuilder <T , ?> builder ) {
35
35
table = Objects .requireNonNull (builder .table );
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2020 the original author or authors.
2
+ * Copyright 2016-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
import java .util .Collection ;
19
19
20
20
import org .jetbrains .annotations .NotNull ;
21
+ import org .mybatis .dynamic .sql .exception .InvalidSqlException ;
21
22
import org .mybatis .dynamic .sql .insert .render .BatchInsert ;
22
23
import org .mybatis .dynamic .sql .insert .render .BatchInsertRenderer ;
23
24
import org .mybatis .dynamic .sql .render .RenderingStrategy ;
@@ -26,6 +27,9 @@ public class BatchInsertModel<T> extends AbstractMultiRowInsertModel<T> {
26
27
27
28
private BatchInsertModel (Builder <T > builder ) {
28
29
super (builder );
30
+ if (columnMappings .isEmpty ()) {
31
+ throw new InvalidSqlException ("Batch insert statements must have at least one column mapping" );
32
+ }
29
33
}
30
34
31
35
@ NotNull
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2020 the original author or authors.
2
+ * Copyright 2016-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
23
23
24
24
import org .jetbrains .annotations .NotNull ;
25
25
import org .mybatis .dynamic .sql .SqlTable ;
26
+ import org .mybatis .dynamic .sql .exception .InvalidSqlException ;
26
27
import org .mybatis .dynamic .sql .insert .render .GeneralInsertRenderer ;
27
28
import org .mybatis .dynamic .sql .insert .render .GeneralInsertStatementProvider ;
28
29
import org .mybatis .dynamic .sql .render .RenderingStrategy ;
@@ -35,6 +36,9 @@ public class GeneralInsertModel {
35
36
36
37
private GeneralInsertModel (Builder builder ) {
37
38
table = Objects .requireNonNull (builder .table );
39
+ if (builder .insertMappings .isEmpty ()) {
40
+ throw new InvalidSqlException ("General insert statements must have at least one column mapping" );
41
+ }
38
42
insertMappings = builder .insertMappings ;
39
43
}
40
44
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2020 the original author or authors.
2
+ * Copyright 2016-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
18
18
import java .util .ArrayList ;
19
19
import java .util .List ;
20
+ import java .util .Objects ;
20
21
import java .util .function .Function ;
21
22
import java .util .stream .Stream ;
22
23
23
24
import org .mybatis .dynamic .sql .SqlColumn ;
25
+ import org .mybatis .dynamic .sql .exception .InvalidSqlException ;
24
26
25
27
public class InsertColumnListModel {
26
28
private final List <SqlColumn <?>> columns = new ArrayList <>();
27
29
28
30
private InsertColumnListModel (List <SqlColumn <?>> columns ) {
31
+ Objects .requireNonNull (columns );
32
+ if (columns .isEmpty ()) {
33
+ throw new InvalidSqlException ("Insert select statements require at least one column in the column list" );
34
+ }
35
+
29
36
this .columns .addAll (columns );
30
37
}
31
38
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2021 the original author or authors.
2
+ * Copyright 2016-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
23
23
24
24
import org .jetbrains .annotations .NotNull ;
25
25
import org .mybatis .dynamic .sql .SqlTable ;
26
+ import org .mybatis .dynamic .sql .exception .InvalidSqlException ;
26
27
import org .mybatis .dynamic .sql .insert .render .InsertRenderer ;
27
28
import org .mybatis .dynamic .sql .insert .render .InsertStatementProvider ;
28
29
import org .mybatis .dynamic .sql .render .RenderingStrategy ;
@@ -37,6 +38,9 @@ private InsertModel(Builder<T> builder) {
37
38
table = Objects .requireNonNull (builder .table );
38
39
row = Objects .requireNonNull (builder .row );
39
40
columnMappings = Objects .requireNonNull (builder .columnMappings );
41
+ if (columnMappings .isEmpty ()) {
42
+ throw new InvalidSqlException ("Insert statements must have at least one column mapping" ); // $NON-NLS-1$
43
+ }
40
44
}
41
45
42
46
public <R > Stream <R > mapColumnMappings (Function <AbstractColumnMapping , R > mapper ) {
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2020 the original author or authors.
2
+ * Copyright 2016-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
import java .util .Collection ;
19
19
20
20
import org .jetbrains .annotations .NotNull ;
21
+ import org .mybatis .dynamic .sql .exception .InvalidSqlException ;
21
22
import org .mybatis .dynamic .sql .insert .render .MultiRowInsertRenderer ;
22
23
import org .mybatis .dynamic .sql .insert .render .MultiRowInsertStatementProvider ;
23
24
import org .mybatis .dynamic .sql .render .RenderingStrategy ;
@@ -26,6 +27,9 @@ public class MultiRowInsertModel<T> extends AbstractMultiRowInsertModel<T> {
26
27
27
28
private MultiRowInsertModel (Builder <T > builder ) {
28
29
super (builder );
30
+ if (columnMappings .isEmpty ()) {
31
+ throw new InvalidSqlException ("Multi row insert statements must have at least one column mapping" );
32
+ }
29
33
}
30
34
31
35
@ NotNull
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2020 the original author or authors.
2
+ * Copyright 2016-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
import java .util .ArrayList ;
19
19
import java .util .Collection ;
20
20
import java .util .List ;
21
+ import java .util .Objects ;
21
22
import java .util .function .Function ;
22
23
import java .util .stream .Stream ;
23
24
24
25
import org .mybatis .dynamic .sql .BasicColumn ;
26
+ import org .mybatis .dynamic .sql .exception .InvalidSqlException ;
25
27
26
28
public class GroupByModel {
27
29
private final List <BasicColumn > columns = new ArrayList <>();
28
30
29
31
private GroupByModel (Collection <BasicColumn > columns ) {
32
+ Objects .requireNonNull (columns );
33
+ if (columns .isEmpty ()) {
34
+ throw new InvalidSqlException ("Group by expressions must have at least one column" );
35
+ }
30
36
this .columns .addAll (columns );
31
37
}
32
38
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2020 the original author or authors.
2
+ * Copyright 2016-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
import java .util .ArrayList ;
19
19
import java .util .Collection ;
20
20
import java .util .List ;
21
+ import java .util .Objects ;
21
22
import java .util .function .Function ;
22
23
import java .util .stream .Stream ;
23
24
24
25
import org .mybatis .dynamic .sql .SortSpecification ;
26
+ import org .mybatis .dynamic .sql .exception .InvalidSqlException ;
25
27
26
28
public class OrderByModel {
27
29
private final List <SortSpecification > columns = new ArrayList <>();
28
30
29
31
private OrderByModel (Collection <SortSpecification > columns ) {
32
+ Objects .requireNonNull (columns );
33
+ if (columns .isEmpty ()) {
34
+ throw new InvalidSqlException ("Order by expressions must have at least one column" );
35
+ }
30
36
this .columns .addAll (columns );
31
37
}
32
38
Original file line number Diff line number Diff line change 27
27
import org .mybatis .dynamic .sql .BasicColumn ;
28
28
import org .mybatis .dynamic .sql .SqlTable ;
29
29
import org .mybatis .dynamic .sql .TableExpression ;
30
+ import org .mybatis .dynamic .sql .exception .InvalidSqlException ;
30
31
import org .mybatis .dynamic .sql .select .join .JoinModel ;
31
32
import org .mybatis .dynamic .sql .where .WhereModel ;
32
33
@@ -49,6 +50,10 @@ private QueryExpressionModel(Builder builder) {
49
50
tableAliases = builder .tableAliases ;
50
51
whereModel = builder .whereModel ;
51
52
groupByModel = builder .groupByModel ;
53
+
54
+ if (selectList .isEmpty ()) {
55
+ throw new InvalidSqlException ("Query expressions must have at least one column in the select list" );
56
+ }
52
57
}
53
58
54
59
public Optional <String > connector () {
You can’t perform that action at this time.
0 commit comments