Skip to content

Commit

Permalink
Merge pull request #74 from kazuki43zoo/gh-65
Browse files Browse the repository at this point in the history
Rename Driver to VelocityLanguageDriver
  • Loading branch information
kazuki43zoo authored May 4, 2019
2 parents 9a1f0cc + d176ffd commit 15d7040
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 50 deletions.
51 changes: 5 additions & 46 deletions src/main/java/org/mybatis/scripting/velocity/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,9 @@
*/
package org.mybatis.scripting.velocity;

import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.parsing.XNode;
import org.apache.ibatis.scripting.LanguageDriver;
import org.apache.ibatis.scripting.defaults.DefaultParameterHandler;
import org.apache.ibatis.session.Configuration;

public class Driver implements LanguageDriver {

/**
* Default constructor.
*/
public Driver() {
this(VelocityLanguageDriverConfig.newInstance());
}

/**
* Constructor.
*
* @param driverConfig
* a language driver configuration
* @since 2.1.0
*/
public Driver(VelocityLanguageDriverConfig driverConfig) {
VelocityFacade.initialize(driverConfig);
}

@Override
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject,
BoundSql boundSql) {
return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}

@Override
public SqlSource createSqlSource(Configuration configuration, XNode script, Class<?> parameterTypeClass) {
return new SQLScriptSource(configuration, script.getNode().getTextContent(),
parameterTypeClass == null ? Object.class : parameterTypeClass);
}

@Override
public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterTypeClass) {
return new SQLScriptSource(configuration, script, parameterTypeClass == null ? Object.class : parameterTypeClass);
}

/**
* @deprecated Since 2.1.0, recommend to use the {@link VelocityLanguageDriver}.
*/
@Deprecated
public class Driver extends VelocityLanguageDriver {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mybatis.scripting.velocity;

import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.parsing.XNode;
import org.apache.ibatis.scripting.LanguageDriver;
import org.apache.ibatis.scripting.defaults.DefaultParameterHandler;
import org.apache.ibatis.session.Configuration;

/**
* The {@link LanguageDriver} using Velocity.
* <p>
* This class rename from {@code Driver}.
* </p>
*
* @since 2.1.0
* @author Kazuki Shimizu
*/
public class VelocityLanguageDriver implements LanguageDriver {

/**
* Default constructor.
*/
public VelocityLanguageDriver() {
this(VelocityLanguageDriverConfig.newInstance());
}

/**
* Constructor.
*
* @param driverConfig
* a language driver configuration
*/
public VelocityLanguageDriver(VelocityLanguageDriverConfig driverConfig) {
VelocityFacade.initialize(driverConfig);
}

/**
* {@inheritDoc}
*/
@Override
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject,
BoundSql boundSql) {
return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}

/**
* {@inheritDoc}
*/
@Override
public SqlSource createSqlSource(Configuration configuration, XNode script, Class<?> parameterTypeClass) {
return new SQLScriptSource(configuration, script.getNode().getTextContent(),
parameterTypeClass == null ? Object.class : parameterTypeClass);
}

/**
* {@inheritDoc}
*/
@Override
public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterTypeClass) {
return new SQLScriptSource(configuration, script, parameterTypeClass == null ? Object.class : parameterTypeClass);
}

}
4 changes: 2 additions & 2 deletions src/site/xdoc/index.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2012-2018 the original author or authors.
Copyright 2012-2019 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,7 +57,7 @@
<configuration>
...
<typeAliases>
<typeAlias alias="velocity" type="org.mybatis.scripting.velocity.Driver"/>
<typeAlias alias="velocity" type="org.mybatis.scripting.velocity.VelocityLanguageDriver"/>
</typeAliases>
...
</configuration>]]></source>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright 2012-2016 the original author or authors.
Copyright 2012-2019 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -27,7 +27,7 @@
</settings>

<typeAliases>
<typeAlias alias="velocity" type="org.mybatis.scripting.velocity.Driver"/>
<typeAlias alias="velocity" type="org.mybatis.scripting.velocity.VelocityLanguageDriver"/>
</typeAliases>

<environments default="development">
Expand Down

0 comments on commit 15d7040

Please sign in to comment.