|
15 | 15 | */
|
16 | 16 | package org.apache.ibatis.scripting.defaults;
|
17 | 17 |
|
18 |
| -import java.util.ArrayList; |
19 |
| -import java.util.List; |
20 |
| - |
21 | 18 | import org.apache.ibatis.builder.BuilderException;
|
22 |
| -import org.apache.ibatis.executor.parameter.ParameterHandler; |
23 |
| -import org.apache.ibatis.mapping.BoundSql; |
24 |
| -import org.apache.ibatis.mapping.MappedStatement; |
25 | 19 | import org.apache.ibatis.mapping.SqlSource;
|
26 | 20 | import org.apache.ibatis.parsing.XNode;
|
27 |
| -import org.apache.ibatis.scripting.LanguageDriver; |
28 |
| -import org.apache.ibatis.scripting.xmltags.MixedSqlNode; |
29 |
| -import org.apache.ibatis.scripting.xmltags.SqlNode; |
30 |
| -import org.apache.ibatis.scripting.xmltags.StaticTextSqlNode; |
| 21 | +import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver; |
31 | 22 | import org.apache.ibatis.session.Configuration;
|
32 |
| -import org.w3c.dom.Node; |
33 |
| -import org.w3c.dom.NodeList; |
34 | 23 |
|
35 | 24 | /**
|
36 | 25 | * As of 3.2.4 the default XML language is able to identify static statements
|
|
39 | 28 | *
|
40 | 29 | * @since 3.2.0
|
41 | 30 | */
|
42 |
| -public class RawLanguageDriver implements LanguageDriver { |
43 |
| - |
44 |
| - public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) { |
45 |
| - return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql); |
46 |
| - } |
| 31 | +public class RawLanguageDriver extends XMLLanguageDriver { |
47 | 32 |
|
| 33 | + @Override |
48 | 34 | public SqlSource createSqlSource(Configuration configuration, XNode script, Class<?> parameterType) {
|
49 |
| - return new RawSqlSource(configuration, parseXML(script), parameterType); |
| 35 | + SqlSource source = super.createSqlSource(configuration, script, parameterType); |
| 36 | + checkIsNotDynamic(source); |
| 37 | + return source; |
50 | 38 | }
|
51 | 39 |
|
| 40 | + @Override |
52 | 41 | public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterType) {
|
53 |
| - return new RawSqlSource(configuration, script, parameterType); |
| 42 | + SqlSource source = super.createSqlSource(configuration, script, parameterType); |
| 43 | + checkIsNotDynamic(source); |
| 44 | + return source; |
54 | 45 | }
|
55 | 46 |
|
56 |
| - private static SqlNode parseXML(XNode script) { |
57 |
| - List<SqlNode> contents = new ArrayList<SqlNode>(); |
58 |
| - NodeList children = script.getNode().getChildNodes(); |
59 |
| - for (int i = 0; i < children.getLength(); i++) { |
60 |
| - XNode child = script.newXNode(children.item(i)); |
61 |
| - if (child.getNode().getNodeType() == Node.CDATA_SECTION_NODE || child.getNode().getNodeType() == Node.TEXT_NODE) { |
62 |
| - contents.add(new StaticTextSqlNode(child.getStringBody(""))); |
63 |
| - } else if (child.getNode().getNodeType() == Node.ELEMENT_NODE) { |
64 |
| - throw new BuilderException("Found an invalid element <" + child.getNode().getNodeName() + "> for RAW language."); |
65 |
| - } |
| 47 | + private void checkIsNotDynamic(SqlSource source) { |
| 48 | + if (!RawSqlSource.class.equals(source.getClass())) { |
| 49 | + throw new BuilderException("Dynamic content is not allowed when using RAW language"); |
66 | 50 | }
|
67 |
| - return new MixedSqlNode(contents); |
68 | 51 | }
|
69 | 52 |
|
70 | 53 | }
|
0 commit comments