|
| 1 | +/** |
| 2 | + * Copyright 2012-2019 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.mybatis.scripting.velocity; |
| 17 | + |
| 18 | +import org.apache.ibatis.executor.parameter.ParameterHandler; |
| 19 | +import org.apache.ibatis.mapping.BoundSql; |
| 20 | +import org.apache.ibatis.mapping.MappedStatement; |
| 21 | +import org.apache.ibatis.mapping.SqlSource; |
| 22 | +import org.apache.ibatis.parsing.XNode; |
| 23 | +import org.apache.ibatis.scripting.LanguageDriver; |
| 24 | +import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; |
| 25 | +import org.apache.ibatis.session.Configuration; |
| 26 | + |
| 27 | +/** |
| 28 | + * The {@link LanguageDriver} using Velocity. |
| 29 | + * <p> |
| 30 | + * This class rename from {@code Driver}. |
| 31 | + * </p> |
| 32 | + * |
| 33 | + * @since 2.1.0 |
| 34 | + * @author Kazuki Shimizu |
| 35 | + */ |
| 36 | +public class VelocityLanguageDriver implements LanguageDriver { |
| 37 | + |
| 38 | + /** |
| 39 | + * Default constructor. |
| 40 | + */ |
| 41 | + public VelocityLanguageDriver() { |
| 42 | + this(VelocityLanguageDriverConfig.newInstance()); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Constructor. |
| 47 | + * |
| 48 | + * @param driverConfig |
| 49 | + * a language driver configuration |
| 50 | + */ |
| 51 | + public VelocityLanguageDriver(VelocityLanguageDriverConfig driverConfig) { |
| 52 | + VelocityFacade.initialize(driverConfig); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * {@inheritDoc} |
| 57 | + */ |
| 58 | + @Override |
| 59 | + public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, |
| 60 | + BoundSql boundSql) { |
| 61 | + return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * {@inheritDoc} |
| 66 | + */ |
| 67 | + @Override |
| 68 | + public SqlSource createSqlSource(Configuration configuration, XNode script, Class<?> parameterTypeClass) { |
| 69 | + return new SQLScriptSource(configuration, script.getNode().getTextContent(), |
| 70 | + parameterTypeClass == null ? Object.class : parameterTypeClass); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * {@inheritDoc} |
| 75 | + */ |
| 76 | + @Override |
| 77 | + public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterTypeClass) { |
| 78 | + return new SQLScriptSource(configuration, script, parameterTypeClass == null ? Object.class : parameterTypeClass); |
| 79 | + } |
| 80 | + |
| 81 | +} |
0 commit comments