update codegen
This commit is contained in:
parent
ac55d7891b
commit
eaa3fbd0cd
4
pom.xml
4
pom.xml
@ -47,7 +47,6 @@
|
|||||||
<module>tigon-service-api</module>
|
<module>tigon-service-api</module>
|
||||||
<module>tigon-service-support</module>
|
<module>tigon-service-support</module>
|
||||||
<module>tigon-extjs</module>
|
<module>tigon-extjs</module>
|
||||||
<module>tigon-freemarker-support</module>
|
|
||||||
<module>tigon-codegen</module>
|
<module>tigon-codegen</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
@ -159,7 +158,6 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -169,8 +167,6 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<addResources>true</addResources>
|
<addResources>true</addResources>
|
||||||
<layout>ZIP</layout>
|
<layout>ZIP</layout>
|
||||||
<!--<skip>false</skip>-->
|
|
||||||
<!--<fork>true</fork>-->
|
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
|
@ -24,9 +24,12 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.chyxion.tigon</groupId>
|
<groupId>org.freemarker</groupId>
|
||||||
<artifactId>tigon-freemarker-support</artifactId>
|
<artifactId>freemarker</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context-support</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.chyxion.tigon</groupId>
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
@ -50,6 +53,16 @@
|
|||||||
<groupId>me.chyxion.tigon</groupId>
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
<artifactId>tigon-mybatis</artifactId>
|
<artifactId>tigon-mybatis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>5.1.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid</artifactId>
|
||||||
|
<version>1.1.10</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
@ -71,6 +84,7 @@
|
|||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<skip>false</skip>
|
<skip>false</skip>
|
||||||
|
<fork>true</fork>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.chyxion.tigon.codegen;
|
package me.chyxion.tigon.codegen;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@ -8,13 +9,15 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
* chyxion@163.com <br>
|
* chyxion@163.com <br>
|
||||||
* Jun 24, 2018 20:43:36
|
* Jun 24, 2018 20:43:36
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class TigonCodeGen {
|
public class TigonCodeGen {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args start args
|
* @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);
|
SpringApplication.run(TigonCodeGen.class, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ import com.alibaba.fastjson.JSONArray;
|
|||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
import me.chyxion.tigon.codegen.service.CodeGenService;
|
import me.chyxion.tigon.codegen.service.CodeGenService;
|
||||||
@ -35,11 +37,16 @@ public class CodeGenController {
|
|||||||
private CodeGenService service;
|
private CodeGenService service;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CodeGenBaseTool tool;
|
private CodeGenBaseTool tool;
|
||||||
|
@Value("${codegen.components:}")
|
||||||
|
private String genComponents;
|
||||||
|
|
||||||
@RequestMapping(method = GET)
|
@RequestMapping(method = GET)
|
||||||
public ModelAndView index() {
|
public ModelAndView index() {
|
||||||
return new ModelAndView("webapp/views/codegen")
|
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")
|
@RequestMapping(value = "/tables")
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package me.chyxion.tigon.freemarker;
|
package me.chyxion.tigon.codegen.freemarker;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import org.slf4j.Logger;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.web.servlet.View;
|
import org.springframework.web.servlet.View;
|
||||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
||||||
|
|
||||||
@ -13,9 +12,8 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
|||||||
* chyxion@163.com <br>
|
* chyxion@163.com <br>
|
||||||
* Dec 5, 2014 2:31:39 PM
|
* Dec 5, 2014 2:31:39 PM
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver {
|
public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver {
|
||||||
private static final Logger log =
|
|
||||||
LoggerFactory.getLogger(FreeMarkerViewResolverExt.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
@ -24,6 +22,6 @@ public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver {
|
|||||||
public View resolveViewName(String viewName, Locale locale)
|
public View resolveViewName(String viewName, Locale locale)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
log.debug("Try to resolve view name [{}], locale [{}] as freemarker view.", viewName, locale);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,41 +1,25 @@
|
|||||||
package me.chyxion.tigon.codegen.service;
|
package me.chyxion.tigon.codegen.service;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
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.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import org.slf4j.LoggerFactory;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import java.sql.DatabaseMetaData;
|
import java.sql.DatabaseMetaData;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import me.chyxion.tigon.model.M1;
|
import me.chyxion.tigon.model.M1;
|
||||||
import freemarker.template.Template;
|
import freemarker.template.Template;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import me.chyxion.tigon.util.WordUtils;
|
import me.chyxion.tigon.util.WordUtils;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.CharEncoding;
|
import me.chyxion.tigon.codegen.util.DbTool;
|
||||||
import me.chyxion.tigon.codegen.utils.DbTool;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.support.JdbcUtils;
|
import org.springframework.jdbc.support.JdbcUtils;
|
||||||
import org.springframework.dao.DataAccessException;
|
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.Value;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
|
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
|
||||||
import static org.springframework.context.ConfigurableApplicationContext.*;
|
|
||||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,92 +39,21 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
|||||||
* chyxion@163.com <br>
|
* chyxion@163.com <br>
|
||||||
* Dec 3, 2014 11:25:17 AM
|
* Dec 3, 2014 11:25:17 AM
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class CodeGenBaseTool {
|
public class CodeGenBaseTool {
|
||||||
private static final Logger log =
|
|
||||||
LoggerFactory.getLogger(CodeGenBaseTool.class);
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FreeMarkerConfigurer fmCfg;
|
private FreeMarkerConfigurer fmCfg;
|
||||||
@Autowired(required = false)
|
@Autowired
|
||||||
private DataSource dataSource;
|
|
||||||
private JdbcTemplate jdbcTpl;
|
private JdbcTemplate jdbcTpl;
|
||||||
@Value("#{systemProperties['project.basedir']}")
|
@Value("${project.base-dir}")
|
||||||
private String projDir;
|
private String projDir;
|
||||||
private String groupId;
|
@Value("${project.base-package}")
|
||||||
private String pkg;
|
private String pkg;
|
||||||
private Properties config = new Properties();
|
@Value("${codegen.table-prefix:}")
|
||||||
private Set<String> baseCols = new HashSet<String>();
|
private String tablePrefix;
|
||||||
|
|
||||||
/**
|
private Set<String> baseCols = new HashSet<>();
|
||||||
* @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)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the projDir
|
* @return the projDir
|
||||||
@ -150,13 +62,6 @@ public class CodeGenBaseTool {
|
|||||||
return projDir;
|
return projDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the groupId
|
|
||||||
*/
|
|
||||||
public String getGroupId() {
|
|
||||||
return groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the 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
|
* list all model generated
|
||||||
* @return
|
* @return
|
||||||
@ -270,7 +118,7 @@ public class CodeGenBaseTool {
|
|||||||
FileInputStream fin = null;
|
FileInputStream fin = null;
|
||||||
try {
|
try {
|
||||||
fin = new FileInputStream(file);
|
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) {
|
catch (IOException e) {
|
||||||
log.info("Parse JSON File [{}] ERROR Caused.", file.getName());
|
log.info("Parse JSON File [{}] ERROR Caused.", file.getName());
|
||||||
@ -284,7 +132,7 @@ public class CodeGenBaseTool {
|
|||||||
// backup data file
|
// backup data file
|
||||||
IOUtils.copy(fin,
|
IOUtils.copy(fin,
|
||||||
new FileWriter(new File(projDir, backupFileName)),
|
new FileWriter(new File(projDir, backupFileName)),
|
||||||
CharEncoding.UTF_8);
|
StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e1) {
|
catch (IOException e1) {
|
||||||
@ -296,8 +144,8 @@ public class CodeGenBaseTool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mapData == null) {
|
if (mapData == null) {
|
||||||
mapData = new HashMap<String, Object>();
|
mapData = new HashMap<>();
|
||||||
mapData.put("items", new LinkedList<Object>());
|
mapData.put("items", new LinkedList<>());
|
||||||
}
|
}
|
||||||
return mapData;
|
return mapData;
|
||||||
}
|
}
|
||||||
@ -309,7 +157,7 @@ public class CodeGenBaseTool {
|
|||||||
FileUtils.write(file, JSON.toJSONStringWithDateFormat(storeData,
|
FileUtils.write(file, JSON.toJSONStringWithDateFormat(storeData,
|
||||||
"yyyy-MM-dd HH:mm:ss",
|
"yyyy-MM-dd HH:mm:ss",
|
||||||
SerializerFeature.PrettyFormat),
|
SerializerFeature.PrettyFormat),
|
||||||
CharEncoding.UTF_8);
|
StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new RuntimeException("Write Data To File [" + file.getAbsolutePath() + "] ERROR Caused.", 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"));
|
execSQL("drop table " + item.get("table"));
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
log.info("Drop Table Error Caused.", e);
|
log.info("Drop table error caused.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
it.remove();
|
it.remove();
|
||||||
@ -392,7 +240,7 @@ public class CodeGenBaseTool {
|
|||||||
return FreeMarkerTemplateUtils.processTemplateIntoString(
|
return FreeMarkerTemplateUtils.processTemplateIntoString(
|
||||||
new Template(ftl, new InputStreamReader(
|
new Template(ftl, new InputStreamReader(
|
||||||
CodeGenBaseTool.class.getResourceAsStream(ftl),
|
CodeGenBaseTool.class.getResourceAsStream(ftl),
|
||||||
CharEncoding.UTF_8), fmCfg.getConfiguration()), model);
|
StandardCharsets.UTF_8), fmCfg.getConfiguration()), model);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new RuntimeException("Code Generate Render ERROR, [" + e.getMessage() + "].", e);
|
throw new RuntimeException("Code Generate Render ERROR, [" + e.getMessage() + "].", e);
|
||||||
@ -410,9 +258,6 @@ public class CodeGenBaseTool {
|
|||||||
try {
|
try {
|
||||||
DatabaseMetaData md = conn.getMetaData();
|
DatabaseMetaData md = conn.getMetaData();
|
||||||
rs = md.getTables(null, null, "%", new String[] {"TABLE"});
|
rs = md.getTables(null, null, "%", new String[] {"TABLE"});
|
||||||
String tablePrefix =
|
|
||||||
config.getProperty("table.prefix", "")
|
|
||||||
.toLowerCase();
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
Map<String, Object> mapTable = new HashMap<String, Object>();
|
Map<String, Object> mapTable = new HashMap<String, Object>();
|
||||||
String table = rs.getString(3).toLowerCase();
|
String table = rs.getString(3).toLowerCase();
|
||||||
@ -422,7 +267,7 @@ public class CodeGenBaseTool {
|
|||||||
String[] tableNameParts = null;
|
String[] tableNameParts = null;
|
||||||
if (StringUtils.isNotBlank(tablePrefix) &&
|
if (StringUtils.isNotBlank(tablePrefix) &&
|
||||||
table.startsWith(tablePrefix + "_")) {
|
table.startsWith(tablePrefix + "_")) {
|
||||||
log.info("Table Prefix [{}] Found, Trim.", tablePrefix);
|
log.info("Table prefix [{}] found, trim.", tablePrefix);
|
||||||
tableNameParts =
|
tableNameParts =
|
||||||
table.substring(tablePrefix.length() + 1)
|
table.substring(tablePrefix.length() + 1)
|
||||||
.split("_");
|
.split("_");
|
||||||
@ -451,7 +296,7 @@ public class CodeGenBaseTool {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return new LinkedList<Map<String, Object>>();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --
|
// --
|
||||||
|
@ -1,38 +1,42 @@
|
|||||||
package me.chyxion.tigon.codegen.service.support;
|
package me.chyxion.tigon.codegen.service.support;
|
||||||
|
|
||||||
import me.chyxion.tigon.mybatis.Table;
|
import java.util.Map;
|
||||||
import me.chyxion.tigon.service.BaseCrudService;
|
import java.util.Set;
|
||||||
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.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.text.DateFormat;
|
||||||
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 me.chyxion.tigon.model.M0;
|
import me.chyxion.tigon.model.M0;
|
||||||
import me.chyxion.tigon.model.M1;
|
import me.chyxion.tigon.model.M1;
|
||||||
import me.chyxion.tigon.model.M2;
|
import me.chyxion.tigon.model.M2;
|
||||||
import me.chyxion.tigon.model.M3;
|
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.ArrayUtils;
|
||||||
|
import org.apache.commons.lang3.ClassUtils;
|
||||||
|
import me.chyxion.tigon.service.BaseService;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
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 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
|
* @version 0.0.1
|
||||||
@ -41,8 +45,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
* chyxion@163.com <br>
|
* chyxion@163.com <br>
|
||||||
* Oct 6, 2014 1:10:02 PM
|
* Oct 6, 2014 1:10:02 PM
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class CodeGenServiceSupport implements CodeGenService {
|
public class CodeGenServiceSupport implements CodeGenService {
|
||||||
private static final Logger log = LoggerFactory.getLogger(CodeGenServiceSupport.class);
|
|
||||||
private static final Map<String, String> TYPE_PACKAGES = new HashMap<String, String>() {
|
private static final Map<String, String> TYPE_PACKAGES = new HashMap<String, String>() {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
{
|
{
|
||||||
@ -54,6 +58,14 @@ public class CodeGenServiceSupport implements CodeGenService {
|
|||||||
private CodeGenBaseTool baseTool;
|
private CodeGenBaseTool baseTool;
|
||||||
@Autowired
|
@Autowired
|
||||||
private List<CodeGenerator> codeGen;
|
private List<CodeGenerator> 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}
|
* {@inheritDoc}
|
||||||
@ -88,7 +100,7 @@ public class CodeGenServiceSupport implements CodeGenService {
|
|||||||
fmDataModel.put("table", table.toLowerCase());
|
fmDataModel.put("table", table.toLowerCase());
|
||||||
fmDataModel.put("notNull", false);
|
fmDataModel.put("notNull", false);
|
||||||
fmDataModel.put("notBlank", false);
|
fmDataModel.put("notBlank", false);
|
||||||
fmDataModel.put("cacheEnabled", baseTool.getConfig("cache.enabled", false));
|
fmDataModel.put("cacheEnabled", cacheEnabled);
|
||||||
fmDataModel.put("useGeneratedKeys", false);
|
fmDataModel.put("useGeneratedKeys", false);
|
||||||
|
|
||||||
// collect col names
|
// collect col names
|
||||||
@ -98,69 +110,91 @@ public class CodeGenServiceSupport implements CodeGenService {
|
|||||||
String colName = ((String) col.get("col")).toLowerCase();
|
String colName = ((String) col.get("col")).toLowerCase();
|
||||||
colNames.add(colName);
|
colNames.add(colName);
|
||||||
if (M0.ID.equals(colName)) {
|
if (M0.ID.equals(colName)) {
|
||||||
String javaType = (String) col.get("javaType");
|
String javaType = (String) col.get("javaType");
|
||||||
if (ArrayUtils.contains(
|
if (ArrayUtils.contains(
|
||||||
new String[] {"int", "long", "boolean", "double", "byte"},
|
new String[] {"int", "long", "boolean", "double", "byte"},
|
||||||
javaType)) {
|
javaType)) {
|
||||||
javaType = StringUtils.capitalize(javaType);
|
javaType = "int".equals(javaType) ?
|
||||||
}
|
Integer.class.getSimpleName() :
|
||||||
idType = javaType;
|
StringUtils.capitalize(javaType);
|
||||||
}
|
}
|
||||||
|
idType = javaType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String baseModelName = null;
|
|
||||||
String baseModelFullName = null;
|
final String baseModelName;
|
||||||
Collection<String> baseCols = null;
|
final String baseModelFullName;
|
||||||
if (colNames.containsAll(new M3<String, String>().cols())) {
|
final Collection<String> 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<String, String>().cols())) {
|
||||||
baseModelName = M3.class.getSimpleName() +
|
baseModelName = M3.class.getSimpleName() +
|
||||||
"<" + idType + ", " + idType + ">";
|
"<" + idType + ", " + idType + ">";
|
||||||
baseModelFullName = M3.class.getName();
|
baseModelFullName = M3.class.getName();
|
||||||
baseCols = new M3<String, String>().cols();
|
baseCols = new M3<String, String>().cols();
|
||||||
|
log.info("Base cols [{}] read from M3.", baseCols);
|
||||||
}
|
}
|
||||||
else if (colNames.containsAll(new M2<String>().cols())) {
|
else if (colNames.containsAll(new M2<String>().cols())) {
|
||||||
baseModelName = M2.class.getSimpleName() + "<" + idType + ">";
|
baseModelName = M2.class.getSimpleName() + "<" + idType + ">";
|
||||||
baseModelFullName = M2.class.getName();
|
baseModelFullName = M2.class.getName();
|
||||||
baseCols = new M2<String>().cols();
|
baseCols = new M2<String>().cols();
|
||||||
|
log.info("Base cols [{}] read from M2.", baseCols);
|
||||||
}
|
}
|
||||||
else if (colNames.containsAll(new M1<String>().cols())) {
|
else if (colNames.containsAll(new M1<String>().cols())) {
|
||||||
baseModelName = M1.class.getSimpleName() + "<" + idType + ">";
|
baseModelName = M1.class.getSimpleName() + "<" + idType + ">";
|
||||||
baseModelFullName = M1.class.getName();
|
baseModelFullName = M1.class.getName();
|
||||||
baseCols = new M1<String>().cols();
|
baseCols = new M1<String>().cols();
|
||||||
|
log.info("Base cols [{}] read from M1.", baseCols);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
baseModelName = M0.class.getSimpleName();
|
baseModelName = M0.class.getSimpleName();
|
||||||
baseModelFullName = M0.class.getName();
|
baseModelFullName = M0.class.getName();
|
||||||
baseCols = new M0<String>().cols();
|
baseCols = new M0<String>().cols();
|
||||||
}
|
log.info("Base cols [{}] read from M0.", baseCols);
|
||||||
// custom config
|
|
||||||
String cfgBaseModelName = baseTool.getConfig("super.base.model.name");
|
|
||||||
if (StringUtils.isNotBlank(cfgBaseModelName)) {
|
|
||||||
baseCols = baseTool.getBaseCols();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String cfgBaseModelFullName =
|
fmDataModel.put("baseModelFullName", baseModelFullName);
|
||||||
baseTool.getConfig("super.base.model.full.name");
|
fmDataModel.put("baseModelName", baseModelName);
|
||||||
|
|
||||||
fmDataModel.put("baseModelName",
|
|
||||||
baseTool.getConfig("super.base.model.name", baseModelName));
|
|
||||||
|
|
||||||
fmDataModel.put("baseModelFullName",
|
|
||||||
"NONE".equalsIgnoreCase(cfgBaseModelFullName) ? null :
|
|
||||||
StringUtils.isNotBlank(cfgBaseModelFullName) ?
|
|
||||||
cfgBaseModelFullName : baseModelFullName);
|
|
||||||
|
|
||||||
fmDataModel.put("tableAnnotationClassName", Table.class.getName());
|
fmDataModel.put("tableAnnotationClassName", Table.class.getName());
|
||||||
fmDataModel.put("tableAnnotationName", Table.class.getSimpleName());
|
fmDataModel.put("tableAnnotationName", Table.class.getSimpleName());
|
||||||
|
|
||||||
Set<String> imports = new HashSet<String>();
|
final Set<String> imports = new HashSet<>();
|
||||||
List<Map<String, Object>> colsWithoutBase =
|
final List<Map<String, Object>> colsWithoutBase =
|
||||||
(List<Map<String, Object>>) columns;
|
(List<Map<String, Object>>) columns;
|
||||||
Iterator<Map<String, Object>> colIt =
|
final Iterator<Map<String, Object>> colIt =
|
||||||
colsWithoutBase.iterator();
|
colsWithoutBase.iterator();
|
||||||
|
|
||||||
while (colIt.hasNext()) {
|
while (colIt.hasNext()) {
|
||||||
Map<String, Object> col = colIt.next();
|
Map<String, Object> col = colIt.next();
|
||||||
// col name
|
// 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)) {
|
if (!baseCols.contains(colName)) {
|
||||||
// prop name
|
// prop name
|
||||||
String propName = (String) col.get("name");
|
String propName = (String) col.get("name");
|
||||||
@ -175,13 +209,14 @@ public class CodeGenServiceSupport implements CodeGenService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// imports
|
// imports
|
||||||
String p = TYPE_PACKAGES.get(col.get("javaType"));
|
final String imp = TYPE_PACKAGES.get(col.get("javaType"));
|
||||||
if (StringUtils.isNotBlank(p)) {
|
if (StringUtils.isNotBlank(imp)) {
|
||||||
imports.add(p);
|
imports.add(imp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// remove base col
|
// remove base col
|
||||||
else {
|
else {
|
||||||
|
log.info("Remove base col [{}].", colName);
|
||||||
colIt.remove();
|
colIt.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import java.io.File;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.Ordered;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import me.chyxion.tigon.codegen.model.CodeGenArgs;
|
import me.chyxion.tigon.codegen.model.CodeGenArgs;
|
||||||
@ -17,7 +16,7 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
|
|||||||
* chyxion@163.com <br>
|
* chyxion@163.com <br>
|
||||||
* Oct 7, 2014 12:23:13 PM
|
* Oct 7, 2014 12:23:13 PM
|
||||||
*/
|
*/
|
||||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
@Order
|
||||||
public class TableCodeGen extends CodeGenerator {
|
public class TableCodeGen extends CodeGenerator {
|
||||||
private static final Logger log = LoggerFactory.getLogger(TableCodeGen.class);
|
private static final Logger log = LoggerFactory.getLogger(TableCodeGen.class);
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ public class TableCodeGen extends CodeGenerator {
|
|||||||
@Override
|
@Override
|
||||||
public String process(Map<String, Object> dataModel, String module, String model) {
|
public String process(Map<String, Object> dataModel, String module, String model) {
|
||||||
String table = (String) dataModel.get("table");
|
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)
|
StringBuilder filePath = new StringBuilder(resourcesDir)
|
||||||
.append("db/");
|
.append("db/");
|
||||||
if (StringUtils.isNotBlank(module)) {
|
if (StringUtils.isNotBlank(module)) {
|
||||||
@ -51,21 +50,21 @@ public class TableCodeGen extends CodeGenerator {
|
|||||||
if (!Boolean.FALSE.equals(dataModel.get("createTable"))) {
|
if (!Boolean.FALSE.equals(dataModel.get("createTable"))) {
|
||||||
// ignore drop table error
|
// ignore drop table error
|
||||||
try {
|
try {
|
||||||
log.info("Execute Drop Table [{}].", table);
|
log.info("Execute drop table [{}].", table);
|
||||||
baseTool.execSQL("drop table " + table);
|
baseTool.execSQL("drop table " + table);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
log.info("Drop Table Failed, Error Message [{}], Ingore.",
|
log.info("Drop table failed, error message [{}], ignore.",
|
||||||
e.getMessage());
|
e.getMessage());
|
||||||
}
|
}
|
||||||
// ignore execute sql error
|
// ignore execute sql error
|
||||||
try {
|
try {
|
||||||
log.info("Execut Create Table SQL File [{}].", filePath);
|
log.info("Execute create table SQL file [{}].", filePath);
|
||||||
baseTool.execSQL(new File(baseTool.getProjDir(), filePath
|
baseTool.execSQL(new File(baseTool.getProjDir(), filePath
|
||||||
.toString()));
|
.toString()));
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
log.warn("Database Create Table Error, Ingore.", e);
|
log.warn("Database create table error, ignore.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filePath.toString();
|
return filePath.toString();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package me.chyxion.tigon.codegen.utils;
|
package me.chyxion.tigon.codegen.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.LineNumberReader;
|
import java.io.LineNumberReader;
|
@ -1,13 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
xmlns:p="http://www.springframework.org/schema/p"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
|
||||||
|
|
||||||
<context:component-scan base-package="me.chyxion.tigon.codegen.controller" />
|
|
||||||
<!-- Tool -->
|
<!-- Tool -->
|
||||||
<bean class="me.chyxion.tigon.codegen.service.CodeGenBaseTool" />
|
<bean class="me.chyxion.tigon.codegen.service.CodeGenBaseTool" />
|
||||||
|
|
||||||
@ -23,4 +20,40 @@
|
|||||||
<bean class="me.chyxion.tigon.codegen.service.support.TableCodeGen" />
|
<bean class="me.chyxion.tigon.codegen.service.support.TableCodeGen" />
|
||||||
<bean class="me.chyxion.tigon.codegen.service.support.ViewCodeGen" />
|
<bean class="me.chyxion.tigon.codegen.service.support.ViewCodeGen" />
|
||||||
|
|
||||||
|
<!-- FreeMarker Config -->
|
||||||
|
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"
|
||||||
|
p:templateLoaderPaths="/WEB-INF/views/, classpath:/, classpath:/webapp/views/"
|
||||||
|
p:defaultEncoding="utf-8"
|
||||||
|
p:preferFileSystemAccess="false">
|
||||||
|
<property name="freemarkerSettings">
|
||||||
|
<props>
|
||||||
|
<prop key="template_update_delay">${tigon.codegen.freemarker.cache.expire:36000}</prop>
|
||||||
|
<prop key="output_encoding">utf-8</prop>
|
||||||
|
<prop key="locale">en_US</prop>
|
||||||
|
<prop key="date_format">yyyy-MM-dd</prop>
|
||||||
|
<prop key="time_format">HH:mm:ss</prop>
|
||||||
|
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
|
||||||
|
<!-- avoid 000.00 -->
|
||||||
|
<prop key="number_format">#</prop>
|
||||||
|
</props>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
<bean class="me.chyxion.tigon.codegen.freemarker.FreeMarkerViewResolverExt"
|
||||||
|
p:suffix=".ftl"
|
||||||
|
p:contentType="text/html; charset=utf-8"
|
||||||
|
p:exposeRequestAttributes="true"
|
||||||
|
p:order="16"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<bean class="org.springframework.jdbc.core.JdbcTemplate">
|
||||||
|
<constructor-arg>
|
||||||
|
<bean class="com.alibaba.druid.pool.DruidDataSource"
|
||||||
|
init-method="init"
|
||||||
|
destroy-method="close"
|
||||||
|
p:url="jdbc:mysql://${datasource.host}:${datasource.port}/${datasource.database-name}?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull"
|
||||||
|
p:username="${datasource.username}"
|
||||||
|
p:password="${datasource.password}"
|
||||||
|
/>
|
||||||
|
</constructor-arg>
|
||||||
|
</bean>
|
||||||
</beans>
|
</beans>
|
||||||
|
@ -86,13 +86,6 @@ Ext.define ('Tigon.views.CodeGen', {
|
|||||||
form = rc.down('form');
|
form = rc.down('form');
|
||||||
form.getForm().setValues(rec.getData());
|
form.getForm().setValues(rec.getData());
|
||||||
form.down('grid').getStore().loadData(rec.get('cols'));
|
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
|
createTable: false
|
||||||
}));
|
}));
|
||||||
form.down('grid').getStore().loadData(rec.get('cols'));
|
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',
|
fieldLabel: 'Options',
|
||||||
xtype: 'checkboxgroup',
|
xtype: 'checkboxgroup',
|
||||||
defaults: {
|
defaults: {
|
||||||
checked: true,
|
checked: false,
|
||||||
xtype: 'checkbox',
|
xtype: 'checkbox',
|
||||||
inputValue: true
|
inputValue: true
|
||||||
},
|
},
|
||||||
columns: 3,
|
columns: 3,
|
||||||
items: [{
|
items: [{
|
||||||
boxLabel: 'Gen controller',
|
boxLabel: 'Gen controller',
|
||||||
|
checked: components.indexOf('controller') > -1,
|
||||||
name: 'genController'
|
name: 'genController'
|
||||||
}, {
|
}, {
|
||||||
boxLabel: 'Gen service',
|
boxLabel: 'Gen service',
|
||||||
name: 'genService'
|
name: 'genService'
|
||||||
}, {
|
}, {
|
||||||
boxLabel: 'Gen mapper',
|
boxLabel: 'Gen mapper',
|
||||||
|
checked: components.indexOf('mapper') > -1,
|
||||||
name: 'genMapper'
|
name: 'genMapper'
|
||||||
}, {
|
}, {
|
||||||
boxLabel: 'Gen model',
|
boxLabel: 'Gen model',
|
||||||
|
checked: components.indexOf('model') > -1,
|
||||||
name: 'genModel'
|
name: 'genModel'
|
||||||
}, {
|
|
||||||
boxLabel: 'Gen table',
|
|
||||||
name: 'genTable'
|
|
||||||
}, {
|
}, {
|
||||||
boxLabel: 'Gen form',
|
boxLabel: 'Gen form',
|
||||||
checked: false,
|
checked: components.indexOf('form') > -1,
|
||||||
name: 'genView'
|
name: 'genView'
|
||||||
}, {
|
|
||||||
boxLabel: 'Create table',
|
|
||||||
checked: false,
|
|
||||||
name: 'createTable'
|
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
xtype: 'fieldcontainer',
|
xtype: 'fieldcontainer',
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
items: [{
|
items: [{
|
||||||
xtype: 'box',
|
xtype: 'box',
|
||||||
region: 'north',
|
region: 'north',
|
||||||
html: '<h1>Super Super Code!</h1>'
|
html: '<h1>Tigon Code Gen!</h1>'
|
||||||
},
|
},
|
||||||
Ext.create('Tigon.views.CodeGen', {
|
Ext.create('Tigon.views.CodeGen', {
|
||||||
region: 'center'
|
region: 'center'
|
||||||
@ -26,6 +26,7 @@
|
|||||||
Ext.create('Tigon.views.ThemesBar').show();
|
Ext.create('Tigon.views.ThemesBar').show();
|
||||||
});
|
});
|
||||||
var pkg = '${pkg}';
|
var pkg = '${pkg}';
|
||||||
|
var components = ${components};
|
||||||
</script>
|
</script>
|
||||||
<title>Auto Code</title>
|
<title>Auto Code</title>
|
||||||
</head>
|
</head>
|
||||||
|
@ -1 +0,0 @@
|
|||||||
# tigon-freemarker-support
|
|
@ -1,54 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
|
||||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<artifactId>tigon-freemarker-support</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
<name>Tigon FreeMarker Support</name>
|
|
||||||
<description>Tigon FreeMarker Support</description>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>me.chyxion.tigon</groupId>
|
|
||||||
<artifactId>tigon</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<relativePath>../</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.freemarker</groupId>
|
|
||||||
<artifactId>freemarker</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-webmvc</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-context-support</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<!-- Test -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
@ -1,31 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:p="http://www.springframework.org/schema/p"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
|
||||||
<!-- FreeMarker Config -->
|
|
||||||
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"
|
|
||||||
p:templateLoaderPaths="/WEB-INF/views/, classpath:/, classpath:/webapp/views/"
|
|
||||||
p:defaultEncoding="utf-8"
|
|
||||||
p:preferFileSystemAccess="false">
|
|
||||||
<property name="freemarkerSettings">
|
|
||||||
<props>
|
|
||||||
<prop key="template_update_delay">${freemarker.cache.expire:36000}</prop>
|
|
||||||
<prop key="output_encoding">utf-8</prop>
|
|
||||||
<prop key="locale">en_US</prop>
|
|
||||||
<prop key="date_format">yyyy-MM-dd</prop>
|
|
||||||
<prop key="time_format">HH:mm:ss</prop>
|
|
||||||
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
|
|
||||||
<!-- avoid 000.00 -->
|
|
||||||
<prop key="number_format">#</prop>
|
|
||||||
</props>
|
|
||||||
</property>
|
|
||||||
</bean>
|
|
||||||
<bean class="me.chyxion.tigon.freemarker.FreeMarkerViewResolverExt"
|
|
||||||
p:suffix=".ftl"
|
|
||||||
p:contentType="text/html; charset=utf-8"
|
|
||||||
p:exposeRequestAttributes="true"
|
|
||||||
p:order="16"
|
|
||||||
/>
|
|
||||||
</beans>
|
|
@ -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 <br>
|
|
||||||
* chyxion@163.com <br>
|
|
||||||
* Jan 27, 2015 3:27:08 PM
|
|
||||||
*/
|
|
||||||
@WebAppConfiguration
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration("classpath:spring/controller-test.xml")
|
|
||||||
public class SiteControllerTest {
|
|
||||||
|
|
||||||
}
|
|
@ -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
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
# Config Dev
|
|
@ -1,21 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:p="http://www.springframework.org/schema/p"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
|
||||||
|
|
||||||
<!-- Scan Mock -->
|
|
||||||
<context:component-scan base-package="me.chyxion.tigon.freemarker.test"
|
|
||||||
use-default-filters="false">
|
|
||||||
<context:include-filter type="annotation"
|
|
||||||
expression="me.chyxion.tigon.webmvc.stereotype.Mock" />
|
|
||||||
<context:include-filter type="annotation"
|
|
||||||
expression="org.springframework.stereotype.Controller" />
|
|
||||||
<context:include-filter type="annotation"
|
|
||||||
expression="org.springframework.stereotype.Service" />
|
|
||||||
</context:component-scan>
|
|
||||||
</beans>
|
|
@ -10,11 +10,11 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
|||||||
* chyxion@163.com <br>
|
* chyxion@163.com <br>
|
||||||
* Oct 8, 2016 6:26:19 PM
|
* Oct 8, 2016 6:26:19 PM
|
||||||
*/
|
*/
|
||||||
@Getter
|
|
||||||
public class FC2<CreatorId> extends FC1 {
|
public class FC2<CreatorId> extends FC1 {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private transient boolean __lock = true;
|
private transient boolean __lock = true;
|
||||||
|
|
||||||
|
@Getter
|
||||||
@NotNullOrBlank
|
@NotNullOrBlank
|
||||||
protected CreatorId createdBy;
|
protected CreatorId createdBy;
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package me.chyxion.tigon.form;
|
package me.chyxion.tigon.form;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
|
||||||
import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,12 +10,12 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
|||||||
* chyxion@163.com <br>
|
* chyxion@163.com <br>
|
||||||
* Oct 8, 2016 6:26:36 PM
|
* Oct 8, 2016 6:26:36 PM
|
||||||
*/
|
*/
|
||||||
@Getter
|
|
||||||
public class FU2<EditorId, Id>
|
public class FU2<EditorId, Id>
|
||||||
extends FU1<Id> {
|
extends FU1<Id> {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private transient boolean __lock = true;
|
private transient boolean __lock = true;
|
||||||
|
|
||||||
|
@Getter
|
||||||
@NotNullOrBlank
|
@NotNullOrBlank
|
||||||
private EditorId updatedBy;
|
private EditorId updatedBy;
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ public final class RedisCache implements Cache {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -45,6 +46,7 @@ public final class RedisCache implements Cache {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
final Long size = hashOp.size(id);
|
final Long size = hashOp.size(id);
|
||||||
log.info("Get redis cache [{}] size [{}].", id, size);
|
log.info("Get redis cache [{}] size [{}].", id, size);
|
||||||
@ -54,6 +56,7 @@ public final class RedisCache implements Cache {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void putObject(final Object key, final Object value) {
|
public void putObject(final Object key, final Object value) {
|
||||||
log.debug("Put redis cache [{}] object key [{}], value [{}].", id, key, value);
|
log.debug("Put redis cache [{}] object key [{}], value [{}].", id, key, value);
|
||||||
hashOp.put(id, keyMd5(key), value);
|
hashOp.put(id, keyMd5(key), value);
|
||||||
@ -62,6 +65,7 @@ public final class RedisCache implements Cache {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Object getObject(final Object key) {
|
public Object getObject(final Object key) {
|
||||||
final Object value = hashOp.get(id, keyMd5(key));
|
final Object value = hashOp.get(id, keyMd5(key));
|
||||||
log.debug("Get redis cache object key [{}], value [{}].", key, value);
|
log.debug("Get redis cache object key [{}], value [{}].", key, value);
|
||||||
@ -71,6 +75,7 @@ public final class RedisCache implements Cache {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Object removeObject(final Object key) {
|
public Object removeObject(final Object key) {
|
||||||
log.info("Remove redis cache [{}] object key [{}].", id, key);
|
log.info("Remove redis cache [{}] object key [{}].", id, key);
|
||||||
return hashOp.delete(id, keyMd5(key));
|
return hashOp.delete(id, keyMd5(key));
|
||||||
@ -79,6 +84,7 @@ public final class RedisCache implements Cache {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
log.info("Clear redis cache [{}].", id);
|
log.info("Clear redis cache [{}].", id);
|
||||||
redisTpl.delete(id);
|
redisTpl.delete(id);
|
||||||
@ -108,7 +114,7 @@ public final class RedisCache implements Cache {
|
|||||||
* @param key cache key
|
* @param key cache key
|
||||||
* @return prefixed 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));
|
final String md5Hex = DigestUtils.md5Hex(key instanceof String ? (String) key : String.valueOf(key));
|
||||||
log.debug("Get redis cache [{}] key [{}] md5 hex [{}].", id, key, md5Hex);
|
log.debug("Get redis cache [{}] key [{}] md5 hex [{}].", id, key, md5Hex);
|
||||||
return md5Hex;
|
return md5Hex;
|
||||||
|
@ -34,11 +34,4 @@ public class RedisCacheConfig {
|
|||||||
public RedisTemplate<String, Object> getRedisTpl() {
|
public RedisTemplate<String, Object> getRedisTpl() {
|
||||||
return redisTpl;
|
return redisTpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param redisTpl the redisTpl to set
|
|
||||||
*/
|
|
||||||
public void setRedisTpl(RedisTemplate<String, Object> redisTpl) {
|
|
||||||
this.redisTpl = redisTpl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package me.chyxion.tigon.mybatis.cache.support;
|
package me.chyxion.tigon.mybatis.cache.support;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.apache.ibatis.cache.Cache;
|
import org.apache.ibatis.cache.Cache;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import org.apache.ibatis.session.Configuration;
|
import org.apache.ibatis.session.Configuration;
|
||||||
@ -16,9 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
* chyxion@163.com <br>
|
* chyxion@163.com <br>
|
||||||
* Aug 26, 2015 10:58:58 AM
|
* Aug 26, 2015 10:58:58 AM
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class CacheToolSupport implements CacheTool {
|
public class CacheToolSupport implements CacheTool {
|
||||||
private static final Logger log =
|
|
||||||
LoggerFactory.getLogger(CacheToolSupport.class);
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SqlSessionFactory ssf;
|
private SqlSessionFactory ssf;
|
||||||
@ -29,13 +27,13 @@ public class CacheToolSupport implements CacheTool {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void clearCache(Class<?> mapper) {
|
public void clearCache(Class<?> mapper) {
|
||||||
log.info("Clear Cache [{}].", mapper);
|
log.info("Clear mybatis cache [{}].", mapper);
|
||||||
Cache cache = getCache(mapper);
|
final Cache cache = getCache(mapper);
|
||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
cache.clear();
|
cache.clear();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.warn("No Cache [{}] Found.", mapper);
|
log.warn("No mybatis cache [{}] found.", mapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package me.chyxion.tigon.service;
|
package me.chyxion.tigon.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.validation.constraints.Min;
|
import java.util.function.Function;
|
||||||
import me.chyxion.tigon.mybatis.Search;
|
import me.chyxion.tigon.mybatis.Search;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
import me.chyxion.tigon.model.BaseModel;
|
import me.chyxion.tigon.model.BaseModel;
|
||||||
import me.chyxion.tigon.model.ViewModel;
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
import me.chyxion.tigon.model.ListResult;
|
import me.chyxion.tigon.model.ListResult;
|
||||||
@ -89,14 +90,14 @@ public interface BaseQueryService<PrimaryKey,
|
|||||||
* scan model of all
|
* scan model of all
|
||||||
* @param scanner scanner
|
* @param scanner scanner
|
||||||
*/
|
*/
|
||||||
Model scan(@NotNull Scanner<Model> scanner);
|
Model scan(@NotNull Function<Model, Boolean> scanner);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* scan model by search
|
* scan model by search
|
||||||
* @param search search
|
* @param search search
|
||||||
* @param scanner scanner
|
* @param scanner scanner
|
||||||
*/
|
*/
|
||||||
Model scan(Search search, @NotNull Scanner<Model> scanner);
|
Model scan(Search search, @NotNull Function<Model, Boolean> scanner);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* scan model by search
|
* scan model by search
|
||||||
@ -104,15 +105,11 @@ public interface BaseQueryService<PrimaryKey,
|
|||||||
* @param search search
|
* @param search search
|
||||||
* @param scanner scanner
|
* @param scanner scanner
|
||||||
*/
|
*/
|
||||||
Model scan(@Min(1) int batchSize, Search search, @NotNull Scanner<Model> scanner);
|
Model scan(@Min(1) int batchSize, Search search, @NotNull Function<Model, Boolean> scanner);
|
||||||
|
|
||||||
interface Scanner<T> {
|
<Model> Model scan(@Min(1) int batchSize,
|
||||||
|
Search search,
|
||||||
/**
|
@NotNull Function<Search, List<Model>> dataQuerier,
|
||||||
* scan model
|
@NotNull Function<Search, Integer> countQuerier,
|
||||||
* @param model model
|
@NotNull Function<Model, Boolean> scanner);
|
||||||
* @return false to break
|
|
||||||
*/
|
|
||||||
boolean found(T model);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,9 @@ package me.chyxion.tigon.service.support;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.mybatis.Search;
|
||||||
|
import me.chyxion.tigon.model.BaseModel;
|
||||||
import me.chyxion.tigon.model.ViewModel;
|
import me.chyxion.tigon.model.ViewModel;
|
||||||
import me.chyxion.tigon.model.ListResult;
|
import me.chyxion.tigon.model.ListResult;
|
||||||
import me.chyxion.tigon.mybatis.BaseMapper;
|
import me.chyxion.tigon.mybatis.BaseMapper;
|
||||||
@ -24,7 +25,7 @@ public class BaseQueryServiceSupport
|
|||||||
extends BaseServiceSupport<PrimaryKey, Model, Mapper>
|
extends BaseServiceSupport<PrimaryKey, Model, Mapper>
|
||||||
implements BaseQueryService<PrimaryKey, Model> {
|
implements BaseQueryService<PrimaryKey, Model> {
|
||||||
|
|
||||||
@Value("${default.query.batch.size:256}")
|
@Value("${tigon.query.batch.size:32}")
|
||||||
private int scanBatchSize;
|
private int scanBatchSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,7 +60,7 @@ public class BaseQueryServiceSupport
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ListResult<Model> listPage(Search search) {
|
public ListResult<Model> 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));
|
return new ListResult<>(list(search), count(search));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +78,7 @@ public class BaseQueryServiceSupport
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ViewModel<Model> findViewModel(Search search) {
|
public ViewModel<Model> findViewModel(Search search) {
|
||||||
log.debug("Find view model by search [{}].", search);
|
log.debug("Find View Model By Search [{}].", search);
|
||||||
Model model = find(search);
|
Model model = find(search);
|
||||||
return model != null ? toViewModel(model) : null;
|
return model != null ? toViewModel(model) : null;
|
||||||
}
|
}
|
||||||
@ -116,7 +117,7 @@ public class BaseQueryServiceSupport
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Model scan(Scanner<Model> scanner) {
|
public Model scan(Function<Model, Boolean> scanner) {
|
||||||
return scan(null, scanner);
|
return scan(null, scanner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +125,7 @@ public class BaseQueryServiceSupport
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Model scan(Search search, Scanner<Model> scanner) {
|
public Model scan(Search search, Function<Model, Boolean> scanner) {
|
||||||
return scan(scanBatchSize(), search, scanner);
|
return scan(scanBatchSize(), search, scanner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,25 +133,37 @@ public class BaseQueryServiceSupport
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Model scan(int batchSize, Search search, Scanner<Model> scanner) {
|
public Model scan(int batchSize, Search search, Function<Model, Boolean> scanner) {
|
||||||
|
return scan(batchSize, search, this::list, this::count, scanner);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public <Model> Model scan(final int batchSize,
|
||||||
|
Search search,
|
||||||
|
final Function<Search, List<Model>> dataQuerier,
|
||||||
|
final Function<Search, Integer> countQuerier,
|
||||||
|
final Function<Model, Boolean> scanner) {
|
||||||
log.info("Scan model by search [{}].", search);
|
log.info("Scan model by search [{}].", search);
|
||||||
int total = count(search);
|
int total = countQuerier.apply(search);
|
||||||
if (total > 0) {
|
if (total > 0) {
|
||||||
if (search == null) {
|
if (search == null) {
|
||||||
log.debug("Scan search is null, use default.");
|
log.debug("Scan search is null, use default.");
|
||||||
search = new Search();
|
search = new Search();
|
||||||
}
|
}
|
||||||
for (int start = 0; start < total; start += batchSize) {
|
for (int start = 0; start < total; start += batchSize) {
|
||||||
for (Model model : list(
|
for (Model model : dataQuerier.apply(
|
||||||
search.offset(start)
|
search.offset(start)
|
||||||
.limit(Math.min(batchSize, total - start)))) {
|
.limit(Math.min(batchSize, total - start)))) {
|
||||||
if (scanner.found(model)) {
|
if (scanner.apply(model)) {
|
||||||
log.info("Model [{}] found by scanner.", model);
|
log.info("Model [{}] found by scanner, stop scan.", model);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.debug("No matched model found by scanner.");
|
log.info("Scan completed, no matched model found by scanner.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.info("No model to scan by search [{}].", search);
|
log.info("No model to scan by search [{}].", search);
|
||||||
@ -161,6 +174,7 @@ public class BaseQueryServiceSupport
|
|||||||
/**
|
/**
|
||||||
* @return the mapper
|
* @return the mapper
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Mapper getMapper() {
|
public Mapper getMapper() {
|
||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
@ -168,6 +182,7 @@ public class BaseQueryServiceSupport
|
|||||||
/**
|
/**
|
||||||
* @param mapper the mapper to set
|
* @param mapper the mapper to set
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void setMapper(Mapper mapper) {
|
public void setMapper(Mapper mapper) {
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user