CAY-2345 Own template renderer as a replacement for Velocity - fix
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/86f418cb Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/86f418cb Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/86f418cb Branch: refs/heads/master Commit: 86f418cb7f719b6a552bf8c60299a31ee9ab4ba9 Parents: 38ca728 Author: Nikita Timofeev <stari...@gmail.com> Authored: Wed Aug 9 18:58:20 2017 +0300 Committer: Nikita Timofeev <stari...@gmail.com> Committed: Wed Aug 16 18:30:17 2017 +0300 ---------------------------------------------------------------------- .../apache/cayenne/template/directive/Bind.java | 26 +++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/86f418cb/cayenne-server/src/main/java/org/apache/cayenne/template/directive/Bind.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/main/java/org/apache/cayenne/template/directive/Bind.java b/cayenne-server/src/main/java/org/apache/cayenne/template/directive/Bind.java index 23bcf43..3b39120 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/template/directive/Bind.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/template/directive/Bind.java @@ -42,28 +42,32 @@ public class Bind implements Directive { Object value = expressions[0].evaluateAsObject(context); String jdbcTypeName = expressions.length < 2 ? null : expressions[1].evaluateAsString(context); - - int jdbcType; - if (jdbcTypeName != null) { - jdbcType = TypesMapping.getSqlTypeByName(jdbcTypeName); - } else if (value != null) { - jdbcType = TypesMapping.getSqlTypeByJava(value.getClass()); - } else { - jdbcType = TypesMapping.getSqlTypeByName(TypesMapping.SQL_NULL); - } int scale = expressions.length < 3 ? -1 : (int) expressions[2].evaluateAsLong(context); if (value instanceof Collection) { Iterator<?> it = ((Collection) value).iterator(); while (it.hasNext()) { - processBinding(context, new ParameterBinding(it.next(), jdbcType, scale)); + bindValue(context, it.next(), jdbcTypeName, scale); if (it.hasNext()) { context.getBuilder().append(','); } } } else { - processBinding(context, new ParameterBinding(value, jdbcType, scale)); + bindValue(context, value, jdbcTypeName, scale); + } + } + + protected void bindValue(Context context, Object value, String jdbcTypeName, int scale) { + int jdbcType; + if (jdbcTypeName != null) { + jdbcType = TypesMapping.getSqlTypeByName(jdbcTypeName); + } else if (value != null) { + jdbcType = TypesMapping.getSqlTypeByJava(value.getClass()); + } else { + jdbcType = TypesMapping.getSqlTypeByName(TypesMapping.SQL_NULL); } + + processBinding(context, new ParameterBinding(value, jdbcType, scale)); } protected void processBinding(Context context, ParameterBinding binding) {