From 8a3940b63a55694323525ae9bf4c4e2a9ac802d4 Mon Sep 17 00:00:00 2001 From: Jarvis Song Date: Sat, 10 Dec 2016 23:11:15 +0800 Subject: [PATCH 01/16] Initial commit --- .gitignore | 9 +++ LICENSE | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1cdc9f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8dada3e --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + 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. From 0cc2d7a74c4fd5aa108cc886008293405a14d0b9 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Mon, 19 Dec 2016 10:38:26 +0800 Subject: [PATCH 02/16] init project --- .gitignore | 1 + pom.xml | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore index 1cdc9f7..dba1d20 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ release.properties dependency-reduced-pom.xml buildNumber.properties .mvn/timing.properties +*.iml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..9db75b0 --- /dev/null +++ b/pom.xml @@ -0,0 +1,118 @@ + + + 4.0.0 + + + org.mybatis + mybatis-parent + 27 + + + + com.ifrabbit + mybatis-beetl-scripting + 1.0.BUILD-SNAPSHOT + jar + MyBatis Beetl Scripting + . + + https://github.com/hatunet/mybatis-beetl-scripting + + + jarvis + Jarvis Song + haptou@gmail.com + + + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + https://github.com/hatunet/mybatis-beetl-scripting.git + scm:git:git://github.com/hatunet/mybatis-beetl-scripting.git + scm:git:ssh://git@github.com/hatunet/mybatis-beetl-scripting.git + + + + 2.7.3 + 3.4.1 + + + + + release + + + + org.apache.maven.plugins + maven-source-plugin + + + package + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + package + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + + + verify + + sign + + + + + + + + + oss + https://oss.sonatype.org/content/repositories/snapshots/ + + + oss + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + + + + com.ibeetl + beetl + ${beetl.version} + + + org.mybatis + mybatis + ${mybatis.version} + + + + + From de679bc95a0f785fb2647ef429547a07707cb777 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Mon, 19 Dec 2016 22:33:54 +0800 Subject: [PATCH 03/16] basic fun --- .travis.yml | 17 + README.md | 74 ++++ pom.xml | 26 +- .../mybatis/scripting/beetl/BeetlFacade.java | 117 ++++++ .../scripting/beetl/BeetlSqlSource.java | 78 ++++ .../org/mybatis/scripting/beetl/Driver.java | 53 +++ .../mybatis/scripting/beetl/JoinFunction.java | 79 ++++ .../beetl/ParameterHandlerFunction.java | 45 ++ .../scripting/beetl/PlaceHolderListener.java | 29 ++ .../scripting/beetl/SQLPlaceholderST.java | 92 ++++ .../scripting/beetl/SQLTemplateEngine.java | 51 +++ .../mybatis/scripting/beetl/SQLVarRef.java | 29 ++ .../mybatis/scripting/beetl/StringKit.java | 247 +++++++++++ .../beetl/StringSqlTemplateLoader.java | 28 ++ .../mybatis/scripting/beetl/TextFunction.java | 19 + .../org/mybatis/scripting/beetl/TrimTag.java | 225 ++++++++++ .../org/mybatis/scripting/beetl/WhereTag.java | 48 +++ .../resources/mybatis-beetl-ext.properties | 0 src/main/resources/mybatis-beetl.properties | 31 ++ .../scripting/beetl/TrimDirectiveTest.java | 25 ++ .../beetl/use/BeetlLanguageTest.java | 396 ++++++++++++++++++ .../scripting/beetl/use/CustomUserTag.java | 38 ++ .../scripting/beetl/use/EnumBinder.java | 28 ++ .../scripting/beetl/use/EnumWrapper.java | 37 ++ .../org/mybatis/scripting/beetl/use/Name.java | 61 +++ .../scripting/beetl/use/Parameter.java | 41 ++ .../beetl/use/TrailingWildCardFormatter.java | 39 ++ .../resources/mybatis-beetl-ext.properties | 2 + .../mybatis/scripting/beetl/use/CreateDB.sql | 11 + .../scripting/beetl/use/MapperConfig.xml | 52 +++ .../mybatis/scripting/beetl/use/mapper.xml | 138 ++++++ 31 files changed, 2154 insertions(+), 2 deletions(-) create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 src/main/java/org/mybatis/scripting/beetl/BeetlFacade.java create mode 100644 src/main/java/org/mybatis/scripting/beetl/BeetlSqlSource.java create mode 100644 src/main/java/org/mybatis/scripting/beetl/Driver.java create mode 100644 src/main/java/org/mybatis/scripting/beetl/JoinFunction.java create mode 100644 src/main/java/org/mybatis/scripting/beetl/ParameterHandlerFunction.java create mode 100644 src/main/java/org/mybatis/scripting/beetl/PlaceHolderListener.java create mode 100644 src/main/java/org/mybatis/scripting/beetl/SQLPlaceholderST.java create mode 100644 src/main/java/org/mybatis/scripting/beetl/SQLTemplateEngine.java create mode 100644 src/main/java/org/mybatis/scripting/beetl/SQLVarRef.java create mode 100755 src/main/java/org/mybatis/scripting/beetl/StringKit.java create mode 100644 src/main/java/org/mybatis/scripting/beetl/StringSqlTemplateLoader.java create mode 100755 src/main/java/org/mybatis/scripting/beetl/TextFunction.java create mode 100755 src/main/java/org/mybatis/scripting/beetl/TrimTag.java create mode 100644 src/main/java/org/mybatis/scripting/beetl/WhereTag.java create mode 100644 src/main/resources/mybatis-beetl-ext.properties create mode 100644 src/main/resources/mybatis-beetl.properties create mode 100644 src/test/java/org/mybatis/scripting/beetl/TrimDirectiveTest.java create mode 100644 src/test/java/org/mybatis/scripting/beetl/use/BeetlLanguageTest.java create mode 100644 src/test/java/org/mybatis/scripting/beetl/use/CustomUserTag.java create mode 100644 src/test/java/org/mybatis/scripting/beetl/use/EnumBinder.java create mode 100644 src/test/java/org/mybatis/scripting/beetl/use/EnumWrapper.java create mode 100644 src/test/java/org/mybatis/scripting/beetl/use/Name.java create mode 100644 src/test/java/org/mybatis/scripting/beetl/use/Parameter.java create mode 100644 src/test/java/org/mybatis/scripting/beetl/use/TrailingWildCardFormatter.java create mode 100644 src/test/resources/mybatis-beetl-ext.properties create mode 100644 src/test/resources/org/mybatis/scripting/beetl/use/CreateDB.sql create mode 100644 src/test/resources/org/mybatis/scripting/beetl/use/MapperConfig.xml create mode 100644 src/test/resources/org/mybatis/scripting/beetl/use/mapper.xml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6eb3775 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +language: java + +jdk: + - oraclejdk8 + - oraclejdk7 + - openjdk7 + - openjdk6 + +cache: + directories: + - $HOME/.m2 + +sudo: false + +install: true + +script: "mvn clean dependency:list test -Dsort" diff --git a/README.md b/README.md new file mode 100644 index 0000000..a7f13c3 --- /dev/null +++ b/README.md @@ -0,0 +1,74 @@ +# MyBatis Beetl Support [![Build Status](https://travis-ci.org/hatunet/mybatis-beetl-scripting.svg?branch=master)](https://travis-ci.org/hatunet/mybatis-beetl-scripting) + + +## Introduction + +mybatis-beetl is an extension that allows you to use the Beetl scripting language to generate your dynamic SQL queries on the fly. + +If you are not familiar with beetl, you can learn it from its documentation site: + +[Beetl Reference](http://ibeetl.com/guide/#beetl) + +## Install + +1. Put the mybatis-beetl-scripting-.jar in your classpath. + + If you are using maven, just add a dependency to: +``` +GroupId: com.ifrabbit +ArtifactId: mybatis-beetl-scripting +``` + +2. Register the language driver alias in your mybatis configuration file: +```xml + + ... + + + + ... + + +``` + +3. Optional: Set the beetl as your default scripting language: +```xml + + ... + + + + ... + + +``` + +## Usage + +Just write your dynamic queries and use beetl: + +Example: + + +```xml + +``` + + + + + + +## Contributing to Spring Data MyBatis + +Here are some ways for you to get involved in the community: + +* Github is for social coding: if you want to write code, we encourage contributions through pull requests from [forks of this repository](http://help.github.com/forking/). + +## Help me better - Donation +[![paypal](https://www.paypal.com/en_US/i/btn/x-click-butcc-donate.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W7PLNCBK5K8JS) + diff --git a/pom.xml b/pom.xml index 9db75b0..3a203da 100644 --- a/pom.xml +++ b/pom.xml @@ -15,8 +15,7 @@ 1.0.BUILD-SNAPSHOT jar MyBatis Beetl Scripting - . - + Beetl support for MyBatis. https://github.com/hatunet/mybatis-beetl-scripting @@ -112,6 +111,29 @@ mybatis ${mybatis.version} + + org.slf4j + slf4j-api + 1.7.21 + + + ch.qos.logback + logback-classic + 1.1.7 + test + + + org.hsqldb + hsqldb + 2.3.4 + test + + + junit + junit + 4.12 + test + diff --git a/src/main/java/org/mybatis/scripting/beetl/BeetlFacade.java b/src/main/java/org/mybatis/scripting/beetl/BeetlFacade.java new file mode 100644 index 0000000..beacb58 --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/BeetlFacade.java @@ -0,0 +1,117 @@ +/* + * + * Copyright 2016 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.beetl; + +import org.beetl.core.Configuration; +import org.beetl.core.GroupTemplate; +import org.beetl.core.Template; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.Properties; + +/** + * Beetl Facade. + * + * @author Jarvis Song + */ +public final class BeetlFacade { + + + public static String apply(String script, Map context) { + Template template = getInstance().getGroupTemplate().getTemplate(script); + template.fastBinding(context); + return template.render(); + } + + GroupTemplate gt = null; + Properties ps = null; + + private final static BeetlFacade instance = new BeetlFacade(); + + public static BeetlFacade getInstance() { + return instance; + } + + + private BeetlFacade() { + try { + ps = loadDefaultConfig(); + Properties ext = loadExtConfig(); + ps.putAll(ext); + StringSqlTemplateLoader resourceLoader = new StringSqlTemplateLoader(); + Configuration cfg = new Configuration(ps); + gt = new GroupTemplate(resourceLoader, cfg); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + /** + * load default configuration. + * + * @return Properties + */ + public Properties loadDefaultConfig() { + Properties ps = new Properties(); + InputStream ins = this.getClass().getResourceAsStream( + "/mybatis-beetl.properties"); + if (ins == null) { + return ps; + } + try { + ps.load(ins); + } catch (IOException e) { + throw new RuntimeException("load default configuration error: /mybatis-beetl.properties"); + } + return ps; + } + + /** + * 加载扩展配置. + * + * @return Properties + */ + public Properties loadExtConfig() { + Properties ps = new Properties(); + InputStream ins = Thread.currentThread().getContextClassLoader().getResourceAsStream( + "mybatis-beetl-ext.properties"); + if (ins == null) { + return ps; + } + try { + ps.load(ins); + ins.close(); + } catch (IOException e) { + throw new RuntimeException("load ext configuration error: /mybatis-beetl-ext.properties"); + } + return ps; + } + + + public GroupTemplate getGroupTemplate() { + return gt; + } + + public Properties getPs() { + return ps; + } + +} diff --git a/src/main/java/org/mybatis/scripting/beetl/BeetlSqlSource.java b/src/main/java/org/mybatis/scripting/beetl/BeetlSqlSource.java new file mode 100644 index 0000000..8ef0101 --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/BeetlSqlSource.java @@ -0,0 +1,78 @@ +/* + * + * Copyright 2016 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.beetl; + +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.ParameterMapping; +import org.apache.ibatis.mapping.SqlSource; +import org.apache.ibatis.session.Configuration; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Beetl SQL Source. + * + * @author Jarvis Song + */ +public class BeetlSqlSource implements SqlSource { + + + private final Configuration configuration; + private final String script; + private final Class parameterType; + + /** + * constructor. + */ + public BeetlSqlSource(Configuration configuration, String script, Class parameterType) { + this.configuration = configuration; + this.script = script; + this.parameterType = parameterType; + } + + @Override + public BoundSql getBoundSql(Object parameterObject) { + + List parameterMappings = new ArrayList(); + + Map context = new HashMap(); + context.put("_configuration", configuration); + context.put("_parameterMappings", parameterMappings); + + context.put("_databaseId", configuration.getDatabaseId()); + context.put("_parameter", parameterObject); + Map params = new HashMap(); + context.put("_params", params); + + + String sql = BeetlFacade.apply(script, context); + + BoundSql boundSql = new BoundSql(configuration, sql, parameterMappings, parameterObject); + + for (Map.Entry entry : params.entrySet()) { + boundSql.setAdditionalParameter(entry.getKey(), entry.getValue()); + } + + + return boundSql; + } +} diff --git a/src/main/java/org/mybatis/scripting/beetl/Driver.java b/src/main/java/org/mybatis/scripting/beetl/Driver.java new file mode 100644 index 0000000..ac48b76 --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/Driver.java @@ -0,0 +1,53 @@ +/* + * + * Copyright 2016 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.beetl; + +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; +import org.apache.ibatis.type.Alias; + +/** + * @author Jarvis Song + */ +@Alias("beetl") +public class Driver implements LanguageDriver { + @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 parameterType) { + return createSqlSource(configuration, script.getNode().getTextContent(), parameterType); + } + + @Override + public SqlSource createSqlSource(Configuration configuration, String script, Class parameterType) { + if (null == parameterType) { + parameterType = Object.class; + } + return new BeetlSqlSource(configuration, script, parameterType); + } +} diff --git a/src/main/java/org/mybatis/scripting/beetl/JoinFunction.java b/src/main/java/org/mybatis/scripting/beetl/JoinFunction.java new file mode 100644 index 0000000..d6e4651 --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/JoinFunction.java @@ -0,0 +1,79 @@ +/* + * + * Copyright 2016 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.beetl; + +import org.apache.ibatis.mapping.ParameterMapping; +import org.apache.ibatis.session.Configuration; +import org.beetl.core.Context; +import org.beetl.core.Function; + +import java.io.IOException; +import java.lang.reflect.Array; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** + * JoinFunction. + */ +public class JoinFunction implements Function { + @Override + public Object call(Object[] paras, Context ctx) { + Object[] objs; + Object temp = paras[0]; + if (temp instanceof Object[]) { + objs = (Object[]) temp; + } else if (temp.getClass().isArray()) { + int len = Array.getLength(temp); + objs = new Object[len]; + for (int i = 0; i < len; i++) { + objs[i] = Array.get(temp, i); + } + } else if (temp instanceof Collection) { + objs = ((Collection) temp).toArray(); + } else { + throw new RuntimeException("join.paras[0] must be a collection or an array!"); + } + + Configuration configuration = (Configuration) ctx.getGlobal("_configuration"); + List parameterMappings = (List) ctx.getGlobal("_parameterMappings"); + Map params = (Map) ctx.getGlobal("_params"); + + int c = 0; + StringBuilder builder = new StringBuilder(); + for (Object obj : objs) { + builder.append("?,"); + params.put("_JOIN_C_" + c, obj); + + ParameterMapping parameterMapping = new ParameterMapping.Builder(configuration, "_JOIN_C_" + c, null == obj ? Object.class : obj.getClass()).build(); + parameterMappings.add(parameterMapping); + c++; + } + if (builder.length() > 0) { + builder.deleteCharAt(builder.length() - 1); + } + try { + ctx.byteWriter.writeString(builder.toString()); + } catch (IOException e) { + } + + return null; + } + +} diff --git a/src/main/java/org/mybatis/scripting/beetl/ParameterHandlerFunction.java b/src/main/java/org/mybatis/scripting/beetl/ParameterHandlerFunction.java new file mode 100644 index 0000000..965face --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/ParameterHandlerFunction.java @@ -0,0 +1,45 @@ +package org.mybatis.scripting.beetl; + +import org.apache.ibatis.mapping.ParameterMapping; +import org.apache.ibatis.session.Configuration; +import org.apache.ibatis.type.JdbcType; +import org.beetl.core.Context; +import org.beetl.core.Function; + +import java.util.List; +import java.util.Map; + +/** + * @author jarvis@ifrabbit.com + * @date 16/3/17 + */ +public class ParameterHandlerFunction implements Function { + + @Override + public Object call(Object[] paras, Context ctx) { + if (null == paras || paras.length == 0) + throw new RuntimeException("param.paras[0] must not be empty!"); + + Configuration configuration = (Configuration) ctx.getGlobal("_configuration"); + List parameterMappings = (List) ctx.getGlobal("_parameterMappings"); + Map params = (Map) ctx.getGlobal("_params"); + + String jdbcType = paras.length > 1 ? (String) paras[1] : null, javaType = paras.length > 2 ? (String) paras[2] : null; + String property = "_PARAM_" + parameterMappings.size(); + params.put(property, paras[0]); + Class javaTypeClass; + try { + javaTypeClass = null != javaType ? Class.forName(javaType) : (null == paras[0] ? Object.class : paras[0].getClass()); + } catch (ClassNotFoundException e) { + javaTypeClass = (null == paras[0] ? Object.class : paras[0].getClass()); + } + ParameterMapping parameterMapping = new ParameterMapping.Builder(configuration, property, javaTypeClass) + .jdbcTypeName(jdbcType) + .jdbcType(null != jdbcType ? JdbcType.valueOf(jdbcType) : null).build(); + + parameterMappings.add(parameterMapping); + + return "?"; + } + +} diff --git a/src/main/java/org/mybatis/scripting/beetl/PlaceHolderListener.java b/src/main/java/org/mybatis/scripting/beetl/PlaceHolderListener.java new file mode 100644 index 0000000..039680a --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/PlaceHolderListener.java @@ -0,0 +1,29 @@ +package org.mybatis.scripting.beetl; + +import org.beetl.core.Event; +import org.beetl.core.Listener; +import org.beetl.core.statement.PlaceholderST; +import org.beetl.core.statement.VarRef; + +import java.util.Stack; + +/** + * @author jarvis@ifrabbit.com + * @date 16/3/16 + */ +public class PlaceHolderListener implements Listener { + @Override + public Object onEvent(Event e) { + Stack stack = (Stack) e.getEventTaget(); + Object o = stack.peek(); + if (o instanceof PlaceholderST) { + PlaceholderST pst = (PlaceholderST) o; + SQLPlaceholderST sst = new SQLPlaceholderST(pst); + return sst; + } + if (o instanceof VarRef) { + return new SQLVarRef((VarRef) o); + } + return null; + } +} diff --git a/src/main/java/org/mybatis/scripting/beetl/SQLPlaceholderST.java b/src/main/java/org/mybatis/scripting/beetl/SQLPlaceholderST.java new file mode 100644 index 0000000..ba8cc7e --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/SQLPlaceholderST.java @@ -0,0 +1,92 @@ +/* + * + * Copyright 2016 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.beetl; + +import org.apache.ibatis.mapping.ParameterMapping; +import org.apache.ibatis.session.Configuration; +import org.beetl.core.Context; +import org.beetl.core.InferContext; +import org.beetl.core.exception.BeetlException; +import org.beetl.core.statement.*; + +import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author Jarvis Song + */ +public class SQLPlaceholderST extends Statement { + + private Type type; + private Expression expression; + + private static final Set textFunList = new HashSet() { + { + add("text"); + add("join"); + add("param"); + } + }; + + public SQLPlaceholderST(PlaceholderST st) { + super(st.token); + this.type = st.type; + this.expression = st.expression; + } + + @Override + public void execute(Context ctx) { + try { + Object value = expression.evaluate(ctx); + + if (expression instanceof FunctionExpression) { + FunctionExpression fun = (FunctionExpression) expression; + String funName = fun.token.text; + if (funName.startsWith("db") || textFunList.contains(funName)) { + ctx.byteWriter.writeString(null != value ? String.valueOf(value) : ""); + return; + } + } + ctx.byteWriter.writeString("?"); + + + Map params = (Map) ctx.getGlobal("_params"); + Configuration configuration = (Configuration) ctx.getGlobal("_configuration"); + List parameterMappings = (List) ctx.getGlobal("_parameterMappings"); + String property = "_PARAM_" + parameterMappings.size(); + params.put(property, value);//add param value to context's params map + ParameterMapping parameterMapping = new ParameterMapping.Builder(configuration, property, null == value ? Object.class : value.getClass()).build(); + parameterMappings.add(parameterMapping); + + } catch (IOException e) { + BeetlException be = new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, e.getMessage(), e); + be.pushToken(this.token); + throw be; + } + } + + @Override + public void infer(InferContext inferCtx) { + expression.infer(inferCtx); + this.type = expression.type; + } +} diff --git a/src/main/java/org/mybatis/scripting/beetl/SQLTemplateEngine.java b/src/main/java/org/mybatis/scripting/beetl/SQLTemplateEngine.java new file mode 100644 index 0000000..a599e16 --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/SQLTemplateEngine.java @@ -0,0 +1,51 @@ +/* + * + * Copyright 2016 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.beetl; + +import org.beetl.core.GroupTemplate; +import org.beetl.core.Resource; +import org.beetl.core.engine.DefaultTemplateEngine; +import org.beetl.core.engine.StatementParser; +import org.beetl.core.statement.PlaceholderST; +import org.beetl.core.statement.Program; +import org.beetl.core.statement.Statement; + +import java.io.Reader; +import java.util.Map; + +/** + * @author Jarvis Song + */ +public class SQLTemplateEngine extends DefaultTemplateEngine { + + @Override + public Program createProgram(Resource resource, Reader reader, Map textMap, String cr, GroupTemplate gt) { + Program program = super.createProgram(resource, reader, textMap, cr, gt); + + Statement[] statements = program.metaData.statements; + StatementParser parser = new StatementParser(statements, gt, resource.getId()); + + parser.addListener(PlaceholderST.class, new PlaceHolderListener()); +// parser.addListener(VarRef.class, new PlaceHolderListener()); + + parser.parse(); + + return program; + } +} diff --git a/src/main/java/org/mybatis/scripting/beetl/SQLVarRef.java b/src/main/java/org/mybatis/scripting/beetl/SQLVarRef.java new file mode 100644 index 0000000..390b379 --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/SQLVarRef.java @@ -0,0 +1,29 @@ +package org.mybatis.scripting.beetl; + +import org.beetl.core.Context; +import org.beetl.core.statement.VarRef; + +/** + * @author jarvis@ifrabbit.com + * @date 16/3/16 + */ +public class SQLVarRef extends VarRef { + + public SQLVarRef(VarRef ref) { + super(ref.attributes, ref.hasSafe, ref.safe, ref.token, ref.token); + this.varIndex = ref.varIndex; + } + + @Override + public Object evaluate(Context ctx) { + + + Object value = ctx.vars[varIndex]; + if (value == Context.NOT_EXIST_OBJECT) { + ctx.getGlobal("_root"); + + } + return super.evaluate(ctx); + } + +} diff --git a/src/main/java/org/mybatis/scripting/beetl/StringKit.java b/src/main/java/org/mybatis/scripting/beetl/StringKit.java new file mode 100755 index 0000000..dcf7af6 --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/StringKit.java @@ -0,0 +1,247 @@ +/* + * + * Copyright 2016 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.beetl; + +import java.util.ArrayList; +import java.util.List; + +public class StringKit { + public static final String EMPTY = ""; + + public static final int INDEX_NOT_FOUND = -1; + + public static final String[] EMPTY_STRING_ARRAY = new String[0]; + + // 首字母转小写 + + + public static String toLowerCaseFirstOne(String s) { + if (Character.isLowerCase(s.charAt(0))) + return s; + else + return (new StringBuilder()) + .append(Character.toLowerCase(s.charAt(0))) + .append(s.substring(1)).toString(); + } + + // 首字母转大写 + + + public static String toUpperCaseFirstOne(String s) { + if (Character.isUpperCase(s.charAt(0))) + return s; + else + return (new StringBuilder()) + .append(Character.toUpperCase(s.charAt(0))) + .append(s.substring(1)).toString(); + } + + // 大写字母前面加上下划线并转为全小写 + + + public static String enCodeUnderlined(String s) { + char[] chars = toLowerCaseFirstOne(s).toCharArray(); + StringBuilder temp = new StringBuilder(); + for (int i = 0; i < chars.length; i++) { + if (Character.isUpperCase(chars[i])) { + temp.append("_"); + } + temp.append(Character.toLowerCase(chars[i])); + } + return temp.toString(); + } + + // 删除下划线并转把后一个字母转成大写 + + + public static String deCodeUnderlined(String str) { + + String[] splitArr = str.split("_"); + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < splitArr.length; i++) { + if (i == 0) { + sb.append(splitArr[0].toLowerCase()); + continue; + } + + sb.append(toUpperCaseFirstOne(splitArr[i].toLowerCase())); + } + + return sb.toString(); + } + + + /** + * 去空格 + * + * @param str + * @return + */ + public static String trimAllWhitespace(String str) { + if (!((CharSequence) str != null && ((CharSequence) str).length() > 0)) { + return str; + } + StringBuilder sb = new StringBuilder(str); + int index = 0; + while (sb.length() > index) { + if (Character.isWhitespace(sb.charAt(index))) { + sb.deleteCharAt(index); + } else { + index++; + } + } + return sb.toString(); + } + + public static String substringBeforeLast(String str, String separator) { + if (isEmpty(str) || isEmpty(separator)) { + return str; + } + int pos = str.lastIndexOf(separator); + if (pos == INDEX_NOT_FOUND) { + return str; + } + return str.substring(0, pos); + } + + public static boolean isNotBlank(String str) { + return !isBlank(str); + } + + public static boolean isBlank(String str) { + int strLen; + if (str == null || (strLen = str.length()) == 0) { + return true; + } + for (int i = 0; i < strLen; i++) { + if ((Character.isWhitespace(str.charAt(i)) == false)) { + return false; + } + } + return true; + } + + public static boolean endsWith(String str, String suffix, boolean ignoreCase) { + if (str == null || suffix == null) { + return (str == null && suffix == null); + } + if (suffix.length() > str.length()) { + return false; + } + int strOffset = str.length() - suffix.length(); + return str.regionMatches(ignoreCase, strOffset, suffix, 0, suffix.length()); + } + + public static boolean startsWith(String str, String prefix, boolean ignoreCase) { + if (str == null || prefix == null) { + return (str == null && prefix == null); + } + if (prefix.length() > str.length()) { + return false; + } + return str.regionMatches(ignoreCase, 0, prefix, 0, prefix.length()); + } + + + public static String substringAfter(String str, String separator) { + if (isEmpty(str)) { + return str; + } + if (separator == null) { + return EMPTY; + } + int pos = str.indexOf(separator); + if (pos == INDEX_NOT_FOUND) { + return EMPTY; + } + return str.substring(pos + separator.length()); + } + + + public static boolean isBlank(final CharSequence cs) { + int strLen; + if (cs == null || (strLen = cs.length()) == 0) { + return true; + } + for (int i = 0; i < strLen; i++) { + if (Character.isWhitespace(cs.charAt(i)) == false) { + return false; + } + } + return true; + } + + + public static void main(String[] args) { +// System.out.println(deCodeUnderlined("USER_NAME")); + + + System.out.println(trimAllWhitespace(" fsdfsd sdfds fsd ")); + } + + + public static boolean isEmpty(String str) { + return str == null || str.length() == 0; + } + + public static String trim(String str) { + return str == null ? null : str.trim(); + } + + public static String[] split(String str, char separatorChar) { + return splitWorker(str, separatorChar, false); + } + + private static String[] splitWorker(String str, char separatorChar, boolean preserveAllTokens) { + // Performance tuned for 2.0 (JDK1.4) + + + if (str == null) { + return null; + } + int len = str.length(); + if (len == 0) { + return EMPTY_STRING_ARRAY; + } + List list = new ArrayList(); + int i = 0, start = 0; + boolean match = false; + boolean lastMatch = false; + while (i < len) { + if (str.charAt(i) == separatorChar) { + if (match || preserveAllTokens) { + list.add(str.substring(start, i)); + match = false; + lastMatch = true; + } + start = ++i; + continue; + } + lastMatch = false; + match = true; + i++; + } + if (match || (preserveAllTokens && lastMatch)) { + list.add(str.substring(start, i)); + } + return (String[]) list.toArray(new String[list.size()]); + } + +} diff --git a/src/main/java/org/mybatis/scripting/beetl/StringSqlTemplateLoader.java b/src/main/java/org/mybatis/scripting/beetl/StringSqlTemplateLoader.java new file mode 100644 index 0000000..8e287a4 --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/StringSqlTemplateLoader.java @@ -0,0 +1,28 @@ +/* + * + * Copyright 2016 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.beetl; + +import org.beetl.core.resource.StringTemplateResourceLoader; + +/** + * @author Jarvis Song + */ +public class StringSqlTemplateLoader extends StringTemplateResourceLoader { + +} diff --git a/src/main/java/org/mybatis/scripting/beetl/TextFunction.java b/src/main/java/org/mybatis/scripting/beetl/TextFunction.java new file mode 100755 index 0000000..a5a8329 --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/TextFunction.java @@ -0,0 +1,19 @@ +package org.mybatis.scripting.beetl; + +import org.beetl.core.Context; +import org.beetl.core.Function; + +/** + * 站位符号调用此函数将直接输出文本而不是? + * + * @author joelli + */ +public class TextFunction implements Function { + + @Override + public Object call(Object[] paras, Context ctx) { + return paras[0]; + } + + +} diff --git a/src/main/java/org/mybatis/scripting/beetl/TrimTag.java b/src/main/java/org/mybatis/scripting/beetl/TrimTag.java new file mode 100755 index 0000000..8639a0a --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/TrimTag.java @@ -0,0 +1,225 @@ +/* + * + * Copyright 2016 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.beetl; + +import org.beetl.core.Tag; + +import java.io.IOException; +import java.util.Map; + +/** + * implementation of mybatis trim. + * <trim prefix="WHERE" prefixOverrides="AND |OR"> </trim> + * <trim prefix="SET" suffixOverrides=","></trim> + * + * + * @author zhoupan + */ +public class TrimTag extends Tag { + + /** The Constant SPACE. */ + public static final String SPACE = " "; + + /** The Constant SEPARATOR_CHAR. */ + public static final char SEPARATOR_CHAR = '|'; + + /** The Constant SUFFIX_OVERRIDES. */ + public static final String SUFFIX_OVERRIDES = "suffixOverrides"; + + /** The Constant PREFIX_OVERRIDES. */ + public static final String PREFIX_OVERRIDES = "prefixOverrides"; + + /** The Constant SUFFIX. */ + public static final String SUFFIX = "suffix"; + + /** The Constant PREFIX. */ + public static final String PREFIX = "prefix"; + + /** The prefix. */ + private String prefix = ""; + + /** The prefix overrides. */ + private String[] prefixOverrides; + + /** The suffix overrides. */ + private String[] suffixOverrides; + + /** The suffix. */ + private String suffix = ""; + + /* + + * (non-Javadoc) + + * + + * @see org.beetl.core.Tag#render() + + */ + public void render() { + try { + Object[] args = this.args; + if (args != null && args.length!=0) { + initTrimArgs(args); + StringBuilder sb = buildTrimContent(); + this.ctx.byteWriter.writeString(sb.toString()); + } else { + // 兼容老版本 trim. + + + String sql = getBodyContent().getBody().trim(); + if (sql.endsWith(",")) { + this.ctx.byteWriter.writeString(sql.substring(0, sql.length()-1)); + } else { + this.ctx.byteWriter.writeString(sql); + } + } + } catch (IOException ie) { + ie.printStackTrace(); + } + + } + + /** + + * Builds the trim content. + + * + + * @return the string builder + + */ + protected StringBuilder buildTrimContent() { + StringBuilder sb = new StringBuilder(); + String sql = getBodyContent().getBody(); + boolean isSqlBlank = this.isSqlBlank(sql); + if (!isSqlBlank) { + // prefix + + + if (StringKit.isNotBlank(this.prefix)) { + appendSql(sb, this.prefix); + } + // prefixOverrides + + + String trimSql = StringKit.trim(sql); + if (this.prefixOverrides != null && this.prefixOverrides.length > 0) { + for (String prefixOverride : this.prefixOverrides) { + if (StringKit.startsWith(trimSql, prefixOverride,true)) { + trimSql = StringKit.substringAfter(trimSql, prefixOverride); + } + } + } + // suffixOverrides + + + if (this.suffixOverrides != null && this.suffixOverrides.length > 0) { + for (String suffixOverride : this.suffixOverrides) { + if (StringKit.endsWith(trimSql, suffixOverride,true)) { + trimSql = StringKit.substringBeforeLast(trimSql, suffixOverride); + } + } + } + this.appendSql(sb, trimSql); + // suffix + + + if (StringKit.isNotBlank(this.suffix)) { + appendSql(sb, this.suffix); + } + } + return sb; + } + + /** + + * 初始化参数. + + * + + * @param args + + * the args + + */ + @SuppressWarnings("unchecked") + protected void initTrimArgs(Object[] args) { + for (Object arg : args) { + if (arg instanceof Map) { + Map params = (Map) arg; + if (params.containsKey(PREFIX)) { + this.prefix = (String) params.get(PREFIX); + } + if (params.containsKey(SUFFIX)) { + this.suffix = (String) params.get(SUFFIX); + } + if (params.containsKey(PREFIX_OVERRIDES)) { + this.prefixOverrides = StringKit.split((String) params.get(PREFIX_OVERRIDES), SEPARATOR_CHAR); + } + if (params.containsKey(SUFFIX_OVERRIDES)) { + this.suffixOverrides = StringKit.split((String) params.get(SUFFIX_OVERRIDES), SEPARATOR_CHAR); + } + } + } + } + + /** + + * Append sql. + + * + + * @param sb + + * the sb + + * @param sql + + * the sql + + */ + protected void appendSql(StringBuilder sb, String sql) { + if (StringKit.isNotBlank(sql)) { + sb.append(SPACE).append(sql).append(SPACE); + } + } + + /** + + * Checks if is sql blank. + + * + + * @param sql + + * the sql + + * @return true, if checks if is sql blank + + */ + protected boolean isSqlBlank(String sql) { + if (StringKit.isBlank(sql)) { + return true; + } + return StringKit.trim(sql).isEmpty(); + } + + +} diff --git a/src/main/java/org/mybatis/scripting/beetl/WhereTag.java b/src/main/java/org/mybatis/scripting/beetl/WhereTag.java new file mode 100644 index 0000000..9256dd1 --- /dev/null +++ b/src/main/java/org/mybatis/scripting/beetl/WhereTag.java @@ -0,0 +1,48 @@ +/* + * + * Copyright 2016 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.beetl; + +import org.beetl.core.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * @author Jarvis Song + */ +public class WhereTag extends Tag { + private transient static final Logger logger = LoggerFactory.getLogger(WhereTag.class); + + @Override + public void render() { + String body = getBodyContent().getBody().trim(); + if (null != body && body.length() > 0) { + if (body.startsWith("AND ") || body.startsWith("and ")) { + body = body.substring(4); + } + try { + ctx.byteWriter.writeString(" where " + body); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + } + + } +} diff --git a/src/main/resources/mybatis-beetl-ext.properties b/src/main/resources/mybatis-beetl-ext.properties new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/mybatis-beetl.properties b/src/main/resources/mybatis-beetl.properties new file mode 100644 index 0000000..a2a1b57 --- /dev/null +++ b/src/main/resources/mybatis-beetl.properties @@ -0,0 +1,31 @@ +# +# /* +# Copyright 2016 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. +# */ +# +ENGINE=org.mybatis.scripting.beetl.SQLTemplateEngine +DELIMITER_PLACEHOLDER_START=# +DELIMITER_PLACEHOLDER_END=# +DELIMITER_STATEMENT_START=@ +DELIMITER_STATEMENT_END= +HTML_TAG_SUPPORT=false +FN.isEmpty=org.beetl.ext.fn.EmptyExpressionFunction +FN.isNotEmpty=org.beetl.ext.fn.IsNotEmptyExpressionFunction +FN.has=org.beetl.ext.fn.CheckExistFunction +FN.text=org.mybatis.scripting.beetl.TextFunction +FN.param=org.mybatis.scripting.beetl.ParameterHandlerFunction +FN.join=org.mybatis.scripting.beetl.JoinFunction +TAG.trim=org.mybatis.scripting.beetl.TrimTag +TAG.where=org.mybatis.scripting.beetl.WhereTag diff --git a/src/test/java/org/mybatis/scripting/beetl/TrimDirectiveTest.java b/src/test/java/org/mybatis/scripting/beetl/TrimDirectiveTest.java new file mode 100644 index 0000000..a05347f --- /dev/null +++ b/src/test/java/org/mybatis/scripting/beetl/TrimDirectiveTest.java @@ -0,0 +1,25 @@ +/* + * + * Copyright 2016 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.beetl; + +/** + * @author Jarvis Song + */ +public class TrimDirectiveTest { +} diff --git a/src/test/java/org/mybatis/scripting/beetl/use/BeetlLanguageTest.java b/src/test/java/org/mybatis/scripting/beetl/use/BeetlLanguageTest.java new file mode 100644 index 0000000..abdde6b --- /dev/null +++ b/src/test/java/org/mybatis/scripting/beetl/use/BeetlLanguageTest.java @@ -0,0 +1,396 @@ +/* + * + * Copyright 2016 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.beetl.use; + +import org.apache.ibatis.io.Resources; +import org.apache.ibatis.jdbc.ScriptRunner; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.SqlSessionFactoryBuilder; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.Reader; +import java.sql.Connection; +import java.sql.DriverManager; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; + +/** + * @author Jarvis Song + */ +public class BeetlLanguageTest { + protected static SqlSessionFactory sqlSessionFactory; + + public enum IDS { + ZERO, ONE, TWO, THREE, FOUR, FIVE + } + + @BeforeClass + public static void setUp() throws Exception { + Connection conn = null; + + try { + Class.forName("org.hsqldb.jdbcDriver"); + conn = DriverManager.getConnection("jdbc:hsqldb:mem:bname", "sa", ""); + + Reader reader = Resources.getResourceAsReader("org/mybatis/scripting/beetl/use/CreateDB.sql"); + + ScriptRunner runner = new ScriptRunner(conn); + runner.setLogWriter(null); + runner.setErrorLogWriter(null); + runner.runScript(reader); + conn.commit(); + reader.close(); + + reader = Resources.getResourceAsReader("org/mybatis/scripting/beetl/use/MapperConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); + } finally { + if (conn != null) { + conn.close(); + } + } + } + + @Test + public void testDynamicSelectWithPropertyParams() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + + Parameter p = new Parameter(true, "Fli%"); + List answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNames", p); + assertEquals(3, answer.size()); + for (Name n : answer) { + assertEquals("Flintstone", n.getLastName()); + } + + p = new Parameter(false, "Fli%"); + answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNames", p); + assertEquals(3, answer.size()); + for (Name n : answer) { + assertTrue(n.getLastName() == null); + } + + p = new Parameter(false, "Rub%"); + answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNames", p); + assertEquals(2, answer.size()); + for (Name n : answer) { + assertTrue(n.getLastName() == null); + } + + } finally { + sqlSession.close(); + } + } + + @Test + public void testDynamicSelectWithExpressionParams() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + + Parameter p = new Parameter(true, "Fli"); + List answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNamesWithExpressions", p); + assertEquals(3, answer.size()); + for (Name n : answer) { + assertEquals("Flintstone", n.getLastName()); + } + + p = new Parameter(false, "Fli"); + answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNamesWithExpressions", p); + assertEquals(3, answer.size()); + for (Name n : answer) { + assertTrue(n.getLastName() == null); + } + + p = new Parameter(false, "Rub"); + answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNamesWithExpressions", p); + assertEquals(2, answer.size()); + for (Name n : answer) { + assertTrue(n.getLastName() == null); + } + + } finally { + sqlSession.close(); + } + } + + @Test + public void testSelectNamesWithFormattedParam() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + + Parameter p = new Parameter(true, "Fli"); + List answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNamesWithFormattedParam", p); + assertEquals(3, answer.size()); + for (Name n : answer) { + assertEquals("Flintstone", n.getLastName()); + } + + } finally { + sqlSession.close(); + } + } + + + @Test + public void testSelectNamesWithFormattedParamSafe() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + + Parameter p = new Parameter(true, "Fli"); + List answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNamesWithFormattedParamSafe", p); + assertEquals(3, answer.size()); + for (Name n : answer) { + assertEquals("Flintstone", n.getLastName()); + } + + } finally { + sqlSession.close(); + } + } + + @Test + public void testDynamicSelectWithIteration() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + + int[] ids = {2, 4, 5}; + Map param = new HashMap(); + param.put("ids", ids); + List answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNamesWithIteration", param); + assertEquals(3, answer.size()); + for (int i = 0; i < ids.length; i++) { + assertEquals(ids[i], answer.get(i).getId()); + } + + } finally { + sqlSession.close(); + } + } + + @Test + public void testEmptyWhere() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + + int[] ids = {}; + Map param = new HashMap(); + param.put("ids", ids); + List answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNamesWithIteration", param); + assertEquals(5, answer.size()); + + } finally { + sqlSession.close(); + } + } + + @Test + public void testTrim() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + + int[] ids = {}; + Map param = new HashMap(); + param.put("ids", ids); + List answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectWithTrim", param); + assertEquals(5, answer.size()); + + } finally { + sqlSession.close(); + } + } + + @Test + public void testDynamicSelectWithIterationOverMap() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + + Map ids = new HashMap(); + ids.put(2, "Wilma"); + ids.put(4, "Barney"); + ids.put(5, "Betty"); + Map> param = new HashMap>(); + param.put("ids", ids); + List answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNamesWithIterationOverMap", param); + assertEquals(3, answer.size()); + for (Name n : answer) { + assertEquals(ids.get(n.getId()).toString(), n.getFirstName()); + } + + } finally { + sqlSession.close(); + } + } + + @Test + public void testDynamicSelectWithIterationComplex() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + + Name[] names = {new Name(2), new Name(4), new Name(5)}; + Map param = new HashMap(); + param.put("names", names); + List answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNamesWithIterationComplex", param); + assertEquals(3, answer.size()); + for (int i = 0; i < names.length; i++) { + assertEquals(names[i].getId(), answer.get(i).getId()); + } + + } finally { + sqlSession.close(); + } + } + + @Test + public void testDynamicSelectWithIterationBoundary() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + + List names = new ArrayList(); + for (int i = 0; i < 1001; i++) { + names.add(new Name(i)); + } + + Map> param = new HashMap>(); + param.put("names", names); + List answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectNamesWithIterationComplex", param); + assertEquals(5, answer.size()); + } finally { + sqlSession.close(); + } + } + + @Test + public void testSelectKey() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + + Name fred = new Name(); + fred.setFirstName("Fred"); + fred.setLastName("Flinstone"); + sqlSession.insert("org.mybatis.scripting.beetl.use.insertName", fred); + assertTrue(fred.getId() != 0); + + } finally { + sqlSession.close(); + } + } + + @Test + public void testSelectWithCustomUserDirective() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + Map> param = new HashMap>(); + List answer = sqlSession.selectList("org.mybatis.scripting.beetl.use.selectWithCustomUserDirective", param); + assertEquals(5, answer.size()); + } finally { + sqlSession.close(); + } + } + + @Test + public void testDynamicSelectWithInDirectiveForOneThousandPlusOne() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + List names = new ArrayList(); + for (int i = 0; i < 1001; i++) { + names.add(new Name(i + 1)); + } + + Map> param = new HashMap>(); + param.put("names", names); + List answer = sqlSession + .selectList( + "org.mybatis.scripting.beetl.use.selectNamesWithInDirective", + param); + assertEquals(5, answer.size()); + } finally { + sqlSession.close(); + } + } + + @Test + public void testDynamicSelectWithInDirectiveForOneThousand() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + List names = new ArrayList(); + for (int i = 0; i < 1000; i++) { + names.add(new Name(i + 1)); + } + + Map> param = new HashMap>(); + param.put("names", names); + List answer = sqlSession + .selectList( + "org.mybatis.scripting.beetl.use.selectNamesWithInDirective", + param); + assertEquals(5, answer.size()); + } finally { + sqlSession.close(); + } + } + + @Test + public void testDynamicSelectWithInDirectiveForOneThousandMinusOne() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + List names = new ArrayList(); + for (int i = 0; i < 999; i++) { + names.add(new Name(i + 1)); + } + + Map> param = new HashMap>(); + param.put("names", names); + List answer = sqlSession + .selectList( + "org.mybatis.scripting.beetl.use.selectNamesWithInDirective", + param); + assertEquals(5, answer.size()); + } finally { + sqlSession.close(); + } + } + + @Test + public void testDynamicSelectWithInDirectiveForOneItem() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + List names = new ArrayList(); + for (int i = 0; i < 1; i++) { + names.add(new Name(i + 1)); + } + + Map> param = new HashMap>(); + param.put("names", names); + List answer = sqlSession + .selectList( + "org.mybatis.scripting.beetl.use.selectNamesWithInDirective", + param); + assertEquals(1, answer.size()); + } finally { + sqlSession.close(); + } + } +} diff --git a/src/test/java/org/mybatis/scripting/beetl/use/CustomUserTag.java b/src/test/java/org/mybatis/scripting/beetl/use/CustomUserTag.java new file mode 100644 index 0000000..f89bca8 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/beetl/use/CustomUserTag.java @@ -0,0 +1,38 @@ +/* + * + * Copyright 2016 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.beetl.use; + +import org.beetl.core.Tag; + +import java.io.IOException; + +/** + * @author Jarvis Song + */ +public class CustomUserTag extends Tag { + + @Override + public void render() { + try { + bw.writeString("SELECT * FROM Names"); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/test/java/org/mybatis/scripting/beetl/use/EnumBinder.java b/src/test/java/org/mybatis/scripting/beetl/use/EnumBinder.java new file mode 100644 index 0000000..95fd8c7 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/beetl/use/EnumBinder.java @@ -0,0 +1,28 @@ +/* + * + * Copyright 2016 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.beetl.use; + +/** + * @author Jarvis Song + */ +public class EnumBinder { + public static EnumWrapper bind(String className) throws ClassNotFoundException { + return new EnumWrapper(Class.forName(className)); + } +} diff --git a/src/test/java/org/mybatis/scripting/beetl/use/EnumWrapper.java b/src/test/java/org/mybatis/scripting/beetl/use/EnumWrapper.java new file mode 100644 index 0000000..70f5146 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/beetl/use/EnumWrapper.java @@ -0,0 +1,37 @@ +/* + * + * Copyright 2016 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.beetl.use; + +import java.util.HashMap; + +/** + * @author Jarvis Song + */ +public class EnumWrapper extends HashMap { + public EnumWrapper(Class e) { + if (e.isEnum()) { + Object[] consts = e.getEnumConstants(); + for (int i = 0; i < consts.length; i++) { + put(consts[i].toString(), i); + } + } else { + throw new IllegalArgumentException("Supplied argument is not an enum class"); + } + } +} diff --git a/src/test/java/org/mybatis/scripting/beetl/use/Name.java b/src/test/java/org/mybatis/scripting/beetl/use/Name.java new file mode 100644 index 0000000..f340413 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/beetl/use/Name.java @@ -0,0 +1,61 @@ +/* + * + * Copyright 2016 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.beetl.use; + +/** + * @author Jarvis Song + */ +public class Name { + + private int id; + private String firstName; + private String lastName; + + public Name() { + } + + public Name(int value) { + this.id = value; + } + + public String getFirstName() { + return this.firstName; + } + + public void setFirstName(String value) { + this.firstName = value; + } + + public String getLastName() { + return this.lastName; + } + + public void setLastName(String value) { + this.lastName = value; + } + + public int getId() { + return this.id; + } + + public void setId(int value) { + this.id = value; + } + +} diff --git a/src/test/java/org/mybatis/scripting/beetl/use/Parameter.java b/src/test/java/org/mybatis/scripting/beetl/use/Parameter.java new file mode 100644 index 0000000..1355530 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/beetl/use/Parameter.java @@ -0,0 +1,41 @@ +/* + * + * Copyright 2016 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.beetl.use; + +/** + * @author Jarvis Song + */ +public class Parameter { + private final boolean includeLastName; + + private final String name; + + public Parameter(boolean newIncludeLastName, String newName) { + this.includeLastName = newIncludeLastName; + this.name = newName; + } + + public boolean isIncludeLastName() { + return this.includeLastName; + } + + public String getName() { + return this.name; + } +} diff --git a/src/test/java/org/mybatis/scripting/beetl/use/TrailingWildCardFormatter.java b/src/test/java/org/mybatis/scripting/beetl/use/TrailingWildCardFormatter.java new file mode 100644 index 0000000..8b0b582 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/beetl/use/TrailingWildCardFormatter.java @@ -0,0 +1,39 @@ +/* + * + * Copyright 2016 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.beetl.use; + +/** + * @author Jarvis Song + */ +public class TrailingWildCardFormatter { + public static String formatLiteral(Object val) { + if (val == null) { + return "''"; + } + String param = val.toString().replaceAll("\'", "\''"); + return "'" + param + "%'"; + } + + public static String format(Object val) { + if (val == null) { + return ""; + } + return val + "%"; + } +} diff --git a/src/test/resources/mybatis-beetl-ext.properties b/src/test/resources/mybatis-beetl-ext.properties new file mode 100644 index 0000000..2768c2a --- /dev/null +++ b/src/test/resources/mybatis-beetl-ext.properties @@ -0,0 +1,2 @@ + +TAG.genSql=org.mybatis.scripting.beetl.use.CustomUserTag diff --git a/src/test/resources/org/mybatis/scripting/beetl/use/CreateDB.sql b/src/test/resources/org/mybatis/scripting/beetl/use/CreateDB.sql new file mode 100644 index 0000000..1c8d371 --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/beetl/use/CreateDB.sql @@ -0,0 +1,11 @@ +create table names ( + id int generated by default as identity, + firstName varchar(20), + lastName varchar(20) +); + +insert into names (id, firstName, lastName) values(1, 'Fred', 'Flintstone'); +insert into names (id, firstName, lastName) values(2, 'Wilma', 'Flintstone'); +insert into names (id, firstName, lastName) values(3, 'Pebbles', 'Flintstone'); +insert into names (id, firstName, lastName) values(4, 'Barney', 'Rubble'); +insert into names (id, firstName, lastName) values(5, 'Betty', 'Rubble'); \ No newline at end of file diff --git a/src/test/resources/org/mybatis/scripting/beetl/use/MapperConfig.xml b/src/test/resources/org/mybatis/scripting/beetl/use/MapperConfig.xml new file mode 100644 index 0000000..0f2283d --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/beetl/use/MapperConfig.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/mybatis/scripting/beetl/use/mapper.xml b/src/test/resources/org/mybatis/scripting/beetl/use/mapper.xml new file mode 100644 index 0000000..eafe7fc --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/beetl/use/mapper.xml @@ -0,0 +1,138 @@ + + + + + + + firstName +@if(_parameter.includeLastName){ +, lastName +@} + + + + 'SOME NOISE', + + + + + + + + + + + + + + + + + + + + + + + + + + CALL IDENTITY() + + INSERT INTO names(firstName, lastName) + VALUES (#_parameter.firstName#, #_parameter.lastName#) + + + + + \ No newline at end of file From dc79a3a8131fae54f17a42e98b203e9a92ef08fb Mon Sep 17 00:00:00 2001 From: Jarvis Date: Mon, 19 Dec 2016 22:38:34 +0800 Subject: [PATCH 04/16] release 1.0.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3a203da..4174bd5 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.ifrabbit mybatis-beetl-scripting - 1.0.BUILD-SNAPSHOT + 1.0.1.RELEASE jar MyBatis Beetl Scripting Beetl support for MyBatis. From bca2d757c6be50ddd8d2065f02c5a42d23ff4200 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Mon, 19 Dec 2016 22:50:55 +0800 Subject: [PATCH 05/16] snapshost --- pom.xml | 57 +-------------------------------------------------------- 1 file changed, 1 insertion(+), 56 deletions(-) diff --git a/pom.xml b/pom.xml index 4174bd5..ed68932 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.ifrabbit mybatis-beetl-scripting - 1.0.1.RELEASE + 1.0.1.BUILD-SNAPSHOT jar MyBatis Beetl Scripting Beetl support for MyBatis. @@ -43,61 +43,6 @@ 3.4.1 - - - release - - - - org.apache.maven.plugins - maven-source-plugin - - - package - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - package - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - - - verify - - sign - - - - - - - - - oss - https://oss.sonatype.org/content/repositories/snapshots/ - - - oss - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - From a6fd57dd73dfb43ecec71ca154b480ba8143e842 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Mon, 19 Dec 2016 22:51:59 +0800 Subject: [PATCH 06/16] [maven-release-plugin] prepare release 1.0.1.RELEASE --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index ed68932..f4a4eb9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,18 +1,17 @@ - + 4.0.0 org.mybatis mybatis-parent 27 - + com.ifrabbit mybatis-beetl-scripting - 1.0.1.BUILD-SNAPSHOT + 1.0.1.RELEASE jar MyBatis Beetl Scripting Beetl support for MyBatis. @@ -36,7 +35,8 @@ https://github.com/hatunet/mybatis-beetl-scripting.git scm:git:git://github.com/hatunet/mybatis-beetl-scripting.git scm:git:ssh://git@github.com/hatunet/mybatis-beetl-scripting.git - + 1.0.1.RELEASE + 2.7.3 From c892e989f6250a8a1874bf2a62a4857822be1927 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Mon, 19 Dec 2016 22:52:18 +0800 Subject: [PATCH 07/16] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f4a4eb9..536f6f5 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.ifrabbit mybatis-beetl-scripting - 1.0.1.RELEASE + 1.0.2.BUILD-SNAPSHOT jar MyBatis Beetl Scripting Beetl support for MyBatis. @@ -35,7 +35,7 @@ https://github.com/hatunet/mybatis-beetl-scripting.git scm:git:git://github.com/hatunet/mybatis-beetl-scripting.git scm:git:ssh://git@github.com/hatunet/mybatis-beetl-scripting.git - 1.0.1.RELEASE + HEAD From 62b72ee489185dbec5771bc2d9acc2d354823dbd Mon Sep 17 00:00:00 2001 From: Jarvis Date: Mon, 19 Dec 2016 23:00:35 +0800 Subject: [PATCH 08/16] 1.0.2.BUILD-SNAPSHOT --- pom.xml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 536f6f5..fa04ccc 100644 --- a/pom.xml +++ b/pom.xml @@ -1,17 +1,18 @@ - + 4.0.0 org.mybatis mybatis-parent 27 - + com.ifrabbit mybatis-beetl-scripting - 1.0.2.BUILD-SNAPSHOT + 1.0.1.RELEASE jar MyBatis Beetl Scripting Beetl support for MyBatis. @@ -35,8 +36,8 @@ https://github.com/hatunet/mybatis-beetl-scripting.git scm:git:git://github.com/hatunet/mybatis-beetl-scripting.git scm:git:ssh://git@github.com/hatunet/mybatis-beetl-scripting.git - HEAD - + HEAD + 2.7.3 @@ -81,5 +82,17 @@ + + + + org.apache.maven.plugins + maven-release-plugin + + -Prelease,bundle + + + + + From 81ab827a75c62f31ae1bd37ba82d3436db84c6b2 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Mon, 19 Dec 2016 23:02:11 +0800 Subject: [PATCH 09/16] 1.0.2.BUILD-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fa04ccc..a7275bc 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.ifrabbit mybatis-beetl-scripting - 1.0.1.RELEASE + 1.0.2.BUILD-SNAPSHOT jar MyBatis Beetl Scripting Beetl support for MyBatis. From 84c7e50ecbb0ec96a14814c5dccb103fb062b344 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Mon, 19 Dec 2016 23:04:13 +0800 Subject: [PATCH 10/16] [maven-release-plugin] prepare release 1.0.2.RELEASE --- pom.xml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index a7275bc..56da09e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,18 +1,17 @@ - + 4.0.0 org.mybatis mybatis-parent 27 - + com.ifrabbit mybatis-beetl-scripting - 1.0.2.BUILD-SNAPSHOT + 1.0.2.RELEASE jar MyBatis Beetl Scripting Beetl support for MyBatis. @@ -36,7 +35,7 @@ https://github.com/hatunet/mybatis-beetl-scripting.git scm:git:git://github.com/hatunet/mybatis-beetl-scripting.git scm:git:ssh://git@github.com/hatunet/mybatis-beetl-scripting.git - HEAD + 1.0.2.RELEASE From 5529451ba642e206a4b42868b40cb37b4f0fb36f Mon Sep 17 00:00:00 2001 From: Jarvis Date: Mon, 19 Dec 2016 23:04:25 +0800 Subject: [PATCH 11/16] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 56da09e..ab66bd6 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.ifrabbit mybatis-beetl-scripting - 1.0.2.RELEASE + 1.0.3.BUILD-SNAPSHOT jar MyBatis Beetl Scripting Beetl support for MyBatis. @@ -35,7 +35,7 @@ https://github.com/hatunet/mybatis-beetl-scripting.git scm:git:git://github.com/hatunet/mybatis-beetl-scripting.git scm:git:ssh://git@github.com/hatunet/mybatis-beetl-scripting.git - 1.0.2.RELEASE + HEAD From 46b7bf52b468fcc0ee7d1b67e7e4e740985ce3ca Mon Sep 17 00:00:00 2001 From: Jarvis Date: Wed, 21 Dec 2016 11:08:05 +0800 Subject: [PATCH 12/16] 1.0.2 release --- README.md | 2 +- pom.xml | 86 +++++++++++++++---- .../scripting/beetl/BeetlSqlSource.java | 5 +- .../beetl/ParameterHandlerFunction.java | 23 ++++- .../scripting/beetl/PlaceHolderListener.java | 22 ++++- .../mybatis/scripting/beetl/SQLVarRef.java | 5 +- .../mybatis/scripting/beetl/StringKit.java | 23 ----- .../org/mybatis/scripting/beetl/TrimTag.java | 2 +- .../org/mybatis/scripting/beetl/WhereTag.java | 5 +- .../scripting/beetl/TrimDirectiveTest.java | 25 ------ 10 files changed, 112 insertions(+), 86 deletions(-) delete mode 100644 src/test/java/org/mybatis/scripting/beetl/TrimDirectiveTest.java diff --git a/README.md b/README.md index a7f13c3..131ab9a 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Example: ``` diff --git a/pom.xml b/pom.xml index ab66bd6..160af5a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,17 +1,12 @@ - + 4.0.0 - - org.mybatis - mybatis-parent - 27 - - - com.ifrabbit mybatis-beetl-scripting - 1.0.3.BUILD-SNAPSHOT + 1.0.2.RELEASE + jar MyBatis Beetl Scripting Beetl support for MyBatis. @@ -41,6 +36,9 @@ 2.7.3 3.4.1 + + 1.6 + @@ -56,11 +54,6 @@ mybatis ${mybatis.version} - - org.slf4j - slf4j-api - 1.7.21 - ch.qos.logback logback-classic @@ -85,13 +78,74 @@ org.apache.maven.plugins - maven-release-plugin + maven-compiler-plugin + 3.5.1 - -Prelease,bundle + ${source.level} + ${source.level} + + + release + + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + package + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.4 + + + package + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + verify + + sign + + + + + + + + + oss + https://oss.sonatype.org/content/repositories/snapshots/ + + + oss + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + diff --git a/src/main/java/org/mybatis/scripting/beetl/BeetlSqlSource.java b/src/main/java/org/mybatis/scripting/beetl/BeetlSqlSource.java index 8ef0101..aae7520 100644 --- a/src/main/java/org/mybatis/scripting/beetl/BeetlSqlSource.java +++ b/src/main/java/org/mybatis/scripting/beetl/BeetlSqlSource.java @@ -40,16 +40,13 @@ public class BeetlSqlSource implements SqlSource { private final String script; private final Class parameterType; - /** - * constructor. - */ + public BeetlSqlSource(Configuration configuration, String script, Class parameterType) { this.configuration = configuration; this.script = script; this.parameterType = parameterType; } - @Override public BoundSql getBoundSql(Object parameterObject) { List parameterMappings = new ArrayList(); diff --git a/src/main/java/org/mybatis/scripting/beetl/ParameterHandlerFunction.java b/src/main/java/org/mybatis/scripting/beetl/ParameterHandlerFunction.java index 965face..2c8d38e 100644 --- a/src/main/java/org/mybatis/scripting/beetl/ParameterHandlerFunction.java +++ b/src/main/java/org/mybatis/scripting/beetl/ParameterHandlerFunction.java @@ -1,3 +1,21 @@ +/* + * + * Copyright 2016 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.beetl; import org.apache.ibatis.mapping.ParameterMapping; @@ -9,10 +27,7 @@ import java.util.List; import java.util.Map; -/** - * @author jarvis@ifrabbit.com - * @date 16/3/17 - */ + public class ParameterHandlerFunction implements Function { @Override diff --git a/src/main/java/org/mybatis/scripting/beetl/PlaceHolderListener.java b/src/main/java/org/mybatis/scripting/beetl/PlaceHolderListener.java index 039680a..df9ec5c 100644 --- a/src/main/java/org/mybatis/scripting/beetl/PlaceHolderListener.java +++ b/src/main/java/org/mybatis/scripting/beetl/PlaceHolderListener.java @@ -1,3 +1,21 @@ +/* + * + * Copyright 2016 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.beetl; import org.beetl.core.Event; @@ -7,10 +25,6 @@ import java.util.Stack; -/** - * @author jarvis@ifrabbit.com - * @date 16/3/16 - */ public class PlaceHolderListener implements Listener { @Override public Object onEvent(Event e) { diff --git a/src/main/java/org/mybatis/scripting/beetl/SQLVarRef.java b/src/main/java/org/mybatis/scripting/beetl/SQLVarRef.java index 390b379..87c5d32 100644 --- a/src/main/java/org/mybatis/scripting/beetl/SQLVarRef.java +++ b/src/main/java/org/mybatis/scripting/beetl/SQLVarRef.java @@ -3,10 +3,7 @@ import org.beetl.core.Context; import org.beetl.core.statement.VarRef; -/** - * @author jarvis@ifrabbit.com - * @date 16/3/16 - */ + public class SQLVarRef extends VarRef { public SQLVarRef(VarRef ref) { diff --git a/src/main/java/org/mybatis/scripting/beetl/StringKit.java b/src/main/java/org/mybatis/scripting/beetl/StringKit.java index dcf7af6..56b7292 100755 --- a/src/main/java/org/mybatis/scripting/beetl/StringKit.java +++ b/src/main/java/org/mybatis/scripting/beetl/StringKit.java @@ -28,8 +28,6 @@ public class StringKit { public static final String[] EMPTY_STRING_ARRAY = new String[0]; - // 首字母转小写 - public static String toLowerCaseFirstOne(String s) { if (Character.isLowerCase(s.charAt(0))) @@ -40,8 +38,6 @@ public static String toLowerCaseFirstOne(String s) { .append(s.substring(1)).toString(); } - // 首字母转大写 - public static String toUpperCaseFirstOne(String s) { if (Character.isUpperCase(s.charAt(0))) @@ -52,8 +48,6 @@ public static String toUpperCaseFirstOne(String s) { .append(s.substring(1)).toString(); } - // 大写字母前面加上下划线并转为全小写 - public static String enCodeUnderlined(String s) { char[] chars = toLowerCaseFirstOne(s).toCharArray(); @@ -67,8 +61,6 @@ public static String enCodeUnderlined(String s) { return temp.toString(); } - // 删除下划线并转把后一个字母转成大写 - public static String deCodeUnderlined(String str) { @@ -87,13 +79,6 @@ public static String deCodeUnderlined(String str) { return sb.toString(); } - - /** - * 去空格 - * - * @param str - * @return - */ public static String trimAllWhitespace(String str) { if (!((CharSequence) str != null && ((CharSequence) str).length() > 0)) { return str; @@ -189,14 +174,6 @@ public static boolean isBlank(final CharSequence cs) { } - public static void main(String[] args) { -// System.out.println(deCodeUnderlined("USER_NAME")); - - - System.out.println(trimAllWhitespace(" fsdfsd sdfds fsd ")); - } - - public static boolean isEmpty(String str) { return str == null || str.length() == 0; } diff --git a/src/main/java/org/mybatis/scripting/beetl/TrimTag.java b/src/main/java/org/mybatis/scripting/beetl/TrimTag.java index 8639a0a..1167beb 100755 --- a/src/main/java/org/mybatis/scripting/beetl/TrimTag.java +++ b/src/main/java/org/mybatis/scripting/beetl/TrimTag.java @@ -197,7 +197,7 @@ protected void initTrimArgs(Object[] args) { */ protected void appendSql(StringBuilder sb, String sql) { if (StringKit.isNotBlank(sql)) { - sb.append(SPACE).append(sql).append(SPACE); + sb.append(SPACE).append(sql);//.append(SPACE); } } diff --git a/src/main/java/org/mybatis/scripting/beetl/WhereTag.java b/src/main/java/org/mybatis/scripting/beetl/WhereTag.java index 9256dd1..b0094e9 100644 --- a/src/main/java/org/mybatis/scripting/beetl/WhereTag.java +++ b/src/main/java/org/mybatis/scripting/beetl/WhereTag.java @@ -19,8 +19,6 @@ package org.mybatis.scripting.beetl; import org.beetl.core.Tag; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; @@ -28,7 +26,6 @@ * @author Jarvis Song */ public class WhereTag extends Tag { - private transient static final Logger logger = LoggerFactory.getLogger(WhereTag.class); @Override public void render() { @@ -40,7 +37,7 @@ public void render() { try { ctx.byteWriter.writeString(" where " + body); } catch (IOException e) { - logger.error(e.getMessage(), e); + e.printStackTrace(); } } diff --git a/src/test/java/org/mybatis/scripting/beetl/TrimDirectiveTest.java b/src/test/java/org/mybatis/scripting/beetl/TrimDirectiveTest.java deleted file mode 100644 index a05347f..0000000 --- a/src/test/java/org/mybatis/scripting/beetl/TrimDirectiveTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * - * Copyright 2016 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.beetl; - -/** - * @author Jarvis Song - */ -public class TrimDirectiveTest { -} From 83193dd4d05f9c653fe3a8c39142760990ff7229 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Wed, 21 Dec 2016 11:16:10 +0800 Subject: [PATCH 13/16] move to 1.0.3 --- README.md | 3 ++- pom.xml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 131ab9a..9b62241 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # MyBatis Beetl Support [![Build Status](https://travis-ci.org/hatunet/mybatis-beetl-scripting.svg?branch=master)](https://travis-ci.org/hatunet/mybatis-beetl-scripting) +![mybatis-velocity](http://mybatis.github.io/images/mybatis-logo.png) ## Introduction @@ -63,7 +64,7 @@ Example: -## Contributing to Spring Data MyBatis +## Contributing to MyBatis Beetl Scripting Here are some ways for you to get involved in the community: diff --git a/pom.xml b/pom.xml index 160af5a..f0bc202 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.ifrabbit mybatis-beetl-scripting - 1.0.2.RELEASE + 1.0.3.BUILD-SNAPSHOT jar MyBatis Beetl Scripting From 386eddedfe74cf17c5e30affeaf1218e3c568c8d Mon Sep 17 00:00:00 2001 From: Jarvis Date: Wed, 21 Dec 2016 11:18:08 +0800 Subject: [PATCH 14/16] readme update --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9b62241..e5337ce 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,12 @@ If you are not familiar with beetl, you can learn it from its documentation site 1. Put the mybatis-beetl-scripting-.jar in your classpath. If you are using maven, just add a dependency to: -``` -GroupId: com.ifrabbit -ArtifactId: mybatis-beetl-scripting +```xml + + com.ifrabbit + mybatis-beetl-scripting + 1.0.2.RELEASE + ``` 2. Register the language driver alias in your mybatis configuration file: From 9a31ac04b773d9198487c3f7cc8cd7a01b4e84cf Mon Sep 17 00:00:00 2001 From: Jarvis Date: Sun, 12 Mar 2017 01:51:47 +0800 Subject: [PATCH 15/16] upgrade beetl version to 2.7.12 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f0bc202..9c83309 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.ifrabbit mybatis-beetl-scripting - 1.0.3.BUILD-SNAPSHOT + 1.0.3.RELEASE jar MyBatis Beetl Scripting @@ -34,7 +34,7 @@ - 2.7.3 + 2.7.12 3.4.1 1.6 From 7a0cc87ae1288e46d977a3e18f132e0aa2012924 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Sun, 12 Mar 2017 01:52:34 +0800 Subject: [PATCH 16/16] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e5337ce..b77a364 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If you are not familiar with beetl, you can learn it from its documentation site com.ifrabbit mybatis-beetl-scripting - 1.0.2.RELEASE + 1.0.3.RELEASE ```