Skip to content

Commit ef2d0f5

Browse files
committed
fixes #24. Moving the parse operation to the constructor. Big thanks to Eduardo.
1 parent 79096cf commit ef2d0f5

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/main/java/org/apache/ibatis/scripting/defaults/RawLanguageDriver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public ParameterHandler createParameterHandler(MappedStatement mappedStatement,
3030
}
3131

3232
public SqlSource createSqlSource(Configuration configuration, XNode script, Class<?> parameterType) {
33-
return new RawSqlSource(configuration, script.getStringBody(""));
33+
return new RawSqlSource(configuration, script.getStringBody(""), parameterType);
3434
}
3535

3636
public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterType) {
37-
return new RawSqlSource(configuration, script);
37+
return new RawSqlSource(configuration, script, parameterType);
3838
}
3939

4040
}

src/main/java/org/apache/ibatis/scripting/defaults/RawSqlSource.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424

2525
public class RawSqlSource implements SqlSource {
2626

27-
private final Configuration configuration;
28-
private final String sql;
27+
private final SqlSource sqlSource;
2928

30-
public RawSqlSource(Configuration configuration, String sql) {
31-
this.configuration = configuration;
32-
this.sql = sql;
29+
public RawSqlSource(Configuration configuration, String sql, Class<?> parameterType) {
30+
SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
31+
Class<?> clazz = parameterType == null ? Object.class : parameterType;
32+
sqlSource = sqlSourceParser.parse(sql, clazz, new HashMap<String, Object>());
3333
}
3434

3535
public BoundSql getBoundSql(Object parameterObject) {
36-
SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
37-
Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
38-
SqlSource sqlSource = sqlSourceParser.parse(sql, parameterType, new HashMap<String, Object>());
3936
BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
4037
return boundSql;
4138
}

0 commit comments

Comments
 (0)