View Javadoc
1   /**
2    *    Copyright 2009-2015 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.apache.ibatis.mapping;
17  
18  import java.util.HashMap;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.apache.ibatis.reflection.MetaObject;
23  import org.apache.ibatis.session.Configuration;
24  
25  /**
26   * An actual SQL String got form an {@link SqlSource} after having processed any dynamic content.
27   * The SQL may have SQL placeholders "?" and an list (ordered) of an parameter mappings 
28   * with the additional information for each parameter (at least the property name of the input object to read 
29   * the value from). 
30   * </br>
31   * Can also have additional parameters that are created by the dynamic language (for loops, bind...).
32   */
33  /**
34   * @author Clinton Begin
35   */
36  public class BoundSql {
37  
38    private String sql;
39    private List<ParameterMapping> parameterMappings;
40    private Object parameterObject;
41    private Map<String, Object> additionalParameters;
42    private MetaObject metaParameters;
43  
44    public BoundSql(Configuration configuration, String sql, List<ParameterMapping> parameterMappings, Object parameterObject) {
45      this.sql = sql;
46      this.parameterMappings = parameterMappings;
47      this.parameterObject = parameterObject;
48      this.additionalParameters = new HashMap<String, Object>();
49      this.metaParameters = configuration.newMetaObject(additionalParameters);
50    }
51  
52    public String getSql() {
53      return sql;
54    }
55  
56    public List<ParameterMapping> getParameterMappings() {
57      return parameterMappings;
58    }
59  
60    public Object getParameterObject() {
61      return parameterObject;
62    }
63  
64    public boolean hasAdditionalParameter(String name) {
65      return metaParameters.hasGetter(name);
66    }
67  
68    public void setAdditionalParameter(String name, Object value) {
69      metaParameters.setValue(name, value);
70    }
71  
72    public Object getAdditionalParameter(String name) {
73      return metaParameters.getValue(name);
74    }
75  }