From eaa3fbd0cd078f084d75a2948f4c822dc4125b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=9C=E7=9A=87?= Date: Mon, 25 Jun 2018 21:08:53 +0800 Subject: [PATCH] update codegen --- pom.xml | 4 - tigon-codegen/pom.xml | 20 +- .../chyxion/tigon/codegen/TigonCodeGen.java | 5 +- .../codegen/controller/CodeGenController.java | 9 +- .../freemarker/FreeMarkerViewResolverExt.java | 10 +- .../codegen/service/CodeGenBaseTool.java | 195 ++---------------- .../support/CodeGenServiceSupport.java | 147 ++++++++----- .../codegen/service/support/TableCodeGen.java | 13 +- .../tigon/codegen/{utils => util}/DbTool.java | 2 +- .../resources/spring/spring-tigon-codegen.xml | 43 +++- .../webapp/assets/js/views/CodeGen.js | 28 +-- .../main/resources/webapp/views/codegen.ftl | 3 +- tigon-freemarker-support/README.md | 1 - tigon-freemarker-support/pom.xml | 54 ----- .../spring/spring-freemarker-support.xml | 31 --- .../freemarker/test/SiteControllerTest.java | 20 -- .../src/test/resources/log4j.properties | 13 -- .../test/resources/spring/config.properties | 1 - .../test/resources/spring/controller-test.xml | 21 -- .../main/java/me/chyxion/tigon/form/FC2.java | 2 +- .../main/java/me/chyxion/tigon/form/FU2.java | 3 +- .../tigon/mybatis/cache/RedisCache.java | 8 +- .../tigon/mybatis/cache/RedisCacheConfig.java | 7 - .../cache/support/CacheToolSupport.java | 12 +- ...sequence.xml => spring-tigon-sequence.xml} | 0 .../tigon/service/BaseQueryService.java | 23 +-- .../support/BaseQueryServiceSupport.java | 43 ++-- 27 files changed, 249 insertions(+), 469 deletions(-) rename {tigon-freemarker-support/src/main/java/me/chyxion/tigon => tigon-codegen/src/main/java/me/chyxion/tigon/codegen}/freemarker/FreeMarkerViewResolverExt.java (73%) rename tigon-codegen/src/main/java/me/chyxion/tigon/codegen/{utils => util}/DbTool.java (99%) delete mode 100644 tigon-freemarker-support/README.md delete mode 100644 tigon-freemarker-support/pom.xml delete mode 100644 tigon-freemarker-support/src/main/resources/spring/spring-freemarker-support.xml delete mode 100644 tigon-freemarker-support/src/test/java/me/chyxion/tigon/freemarker/test/SiteControllerTest.java delete mode 100644 tigon-freemarker-support/src/test/resources/log4j.properties delete mode 100644 tigon-freemarker-support/src/test/resources/spring/config.properties delete mode 100644 tigon-freemarker-support/src/test/resources/spring/controller-test.xml rename tigon-sequence/src/main/resources/spring/{spring-summer-sequence.xml => spring-tigon-sequence.xml} (100%) diff --git a/pom.xml b/pom.xml index 6137e98..1606b68 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,6 @@ tigon-service-api tigon-service-support tigon-extjs - tigon-freemarker-support tigon-codegen @@ -159,7 +158,6 @@ - @@ -169,8 +167,6 @@ true ZIP - - diff --git a/tigon-codegen/pom.xml b/tigon-codegen/pom.xml index 66c31bb..7976295 100644 --- a/tigon-codegen/pom.xml +++ b/tigon-codegen/pom.xml @@ -24,9 +24,12 @@ - me.chyxion.tigon - tigon-freemarker-support - 0.0.1-SNAPSHOT + org.freemarker + freemarker + + + org.springframework + spring-context-support me.chyxion.tigon @@ -50,6 +53,16 @@ me.chyxion.tigon tigon-mybatis + + mysql + mysql-connector-java + 5.1.6 + + + com.alibaba + druid + 1.1.10 + org.projectlombok lombok @@ -71,6 +84,7 @@ spring-boot-maven-plugin false + true diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/TigonCodeGen.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/TigonCodeGen.java index 7996d59..bb23368 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/TigonCodeGen.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/TigonCodeGen.java @@ -1,5 +1,6 @@ package me.chyxion.tigon.codegen; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -8,13 +9,15 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; * chyxion@163.com
* Jun 24, 2018 20:43:36 */ +@Slf4j @SpringBootApplication public class TigonCodeGen { /** * @param args start args */ - public static void main(String[] args) { + public static void main(final String[] args) { + log.info("Startup args [{}].", args); SpringApplication.run(TigonCodeGen.class, args); } } diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/controller/CodeGenController.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/controller/CodeGenController.java index aa1eca2..6073db5 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/controller/CodeGenController.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/controller/CodeGenController.java @@ -10,6 +10,8 @@ import com.alibaba.fastjson.JSONArray; import javax.validation.constraints.NotNull; import org.apache.commons.lang3.StringUtils; import javax.validation.constraints.NotBlank; + +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.servlet.ModelAndView; import me.chyxion.tigon.codegen.service.CodeGenService; @@ -35,11 +37,16 @@ public class CodeGenController { private CodeGenService service; @Autowired private CodeGenBaseTool tool; + @Value("${codegen.components:}") + private String genComponents; @RequestMapping(method = GET) public ModelAndView index() { return new ModelAndView("webapp/views/codegen") - .addObject("pkg", tool.getPkg()); + .addObject("pkg", tool.getPkg()) + .addObject("components", + StringUtils.isNotBlank(genComponents) ? + JSON.toJSONString(genComponents.split("\\s*[,;]\\s*")) : "[]"); } @RequestMapping(value = "/tables") diff --git a/tigon-freemarker-support/src/main/java/me/chyxion/tigon/freemarker/FreeMarkerViewResolverExt.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/freemarker/FreeMarkerViewResolverExt.java similarity index 73% rename from tigon-freemarker-support/src/main/java/me/chyxion/tigon/freemarker/FreeMarkerViewResolverExt.java rename to tigon-codegen/src/main/java/me/chyxion/tigon/codegen/freemarker/FreeMarkerViewResolverExt.java index 1a38262..8e76d27 100644 --- a/tigon-freemarker-support/src/main/java/me/chyxion/tigon/freemarker/FreeMarkerViewResolverExt.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/freemarker/FreeMarkerViewResolverExt.java @@ -1,8 +1,7 @@ -package me.chyxion.tigon.freemarker; +package me.chyxion.tigon.codegen.freemarker; import java.util.Locale; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.servlet.View; import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; @@ -13,9 +12,8 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; * chyxion@163.com
* Dec 5, 2014 2:31:39 PM */ +@Slf4j public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver { - private static final Logger log = - LoggerFactory.getLogger(FreeMarkerViewResolverExt.class); /** * {@inheritDoc} @@ -24,6 +22,6 @@ public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver { public View resolveViewName(String viewName, Locale locale) throws Exception { log.debug("Try to resolve view name [{}], locale [{}] as freemarker view.", viewName, locale); - return super.resolveViewName(viewName.replaceAll("(?i)(^\\s*ftl\\:)|(\\.ftl\\s*$)", ""), locale); + return super.resolveViewName(viewName.replaceAll("(?i)(^\\s*ftl:)|(\\.ftl\\s*$)", ""), locale); } } diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenBaseTool.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenBaseTool.java index 1444803..80576b0 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenBaseTool.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenBaseTool.java @@ -1,41 +1,25 @@ package me.chyxion.tigon.codegen.service; import java.io.File; -import java.util.Map; -import java.util.Set; -import java.util.Date; -import java.util.List; -import java.util.Arrays; -import org.slf4j.Logger; -import java.util.TreeSet; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; +import java.util.*; import java.io.FileWriter; import java.sql.ResultSet; -import org.w3c.dom.Element; import java.io.IOException; -import java.io.InputStream; import java.sql.Connection; -import java.util.Properties; -import java.util.LinkedList; -import javax.sql.DataSource; import java.sql.SQLException; import java.io.FileInputStream; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import java.sql.DatabaseMetaData; import com.alibaba.fastjson.JSON; import java.io.InputStreamReader; import me.chyxion.tigon.model.M1; import freemarker.template.Template; import org.apache.commons.io.IOUtils; -import javax.annotation.PostConstruct; import org.apache.commons.io.FileUtils; import me.chyxion.tigon.util.WordUtils; +import java.nio.charset.StandardCharsets; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.CharEncoding; -import me.chyxion.tigon.codegen.utils.DbTool; -import javax.xml.parsers.DocumentBuilderFactory; +import me.chyxion.tigon.codegen.util.DbTool; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.JdbcUtils; import org.springframework.dao.DataAccessException; @@ -46,7 +30,6 @@ import com.alibaba.fastjson.serializer.SerializerFeature; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; -import static org.springframework.context.ConfigurableApplicationContext.*; import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; /** @@ -56,92 +39,21 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; * chyxion@163.com
* Dec 3, 2014 11:25:17 AM */ +@Slf4j public class CodeGenBaseTool { - private static final Logger log = - LoggerFactory.getLogger(CodeGenBaseTool.class); @Autowired private FreeMarkerConfigurer fmCfg; - @Autowired(required = false) - private DataSource dataSource; + @Autowired private JdbcTemplate jdbcTpl; - @Value("#{systemProperties['project.basedir']}") + @Value("${project.base-dir}") private String projDir; - private String groupId; + @Value("${project.base-package}") private String pkg; - private Properties config = new Properties(); - private Set baseCols = new HashSet(); + @Value("${codegen.table-prefix:}") + private String tablePrefix; - /** - * @param col - * @return true if col is base col - */ - public boolean isBaseCol(String col) { - return baseCols.contains(col); - } - - /** - * @param key - * @return - */ - public String getConfig(String key) { - return config.getProperty(key); - } - - /** - * @param key - * @param defaultValue - * @return - */ - public String getConfig(String key, String defaultValue) { - return config.getProperty(key, defaultValue); - } - - /** - * get config - * @param key - * @param defaultValue - * @return - */ - public boolean getConfig(String key, boolean defaultValue) { - return Boolean.valueOf(getConfig(key, String.valueOf(defaultValue))); - } - - /** - * @param key - * @param defaultValue - * @return - */ - public int getConfig(String key, int defaultValue) { - return Integer.valueOf(getConfig(key, String.valueOf(defaultValue))); - } - - /** - * @param key - * @param defaultValue - * @return - */ - public long getConfig(String key, long defaultValue) { - return Long.valueOf(getConfig(key, String.valueOf(defaultValue))); - } - - /** - * @param key - * @param defaultValue - * @return - */ - public double getConfig(String key, double defaultValue) { - return Double.valueOf(getConfig(key, String.valueOf(defaultValue))); - } - - /** - * @param key - * @param defaultValue - * @return - */ - public float getConfig(String key, float defaultValue) { - return Float.valueOf(getConfig(key, String.valueOf(defaultValue))); - } + private Set baseCols = new HashSet<>(); /** * @return the projDir @@ -150,13 +62,6 @@ public class CodeGenBaseTool { return projDir; } - /** - * @return the groupId - */ - public String getGroupId() { - return groupId; - } - /** * @return the groupId */ @@ -193,63 +98,6 @@ public class CodeGenBaseTool { } } - /** - * init config - */ - @PostConstruct - void init() { - // disable cache - log.info("Disable FreeMarker Cache In Dev Mode."); - fmCfg.getConfiguration().setTemplateUpdateDelayMilliseconds(0); - if (dataSource != null) { - jdbcTpl = new JdbcTemplate(dataSource, true); - } - - try { - log.info("Parse Group ID From [{}/pom.xml].", projDir); - Element root = DocumentBuilderFactory.newInstance() - .newDocumentBuilder() - .parse(new File(projDir, "pom.xml")) - .getDocumentElement(); - root.normalize(); - groupId = root.getElementsByTagName("groupId").item(0).getTextContent().trim(); - log.info("Group ID [{}] Found.", groupId); - } - catch (Exception e) { - throw new IllegalStateException( - "Parse [groupId] From Maven POM File [" + projDir + "/pom.xml] Error Caused", e); - } - - InputStream cfgIns = CodeGenBaseTool.class - .getResourceAsStream("/codegen/config.properties"); - if (cfgIns != null) { - try { - config.load(cfgIns); - log.info("Code Gen Config [{}] Found.", config); - } - catch (IOException e) { - throw new IllegalStateException( - "Load Code Gen Config Error Caused", e); - } - finally { - IOUtils.closeQuietly(cfgIns); - } - } - - baseCols.add("id"); - String baseColsProp = config.getProperty("base.cols"); - if (StringUtils.isNotBlank(baseColsProp)) { - log.info("Code Gen Base Cols [{}] Found.", baseColsProp); - baseCols.addAll(Arrays.asList( - org.springframework.util.StringUtils - .tokenizeToStringArray( - baseColsProp, CONFIG_LOCATION_DELIMITERS, true, true))); - } - log.info("Code Gen Base Cols [{}] Result.", baseCols); - pkg = config.getProperty("base.package", groupId); - log.info("Code Gen Package [{}].", pkg); - } - /** * list all model generated * @return @@ -270,7 +118,7 @@ public class CodeGenBaseTool { FileInputStream fin = null; try { fin = new FileInputStream(file); - mapData = JSON.parseObject(IOUtils.toString(fin, CharEncoding.UTF_8)); + mapData = JSON.parseObject(IOUtils.toString(fin, StandardCharsets.UTF_8)); } catch (IOException e) { log.info("Parse JSON File [{}] ERROR Caused.", file.getName()); @@ -284,7 +132,7 @@ public class CodeGenBaseTool { // backup data file IOUtils.copy(fin, new FileWriter(new File(projDir, backupFileName)), - CharEncoding.UTF_8); + StandardCharsets.UTF_8); } } catch (IOException e1) { @@ -296,8 +144,8 @@ public class CodeGenBaseTool { } } if (mapData == null) { - mapData = new HashMap(); - mapData.put("items", new LinkedList()); + mapData = new HashMap<>(); + mapData.put("items", new LinkedList<>()); } return mapData; } @@ -309,7 +157,7 @@ public class CodeGenBaseTool { FileUtils.write(file, JSON.toJSONStringWithDateFormat(storeData, "yyyy-MM-dd HH:mm:ss", SerializerFeature.PrettyFormat), - CharEncoding.UTF_8); + StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException("Write Data To File [" + file.getAbsolutePath() + "] ERROR Caused.", e); @@ -371,7 +219,7 @@ public class CodeGenBaseTool { execSQL("drop table " + item.get("table")); } catch (Exception e) { - log.info("Drop Table Error Caused.", e); + log.info("Drop table error caused.", e); } } it.remove(); @@ -392,7 +240,7 @@ public class CodeGenBaseTool { return FreeMarkerTemplateUtils.processTemplateIntoString( new Template(ftl, new InputStreamReader( CodeGenBaseTool.class.getResourceAsStream(ftl), - CharEncoding.UTF_8), fmCfg.getConfiguration()), model); + StandardCharsets.UTF_8), fmCfg.getConfiguration()), model); } catch (Exception e) { throw new RuntimeException("Code Generate Render ERROR, [" + e.getMessage() + "].", e); @@ -410,9 +258,6 @@ public class CodeGenBaseTool { try { DatabaseMetaData md = conn.getMetaData(); rs = md.getTables(null, null, "%", new String[] {"TABLE"}); - String tablePrefix = - config.getProperty("table.prefix", "") - .toLowerCase(); while (rs.next()) { Map mapTable = new HashMap(); String table = rs.getString(3).toLowerCase(); @@ -422,7 +267,7 @@ public class CodeGenBaseTool { String[] tableNameParts = null; if (StringUtils.isNotBlank(tablePrefix) && table.startsWith(tablePrefix + "_")) { - log.info("Table Prefix [{}] Found, Trim.", tablePrefix); + log.info("Table prefix [{}] found, trim.", tablePrefix); tableNameParts = table.substring(tablePrefix.length() + 1) .split("_"); @@ -451,7 +296,7 @@ public class CodeGenBaseTool { } }); } - return new LinkedList>(); + return Collections.emptyList(); } // -- diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/CodeGenServiceSupport.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/CodeGenServiceSupport.java index eb96572..3675b9f 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/CodeGenServiceSupport.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/CodeGenServiceSupport.java @@ -1,38 +1,42 @@ package me.chyxion.tigon.codegen.service.support; -import me.chyxion.tigon.mybatis.Table; -import me.chyxion.tigon.service.BaseCrudService; -import me.chyxion.tigon.service.BaseService; -import me.chyxion.tigon.service.support.BaseCrudServiceSupport; -import me.chyxion.tigon.util.WordUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; +import java.util.Map; +import java.util.Set; import java.util.Date; +import java.util.List; +import java.util.Arrays; +import java.util.Locale; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.ArrayList; +import java.util.Collection; import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import me.chyxion.tigon.codegen.controller.CodeGenController.GenForm; -import me.chyxion.tigon.codegen.service.CodeGenBaseTool; -import me.chyxion.tigon.codegen.service.CodeGenService; -import me.chyxion.tigon.codegen.service.CodeGenerator; -import me.chyxion.tigon.mybatis.BaseMapper; +import java.text.DateFormat; import me.chyxion.tigon.model.M0; import me.chyxion.tigon.model.M1; import me.chyxion.tigon.model.M2; import me.chyxion.tigon.model.M3; -import me.chyxion.tigon.webmvc.test.ControllerTestTool; +import lombok.extern.slf4j.Slf4j; +import java.lang.reflect.Modifier; +import me.chyxion.tigon.mybatis.Table; +import me.chyxion.tigon.util.WordUtils; +import org.springframework.util.Assert; +import me.chyxion.tigon.mybatis.BaseMapper; import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.ClassUtils; +import me.chyxion.tigon.service.BaseService; import org.apache.commons.lang3.StringUtils; +import me.chyxion.tigon.service.BaseCrudService; +import org.springframework.util.ReflectionUtils; +import me.chyxion.tigon.codegen.service.CodeGenerator; +import me.chyxion.tigon.webmvc.test.ControllerTestTool; +import me.chyxion.tigon.codegen.service.CodeGenService; +import me.chyxion.tigon.codegen.service.CodeGenBaseTool; +import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Autowired; +import me.chyxion.tigon.service.support.BaseCrudServiceSupport; +import me.chyxion.tigon.codegen.controller.CodeGenController.GenForm; /** * @version 0.0.1 @@ -41,8 +45,8 @@ import org.springframework.beans.factory.annotation.Autowired; * chyxion@163.com
* Oct 6, 2014 1:10:02 PM */ +@Slf4j public class CodeGenServiceSupport implements CodeGenService { - private static final Logger log = LoggerFactory.getLogger(CodeGenServiceSupport.class); private static final Map TYPE_PACKAGES = new HashMap() { private static final long serialVersionUID = 1L; { @@ -54,6 +58,14 @@ public class CodeGenServiceSupport implements CodeGenService { private CodeGenBaseTool baseTool; @Autowired private List codeGen; + @Value("${codegen.mapper.cache-enabled:false}") + private boolean cacheEnabled; + @Value("${codegen.model.super-class.name:}") + private String modelSuperClassName; + @Value("${codegen.model.super-class.import-name:}") + private String modelSuperClassImportName; + @Value("${codegen.model.super-class.import-required:true}") + private boolean modelSuperClassImportRequired; /** * {@inheritDoc} @@ -88,7 +100,7 @@ public class CodeGenServiceSupport implements CodeGenService { fmDataModel.put("table", table.toLowerCase()); fmDataModel.put("notNull", false); fmDataModel.put("notBlank", false); - fmDataModel.put("cacheEnabled", baseTool.getConfig("cache.enabled", false)); + fmDataModel.put("cacheEnabled", cacheEnabled); fmDataModel.put("useGeneratedKeys", false); // collect col names @@ -98,69 +110,91 @@ public class CodeGenServiceSupport implements CodeGenService { String colName = ((String) col.get("col")).toLowerCase(); colNames.add(colName); if (M0.ID.equals(colName)) { - String javaType = (String) col.get("javaType"); - if (ArrayUtils.contains( - new String[] {"int", "long", "boolean", "double", "byte"}, - javaType)) { - javaType = StringUtils.capitalize(javaType); - } - idType = javaType; + String javaType = (String) col.get("javaType"); + if (ArrayUtils.contains( + new String[] {"int", "long", "boolean", "double", "byte"}, + javaType)) { + javaType = "int".equals(javaType) ? + Integer.class.getSimpleName() : + StringUtils.capitalize(javaType); } + idType = javaType; + } } - String baseModelName = null; - String baseModelFullName = null; - Collection baseCols = null; - if (colNames.containsAll(new M3().cols())) { + + final String baseModelName; + final String baseModelFullName; + final Collection baseCols; + + // custom super class + if (StringUtils.isNotBlank(modelSuperClassName)) { + Assert.state(StringUtils.isNotBlank(modelSuperClassImportName ), + "config 'codegen.model.super-class.import-name' required"); + baseModelName = modelSuperClassName; + baseModelFullName = modelSuperClassImportRequired ? + modelSuperClassImportName : null; + + try { + baseCols = new HashSet<>(); + ReflectionUtils.doWithFields(ClassUtils.getClass(modelSuperClassImportName), field -> { + log.info("Super model field [{}] found.", field); + final int modifiers = field.getModifiers(); + if (!Modifier.isTransient(modifiers) && !Modifier.isStatic(modifiers)) { + final String fieldName = field.getName(); + log.info("Add super model filed [{}] to base cols.", fieldName); + baseCols.add(WordUtils.convertCamelCase(fieldName, "_").toLowerCase()); + } + }); + } + catch (final ClassNotFoundException e) { + throw new IllegalStateException( + "No model super class [" + modelSuperClassImportName + "] found", e); + } + log.info("Base cols [{}] extracted.", baseCols); + } + else if (colNames.containsAll(new M3().cols())) { baseModelName = M3.class.getSimpleName() + "<" + idType + ", " + idType + ">"; baseModelFullName = M3.class.getName(); baseCols = new M3().cols(); + log.info("Base cols [{}] read from M3.", baseCols); } else if (colNames.containsAll(new M2().cols())) { baseModelName = M2.class.getSimpleName() + "<" + idType + ">"; baseModelFullName = M2.class.getName(); baseCols = new M2().cols(); + log.info("Base cols [{}] read from M2.", baseCols); } else if (colNames.containsAll(new M1().cols())) { baseModelName = M1.class.getSimpleName() + "<" + idType + ">"; baseModelFullName = M1.class.getName(); baseCols = new M1().cols(); + log.info("Base cols [{}] read from M1.", baseCols); } else { baseModelName = M0.class.getSimpleName(); baseModelFullName = M0.class.getName(); baseCols = new M0().cols(); - } - // custom config - String cfgBaseModelName = baseTool.getConfig("super.base.model.name"); - if (StringUtils.isNotBlank(cfgBaseModelName)) { - baseCols = baseTool.getBaseCols(); + log.info("Base cols [{}] read from M0.", baseCols); } - String cfgBaseModelFullName = - baseTool.getConfig("super.base.model.full.name"); - - fmDataModel.put("baseModelName", - baseTool.getConfig("super.base.model.name", baseModelName)); - - fmDataModel.put("baseModelFullName", - "NONE".equalsIgnoreCase(cfgBaseModelFullName) ? null : - StringUtils.isNotBlank(cfgBaseModelFullName) ? - cfgBaseModelFullName : baseModelFullName); + fmDataModel.put("baseModelFullName", baseModelFullName); + fmDataModel.put("baseModelName", baseModelName); fmDataModel.put("tableAnnotationClassName", Table.class.getName()); fmDataModel.put("tableAnnotationName", Table.class.getSimpleName()); - Set imports = new HashSet(); - List> colsWithoutBase = + final Set imports = new HashSet<>(); + final List> colsWithoutBase = (List>) columns; - Iterator> colIt = + final Iterator> colIt = colsWithoutBase.iterator(); while (colIt.hasNext()) { Map col = colIt.next(); // col name - String colName = ((String) col.get("col")).toLowerCase(); + final String colName = ((String) col.get("col")).toLowerCase(); + log.info("Process model col [{}].", colName); if (!baseCols.contains(colName)) { // prop name String propName = (String) col.get("name"); @@ -175,13 +209,14 @@ public class CodeGenServiceSupport implements CodeGenService { } } // imports - String p = TYPE_PACKAGES.get(col.get("javaType")); - if (StringUtils.isNotBlank(p)) { - imports.add(p); + final String imp = TYPE_PACKAGES.get(col.get("javaType")); + if (StringUtils.isNotBlank(imp)) { + imports.add(imp); } } // remove base col else { + log.info("Remove base col [{}].", colName); colIt.remove(); } } diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/TableCodeGen.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/TableCodeGen.java index e07fa78..0822d33 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/TableCodeGen.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/TableCodeGen.java @@ -4,7 +4,6 @@ import java.io.File; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.core.Ordered; import org.apache.commons.lang3.StringUtils; import org.springframework.core.annotation.Order; import me.chyxion.tigon.codegen.model.CodeGenArgs; @@ -17,7 +16,7 @@ import me.chyxion.tigon.codegen.service.CodeGenerator; * chyxion@163.com
* Oct 7, 2014 12:23:13 PM */ -@Order(Ordered.LOWEST_PRECEDENCE) +@Order public class TableCodeGen extends CodeGenerator { private static final Logger log = LoggerFactory.getLogger(TableCodeGen.class); @@ -35,7 +34,7 @@ public class TableCodeGen extends CodeGenerator { @Override public String process(Map dataModel, String module, String model) { String table = (String) dataModel.get("table"); - log.info("Process Generate Table [{}] SQL File.", table); + log.info("Process generate table [{}] SQL file.", table); StringBuilder filePath = new StringBuilder(resourcesDir) .append("db/"); if (StringUtils.isNotBlank(module)) { @@ -51,21 +50,21 @@ public class TableCodeGen extends CodeGenerator { if (!Boolean.FALSE.equals(dataModel.get("createTable"))) { // ignore drop table error try { - log.info("Execute Drop Table [{}].", table); + log.info("Execute drop table [{}].", table); baseTool.execSQL("drop table " + table); } catch (Exception e) { - log.info("Drop Table Failed, Error Message [{}], Ingore.", + log.info("Drop table failed, error message [{}], ignore.", e.getMessage()); } // ignore execute sql error try { - log.info("Execut Create Table SQL File [{}].", filePath); + log.info("Execute create table SQL file [{}].", filePath); baseTool.execSQL(new File(baseTool.getProjDir(), filePath .toString())); } catch (Exception e) { - log.warn("Database Create Table Error, Ingore.", e); + log.warn("Database create table error, ignore.", e); } } return filePath.toString(); diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/utils/DbTool.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/util/DbTool.java similarity index 99% rename from tigon-codegen/src/main/java/me/chyxion/tigon/codegen/utils/DbTool.java rename to tigon-codegen/src/main/java/me/chyxion/tigon/codegen/util/DbTool.java index 2e0b75d..daef2f4 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/utils/DbTool.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/util/DbTool.java @@ -1,4 +1,4 @@ -package me.chyxion.tigon.codegen.utils; +package me.chyxion.tigon.codegen.util; import java.io.IOException; import java.io.LineNumberReader; diff --git a/tigon-codegen/src/main/resources/spring/spring-tigon-codegen.xml b/tigon-codegen/src/main/resources/spring/spring-tigon-codegen.xml index 0d2a029..219291b 100644 --- a/tigon-codegen/src/main/resources/spring/spring-tigon-codegen.xml +++ b/tigon-codegen/src/main/resources/spring/spring-tigon-codegen.xml @@ -1,13 +1,10 @@ + http://www.springframework.org/schema/beans/spring-beans.xsd"> - @@ -23,4 +20,40 @@ + + + + + ${tigon.codegen.freemarker.cache.expire:36000} + utf-8 + en_US + yyyy-MM-dd + HH:mm:ss + yyyy-MM-dd HH:mm:ss + + # + + + + + + + + + + diff --git a/tigon-codegen/src/main/resources/webapp/assets/js/views/CodeGen.js b/tigon-codegen/src/main/resources/webapp/assets/js/views/CodeGen.js index e1e6d09..41f339e 100644 --- a/tigon-codegen/src/main/resources/webapp/assets/js/views/CodeGen.js +++ b/tigon-codegen/src/main/resources/webapp/assets/js/views/CodeGen.js @@ -86,13 +86,6 @@ Ext.define ('Tigon.views.CodeGen', { form = rc.down('form'); form.getForm().setValues(rec.getData()); form.down('grid').getStore().loadData(rec.get('cols')); - // show demo grid - // var dg = rc.down('container[name=demo_grid]'); - // dg.removeAll(); - // load view - // dg.add(Ext.create('App.views.' + - // (rec.get('module') ? rec.get('module') + '.' : '') + - // rec.get('model') + '.List')); } } } @@ -121,13 +114,6 @@ Ext.define ('Tigon.views.CodeGen', { createTable: false })); form.down('grid').getStore().loadData(rec.get('cols')); - // show demo grid - // var dg = rc.down('container[name=demo_grid]'); - // dg.removeAll(); - // load view - // dg.add(Ext.create('App.views.' + - // (rec.get('module') ? rec.get('module') + '.' : '') + - // rec.get('model') + '.List')); } } } @@ -215,34 +201,30 @@ Ext.define ('Tigon.views.CodeGen', { fieldLabel: 'Options', xtype: 'checkboxgroup', defaults: { - checked: true, + checked: false, xtype: 'checkbox', inputValue: true }, columns: 3, items: [{ boxLabel: 'Gen controller', + checked: components.indexOf('controller') > -1, name: 'genController' }, { boxLabel: 'Gen service', name: 'genService' }, { boxLabel: 'Gen mapper', + checked: components.indexOf('mapper') > -1, name: 'genMapper' }, { boxLabel: 'Gen model', + checked: components.indexOf('model') > -1, name: 'genModel' - }, { - boxLabel: 'Gen table', - name: 'genTable' }, { boxLabel: 'Gen form', - checked: false, + checked: components.indexOf('form') > -1, name: 'genView' - }, { - boxLabel: 'Create table', - checked: false, - name: 'createTable' }] }, { xtype: 'fieldcontainer', diff --git a/tigon-codegen/src/main/resources/webapp/views/codegen.ftl b/tigon-codegen/src/main/resources/webapp/views/codegen.ftl index b51863e..5325343 100644 --- a/tigon-codegen/src/main/resources/webapp/views/codegen.ftl +++ b/tigon-codegen/src/main/resources/webapp/views/codegen.ftl @@ -16,7 +16,7 @@ items: [{ xtype: 'box', region: 'north', - html: '

Super Super Code!

' + html: '

Tigon Code Gen!

' }, Ext.create('Tigon.views.CodeGen', { region: 'center' @@ -26,6 +26,7 @@ Ext.create('Tigon.views.ThemesBar').show(); }); var pkg = '${pkg}'; + var components = ${components}; Auto Code diff --git a/tigon-freemarker-support/README.md b/tigon-freemarker-support/README.md deleted file mode 100644 index 891a0aa..0000000 --- a/tigon-freemarker-support/README.md +++ /dev/null @@ -1 +0,0 @@ -# tigon-freemarker-support diff --git a/tigon-freemarker-support/pom.xml b/tigon-freemarker-support/pom.xml deleted file mode 100644 index 253ce73..0000000 --- a/tigon-freemarker-support/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - 4.0.0 - tigon-freemarker-support - jar - Tigon FreeMarker Support - Tigon FreeMarker Support - - - me.chyxion.tigon - tigon - 0.0.1-SNAPSHOT - ../ - - - - - org.freemarker - freemarker - - - org.slf4j - slf4j-api - - - org.springframework - spring-webmvc - - - org.springframework - spring-context-support - - - javax.servlet - javax.servlet-api - provided - - - - org.springframework - spring-test - test - - - junit - junit - test - - - diff --git a/tigon-freemarker-support/src/main/resources/spring/spring-freemarker-support.xml b/tigon-freemarker-support/src/main/resources/spring/spring-freemarker-support.xml deleted file mode 100644 index 07e090e..0000000 --- a/tigon-freemarker-support/src/main/resources/spring/spring-freemarker-support.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - ${freemarker.cache.expire:36000} - utf-8 - en_US - yyyy-MM-dd - HH:mm:ss - yyyy-MM-dd HH:mm:ss - - # - - - - - diff --git a/tigon-freemarker-support/src/test/java/me/chyxion/tigon/freemarker/test/SiteControllerTest.java b/tigon-freemarker-support/src/test/java/me/chyxion/tigon/freemarker/test/SiteControllerTest.java deleted file mode 100644 index 6b834da..0000000 --- a/tigon-freemarker-support/src/test/java/me/chyxion/tigon/freemarker/test/SiteControllerTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package me.chyxion.tigon.freemarker.test; - -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Jan 27, 2015 3:27:08 PM - */ -@WebAppConfiguration -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:spring/controller-test.xml") -public class SiteControllerTest { - -} diff --git a/tigon-freemarker-support/src/test/resources/log4j.properties b/tigon-freemarker-support/src/test/resources/log4j.properties deleted file mode 100644 index 270ed90..0000000 --- a/tigon-freemarker-support/src/test/resources/log4j.properties +++ /dev/null @@ -1,13 +0,0 @@ -log4j.rootLogger=debug, console - -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.Encoding=utf-8 -log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n - -log4j.appender.file=org.apache.log4j.DailyRollingFileAppender -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n -log4j.appender.file.File=${log.dir}/${project.artifactId}-test.log -log4j.appender.file.Encoding=utf-8 - diff --git a/tigon-freemarker-support/src/test/resources/spring/config.properties b/tigon-freemarker-support/src/test/resources/spring/config.properties deleted file mode 100644 index 76dbbbc..0000000 --- a/tigon-freemarker-support/src/test/resources/spring/config.properties +++ /dev/null @@ -1 +0,0 @@ -# Config Dev diff --git a/tigon-freemarker-support/src/test/resources/spring/controller-test.xml b/tigon-freemarker-support/src/test/resources/spring/controller-test.xml deleted file mode 100644 index 6e31ca4..0000000 --- a/tigon-freemarker-support/src/test/resources/spring/controller-test.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - diff --git a/tigon-model/src/main/java/me/chyxion/tigon/form/FC2.java b/tigon-model/src/main/java/me/chyxion/tigon/form/FC2.java index 9586148..1e6ab09 100644 --- a/tigon-model/src/main/java/me/chyxion/tigon/form/FC2.java +++ b/tigon-model/src/main/java/me/chyxion/tigon/form/FC2.java @@ -10,11 +10,11 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank; * chyxion@163.com
* Oct 8, 2016 6:26:19 PM */ -@Getter public class FC2 extends FC1 { private static final long serialVersionUID = 1L; private transient boolean __lock = true; + @Getter @NotNullOrBlank protected CreatorId createdBy; diff --git a/tigon-model/src/main/java/me/chyxion/tigon/form/FU2.java b/tigon-model/src/main/java/me/chyxion/tigon/form/FU2.java index f63beab..3ff5f50 100644 --- a/tigon-model/src/main/java/me/chyxion/tigon/form/FU2.java +++ b/tigon-model/src/main/java/me/chyxion/tigon/form/FU2.java @@ -1,7 +1,6 @@ package me.chyxion.tigon.form; import lombok.Getter; -import lombok.Setter; import me.chyxion.tigon.validation.annotation.NotNullOrBlank; /** @@ -11,12 +10,12 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank; * chyxion@163.com
* Oct 8, 2016 6:26:36 PM */ -@Getter public class FU2 extends FU1 { private static final long serialVersionUID = 1L; private transient boolean __lock = true; + @Getter @NotNullOrBlank private EditorId updatedBy; diff --git a/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCache.java b/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCache.java index ebcf5ce..18e975e 100644 --- a/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCache.java +++ b/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCache.java @@ -38,6 +38,7 @@ public final class RedisCache implements Cache { /** * {@inheritDoc} */ + @Override public String getId() { return id; } @@ -45,6 +46,7 @@ public final class RedisCache implements Cache { /** * {@inheritDoc} */ + @Override public int getSize() { final Long size = hashOp.size(id); log.info("Get redis cache [{}] size [{}].", id, size); @@ -54,6 +56,7 @@ public final class RedisCache implements Cache { /** * {@inheritDoc} */ + @Override public void putObject(final Object key, final Object value) { log.debug("Put redis cache [{}] object key [{}], value [{}].", id, key, value); hashOp.put(id, keyMd5(key), value); @@ -62,6 +65,7 @@ public final class RedisCache implements Cache { /** * {@inheritDoc} */ + @Override public Object getObject(final Object key) { final Object value = hashOp.get(id, keyMd5(key)); log.debug("Get redis cache object key [{}], value [{}].", key, value); @@ -71,6 +75,7 @@ public final class RedisCache implements Cache { /** * {@inheritDoc} */ + @Override public Object removeObject(final Object key) { log.info("Remove redis cache [{}] object key [{}].", id, key); return hashOp.delete(id, keyMd5(key)); @@ -79,6 +84,7 @@ public final class RedisCache implements Cache { /** * {@inheritDoc} */ + @Override public void clear() { log.info("Clear redis cache [{}].", id); redisTpl.delete(id); @@ -108,7 +114,7 @@ public final class RedisCache implements Cache { * @param key cache key * @return prefixed key */ - private String keyMd5(Object key) { + private String keyMd5(final Object key) { final String md5Hex = DigestUtils.md5Hex(key instanceof String ? (String) key : String.valueOf(key)); log.debug("Get redis cache [{}] key [{}] md5 hex [{}].", id, key, md5Hex); return md5Hex; diff --git a/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCacheConfig.java b/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCacheConfig.java index 0305400..108b413 100644 --- a/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCacheConfig.java +++ b/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCacheConfig.java @@ -34,11 +34,4 @@ public class RedisCacheConfig { public RedisTemplate getRedisTpl() { return redisTpl; } - - /** - * @param redisTpl the redisTpl to set - */ - public void setRedisTpl(RedisTemplate redisTpl) { - this.redisTpl = redisTpl; - } } diff --git a/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/support/CacheToolSupport.java b/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/support/CacheToolSupport.java index 0b5cc39..78abe40 100644 --- a/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/support/CacheToolSupport.java +++ b/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/support/CacheToolSupport.java @@ -1,7 +1,6 @@ package me.chyxion.tigon.mybatis.cache.support; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.cache.Cache; import javax.annotation.PostConstruct; import org.apache.ibatis.session.Configuration; @@ -16,9 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired; * chyxion@163.com
* Aug 26, 2015 10:58:58 AM */ +@Slf4j public class CacheToolSupport implements CacheTool { - private static final Logger log = - LoggerFactory.getLogger(CacheToolSupport.class); @Autowired private SqlSessionFactory ssf; @@ -29,13 +27,13 @@ public class CacheToolSupport implements CacheTool { */ @Override public void clearCache(Class mapper) { - log.info("Clear Cache [{}].", mapper); - Cache cache = getCache(mapper); + log.info("Clear mybatis cache [{}].", mapper); + final Cache cache = getCache(mapper); if (cache != null) { cache.clear(); } else { - log.warn("No Cache [{}] Found.", mapper); + log.warn("No mybatis cache [{}] found.", mapper); } } diff --git a/tigon-sequence/src/main/resources/spring/spring-summer-sequence.xml b/tigon-sequence/src/main/resources/spring/spring-tigon-sequence.xml similarity index 100% rename from tigon-sequence/src/main/resources/spring/spring-summer-sequence.xml rename to tigon-sequence/src/main/resources/spring/spring-tigon-sequence.xml diff --git a/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseQueryService.java b/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseQueryService.java index 729ffc8..2f613ba 100644 --- a/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseQueryService.java +++ b/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseQueryService.java @@ -1,8 +1,9 @@ package me.chyxion.tigon.service; import java.util.List; -import javax.validation.constraints.Min; +import java.util.function.Function; import me.chyxion.tigon.mybatis.Search; +import javax.validation.constraints.Min; import me.chyxion.tigon.model.BaseModel; import me.chyxion.tigon.model.ViewModel; import me.chyxion.tigon.model.ListResult; @@ -89,14 +90,14 @@ public interface BaseQueryService scanner); + Model scan(@NotNull Function scanner); /** * scan model by search * @param search search * @param scanner scanner */ - Model scan(Search search, @NotNull Scanner scanner); + Model scan(Search search, @NotNull Function scanner); /** * scan model by search @@ -104,15 +105,11 @@ public interface BaseQueryService scanner); + Model scan(@Min(1) int batchSize, Search search, @NotNull Function scanner); - interface Scanner { - - /** - * scan model - * @param model model - * @return false to break - */ - boolean found(T model); - } + Model scan(@Min(1) int batchSize, + Search search, + @NotNull Function> dataQuerier, + @NotNull Function countQuerier, + @NotNull Function scanner); } diff --git a/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseQueryServiceSupport.java b/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseQueryServiceSupport.java index 682dd59..c521328 100644 --- a/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseQueryServiceSupport.java +++ b/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseQueryServiceSupport.java @@ -2,8 +2,9 @@ package me.chyxion.tigon.service.support; import java.util.List; import lombok.extern.slf4j.Slf4j; -import me.chyxion.tigon.model.BaseModel; +import java.util.function.Function; import me.chyxion.tigon.mybatis.Search; +import me.chyxion.tigon.model.BaseModel; import me.chyxion.tigon.model.ViewModel; import me.chyxion.tigon.model.ListResult; import me.chyxion.tigon.mybatis.BaseMapper; @@ -24,7 +25,7 @@ public class BaseQueryServiceSupport extends BaseServiceSupport implements BaseQueryService { - @Value("${default.query.batch.size:256}") + @Value("${tigon.query.batch.size:32}") private int scanBatchSize; /** @@ -59,7 +60,7 @@ public class BaseQueryServiceSupport */ @Override public ListResult listPage(Search search) { - log.debug("LIST MODELS PAGE BY SEARCH [{}].", search); + log.debug("List models page by search [{}].", search); return new ListResult<>(list(search), count(search)); } @@ -77,7 +78,7 @@ public class BaseQueryServiceSupport */ @Override public ViewModel findViewModel(Search search) { - log.debug("Find view model by search [{}].", search); + log.debug("Find View Model By Search [{}].", search); Model model = find(search); return model != null ? toViewModel(model) : null; } @@ -116,7 +117,7 @@ public class BaseQueryServiceSupport * {@inheritDoc} */ @Override - public Model scan(Scanner scanner) { + public Model scan(Function scanner) { return scan(null, scanner); } @@ -124,7 +125,7 @@ public class BaseQueryServiceSupport * {@inheritDoc} */ @Override - public Model scan(Search search, Scanner scanner) { + public Model scan(Search search, Function scanner) { return scan(scanBatchSize(), search, scanner); } @@ -132,25 +133,37 @@ public class BaseQueryServiceSupport * {@inheritDoc} */ @Override - public Model scan(int batchSize, Search search, Scanner scanner) { + public Model scan(int batchSize, Search search, Function scanner) { + return scan(batchSize, search, this::list, this::count, scanner); + } + + /** + * {@inheritDoc} + */ + @Override + public Model scan(final int batchSize, + Search search, + final Function> dataQuerier, + final Function countQuerier, + final Function scanner) { log.info("Scan model by search [{}].", search); - int total = count(search); + int total = countQuerier.apply(search); if (total > 0) { if (search == null) { log.debug("Scan search is null, use default."); search = new Search(); } for (int start = 0; start < total; start += batchSize) { - for (Model model : list( - search.offset(start) - .limit(Math.min(batchSize, total - start)))) { - if (scanner.found(model)) { - log.info("Model [{}] found by scanner.", model); + for (Model model : dataQuerier.apply( + search.offset(start) + .limit(Math.min(batchSize, total - start)))) { + if (scanner.apply(model)) { + log.info("Model [{}] found by scanner, stop scan.", model); return model; } } } - log.debug("No matched model found by scanner."); + log.info("Scan completed, no matched model found by scanner."); } else { log.info("No model to scan by search [{}].", search); @@ -161,6 +174,7 @@ public class BaseQueryServiceSupport /** * @return the mapper */ + @Override public Mapper getMapper() { return mapper; } @@ -168,6 +182,7 @@ public class BaseQueryServiceSupport /** * @param mapper the mapper to set */ + @Override public void setMapper(Mapper mapper) { this.mapper = mapper; }