View Javadoc
1   /*
2    *    Copyright 2016-2026 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    *       https://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 examples.springbatch.common;
17  
18  import static examples.springbatch.mapper.PersonDynamicSqlSupport.*;
19  import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
20  
21  import java.util.Objects;
22  
23  import org.mybatis.dynamic.sql.render.RenderingStrategies;
24  import org.mybatis.dynamic.sql.update.UpdateDSL;
25  import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
26  import org.springframework.core.convert.converter.Converter;
27  import org.springframework.stereotype.Component;
28  
29  @Component
30  public class UpdateStatementConvertor implements Converter<PersonRecord, UpdateStatementProvider> {
31  
32      @Override
33      public UpdateStatementProvider convert(PersonRecord source) {
34          return UpdateDSL.update(person)
35                  .set(firstName).equalTo(source::firstName)
36                  .set(lastName).equalTo(source::lastName)
37                  .where(id, isEqualTo(Objects.requireNonNull(source.id())))
38                  .build()
39                  .render(RenderingStrategies.MYBATIS3);
40      }
41  }