From c2a089676e19dfe76399382d7b825de4f1007c92 Mon Sep 17 00:00:00 2001 From: Shaun Chyxion Date: Tue, 30 May 2017 12:11:43 +0800 Subject: [PATCH] add jrebel mybatis support --- .../java/me/chyxion/tigon/util/WordUtils.java | 21 +++--- .../me/chyxion/tigon/test/WordUtilsTest.java | 24 +++++++ .../mybatis/TigonSqlSessionFactoryBean.java | 64 ++++++++++++++++--- 3 files changed, 90 insertions(+), 19 deletions(-) create mode 100644 tigon-model/src/test/java/me/chyxion/tigon/test/WordUtilsTest.java diff --git a/tigon-model/src/main/java/me/chyxion/tigon/util/WordUtils.java b/tigon-model/src/main/java/me/chyxion/tigon/util/WordUtils.java index fd757c5..1af53c2 100644 --- a/tigon-model/src/main/java/me/chyxion/tigon/util/WordUtils.java +++ b/tigon-model/src/main/java/me/chyxion/tigon/util/WordUtils.java @@ -21,12 +21,10 @@ public class WordUtils { * JSONObject - [JSON Object] * JPanel - [J Panel] * toJSONString - [to JSON String] - * Log4J - [Log 4 J] - * Log4j - [Log 4 j] + * Log4j - [Log4j] * 99Roses - [99 Roses] - * Varchar2 - [Varchar 2] - * DO178 - [DO 178] - * Do178 - [Do 178] + * DO178 - [DO178] + * Do178 - [Do178] * * @param str word * @return split result @@ -34,13 +32,16 @@ public class WordUtils { public static String[] splitToWords(String str) { return StringUtils.isNotBlank(str) ? // JSONObject - JSON Object - str.split(new StringBuilder("(?<=[A-Z])(?=[A-Z][a-z])|") - // MySQL - My SQL | Log4J - Log 4 J - .append("(?<=[^A-Z])(?=[A-Z])|") + str.split(new StringBuilder("(?<=[A-Z])(?=[A-Z][a-z])") + // MySQL - My SQL + .append("|(?<=[a-z])(?=[A-Z])") + // 99Roses -> 99 Roses + .append("|(?<=[^a-zA-Z])(?=[A-Z])") + // .append("|(?<=[^A-Z])(?=[A-Z])") // 5s - 5 s - .append("(?<=[^a-zA-Z])(?=[a-z])|") + // .append("|(?<=[^a-zA-Z])(?=[a-z])") // A3 - A 3 | a3 - a 3 - .append("(?<=[A-Za-z])(?=[^A-Za-z])") + // .append("|(?<=[A-Za-z])(?=[^A-Za-z])") .toString()) : new String[]{}; } diff --git a/tigon-model/src/test/java/me/chyxion/tigon/test/WordUtilsTest.java b/tigon-model/src/test/java/me/chyxion/tigon/test/WordUtilsTest.java new file mode 100644 index 0000000..8edc85a --- /dev/null +++ b/tigon-model/src/test/java/me/chyxion/tigon/test/WordUtilsTest.java @@ -0,0 +1,24 @@ +package me.chyxion.tigon.test; + +import me.chyxion.tigon.util.WordUtils; +import org.junit.Test; + +/** + * @author Shaun Chyxion
+ * chyxion@163.com
+ * May 30, 2017 12:05:52 + */ +public class WordUtilsTest { + + @Test + public void testSplit() { + System.err.println(WordUtils.convertCamelCase("MySQL", "_")); + System.err.println(WordUtils.convertCamelCase("log4", "_")); + System.err.println(WordUtils.convertCamelCase("log4j", "_")); + System.err.println(WordUtils.convertCamelCase("log4J", "_")); + System.err.println(WordUtils.convertCamelCase("JSONObject", "_")); + System.err.println(WordUtils.convertCamelCase("JSONObject", "_")); + System.err.println(WordUtils.convertCamelCase("99Rose", "_")); + System.err.println(WordUtils.convertCamelCase("99rose", "_")); + } +} diff --git a/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/TigonSqlSessionFactoryBean.java b/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/TigonSqlSessionFactoryBean.java index fd9efbc..f6fb810 100644 --- a/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/TigonSqlSessionFactoryBean.java +++ b/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/TigonSqlSessionFactoryBean.java @@ -1,5 +1,7 @@ package me.chyxion.tigon.mybatis; +import java.io.File; +import java.net.URL; import java.util.List; import java.io.IOException; import java.io.InputStream; @@ -205,15 +207,8 @@ public class TigonSqlSessionFactoryBean extends SqlSessionFactoryBean { docType.getSystemId()); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(doc), new StreamResult(baos)); - final String mapperFilePath = "[TIGON] " + mapperLocation.toString(); - log.info("Use Mapper Path [{}] For Updated Byte Array.", mapperFilePath); - mapperResourceUpdated = new ByteArrayResource(baos.toByteArray()) { - @Override - public String toString() { - return mapperFilePath; - } - }; - log.debug("Mapper Processed [{}].", baos); + mapperResourceUpdated = new TigonMapperResource(baos.toByteArray(), mapperLocation); + log.info("Tigon MyBatis Mapper [{}] Updated Result [{}].", mapperResourceUpdated, baos); } } } @@ -239,4 +234,55 @@ public class TigonSqlSessionFactoryBean extends SqlSessionFactoryBean { } } } + + static class TigonMapperResource extends ByteArrayResource { + private final Resource originResource; + + public TigonMapperResource(byte[] byteArray, Resource originResource) { + super(byteArray); + this.originResource = originResource; + } + + /** + * {@inheritDoc} + * for JRebel monitor file + */ + @Override + public URL getURL() throws IOException { + return originResource.getURL(); + } + + /** + * {@inheritDoc} + * for JRebel monitor file + */ + @Override + public File getFile() throws IOException { + return originResource.getFile(); + } + + /** + * {@inheritDoc} + */ + @Override + public String getFilename() { + return originResource.getFilename(); + } + + /** + * {@inheritDoc} + */ + @Override + public String getDescription() { + return "[TIGON] " + originResource.getDescription(); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "[TIGON] " + originResource.toString(); + } + } }