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