1
1
/**
2
- * Copyright 2016-2018 the original author or authors.
2
+ * Copyright 2016-2019 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.
15
15
*/
16
16
package org .mybatis .dynamic .sql .update .render ;
17
17
18
- import static org .mybatis .dynamic .sql .util .StringUtilities .spaceBefore ;
19
-
20
18
import java .util .HashMap ;
21
19
import java .util .Map ;
22
20
import java .util .Objects ;
23
- import java .util .Optional ;
24
-
25
- import org .mybatis .dynamic .sql .where .render .WhereClauseProvider ;
26
21
27
- /**
28
- * This class combines a "set" clause and a "where" clause into one parameter object
29
- * that can be sent to a MyBatis3 mapper method.
30
- *
31
- * @author Jeff Butler
32
- *
33
- */
34
22
public class DefaultUpdateStatementProvider implements UpdateStatementProvider {
35
- private String tableName ;
36
- private String setClause ;
37
- private Optional <String > whereClause ;
23
+ private String updateStatement ;
38
24
private Map <String , Object > parameters = new HashMap <>();
39
25
40
26
private DefaultUpdateStatementProvider (Builder builder ) {
41
- tableName = Objects .requireNonNull (builder .tableName );
42
- setClause = Objects .requireNonNull (builder .setClause );
43
- whereClause = Optional .ofNullable (builder .whereClause );
27
+ updateStatement = Objects .requireNonNull (builder .updateStatement );
44
28
parameters .putAll (builder .parameters );
45
29
}
46
30
@@ -51,37 +35,19 @@ public Map<String, Object> getParameters() {
51
35
52
36
@ Override
53
37
public String getUpdateStatement () {
54
- return "update" //$NON-NLS-1$
55
- + spaceBefore (tableName )
56
- + spaceBefore (setClause )
57
- + spaceBefore (whereClause );
38
+ return updateStatement ;
58
39
}
59
40
60
- public static Builder withTableName (String tableName ) {
61
- return new Builder ().withTableName ( tableName );
41
+ public static Builder withUpdateStatement (String updateStatement ) {
42
+ return new Builder ().withUpdateStatement ( updateStatement );
62
43
}
63
44
64
45
public static class Builder {
65
- private String tableName ;
66
- private String setClause ;
67
- private String whereClause ;
46
+ private String updateStatement ;
68
47
private Map <String , Object > parameters = new HashMap <>();
69
48
70
- public Builder withTableName (String tableName ) {
71
- this .tableName = tableName ;
72
- return this ;
73
- }
74
-
75
- public Builder withSetClause (String setClause ) {
76
- this .setClause = setClause ;
77
- return this ;
78
- }
79
-
80
- public Builder withWhereClause (Optional <WhereClauseProvider > whereClauseProvider ) {
81
- whereClauseProvider .ifPresent (wcp -> {
82
- whereClause = wcp .getWhereClause ();
83
- parameters .putAll (wcp .getParameters ());
84
- });
49
+ public Builder withUpdateStatement (String updateStatement ) {
50
+ this .updateStatement = updateStatement ;
85
51
return this ;
86
52
}
87
53
0 commit comments