11/**
2- * Copyright 2016-2018 the original author or authors.
2+ * Copyright 2016-2019 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.
1515 */
1616package org .mybatis .dynamic .sql .update .render ;
1717
18- import static org .mybatis .dynamic .sql .util .StringUtilities .spaceBefore ;
19-
2018import java .util .HashMap ;
2119import java .util .Map ;
2220import java .util .Objects ;
23- import java .util .Optional ;
24-
25- import org .mybatis .dynamic .sql .where .render .WhereClauseProvider ;
2621
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- */
3422public class DefaultUpdateStatementProvider implements UpdateStatementProvider {
35- private String tableName ;
36- private String setClause ;
37- private Optional <String > whereClause ;
23+ private String updateStatement ;
3824 private Map <String , Object > parameters = new HashMap <>();
3925
4026 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 );
4428 parameters .putAll (builder .parameters );
4529 }
4630
@@ -51,37 +35,19 @@ public Map<String, Object> getParameters() {
5135
5236 @ Override
5337 public String getUpdateStatement () {
54- return "update" //$NON-NLS-1$
55- + spaceBefore (tableName )
56- + spaceBefore (setClause )
57- + spaceBefore (whereClause );
38+ return updateStatement ;
5839 }
5940
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 );
6243 }
6344
6445 public static class Builder {
65- private String tableName ;
66- private String setClause ;
67- private String whereClause ;
46+ private String updateStatement ;
6847 private Map <String , Object > parameters = new HashMap <>();
6948
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 ;
8551 return this ;
8652 }
8753
0 commit comments