• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / thymeleaf-scripting / #1164

pending completion
#1164

Pull #189

github

web-flow
Merge e930cb29c into 34bbfca66
Pull Request #189: Update dependency org.mybatis:mybatis-parent to v38

611 of 621 relevant lines covered (98.39%)

0.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/main/java/org/mybatis/scripting/thymeleaf/MyBatisIntegratingEngineContextFactory.java
1
/*
2
 *    Copyright 2018-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
 *       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 org.mybatis.scripting.thymeleaf;
17

18
import java.lang.reflect.Proxy;
19
import java.util.Map;
20

21
import org.thymeleaf.IEngineConfiguration;
22
import org.thymeleaf.context.IContext;
23
import org.thymeleaf.context.IEngineContext;
24
import org.thymeleaf.context.IEngineContextFactory;
25
import org.thymeleaf.engine.TemplateData;
26

27
/**
28
 * The implementation of {@link IEngineContextFactory} for integrating with MyBatis.
29
 *
30
 * @author Kazuki Shimizu
31
 *
32
 * @version 1.0.0
33
 */
34
public class MyBatisIntegratingEngineContextFactory implements IEngineContextFactory {
35
  private final IEngineContextFactory delegate;
36
  private final ClassLoader classLoader = getClass().getClassLoader();
1✔
37

38
  /**
39
   * Constructor.
40
   *
41
   * @param delegate
42
   *          A target context factory for delegating
43
   */
44
  public MyBatisIntegratingEngineContextFactory(IEngineContextFactory delegate) {
1✔
45
    this.delegate = delegate;
1✔
46
  }
1✔
47

48
  /**
49
   * {@inheritDoc}
50
   */
51
  @Override
52
  public IEngineContext createEngineContext(IEngineConfiguration configuration, TemplateData templateData,
53
      Map<String, Object> templateResolutionAttributes, IContext context) {
54
    IEngineContext engineContext = delegate.createEngineContext(configuration, templateData,
1✔
55
        templateResolutionAttributes, context);
56
    return (IEngineContext) Proxy.newProxyInstance(classLoader, new Class[] { IEngineContext.class },
1✔
57
        (proxy, method, args) -> {
58
          if (method.getName().equals("getVariable")) {
1✔
59
            String name = (String) args[0];
1✔
60
            Object value;
61
            MyBatisBindingContext bindingContext = MyBatisBindingContext.load(engineContext);
1✔
62
            if (bindingContext.isFallbackParameterObject()) {
1✔
63
              value = engineContext.containsVariable(name) ? engineContext.getVariable(name)
1✔
64
                  : engineContext.getVariable(SqlGenerator.ContextKeys.PARAMETER_OBJECT);
1✔
65
            } else {
66
              value = engineContext.getVariable(name);
1✔
67
            }
68
            return value;
1✔
69
          }
70
          return method.invoke(engineContext, args);
1✔
71
        });
72
  }
73

74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc