tab to spaces, remove Tigon Sql session factory bean thread
This commit is contained in:
parent
c2a089676e
commit
999fc958ad
@ -11,10 +11,10 @@ import me.chyxion.tigon.codegen.model.CodeGenArgs;
|
||||
*/
|
||||
public interface CodeGenCustomizer {
|
||||
|
||||
/**
|
||||
* customize your code gen result
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
void customize(CodeGenArgs args);
|
||||
/**
|
||||
* customize your code gen result
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
void customize(CodeGenArgs args);
|
||||
}
|
||||
|
@ -31,74 +31,74 @@ import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
|
||||
@Controller
|
||||
@RequestMapping("/codegen")
|
||||
public class CodeGenController {
|
||||
@Autowired
|
||||
private CodeGenService service;
|
||||
@Autowired
|
||||
private CodeGenBaseTool tool;
|
||||
@Autowired
|
||||
private CodeGenService service;
|
||||
@Autowired
|
||||
private CodeGenBaseTool tool;
|
||||
|
||||
@RequestMapping(method = GET)
|
||||
public ModelAndView index() {
|
||||
@RequestMapping(method = GET)
|
||||
public ModelAndView index() {
|
||||
return new ModelAndView("webapp/views/codegen")
|
||||
.addObject("pkg", tool.getPkg());
|
||||
}
|
||||
.addObject("pkg", tool.getPkg());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/tables")
|
||||
public List<Map<String, Object>> tables() {
|
||||
return service.tables();
|
||||
}
|
||||
@RequestMapping(value = "/tables")
|
||||
public List<Map<String, Object>> tables() {
|
||||
return service.tables();
|
||||
}
|
||||
|
||||
@RequestMapping(method = POST)
|
||||
public boolean gen(@Valid GenForm form) {
|
||||
service.process(form.getModule(), form.getModel(),
|
||||
form.getJaColumns(), form.getTable(), form);
|
||||
return true;
|
||||
}
|
||||
@RequestMapping(method = POST)
|
||||
public boolean gen(@Valid GenForm form) {
|
||||
service.process(form.getModule(), form.getModel(),
|
||||
form.getJaColumns(), form.getTable(), form);
|
||||
return true;
|
||||
}
|
||||
|
||||
@RequestMapping("/list")
|
||||
public List<?> list() {
|
||||
return service.list();
|
||||
}
|
||||
@RequestMapping("/list")
|
||||
public List<?> list() {
|
||||
return service.list();
|
||||
}
|
||||
|
||||
@RequestMapping(method = DELETE)
|
||||
public boolean delete(
|
||||
@RequestParam("items")
|
||||
String items,
|
||||
@RequestParam(value = "dropTable", defaultValue = "true")
|
||||
boolean dropTable) {
|
||||
service.delete(JSON.parseArray(items), dropTable);
|
||||
return true;
|
||||
}
|
||||
@RequestMapping(method = DELETE)
|
||||
public boolean delete(
|
||||
@RequestParam("items")
|
||||
String items,
|
||||
@RequestParam(value = "dropTable", defaultValue = "true")
|
||||
boolean dropTable) {
|
||||
service.delete(JSON.parseArray(items), dropTable);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class GenForm {
|
||||
@NotNull
|
||||
private String columns;
|
||||
@NotBlank
|
||||
private String model;
|
||||
@NotBlank
|
||||
private String table;
|
||||
private String module;
|
||||
private String pkg;
|
||||
private boolean genController;
|
||||
private boolean genService;
|
||||
private boolean genMapper;
|
||||
private boolean genModel;
|
||||
private boolean genTable;
|
||||
private boolean genView;
|
||||
private boolean createTable;
|
||||
@Getter
|
||||
@Setter
|
||||
public static class GenForm {
|
||||
@NotNull
|
||||
private String columns;
|
||||
@NotBlank
|
||||
private String model;
|
||||
@NotBlank
|
||||
private String table;
|
||||
private String module;
|
||||
private String pkg;
|
||||
private boolean genController;
|
||||
private boolean genService;
|
||||
private boolean genMapper;
|
||||
private boolean genModel;
|
||||
private boolean genTable;
|
||||
private boolean genView;
|
||||
private boolean createTable;
|
||||
|
||||
/**
|
||||
* @return the columns
|
||||
*/
|
||||
public JSONArray getJaColumns() {
|
||||
return JSON.parseArray(columns);
|
||||
}
|
||||
/**
|
||||
* @return the module
|
||||
*/
|
||||
public String getModule() {
|
||||
return StringUtils.isNotBlank(module) ? module : "";
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return the columns
|
||||
*/
|
||||
public JSONArray getJaColumns() {
|
||||
return JSON.parseArray(columns);
|
||||
}
|
||||
/**
|
||||
* @return the module
|
||||
*/
|
||||
public String getModule() {
|
||||
return StringUtils.isNotBlank(module) ? module : "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
public class CodeGenArgs {
|
||||
|
||||
|
||||
public static final String TARGET_MODEL = "MODEL";
|
||||
public static final String TARGET_MAPPER = "MAPPER";
|
||||
public static final String TARGET_MAPPER_XML = "MAPPER_XML";
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -12,31 +12,31 @@ import me.chyxion.tigon.codegen.controller.CodeGenController.GenForm;
|
||||
* Oct 6, 2014 1:08:14 PM
|
||||
*/
|
||||
public interface CodeGenService {
|
||||
/**
|
||||
* process code generation
|
||||
* @param module
|
||||
* @param model
|
||||
* @param cols
|
||||
* @param table
|
||||
* @param form
|
||||
*/
|
||||
void process(String module, String model, List<?> cols, String table, GenForm form);
|
||||
/**
|
||||
* process code generation
|
||||
* @param module
|
||||
* @param model
|
||||
* @param cols
|
||||
* @param table
|
||||
* @param form
|
||||
*/
|
||||
void process(String module, String model, List<?> cols, String table, GenForm form);
|
||||
|
||||
/**
|
||||
* list generated items
|
||||
* @return items list
|
||||
*/
|
||||
List<?> list();
|
||||
/**
|
||||
* list generated items
|
||||
* @return items list
|
||||
*/
|
||||
List<?> list();
|
||||
|
||||
/**
|
||||
* list tables
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> tables();
|
||||
/**
|
||||
* list tables
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> tables();
|
||||
|
||||
/**
|
||||
* delete items
|
||||
* @param items
|
||||
*/
|
||||
void delete(List<?> items, boolean dropTable);
|
||||
/**
|
||||
* delete items
|
||||
* @param items
|
||||
*/
|
||||
void delete(List<?> items, boolean dropTable);
|
||||
}
|
||||
|
@ -17,52 +17,52 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* Oct 6, 2014 1:10:55 PM
|
||||
*/
|
||||
public abstract class CodeGenerator {
|
||||
@Autowired(required = false)
|
||||
private List<CodeGenCustomizer> customizers;
|
||||
@Autowired
|
||||
protected CodeGenBaseTool baseTool;
|
||||
protected String codeDir = "src/main/java/";
|
||||
protected String testDir = "src/test/java/";
|
||||
protected String resourcesDir = "src/main/resources/";
|
||||
protected String viewsDir = "src/main/webapp/assets/js/views/";
|
||||
@Autowired(required = false)
|
||||
private List<CodeGenCustomizer> customizers;
|
||||
@Autowired
|
||||
protected CodeGenBaseTool baseTool;
|
||||
protected String codeDir = "src/main/java/";
|
||||
protected String testDir = "src/test/java/";
|
||||
protected String resourcesDir = "src/main/resources/";
|
||||
protected String viewsDir = "src/main/webapp/assets/js/views/";
|
||||
|
||||
/**
|
||||
* @param dataModel
|
||||
* @param module
|
||||
* @param model
|
||||
*/
|
||||
public abstract String process(Map<String, Object> dataModel, String module, String model);
|
||||
/**
|
||||
* @param dataModel
|
||||
* @param module
|
||||
* @param model
|
||||
*/
|
||||
public abstract String process(Map<String, Object> dataModel, String module, String model);
|
||||
|
||||
/**
|
||||
* @param dataModel
|
||||
* @return
|
||||
*/
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @param dataModel
|
||||
* @return
|
||||
*/
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* render FreeMarker Tpl
|
||||
* @param args code gen args
|
||||
* @return gen result file path
|
||||
*/
|
||||
protected String render(CodeGenArgs args) {
|
||||
try {
|
||||
// customize
|
||||
if (customizers != null && customizers.size() > 0) {
|
||||
for (CodeGenCustomizer customizer : customizers) {
|
||||
customizer.customize(args);
|
||||
}
|
||||
}
|
||||
// write result
|
||||
FileUtils.write(new File(baseTool.getProjDir(), args.getFile()),
|
||||
baseTool.renderFtl(args.getFtl(), args.getModel()),
|
||||
CharEncoding.UTF_8);
|
||||
return args.getFile();
|
||||
/**
|
||||
* render FreeMarker Tpl
|
||||
* @param args code gen args
|
||||
* @return gen result file path
|
||||
*/
|
||||
protected String render(CodeGenArgs args) {
|
||||
try {
|
||||
// customize
|
||||
if (customizers != null && customizers.size() > 0) {
|
||||
for (CodeGenCustomizer customizer : customizers) {
|
||||
customizer.customize(args);
|
||||
}
|
||||
}
|
||||
// write result
|
||||
FileUtils.write(new File(baseTool.getProjDir(), args.getFile()),
|
||||
baseTool.renderFtl(args.getFtl(), args.getModel()),
|
||||
CharEncoding.UTF_8);
|
||||
return args.getFile();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Code Gen Render File Error Caused.", e);
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Code Gen Render File Error Caused.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,251 +42,251 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* Oct 6, 2014 1:10:02 PM
|
||||
*/
|
||||
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 Logger log = LoggerFactory.getLogger(CodeGenServiceSupport.class);
|
||||
private static final Map<String, String> TYPE_PACKAGES = new HashMap<String, String>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
{
|
||||
put(Date.class.getSimpleName(), Date.class.getName());
|
||||
put(Date.class.getSimpleName(), Date.class.getName());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@Autowired
|
||||
private CodeGenBaseTool baseTool;
|
||||
@Autowired
|
||||
private List<CodeGenerator> codeGen;
|
||||
@Autowired
|
||||
private CodeGenBaseTool baseTool;
|
||||
@Autowired
|
||||
private List<CodeGenerator> codeGen;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void process(String module, String model, List<?> columns, String table, GenForm form) {
|
||||
String minusJoinedModelName = WordUtils.convertCamelCase(model, "-").toLowerCase();
|
||||
String mappingUrl = minusJoinedModelName;
|
||||
String pkg = form.getPkg();
|
||||
if (StringUtils.isBlank(pkg)) {
|
||||
pkg = baseTool.getPkg();
|
||||
}
|
||||
if (StringUtils.isNotBlank(module)) {
|
||||
mappingUrl = module + "/" + mappingUrl;
|
||||
pkg += "." + module;
|
||||
}
|
||||
else {
|
||||
module = "";
|
||||
}
|
||||
String minusJoinedModelName = WordUtils.convertCamelCase(model, "-").toLowerCase();
|
||||
String mappingUrl = minusJoinedModelName;
|
||||
String pkg = form.getPkg();
|
||||
if (StringUtils.isBlank(pkg)) {
|
||||
pkg = baseTool.getPkg();
|
||||
}
|
||||
if (StringUtils.isNotBlank(module)) {
|
||||
mappingUrl = module + "/" + mappingUrl;
|
||||
pkg += "." + module;
|
||||
}
|
||||
else {
|
||||
module = "";
|
||||
}
|
||||
|
||||
model = StringUtils.capitalize(model);
|
||||
Map<String, Object> fmDataModel = new HashMap<String, Object>();
|
||||
fmDataModel.put("genController", form.isGenController());
|
||||
fmDataModel.put("genService", form.isGenService());
|
||||
fmDataModel.put("genMapper", form.isGenMapper());
|
||||
fmDataModel.put("genModel", form.isGenModel());
|
||||
fmDataModel.put("genTable", form.isGenTable());
|
||||
fmDataModel.put("genView", form.isGenView());
|
||||
fmDataModel.put("createTable", form.isCreateTable());
|
||||
model = StringUtils.capitalize(model);
|
||||
Map<String, Object> fmDataModel = new HashMap<String, Object>();
|
||||
fmDataModel.put("genController", form.isGenController());
|
||||
fmDataModel.put("genService", form.isGenService());
|
||||
fmDataModel.put("genMapper", form.isGenMapper());
|
||||
fmDataModel.put("genModel", form.isGenModel());
|
||||
fmDataModel.put("genTable", form.isGenTable());
|
||||
fmDataModel.put("genView", form.isGenView());
|
||||
fmDataModel.put("createTable", form.isCreateTable());
|
||||
|
||||
fmDataModel.put("table", table.toLowerCase());
|
||||
fmDataModel.put("notNull", false);
|
||||
fmDataModel.put("notBlank", false);
|
||||
fmDataModel.put("cacheEnabled", baseTool.getConfig("cache.enabled", false));
|
||||
fmDataModel.put("useGeneratedKeys", false);
|
||||
fmDataModel.put("table", table.toLowerCase());
|
||||
fmDataModel.put("notNull", false);
|
||||
fmDataModel.put("notBlank", false);
|
||||
fmDataModel.put("cacheEnabled", baseTool.getConfig("cache.enabled", false));
|
||||
fmDataModel.put("useGeneratedKeys", false);
|
||||
|
||||
// collect col names
|
||||
String idType = null;
|
||||
List<String> colNames = new ArrayList<String>(columns.size());
|
||||
for (Map<String, Object> col : (List<Map<String, Object>>) columns) {
|
||||
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 baseModelName = null;
|
||||
String baseModelFullName = null;
|
||||
Collection<String> baseCols = null;
|
||||
if (colNames.containsAll(new M3<String, String>().cols())) {
|
||||
baseModelName = M3.class.getSimpleName() +
|
||||
"<" + idType + ", " + idType + ">";
|
||||
baseModelFullName = M3.class.getName();
|
||||
baseCols = new M3<String, String>().cols();
|
||||
}
|
||||
else if (colNames.containsAll(new M2<String>().cols())) {
|
||||
baseModelName = M2.class.getSimpleName() + "<" + idType + ">";
|
||||
baseModelFullName = M2.class.getName();
|
||||
baseCols = new M2<String>().cols();
|
||||
}
|
||||
else if (colNames.containsAll(new M1<String>().cols())) {
|
||||
baseModelName = M1.class.getSimpleName() + "<" + idType + ">";
|
||||
baseModelFullName = M1.class.getName();
|
||||
baseCols = new M1<String>().cols();
|
||||
}
|
||||
else {
|
||||
baseModelName = M0.class.getSimpleName();
|
||||
baseModelFullName = M0.class.getName();
|
||||
baseCols = new M0<String>().cols();
|
||||
}
|
||||
// custom config
|
||||
String cfgBaseModelName = baseTool.getConfig("super.base.model.name");
|
||||
if (StringUtils.isNotBlank(cfgBaseModelName)) {
|
||||
baseCols = baseTool.getBaseCols();
|
||||
}
|
||||
// collect col names
|
||||
String idType = null;
|
||||
List<String> colNames = new ArrayList<String>(columns.size());
|
||||
for (Map<String, Object> col : (List<Map<String, Object>>) columns) {
|
||||
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 baseModelName = null;
|
||||
String baseModelFullName = null;
|
||||
Collection<String> baseCols = null;
|
||||
if (colNames.containsAll(new M3<String, String>().cols())) {
|
||||
baseModelName = M3.class.getSimpleName() +
|
||||
"<" + idType + ", " + idType + ">";
|
||||
baseModelFullName = M3.class.getName();
|
||||
baseCols = new M3<String, String>().cols();
|
||||
}
|
||||
else if (colNames.containsAll(new M2<String>().cols())) {
|
||||
baseModelName = M2.class.getSimpleName() + "<" + idType + ">";
|
||||
baseModelFullName = M2.class.getName();
|
||||
baseCols = new M2<String>().cols();
|
||||
}
|
||||
else if (colNames.containsAll(new M1<String>().cols())) {
|
||||
baseModelName = M1.class.getSimpleName() + "<" + idType + ">";
|
||||
baseModelFullName = M1.class.getName();
|
||||
baseCols = new M1<String>().cols();
|
||||
}
|
||||
else {
|
||||
baseModelName = M0.class.getSimpleName();
|
||||
baseModelFullName = M0.class.getName();
|
||||
baseCols = new M0<String>().cols();
|
||||
}
|
||||
// custom config
|
||||
String cfgBaseModelName = baseTool.getConfig("super.base.model.name");
|
||||
if (StringUtils.isNotBlank(cfgBaseModelName)) {
|
||||
baseCols = baseTool.getBaseCols();
|
||||
}
|
||||
|
||||
String cfgBaseModelFullName =
|
||||
baseTool.getConfig("super.base.model.full.name");
|
||||
String cfgBaseModelFullName =
|
||||
baseTool.getConfig("super.base.model.full.name");
|
||||
|
||||
fmDataModel.put("baseModelName",
|
||||
baseTool.getConfig("super.base.model.name", 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("baseModelFullName",
|
||||
"NONE".equalsIgnoreCase(cfgBaseModelFullName) ? null :
|
||||
StringUtils.isNotBlank(cfgBaseModelFullName) ?
|
||||
cfgBaseModelFullName : baseModelFullName);
|
||||
|
||||
fmDataModel.put("tableAnnotationClassName", Table.class.getName());
|
||||
fmDataModel.put("tableAnnotationName", Table.class.getSimpleName());
|
||||
fmDataModel.put("tableAnnotationClassName", Table.class.getName());
|
||||
fmDataModel.put("tableAnnotationName", Table.class.getSimpleName());
|
||||
|
||||
Set<String> imports = new HashSet<String>();
|
||||
Set<String> imports = new HashSet<String>();
|
||||
List<Map<String, Object>> colsWithoutBase =
|
||||
(List<Map<String, Object>>) columns;
|
||||
Iterator<Map<String, Object>> colIt =
|
||||
colsWithoutBase.iterator();
|
||||
(List<Map<String, Object>>) columns;
|
||||
Iterator<Map<String, Object>> colIt =
|
||||
colsWithoutBase.iterator();
|
||||
|
||||
while (colIt.hasNext()) {
|
||||
Map<String, Object> col = colIt.next();
|
||||
// col name
|
||||
String colName = ((String) col.get("col")).toLowerCase();
|
||||
if (!baseCols.contains(colName)) {
|
||||
// prop name
|
||||
String propName = (String) col.get("name");
|
||||
// for setName
|
||||
col.put("Name", StringUtils.capitalize(propName));
|
||||
if ((Boolean) col.get("notNull")) {
|
||||
if ("String".equals(col.get("javaType"))) {
|
||||
fmDataModel.put("notBlank", true);
|
||||
}
|
||||
else {
|
||||
fmDataModel.put("notNull", true);
|
||||
}
|
||||
}
|
||||
// imports
|
||||
String p = TYPE_PACKAGES.get(col.get("javaType"));
|
||||
if (StringUtils.isNotBlank(p)) {
|
||||
imports.add(p);
|
||||
}
|
||||
}
|
||||
// remove base col
|
||||
else {
|
||||
colIt.remove();
|
||||
}
|
||||
while (colIt.hasNext()) {
|
||||
Map<String, Object> col = colIt.next();
|
||||
// col name
|
||||
String colName = ((String) col.get("col")).toLowerCase();
|
||||
if (!baseCols.contains(colName)) {
|
||||
// prop name
|
||||
String propName = (String) col.get("name");
|
||||
// for setName
|
||||
col.put("Name", StringUtils.capitalize(propName));
|
||||
if ((Boolean) col.get("notNull")) {
|
||||
if ("String".equals(col.get("javaType"))) {
|
||||
fmDataModel.put("notBlank", true);
|
||||
}
|
||||
else {
|
||||
fmDataModel.put("notNull", true);
|
||||
}
|
||||
}
|
||||
// imports
|
||||
String p = TYPE_PACKAGES.get(col.get("javaType"));
|
||||
if (StringUtils.isNotBlank(p)) {
|
||||
imports.add(p);
|
||||
}
|
||||
}
|
||||
// remove base col
|
||||
else {
|
||||
colIt.remove();
|
||||
}
|
||||
}
|
||||
|
||||
fmDataModel.put("idType", idType);
|
||||
fmDataModel.put("cols", colsWithoutBase);
|
||||
fmDataModel.put("imports", imports);
|
||||
fmDataModel.put("url", mappingUrl);
|
||||
fmDataModel.put("pkg", pkg);
|
||||
fmDataModel.put("pkgDir", pkg.replace('.', '/'));
|
||||
fmDataModel.put("modelFullName", pkg + "." + model);
|
||||
fmDataModel.put("module", module);
|
||||
fmDataModel.put("ModelName", model);
|
||||
fmDataModel.put("modelName", StringUtils.uncapitalize(model));
|
||||
fmDataModel.put("minusJoinedModelName", minusJoinedModelName);
|
||||
/*
|
||||
// super classes name
|
||||
fmDataModel.put("baseControllerName", BaseController.class.getSimpleName());
|
||||
fmDataModel.put("baseControllerFullName", BaseController.class.getName());
|
||||
*/
|
||||
fmDataModel.put("idType", idType);
|
||||
fmDataModel.put("cols", colsWithoutBase);
|
||||
fmDataModel.put("imports", imports);
|
||||
fmDataModel.put("url", mappingUrl);
|
||||
fmDataModel.put("pkg", pkg);
|
||||
fmDataModel.put("pkgDir", pkg.replace('.', '/'));
|
||||
fmDataModel.put("modelFullName", pkg + "." + model);
|
||||
fmDataModel.put("module", module);
|
||||
fmDataModel.put("ModelName", model);
|
||||
fmDataModel.put("modelName", StringUtils.uncapitalize(model));
|
||||
fmDataModel.put("minusJoinedModelName", minusJoinedModelName);
|
||||
/*
|
||||
// super classes name
|
||||
fmDataModel.put("baseControllerName", BaseController.class.getSimpleName());
|
||||
fmDataModel.put("baseControllerFullName", BaseController.class.getName());
|
||||
*/
|
||||
|
||||
// service interface
|
||||
fmDataModel.put("baseServiceName", BaseCrudService.class.getSimpleName());
|
||||
fmDataModel.put("baseServiceFullName", BaseService.class.getName());
|
||||
// server support
|
||||
fmDataModel.put("baseServiceSupportName", BaseCrudServiceSupport.class.getSimpleName());
|
||||
fmDataModel.put("baseServiceSupportFullName", BaseCrudServiceSupport.class.getName());
|
||||
// service interface
|
||||
fmDataModel.put("baseServiceName", BaseCrudService.class.getSimpleName());
|
||||
fmDataModel.put("baseServiceFullName", BaseService.class.getName());
|
||||
// server support
|
||||
fmDataModel.put("baseServiceSupportName", BaseCrudServiceSupport.class.getSimpleName());
|
||||
fmDataModel.put("baseServiceSupportFullName", BaseCrudServiceSupport.class.getName());
|
||||
|
||||
// model
|
||||
//
|
||||
// mapper
|
||||
fmDataModel.put("baseMapperName", BaseMapper.class.getSimpleName());
|
||||
fmDataModel.put("baseMapperFullName", BaseMapper.class.getName());
|
||||
// model
|
||||
//
|
||||
// mapper
|
||||
fmDataModel.put("baseMapperName", BaseMapper.class.getSimpleName());
|
||||
fmDataModel.put("baseMapperFullName", BaseMapper.class.getName());
|
||||
|
||||
// fmDataModel.put("mockMapperName", MockMapper.class.getSimpleName());
|
||||
// fmDataModel.put("mockMapperFullName", MockMapper.class.getName());
|
||||
// fmDataModel.put("mockName", Mock.class.getSimpleName());
|
||||
// fmDataModel.put("mockFullName", Mock.class.getName());
|
||||
// fmDataModel.put("mockMapperName", MockMapper.class.getSimpleName());
|
||||
// fmDataModel.put("mockMapperFullName", MockMapper.class.getName());
|
||||
// fmDataModel.put("mockName", Mock.class.getSimpleName());
|
||||
// fmDataModel.put("mockFullName", Mock.class.getName());
|
||||
|
||||
fmDataModel.put("ctrlrTestToolName", ControllerTestTool.class.getSimpleName());
|
||||
fmDataModel.put("ctrlrTestToolFullName", ControllerTestTool.class.getName());
|
||||
// Object Doc
|
||||
Map<String, Object> objDocModel = new HashMap<String, Object>();
|
||||
// time now
|
||||
objDocModel.put("now",
|
||||
DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
|
||||
DateFormat.DEFAULT, Locale.US).format(new Date()));
|
||||
// code doc
|
||||
fmDataModel.put("objDoc",
|
||||
baseTool.renderFtl("/codegen/obj-doc.ftl", objDocModel));
|
||||
List<String> files = new LinkedList<String>();
|
||||
for (CodeGenerator gen : codeGen) {
|
||||
if (gen.accept(fmDataModel)) {
|
||||
String genResult = gen.process(fmDataModel, module, model);
|
||||
if (StringUtils.isNotBlank(genResult)) {
|
||||
files.addAll(Arrays.asList(genResult.split(";")));
|
||||
}
|
||||
}
|
||||
fmDataModel.put("ctrlrTestToolName", ControllerTestTool.class.getSimpleName());
|
||||
fmDataModel.put("ctrlrTestToolFullName", ControllerTestTool.class.getName());
|
||||
// Object Doc
|
||||
Map<String, Object> objDocModel = new HashMap<String, Object>();
|
||||
// time now
|
||||
objDocModel.put("now",
|
||||
DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
|
||||
DateFormat.DEFAULT, Locale.US).format(new Date()));
|
||||
// code doc
|
||||
fmDataModel.put("objDoc",
|
||||
baseTool.renderFtl("/codegen/obj-doc.ftl", objDocModel));
|
||||
List<String> files = new LinkedList<String>();
|
||||
for (CodeGenerator gen : codeGen) {
|
||||
if (gen.accept(fmDataModel)) {
|
||||
String genResult = gen.process(fmDataModel, module, model);
|
||||
if (StringUtils.isNotBlank(genResult)) {
|
||||
files.addAll(Arrays.asList(genResult.split(";")));
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("Save Code Generated Data, Module [{}], Model [{}].", module, model);
|
||||
Map<String, Object> mapRec = new HashMap<String, Object>();
|
||||
mapRec.put("cols", columns);
|
||||
mapRec.put("module", module);
|
||||
mapRec.put("model", model);
|
||||
mapRec.put("files", files);
|
||||
mapRec.put("table", table);
|
||||
baseTool.saveRecord(mapRec);
|
||||
log.info("Save Code Generated Data, Module [{}], Model [{}].", module, model);
|
||||
Map<String, Object> mapRec = new HashMap<String, Object>();
|
||||
mapRec.put("cols", columns);
|
||||
mapRec.put("module", module);
|
||||
mapRec.put("model", model);
|
||||
mapRec.put("files", files);
|
||||
mapRec.put("table", table);
|
||||
baseTool.saveRecord(mapRec);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<?> list() {
|
||||
List<Map<String, Object>> items = baseTool.listAll();
|
||||
for (Map<String, Object> item : items) {
|
||||
String text = (String) item.get("model");
|
||||
String module = (String) item.get("module");
|
||||
if (StringUtils.isNotBlank(module)) {
|
||||
text = module + "/" + text;
|
||||
}
|
||||
item.put("text", text);
|
||||
item.put("checked", false);
|
||||
item.put("leaf", true);
|
||||
item.remove("files");
|
||||
}
|
||||
return items;
|
||||
}
|
||||
@Override
|
||||
public List<?> list() {
|
||||
List<Map<String, Object>> items = baseTool.listAll();
|
||||
for (Map<String, Object> item : items) {
|
||||
String text = (String) item.get("model");
|
||||
String module = (String) item.get("module");
|
||||
if (StringUtils.isNotBlank(module)) {
|
||||
text = module + "/" + text;
|
||||
}
|
||||
item.put("text", text);
|
||||
item.put("checked", false);
|
||||
item.put("leaf", true);
|
||||
item.remove("files");
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void delete(List<?> items, boolean dropTable) {
|
||||
for (Map<String, Object> item : (List<Map<String, Object>>) items) {
|
||||
baseTool.deleteRec((String) item.get("module"), (String) item.get("model"), dropTable);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void delete(List<?> items, boolean dropTable) {
|
||||
for (Map<String, Object> item : (List<Map<String, Object>>) items) {
|
||||
baseTool.deleteRec((String) item.get("module"), (String) item.get("model"), dropTable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> tables() {
|
||||
return baseTool.tables();
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> tables() {
|
||||
return baseTool.tables();
|
||||
}
|
||||
}
|
||||
|
@ -13,25 +13,25 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
|
||||
*/
|
||||
public class ControllerCodeGen extends CodeGenerator {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return (Boolean) dataModel.get("genController");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String process(Map<String, Object> dataModel, String module, String model) {
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_CONTROLLER,
|
||||
"/codegen/controller.ftl",
|
||||
dataModel,
|
||||
codeDir + dataModel.get("pkgDir") +
|
||||
"/controller/" +
|
||||
model + "Controller.java"));
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return (Boolean) dataModel.get("genController");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String process(Map<String, Object> dataModel, String module, String model) {
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_CONTROLLER,
|
||||
"/codegen/controller.ftl",
|
||||
dataModel,
|
||||
codeDir + dataModel.get("pkgDir") +
|
||||
"/controller/" +
|
||||
model + "Controller.java"));
|
||||
}
|
||||
}
|
||||
|
@ -12,16 +12,16 @@ import me.chyxion.tigon.codegen.model.CodeGenArgs;
|
||||
*/
|
||||
public class ControllerTestCodeGen extends ControllerCodeGen {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String process(Map<String, Object> dataModel, String module, String model) {
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_CONTROLLER_TEST,
|
||||
"/codegen/controller-test.ftl",
|
||||
dataModel,
|
||||
testDir + dataModel.get("pkgDir") +
|
||||
"/controller/" + model + "ControllerTest.java"));
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_CONTROLLER_TEST,
|
||||
"/codegen/controller-test.ftl",
|
||||
dataModel,
|
||||
testDir + dataModel.get("pkgDir") +
|
||||
"/controller/" + model + "ControllerTest.java"));
|
||||
}
|
||||
}
|
||||
|
@ -13,24 +13,24 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
|
||||
*/
|
||||
public class MapperCodeGen extends CodeGenerator {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return (Boolean) dataModel.get("genMapper");
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return (Boolean) dataModel.get("genMapper");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String process(Map<String, Object> dataModel, String module, String model) {
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_MAPPER,
|
||||
"/codegen/mapper.ftl",
|
||||
dataModel,
|
||||
codeDir + dataModel.get("pkgDir") +
|
||||
"/mapper/" + model + "Mapper.java"));
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_MAPPER,
|
||||
"/codegen/mapper.ftl",
|
||||
dataModel,
|
||||
codeDir + dataModel.get("pkgDir") +
|
||||
"/mapper/" + model + "Mapper.java"));
|
||||
}
|
||||
}
|
||||
|
@ -12,16 +12,16 @@ import me.chyxion.tigon.codegen.model.CodeGenArgs;
|
||||
*/
|
||||
public class MapperTestCodeGen extends MapperCodeGen {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String process(Map<String, Object> dataModel, String module, String model) {
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_MAPPER_TEST,
|
||||
"/codegen/mapper-test.ftl",
|
||||
dataModel,
|
||||
testDir + dataModel.get("pkgDir") +
|
||||
"/mapper/" + model + "MapperTest.java"));
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_MAPPER_TEST,
|
||||
"/codegen/mapper-test.ftl",
|
||||
dataModel,
|
||||
testDir + dataModel.get("pkgDir") +
|
||||
"/mapper/" + model + "MapperTest.java"));
|
||||
}
|
||||
}
|
||||
|
@ -13,23 +13,23 @@ import me.chyxion.tigon.codegen.model.CodeGenArgs;
|
||||
*/
|
||||
public class MapperXmlCodeGen extends MapperCodeGen {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String process(Map<String, Object> dataModel,
|
||||
String module, String model) {
|
||||
StringBuilder sbFilePath = new StringBuilder(resourcesDir)
|
||||
.append("mybatis/mappers/");
|
||||
if (StringUtils.isNotBlank(module)) {
|
||||
sbFilePath.append(module).append("/");
|
||||
}
|
||||
sbFilePath.append(dataModel.get("minusJoinedModelName")).append("-mapper.xml");
|
||||
public String process(Map<String, Object> dataModel,
|
||||
String module, String model) {
|
||||
StringBuilder sbFilePath = new StringBuilder(resourcesDir)
|
||||
.append("mybatis/mappers/");
|
||||
if (StringUtils.isNotBlank(module)) {
|
||||
sbFilePath.append(module).append("/");
|
||||
}
|
||||
sbFilePath.append(dataModel.get("minusJoinedModelName")).append("-mapper.xml");
|
||||
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_MAPPER_XML,
|
||||
"/codegen/mapper-xml.ftl",
|
||||
dataModel,
|
||||
sbFilePath.toString()));
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_MAPPER_XML,
|
||||
"/codegen/mapper-xml.ftl",
|
||||
dataModel,
|
||||
sbFilePath.toString()));
|
||||
}
|
||||
}
|
||||
|
@ -13,24 +13,24 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
|
||||
*/
|
||||
public class ModelCodeGen extends CodeGenerator {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return (Boolean) dataModel.get("genModel");
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return (Boolean) dataModel.get("genModel");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String process(Map<String, Object> dataModel, String module, String model) {
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_MODEL,
|
||||
"/codegen/model.ftl",
|
||||
dataModel,
|
||||
codeDir + dataModel.get("pkgDir") +
|
||||
"/model/" + model + ".java"));
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_MODEL,
|
||||
"/codegen/model.ftl",
|
||||
dataModel,
|
||||
codeDir + dataModel.get("pkgDir") +
|
||||
"/model/" + model + ".java"));
|
||||
}
|
||||
}
|
||||
|
@ -13,37 +13,37 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
|
||||
*/
|
||||
public class ServiceCodeGen extends CodeGenerator {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return (Boolean) dataModel.get("genService");
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return (Boolean) dataModel.get("genService");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String process(Map<String, Object> dataModel, String module, String model) {
|
||||
String pkgDir = (String) dataModel.get("pkgDir");
|
||||
// interface
|
||||
String strRtn = render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_SERVICE,
|
||||
"/codegen/service.ftl",
|
||||
dataModel,
|
||||
codeDir + pkgDir +
|
||||
"/service/" + model + "Service.java"));
|
||||
|
||||
// support
|
||||
strRtn +=";";
|
||||
strRtn += render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_SERVICE_SUPPORT,
|
||||
"/codegen/service-support.ftl",
|
||||
dataModel,
|
||||
codeDir + pkgDir +
|
||||
"/service/support/" + model + "ServiceSupport.java"
|
||||
));
|
||||
return strRtn;
|
||||
String pkgDir = (String) dataModel.get("pkgDir");
|
||||
// interface
|
||||
String strRtn = render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_SERVICE,
|
||||
"/codegen/service.ftl",
|
||||
dataModel,
|
||||
codeDir + pkgDir +
|
||||
"/service/" + model + "Service.java"));
|
||||
|
||||
// support
|
||||
strRtn +=";";
|
||||
strRtn += render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_SERVICE_SUPPORT,
|
||||
"/codegen/service-support.ftl",
|
||||
dataModel,
|
||||
codeDir + pkgDir +
|
||||
"/service/support/" + model + "ServiceSupport.java"
|
||||
));
|
||||
return strRtn;
|
||||
}
|
||||
}
|
||||
|
@ -19,55 +19,55 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
|
||||
*/
|
||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||
public class TableCodeGen extends CodeGenerator {
|
||||
private static final Logger log = LoggerFactory.getLogger(TableCodeGen.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(TableCodeGen.class);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return (Boolean) dataModel.get("genTable");
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return (Boolean) dataModel.get("genTable");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String process(Map<String, Object> dataModel, String module, String model) {
|
||||
String table = (String) dataModel.get("table");
|
||||
log.info("Process Generate Table [{}] SQL File.", table);
|
||||
StringBuilder filePath = new StringBuilder(resourcesDir)
|
||||
.append("db/");
|
||||
if (StringUtils.isNotBlank(module)) {
|
||||
filePath.append(module).append("/");
|
||||
}
|
||||
filePath.append(table).append(".sql");
|
||||
render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_TABLE,
|
||||
"/codegen/table.ftl",
|
||||
dataModel,
|
||||
filePath.toString()));
|
||||
|
||||
if (!Boolean.FALSE.equals(dataModel.get("createTable"))) {
|
||||
// ignore drop table error
|
||||
try {
|
||||
log.info("Execute Drop Table [{}].", table);
|
||||
baseTool.execSQL("drop table " + table);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.info("Drop Table Failed, Error Message [{}], Ingore.",
|
||||
e.getMessage());
|
||||
}
|
||||
// ignore execute sql error
|
||||
try {
|
||||
log.info("Execut Create Table SQL File [{}].", filePath);
|
||||
baseTool.execSQL(new File(baseTool.getProjDir(), filePath
|
||||
.toString()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warn("Database Create Table Error, Ingore.", e);
|
||||
}
|
||||
}
|
||||
return filePath.toString();
|
||||
String table = (String) dataModel.get("table");
|
||||
log.info("Process Generate Table [{}] SQL File.", table);
|
||||
StringBuilder filePath = new StringBuilder(resourcesDir)
|
||||
.append("db/");
|
||||
if (StringUtils.isNotBlank(module)) {
|
||||
filePath.append(module).append("/");
|
||||
}
|
||||
filePath.append(table).append(".sql");
|
||||
render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_TABLE,
|
||||
"/codegen/table.ftl",
|
||||
dataModel,
|
||||
filePath.toString()));
|
||||
|
||||
if (!Boolean.FALSE.equals(dataModel.get("createTable"))) {
|
||||
// ignore drop table error
|
||||
try {
|
||||
log.info("Execute Drop Table [{}].", table);
|
||||
baseTool.execSQL("drop table " + table);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.info("Drop Table Failed, Error Message [{}], Ingore.",
|
||||
e.getMessage());
|
||||
}
|
||||
// ignore execute sql error
|
||||
try {
|
||||
log.info("Execut Create Table SQL File [{}].", filePath);
|
||||
baseTool.execSQL(new File(baseTool.getProjDir(), filePath
|
||||
.toString()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warn("Database Create Table Error, Ingore.", e);
|
||||
}
|
||||
}
|
||||
return filePath.toString();
|
||||
}
|
||||
}
|
||||
|
@ -14,28 +14,28 @@ import me.chyxion.tigon.codegen.service.CodeGenerator;
|
||||
*/
|
||||
public class ViewCodeGen extends CodeGenerator {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return (Boolean) dataModel.get("genView");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(Map<String, Object> dataModel) {
|
||||
return (Boolean) dataModel.get("genView");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String process(Map<String, Object> dataModel, String module, String model) {
|
||||
StringBuilder sbFilePath = new StringBuilder(viewsDir);
|
||||
if (StringUtils.isNotBlank(module)) {
|
||||
sbFilePath.append(module).append("/");
|
||||
}
|
||||
sbFilePath.append(model).append("/List.js");
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_VIEW,
|
||||
"/codegen/view.ftl",
|
||||
dataModel,
|
||||
sbFilePath.toString()));
|
||||
StringBuilder sbFilePath = new StringBuilder(viewsDir);
|
||||
if (StringUtils.isNotBlank(module)) {
|
||||
sbFilePath.append(module).append("/");
|
||||
}
|
||||
sbFilePath.append(model).append("/List.js");
|
||||
return render(new CodeGenArgs(
|
||||
CodeGenArgs.TARGET_VIEW,
|
||||
"/codegen/view.ftl",
|
||||
dataModel,
|
||||
sbFilePath.toString()));
|
||||
}
|
||||
}
|
||||
|
@ -21,253 +21,253 @@ import org.springframework.util.StringUtils;
|
||||
* Oct 30, 2014 5:08:25 PM
|
||||
*/
|
||||
public class DbTool {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DbTool.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(DbTool.class);
|
||||
|
||||
private static final String DEFAULT_COMMENT_PREFIX = "--";
|
||||
private static final String DEFAULT_COMMENT_PREFIX = "--";
|
||||
|
||||
private static final char DEFAULT_STATEMENT_SEPARATOR = ';';
|
||||
private static final char DEFAULT_STATEMENT_SEPARATOR = ';';
|
||||
|
||||
/**
|
||||
* Execute the given SQL script.
|
||||
* <p>The script will typically be loaded from the classpath. Statements
|
||||
* should be delimited with a semicolon. If statements are not delimited with
|
||||
* a semicolon then there should be one statement per line. Statements are
|
||||
* allowed to span lines only if they are delimited with a semicolon. Any
|
||||
* line comments will be removed.
|
||||
* <p><b>Do not use this method to execute DDL if you expect rollback.</b>
|
||||
* @param jdbcTemplate the JdbcTemplate with which to perform JDBC operations
|
||||
* @param resource the resource to load the SQL script from
|
||||
* @param continueOnError whether or not to continue without throwing an
|
||||
* exception in the event of an error
|
||||
* @throws DataAccessException if there is an error executing a statement
|
||||
* and {@code continueOnError} is {@code false}
|
||||
* @see ResourceDatabasePopulator
|
||||
* @see #executeSqlScript(JdbcTemplate, EncodedResource, boolean)
|
||||
*/
|
||||
public static void executeSqlScript(JdbcTemplate jdbcTemplate, Resource resource, boolean continueOnError)
|
||||
throws DataAccessException {
|
||||
executeSqlScript(jdbcTemplate, new EncodedResource(resource), continueOnError);
|
||||
}
|
||||
/**
|
||||
* Execute the given SQL script.
|
||||
* <p>The script will typically be loaded from the classpath. Statements
|
||||
* should be delimited with a semicolon. If statements are not delimited with
|
||||
* a semicolon then there should be one statement per line. Statements are
|
||||
* allowed to span lines only if they are delimited with a semicolon. Any
|
||||
* line comments will be removed.
|
||||
* <p><b>Do not use this method to execute DDL if you expect rollback.</b>
|
||||
* @param jdbcTemplate the JdbcTemplate with which to perform JDBC operations
|
||||
* @param resource the resource to load the SQL script from
|
||||
* @param continueOnError whether or not to continue without throwing an
|
||||
* exception in the event of an error
|
||||
* @throws DataAccessException if there is an error executing a statement
|
||||
* and {@code continueOnError} is {@code false}
|
||||
* @see ResourceDatabasePopulator
|
||||
* @see #executeSqlScript(JdbcTemplate, EncodedResource, boolean)
|
||||
*/
|
||||
public static void executeSqlScript(JdbcTemplate jdbcTemplate, Resource resource, boolean continueOnError)
|
||||
throws DataAccessException {
|
||||
executeSqlScript(jdbcTemplate, new EncodedResource(resource), continueOnError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the given SQL script.
|
||||
* <p>The script will typically be loaded from the classpath. There should
|
||||
* be one statement per line. Any semicolons and line comments will be removed.
|
||||
* <p><b>Do not use this method to execute DDL if you expect rollback.</b>
|
||||
* @param jdbcTemplate the JdbcTemplate with which to perform JDBC operations
|
||||
* @param resource the resource (potentially associated with a specific encoding)
|
||||
* to load the SQL script from
|
||||
* @param continueOnError whether or not to continue without throwing an
|
||||
* exception in the event of an error
|
||||
* @throws DataAccessException if there is an error executing a statement
|
||||
* and {@code continueOnError} is {@code false}
|
||||
* @see ResourceDatabasePopulator
|
||||
*/
|
||||
public static void executeSqlScript(JdbcTemplate jdbcTemplate, EncodedResource resource, boolean continueOnError)
|
||||
throws DataAccessException {
|
||||
/**
|
||||
* Execute the given SQL script.
|
||||
* <p>The script will typically be loaded from the classpath. There should
|
||||
* be one statement per line. Any semicolons and line comments will be removed.
|
||||
* <p><b>Do not use this method to execute DDL if you expect rollback.</b>
|
||||
* @param jdbcTemplate the JdbcTemplate with which to perform JDBC operations
|
||||
* @param resource the resource (potentially associated with a specific encoding)
|
||||
* to load the SQL script from
|
||||
* @param continueOnError whether or not to continue without throwing an
|
||||
* exception in the event of an error
|
||||
* @throws DataAccessException if there is an error executing a statement
|
||||
* and {@code continueOnError} is {@code false}
|
||||
* @see ResourceDatabasePopulator
|
||||
*/
|
||||
public static void executeSqlScript(JdbcTemplate jdbcTemplate, EncodedResource resource, boolean continueOnError)
|
||||
throws DataAccessException {
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Executing SQL script from " + resource);
|
||||
}
|
||||
long startTime = System.currentTimeMillis();
|
||||
List<String> statements = new LinkedList<String>();
|
||||
LineNumberReader reader = null;
|
||||
try {
|
||||
reader = new LineNumberReader(resource.getReader());
|
||||
String script = readScript(reader);
|
||||
char delimiter = DEFAULT_STATEMENT_SEPARATOR;
|
||||
if (!containsSqlScriptDelimiters(script, delimiter)) {
|
||||
delimiter = '\n';
|
||||
}
|
||||
splitSqlScript(script, delimiter, statements);
|
||||
int lineNumber = 0;
|
||||
for (String statement : statements) {
|
||||
lineNumber++;
|
||||
try {
|
||||
int rowsAffected = jdbcTemplate.update(statement);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(rowsAffected + " rows affected by SQL: " + statement);
|
||||
}
|
||||
}
|
||||
catch (DataAccessException ex) {
|
||||
if (continueOnError) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to execute SQL script statement at line " + lineNumber
|
||||
+ " of resource " + resource + ": " + statement, ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
long elapsedTime = System.currentTimeMillis() - startTime;
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info(String.format("Executed SQL script from %s in %s ms.", resource, elapsedTime));
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new DataAccessResourceFailureException("Failed to open SQL script from " + resource, ex);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Executing SQL script from " + resource);
|
||||
}
|
||||
long startTime = System.currentTimeMillis();
|
||||
List<String> statements = new LinkedList<String>();
|
||||
LineNumberReader reader = null;
|
||||
try {
|
||||
reader = new LineNumberReader(resource.getReader());
|
||||
String script = readScript(reader);
|
||||
char delimiter = DEFAULT_STATEMENT_SEPARATOR;
|
||||
if (!containsSqlScriptDelimiters(script, delimiter)) {
|
||||
delimiter = '\n';
|
||||
}
|
||||
splitSqlScript(script, delimiter, statements);
|
||||
int lineNumber = 0;
|
||||
for (String statement : statements) {
|
||||
lineNumber++;
|
||||
try {
|
||||
int rowsAffected = jdbcTemplate.update(statement);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(rowsAffected + " rows affected by SQL: " + statement);
|
||||
}
|
||||
}
|
||||
catch (DataAccessException ex) {
|
||||
if (continueOnError) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to execute SQL script statement at line " + lineNumber
|
||||
+ " of resource " + resource + ": " + statement, ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
long elapsedTime = System.currentTimeMillis() - startTime;
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info(String.format("Executed SQL script from %s in %s ms.", resource, elapsedTime));
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new DataAccessResourceFailureException("Failed to open SQL script from " + resource, ex);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a script from the provided {@code LineNumberReader}, using
|
||||
* "{@code --}" as the comment prefix, and build a {@code String} containing
|
||||
* the lines.
|
||||
* @param lineNumberReader the {@code LineNumberReader} containing the script
|
||||
* to be processed
|
||||
* @return a {@code String} containing the script lines
|
||||
* @see #readScript(LineNumberReader, String)
|
||||
*/
|
||||
public static String readScript(LineNumberReader lineNumberReader) throws IOException {
|
||||
return readScript(lineNumberReader, DEFAULT_COMMENT_PREFIX);
|
||||
}
|
||||
/**
|
||||
* Read a script from the provided {@code LineNumberReader}, using
|
||||
* "{@code --}" as the comment prefix, and build a {@code String} containing
|
||||
* the lines.
|
||||
* @param lineNumberReader the {@code LineNumberReader} containing the script
|
||||
* to be processed
|
||||
* @return a {@code String} containing the script lines
|
||||
* @see #readScript(LineNumberReader, String)
|
||||
*/
|
||||
public static String readScript(LineNumberReader lineNumberReader) throws IOException {
|
||||
return readScript(lineNumberReader, DEFAULT_COMMENT_PREFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a script from the provided {@code LineNumberReader}, using the supplied
|
||||
* comment prefix, and build a {@code String} containing the lines.
|
||||
* <p>Lines <em>beginning</em> with the comment prefix are excluded from the
|
||||
* results; however, line comments anywhere else — for example, within
|
||||
* a statement — will be included in the results.
|
||||
* @param lineNumberReader the {@code LineNumberReader} containing the script
|
||||
* to be processed
|
||||
* @param commentPrefix the prefix that identifies comments in the SQL script — typically "--"
|
||||
* @return a {@code String} containing the script lines
|
||||
*/
|
||||
public static String readScript(LineNumberReader lineNumberReader, String commentPrefix) throws IOException {
|
||||
String currentStatement = lineNumberReader.readLine();
|
||||
StringBuilder scriptBuilder = new StringBuilder();
|
||||
while (currentStatement != null) {
|
||||
if (StringUtils.hasText(currentStatement)
|
||||
&& (commentPrefix != null && !currentStatement.startsWith(commentPrefix))) {
|
||||
if (scriptBuilder.length() > 0) {
|
||||
scriptBuilder.append('\n');
|
||||
}
|
||||
scriptBuilder.append(currentStatement);
|
||||
}
|
||||
currentStatement = lineNumberReader.readLine();
|
||||
}
|
||||
return scriptBuilder.toString();
|
||||
}
|
||||
/**
|
||||
* Read a script from the provided {@code LineNumberReader}, using the supplied
|
||||
* comment prefix, and build a {@code String} containing the lines.
|
||||
* <p>Lines <em>beginning</em> with the comment prefix are excluded from the
|
||||
* results; however, line comments anywhere else — for example, within
|
||||
* a statement — will be included in the results.
|
||||
* @param lineNumberReader the {@code LineNumberReader} containing the script
|
||||
* to be processed
|
||||
* @param commentPrefix the prefix that identifies comments in the SQL script — typically "--"
|
||||
* @return a {@code String} containing the script lines
|
||||
*/
|
||||
public static String readScript(LineNumberReader lineNumberReader, String commentPrefix) throws IOException {
|
||||
String currentStatement = lineNumberReader.readLine();
|
||||
StringBuilder scriptBuilder = new StringBuilder();
|
||||
while (currentStatement != null) {
|
||||
if (StringUtils.hasText(currentStatement)
|
||||
&& (commentPrefix != null && !currentStatement.startsWith(commentPrefix))) {
|
||||
if (scriptBuilder.length() > 0) {
|
||||
scriptBuilder.append('\n');
|
||||
}
|
||||
scriptBuilder.append(currentStatement);
|
||||
}
|
||||
currentStatement = lineNumberReader.readLine();
|
||||
}
|
||||
return scriptBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the provided SQL script contains the specified delimiter.
|
||||
* @param script the SQL script
|
||||
* @param delim character delimiting each statement — typically a ';' character
|
||||
* @return {@code true} if the script contains the delimiter; {@code false} otherwise
|
||||
*/
|
||||
public static boolean containsSqlScriptDelimiters(String script, char delim) {
|
||||
boolean inLiteral = false;
|
||||
char[] content = script.toCharArray();
|
||||
for (int i = 0; i < script.length(); i++) {
|
||||
if (content[i] == '\'') {
|
||||
inLiteral = !inLiteral;
|
||||
}
|
||||
if (content[i] == delim && !inLiteral) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Determine if the provided SQL script contains the specified delimiter.
|
||||
* @param script the SQL script
|
||||
* @param delim character delimiting each statement — typically a ';' character
|
||||
* @return {@code true} if the script contains the delimiter; {@code false} otherwise
|
||||
*/
|
||||
public static boolean containsSqlScriptDelimiters(String script, char delim) {
|
||||
boolean inLiteral = false;
|
||||
char[] content = script.toCharArray();
|
||||
for (int i = 0; i < script.length(); i++) {
|
||||
if (content[i] == '\'') {
|
||||
inLiteral = !inLiteral;
|
||||
}
|
||||
if (content[i] == delim && !inLiteral) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split an SQL script into separate statements delimited by the provided
|
||||
* delimiter character. Each individual statement will be added to the
|
||||
* provided {@code List}.
|
||||
* <p>Within a statement, "{@code --}" will be used as the comment prefix;
|
||||
* any text beginning with the comment prefix and extending to the end of
|
||||
* the line will be omitted from the statement. In addition, multiple adjacent
|
||||
* whitespace characters will be collapsed into a single space.
|
||||
* @param script the SQL script
|
||||
* @param delim character delimiting each statement — typically a ';' character
|
||||
* @param statements the list that will contain the individual statements
|
||||
*/
|
||||
public static void splitSqlScript(String script, char delim, List<String> statements) {
|
||||
splitSqlScript(script, "" + delim, DEFAULT_COMMENT_PREFIX, statements);
|
||||
}
|
||||
/**
|
||||
* Split an SQL script into separate statements delimited by the provided
|
||||
* delimiter character. Each individual statement will be added to the
|
||||
* provided {@code List}.
|
||||
* <p>Within a statement, "{@code --}" will be used as the comment prefix;
|
||||
* any text beginning with the comment prefix and extending to the end of
|
||||
* the line will be omitted from the statement. In addition, multiple adjacent
|
||||
* whitespace characters will be collapsed into a single space.
|
||||
* @param script the SQL script
|
||||
* @param delim character delimiting each statement — typically a ';' character
|
||||
* @param statements the list that will contain the individual statements
|
||||
*/
|
||||
public static void splitSqlScript(String script, char delim, List<String> statements) {
|
||||
splitSqlScript(script, "" + delim, DEFAULT_COMMENT_PREFIX, statements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split an SQL script into separate statements delimited by the provided
|
||||
* delimiter string. Each individual statement will be added to the provided
|
||||
* {@code List}.
|
||||
* <p>Within a statement, the provided {@code commentPrefix} will be honored;
|
||||
* any text beginning with the comment prefix and extending to the end of the
|
||||
* line will be omitted from the statement. In addition, multiple adjacent
|
||||
* whitespace characters will be collapsed into a single space.
|
||||
* @param script the SQL script
|
||||
* @param delim character delimiting each statement — typically a ';' character
|
||||
* @param commentPrefix the prefix that identifies line comments in the SQL script — typically "--"
|
||||
* @param statements the List that will contain the individual statements
|
||||
*/
|
||||
private static void splitSqlScript(String script, String delim, String commentPrefix, List<String> statements) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean inLiteral = false;
|
||||
boolean inEscape = false;
|
||||
char[] content = script.toCharArray();
|
||||
for (int i = 0; i < script.length(); i++) {
|
||||
char c = content[i];
|
||||
if (inEscape) {
|
||||
inEscape = false;
|
||||
sb.append(c);
|
||||
continue;
|
||||
}
|
||||
// MySQL style escapes
|
||||
if (c == '\\') {
|
||||
inEscape = true;
|
||||
sb.append(c);
|
||||
continue;
|
||||
}
|
||||
if (c == '\'') {
|
||||
inLiteral = !inLiteral;
|
||||
}
|
||||
if (!inLiteral) {
|
||||
if (script.startsWith(delim, i)) {
|
||||
// we've reached the end of the current statement
|
||||
if (sb.length() > 0) {
|
||||
statements.add(sb.toString());
|
||||
sb = new StringBuilder();
|
||||
}
|
||||
i += delim.length() - 1;
|
||||
continue;
|
||||
}
|
||||
else if (script.startsWith(commentPrefix, i)) {
|
||||
// skip over any content from the start of the comment to the EOL
|
||||
int indexOfNextNewline = script.indexOf("\n", i);
|
||||
if (indexOfNextNewline > i) {
|
||||
i = indexOfNextNewline;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// if there's no newline after the comment, we must be at the end
|
||||
// of the script, so stop here.
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (c == ' ' || c == '\n' || c == '\t') {
|
||||
// avoid multiple adjacent whitespace characters
|
||||
if (sb.length() > 0 && sb.charAt(sb.length() - 1) != ' ') {
|
||||
c = ' ';
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
if (StringUtils.hasText(sb)) {
|
||||
statements.add(sb.toString());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Split an SQL script into separate statements delimited by the provided
|
||||
* delimiter string. Each individual statement will be added to the provided
|
||||
* {@code List}.
|
||||
* <p>Within a statement, the provided {@code commentPrefix} will be honored;
|
||||
* any text beginning with the comment prefix and extending to the end of the
|
||||
* line will be omitted from the statement. In addition, multiple adjacent
|
||||
* whitespace characters will be collapsed into a single space.
|
||||
* @param script the SQL script
|
||||
* @param delim character delimiting each statement — typically a ';' character
|
||||
* @param commentPrefix the prefix that identifies line comments in the SQL script — typically "--"
|
||||
* @param statements the List that will contain the individual statements
|
||||
*/
|
||||
private static void splitSqlScript(String script, String delim, String commentPrefix, List<String> statements) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean inLiteral = false;
|
||||
boolean inEscape = false;
|
||||
char[] content = script.toCharArray();
|
||||
for (int i = 0; i < script.length(); i++) {
|
||||
char c = content[i];
|
||||
if (inEscape) {
|
||||
inEscape = false;
|
||||
sb.append(c);
|
||||
continue;
|
||||
}
|
||||
// MySQL style escapes
|
||||
if (c == '\\') {
|
||||
inEscape = true;
|
||||
sb.append(c);
|
||||
continue;
|
||||
}
|
||||
if (c == '\'') {
|
||||
inLiteral = !inLiteral;
|
||||
}
|
||||
if (!inLiteral) {
|
||||
if (script.startsWith(delim, i)) {
|
||||
// we've reached the end of the current statement
|
||||
if (sb.length() > 0) {
|
||||
statements.add(sb.toString());
|
||||
sb = new StringBuilder();
|
||||
}
|
||||
i += delim.length() - 1;
|
||||
continue;
|
||||
}
|
||||
else if (script.startsWith(commentPrefix, i)) {
|
||||
// skip over any content from the start of the comment to the EOL
|
||||
int indexOfNextNewline = script.indexOf("\n", i);
|
||||
if (indexOfNextNewline > i) {
|
||||
i = indexOfNextNewline;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// if there's no newline after the comment, we must be at the end
|
||||
// of the script, so stop here.
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (c == ' ' || c == '\n' || c == '\t') {
|
||||
// avoid multiple adjacent whitespace characters
|
||||
if (sb.length() > 0 && sb.charAt(sb.length() - 1) != ' ') {
|
||||
c = ' ';
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
if (StringUtils.hasText(sb)) {
|
||||
statements.add(sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,4 +5,4 @@
|
||||
* chyxion@163.com <br>
|
||||
* Oct 18, 2015 1:09:11 PM
|
||||
*/
|
||||
package me.chyxion.tigon.codegen.test;
|
||||
package me.chyxion.tigon.codegen.test;
|
||||
|
@ -9,95 +9,95 @@
|
||||
*/
|
||||
-->
|
||||
<!DOCTYPE mapper PUBLIC
|
||||
"-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
"-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.com.flaginfo.echat.mappers.TableTestMapper">
|
||||
|
||||
<resultMap id="modelMap" type="TableTest">
|
||||
<id column="id" property="id" />
|
||||
<id column="name" property="name" />
|
||||
<result column="date_created" property="dateCreated" />
|
||||
<result column="date_updated" property="dateUpdated" />
|
||||
<result column="type" property="type" />
|
||||
</resultMap>
|
||||
<resultMap id="modelMap" type="TableTest">
|
||||
<id column="id" property="id" />
|
||||
<id column="name" property="name" />
|
||||
<result column="date_created" property="dateCreated" />
|
||||
<result column="date_updated" property="dateUpdated" />
|
||||
<result column="type" property="type" />
|
||||
</resultMap>
|
||||
|
||||
<!-- variables -->
|
||||
<sql id="columns">
|
||||
id, name, date_created, date_updated
|
||||
</sql>
|
||||
<sql id="table">
|
||||
table_test
|
||||
</sql>
|
||||
<sql id="updateClause">
|
||||
<sql id="columns">
|
||||
id, name, date_created, date_updated
|
||||
</sql>
|
||||
<sql id="table">
|
||||
table_test
|
||||
</sql>
|
||||
<sql id="updateClause">
|
||||
update <include refid="table" />
|
||||
<set>
|
||||
<if test="model.name != null">
|
||||
name = #{model.name}
|
||||
</if>
|
||||
</set>
|
||||
</sql>
|
||||
</sql>
|
||||
<!-- /variables -->
|
||||
|
||||
<!-- methods -->
|
||||
<!-- Insert Models -->
|
||||
<insert id="insert">
|
||||
<insert id="insert">
|
||||
insert into <include refid="table" />
|
||||
(<include refid="columns" />) values
|
||||
<foreach item="model" collection="models" separator=", ">
|
||||
(#{model.id}, #{model.name}, #{model.dateCreated}, #{model.dateUpdated})
|
||||
</foreach>
|
||||
</insert>
|
||||
</insert>
|
||||
|
||||
<!-- Update By Key -->
|
||||
<update id="update">
|
||||
<update id="update">
|
||||
<foreach item="model" collection="models" separator="; ">
|
||||
<include refid="updateClause" />
|
||||
where id = #{model.id}
|
||||
</foreach>
|
||||
</update>
|
||||
</update>
|
||||
|
||||
<!-- Update By Condition -->
|
||||
<update id="updateBy">
|
||||
<update id="updateBy">
|
||||
<bind name="key" value="'id'" />
|
||||
<include refid="updateClause" />
|
||||
<include refid="Commons.search" />
|
||||
</update>
|
||||
<include refid="Commons.search" />
|
||||
</update>
|
||||
|
||||
<!-- Delete -->
|
||||
<delete id="delete">
|
||||
<delete id="delete">
|
||||
<bind name="key" value="'id'" />
|
||||
delete from <include refid="table" />
|
||||
<include refid="Commons.search" />
|
||||
</delete>
|
||||
delete from <include refid="table" />
|
||||
<include refid="Commons.search" />
|
||||
</delete>
|
||||
|
||||
<!-- Find One -->
|
||||
<select id="find" resultMap="modelMap">
|
||||
<select id="find" resultMap="modelMap">
|
||||
<bind name="key" value="'id'" />
|
||||
<include refid="Commons.selectAllFromTable" />
|
||||
<include refid="Commons.search" />
|
||||
</select>
|
||||
<include refid="Commons.search" />
|
||||
</select>
|
||||
|
||||
<!-- List -->
|
||||
<select id="list" resultMap="modelMap">
|
||||
<select id="list" resultMap="modelMap">
|
||||
<bind name="key" value="'id'" />
|
||||
<include refid="Commons.selectAllFromTable" />
|
||||
<include refid="Commons.search" />
|
||||
</select>
|
||||
<include refid="Commons.selectAllFromTable" />
|
||||
<include refid="Commons.search" />
|
||||
</select>
|
||||
|
||||
<!-- List Page All -->
|
||||
<select id="listPage" resultMap="modelMap">
|
||||
<!-- Default List All -->
|
||||
<include refid="Commons.selectAllFromTable" />
|
||||
</select>
|
||||
<select id="listPage" resultMap="modelMap">
|
||||
<!-- Default List All -->
|
||||
<include refid="Commons.selectAllFromTable" />
|
||||
</select>
|
||||
|
||||
<!-- List Page By Condition -->
|
||||
<select id="listPageBy" resultMap="modelMap">
|
||||
<include refid="Commons.selectAllFromTable" />
|
||||
<include refid="Commons.search" />
|
||||
<!-- TODO: Your Query Logics Are Here, For Example: -->
|
||||
<select id="listPageBy" resultMap="modelMap">
|
||||
<include refid="Commons.selectAllFromTable" />
|
||||
<include refid="Commons.search" />
|
||||
<!-- TODO: Your Query Logics Are Here, For Example: -->
|
||||
<!-- <if test="s != null"> -->
|
||||
<!-- where name like #{s} -->
|
||||
<!-- </if> -->
|
||||
</select>
|
||||
</select>
|
||||
<!-- /methods -->
|
||||
</mapper>
|
||||
|
@ -1,13 +1,13 @@
|
||||
<?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: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
|
||||
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"
|
||||
default-autowire="byName">
|
||||
default-autowire="byName">
|
||||
<!-- Scan Mock -->
|
||||
<context:component-scan base-package="me.chyxion.tigon.webmvc.test"
|
||||
use-default-filters="false">
|
||||
|
@ -4,11 +4,11 @@
|
||||
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-extjs</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Ext JS</name>
|
||||
<description>Tigon Ext JS</description>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>tigon-extjs</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Ext JS</name>
|
||||
<description>Tigon Ext JS</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
|
@ -4,51 +4,51 @@
|
||||
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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
|
@ -14,16 +14,16 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
||||
* Dec 5, 2014 2:31:39 PM
|
||||
*/
|
||||
public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(FreeMarkerViewResolverExt.class);
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(FreeMarkerViewResolverExt.class);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
</property>
|
||||
</bean>
|
||||
<bean class="me.chyxion.tigon.freemarker.FreeMarkerViewResolverExt"
|
||||
p:suffix=".ftl"
|
||||
p:suffix=".ftl"
|
||||
p:contentType="text/html; charset=utf-8"
|
||||
p:exposeRequestAttributes="true"
|
||||
p:order="16"
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?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: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
|
||||
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">
|
||||
|
||||
|
@ -4,46 +4,46 @@
|
||||
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-jsp-support</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon JSP Support</name>
|
||||
<description>Tigon JSP Support</description>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>tigon-jsp-support</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon JSP Support</name>
|
||||
<description>Tigon JSP Support</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</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-test</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -17,9 +17,9 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
* Dec 5, 2014 2:33:18 PM
|
||||
*/
|
||||
public class InternalResourceViewResolverExt
|
||||
extends InternalResourceViewResolver {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(InternalResourceViewResolverExt.class);
|
||||
extends InternalResourceViewResolver {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(InternalResourceViewResolverExt.class);
|
||||
|
||||
@Autowired
|
||||
private ServletContext sc;
|
||||
@ -29,31 +29,31 @@ public class InternalResourceViewResolverExt
|
||||
*/
|
||||
@Override
|
||||
public View resolveViewName(String viewName, Locale locale)
|
||||
throws Exception {
|
||||
return super.resolveViewName(viewName(viewName), locale);
|
||||
throws Exception {
|
||||
return super.resolveViewName(viewName(viewName), locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected boolean canHandle(String viewName, Locale locale) {
|
||||
try {
|
||||
// avoid 404
|
||||
return sc.getResource(getPrefix() + viewName(viewName) + getSuffix()) != null;
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
log.warn("InternalResourceViewResolverExt#canHandle Eorror Caused.", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected boolean canHandle(String viewName, Locale locale) {
|
||||
try {
|
||||
// avoid 404
|
||||
return sc.getResource(getPrefix() + viewName(viewName) + getSuffix()) != null;
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
log.warn("InternalResourceViewResolverExt#canHandle Eorror Caused.", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process View Name
|
||||
* @param name raw name
|
||||
* @return jsp file name
|
||||
*/
|
||||
private String viewName(String name) {
|
||||
return name.replaceAll("(?i)(^\\s*jsp\\:)|(\\.jsp\\s*$)", "");
|
||||
}
|
||||
/**
|
||||
* Process View Name
|
||||
* @param name raw name
|
||||
* @return jsp file name
|
||||
*/
|
||||
private String viewName(String name) {
|
||||
return name.replaceAll("(?i)(^\\s*jsp\\:)|(\\.jsp\\s*$)", "");
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,8 @@
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<!-- JSP View Resolver -->
|
||||
<bean class="me.chyxion.tigon.jsp.InternalResourceViewResolverExt"
|
||||
p:prefix="/WEB-INF/views/"
|
||||
p:suffix=".jsp"
|
||||
p:prefix="/WEB-INF/views/"
|
||||
p:suffix=".jsp"
|
||||
p:contentType="text/html; charset=utf-8"
|
||||
p:order="32"
|
||||
/>
|
||||
|
@ -4,11 +4,11 @@
|
||||
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-model</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Model</name>
|
||||
<description>Tigon Model</description>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>tigon-model</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Model</name>
|
||||
<description>Tigon Model</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
@ -17,11 +17,11 @@
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
@ -40,7 +40,7 @@
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
@ -55,11 +55,11 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
@ -70,5 +70,5 @@
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -11,37 +11,37 @@ import static org.slf4j.helpers.MessageFormatter.arrayFormat;
|
||||
* Oct 9, 2016 10:04:10 AM
|
||||
*/
|
||||
public class BaseException
|
||||
extends RuntimeException
|
||||
implements ErrorCoded<Object> {
|
||||
extends RuntimeException
|
||||
implements ErrorCoded<Object> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static final int CODE = 5000;
|
||||
protected Object code = CODE;
|
||||
|
||||
public BaseException() {
|
||||
}
|
||||
public BaseException() {
|
||||
}
|
||||
|
||||
public BaseException(Object code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public BaseException(Object code, Throwable e) {
|
||||
super(e);
|
||||
this.code = code;
|
||||
}
|
||||
public BaseException(Object code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public BaseException(Object code, Throwable e) {
|
||||
super(e);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public BaseException(Object code, String message, Object ... args) {
|
||||
this(message, args);
|
||||
this.code = code;
|
||||
}
|
||||
public BaseException(Object code, String message, Object ... args) {
|
||||
this(message, args);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public BaseException(String message, Object ... args) {
|
||||
super(arrayFormat(message, args).getMessage(),
|
||||
arrayFormat(null, args).getThrowable());
|
||||
}
|
||||
public BaseException(String message, Object ... args) {
|
||||
super(arrayFormat(message, args).getMessage(),
|
||||
arrayFormat(null, args).getThrowable());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object getCode() {
|
||||
return code;
|
||||
|
@ -8,14 +8,14 @@ package me.chyxion.tigon.exception;
|
||||
* Oct 8, 2016 5:54:52 PM
|
||||
*/
|
||||
public interface ErrorCoded<T> {
|
||||
|
||||
/**
|
||||
* @return error code
|
||||
*/
|
||||
T getCode();
|
||||
|
||||
/**
|
||||
* @param code error code
|
||||
*/
|
||||
void setCode(T code);
|
||||
|
||||
/**
|
||||
* @return error code
|
||||
*/
|
||||
T getCode();
|
||||
|
||||
/**
|
||||
* @param code error code
|
||||
*/
|
||||
void setCode(T code);
|
||||
}
|
||||
|
@ -9,10 +9,10 @@ package me.chyxion.tigon.exception;
|
||||
* Oct 26, 2015 12:13:52 PM
|
||||
*/
|
||||
public class InvalidParamException extends BaseException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static final int CODE = 4001;
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static final int CODE = 4001;
|
||||
|
||||
public InvalidParamException(String message, Object ... args) {
|
||||
super(CODE, message, args);
|
||||
}
|
||||
public InvalidParamException(String message, Object ... args) {
|
||||
super(CODE, message, args);
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,10 @@ package me.chyxion.tigon.exception;
|
||||
* Oct 9, 2016 10:05:29 AM
|
||||
*/
|
||||
public class InvalidStateException extends BaseException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static final int CODE = 4002;
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static final int CODE = 4002;
|
||||
|
||||
public InvalidStateException(String message, Object ... args) {
|
||||
super(CODE, message, args);
|
||||
}
|
||||
public InvalidStateException(String message, Object ... args) {
|
||||
super(CODE, message, args);
|
||||
}
|
||||
}
|
||||
|
@ -13,78 +13,78 @@ import org.springframework.beans.BeanUtils;
|
||||
*/
|
||||
@Slf4j
|
||||
public class BaseForm implements BaseFormApi {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* clone to class
|
||||
* @param clazz copy to class
|
||||
* @return copy result
|
||||
*/
|
||||
@Override
|
||||
public <T> T copy(Class<T> clazz) {
|
||||
return copy(clazz, false);
|
||||
}
|
||||
/**
|
||||
* clone to class
|
||||
* @param clazz copy to class
|
||||
* @return copy result
|
||||
*/
|
||||
@Override
|
||||
public <T> T copy(Class<T> clazz) {
|
||||
return copy(clazz, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* copy to class
|
||||
* @param clazz copy to class
|
||||
* @param convert true to convert fields
|
||||
* @return copy result
|
||||
*/
|
||||
@Override
|
||||
public <T> T copy(Class<T> clazz, boolean convert) {
|
||||
log.debug("Copy Form [{}] To Class [{}].", this, clazz);
|
||||
T obj = null;
|
||||
try {
|
||||
obj = clazz.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Create [" + clazz + "] Object Error Caused", e);
|
||||
}
|
||||
return copy(obj, convert);
|
||||
}
|
||||
/**
|
||||
* copy to class
|
||||
* @param clazz copy to class
|
||||
* @param convert true to convert fields
|
||||
* @return copy result
|
||||
*/
|
||||
@Override
|
||||
public <T> T copy(Class<T> clazz, boolean convert) {
|
||||
log.debug("Copy Form [{}] To Class [{}].", this, clazz);
|
||||
T obj = null;
|
||||
try {
|
||||
obj = clazz.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Create [" + clazz + "] Object Error Caused", e);
|
||||
}
|
||||
return copy(obj, convert);
|
||||
}
|
||||
|
||||
/**
|
||||
* copy to object
|
||||
* @param obj copy to object
|
||||
* @return copy result
|
||||
*/
|
||||
@Override
|
||||
public <T> T copy(T obj) {
|
||||
return copy(obj, false);
|
||||
}
|
||||
/**
|
||||
* copy to object
|
||||
* @param obj copy to object
|
||||
* @return copy result
|
||||
*/
|
||||
@Override
|
||||
public <T> T copy(T obj) {
|
||||
return copy(obj, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* copy props with converting
|
||||
* @param obj copy to object
|
||||
* @param convert true to convert object fields
|
||||
* @return copy result object
|
||||
*/
|
||||
@Override
|
||||
public <T> T copy(T obj, boolean convert) {
|
||||
try {
|
||||
if (convert) {
|
||||
log.debug("Copy Form [{}] To [{}] With Type Converting.", this, obj);
|
||||
org.apache.commons.beanutils.BeanUtils.copyProperties(obj, this);
|
||||
}
|
||||
else {
|
||||
log.debug("Copy Form [{}] To [{}].", this, obj);
|
||||
BeanUtils.copyProperties(this, obj);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Copy [" + this + "] Error Caused", e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* copy props with converting
|
||||
* @param obj copy to object
|
||||
* @param convert true to convert object fields
|
||||
* @return copy result object
|
||||
*/
|
||||
@Override
|
||||
public <T> T copy(T obj, boolean convert) {
|
||||
try {
|
||||
if (convert) {
|
||||
log.debug("Copy Form [{}] To [{}] With Type Converting.", this, obj);
|
||||
org.apache.commons.beanutils.BeanUtils.copyProperties(obj, this);
|
||||
}
|
||||
else {
|
||||
log.debug("Copy Form [{}] To [{}].", this, obj);
|
||||
BeanUtils.copyProperties(this, obj);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Copy [" + this + "] Error Caused", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return JSON.toJSONString(this);
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return JSON.toJSONString(this);
|
||||
}
|
||||
}
|
||||
|
@ -11,35 +11,35 @@ import java.io.Serializable;
|
||||
*/
|
||||
public interface BaseFormApi extends Serializable {
|
||||
|
||||
/**
|
||||
* copy to class
|
||||
* @param clazz to class
|
||||
* @param <T> to class type
|
||||
* @return copy result
|
||||
*/
|
||||
<T> T copy(Class<T> clazz);
|
||||
/**
|
||||
* copy to class
|
||||
* @param clazz to class
|
||||
* @param <T> to class type
|
||||
* @return copy result
|
||||
*/
|
||||
<T> T copy(Class<T> clazz);
|
||||
|
||||
/**
|
||||
* @param clazz to class
|
||||
* @param <T> to class type
|
||||
* @param convert convert prop
|
||||
* @return copy result
|
||||
*/
|
||||
<T> T copy(Class<T> clazz, boolean convert);
|
||||
/**
|
||||
* @param clazz to class
|
||||
* @param <T> to class type
|
||||
* @param convert convert prop
|
||||
* @return copy result
|
||||
*/
|
||||
<T> T copy(Class<T> clazz, boolean convert);
|
||||
|
||||
/**
|
||||
* @param obj copy to object
|
||||
* @param <T> to class type
|
||||
* @return copy result
|
||||
*/
|
||||
<T> T copy(T obj);
|
||||
/**
|
||||
* @param obj copy to object
|
||||
* @param <T> to class type
|
||||
* @return copy result
|
||||
*/
|
||||
<T> T copy(T obj);
|
||||
|
||||
/**
|
||||
* copy props with converting
|
||||
* @param obj copy to object
|
||||
* @param convert convert prop
|
||||
* @param <T> to class type
|
||||
* @return copy result
|
||||
*/
|
||||
<T> T copy(T obj, boolean convert);
|
||||
/**
|
||||
* copy props with converting
|
||||
* @param obj copy to object
|
||||
* @param convert convert prop
|
||||
* @param <T> to class type
|
||||
* @return copy result
|
||||
*/
|
||||
<T> T copy(T obj, boolean convert);
|
||||
}
|
||||
|
@ -8,14 +8,14 @@ package me.chyxion.tigon.form;
|
||||
* Oct 8, 2016 6:24:03 PM
|
||||
*/
|
||||
public interface BaseFormForUpdateApi<Id> extends BaseFormApi {
|
||||
|
||||
/**
|
||||
* @return id
|
||||
*/
|
||||
Id getId();
|
||||
|
||||
/**
|
||||
* @param id id
|
||||
*/
|
||||
void setId(Id id);
|
||||
|
||||
/**
|
||||
* @return id
|
||||
*/
|
||||
Id getId();
|
||||
|
||||
/**
|
||||
* @param id id
|
||||
*/
|
||||
void setId(Id id);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ package me.chyxion.tigon.form;
|
||||
* Oct 8, 2016 6:26:19 PM
|
||||
*/
|
||||
public class FC0 extends BaseForm
|
||||
implements BaseFormForCreateApi {
|
||||
private static final long serialVersionUID = 1L;
|
||||
implements BaseFormForCreateApi {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,10 @@ import me.chyxion.tigon.format.annotation.EmptyToNull;
|
||||
@Getter
|
||||
@Setter
|
||||
public class FC1 extends FC0 {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
protected Boolean enabled = true;
|
||||
@EmptyToNull
|
||||
protected String note;
|
||||
@NotNull
|
||||
protected Boolean enabled = true;
|
||||
@EmptyToNull
|
||||
protected String note;
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
||||
@Getter
|
||||
@Setter
|
||||
public class FC2<CreatorId> extends FC1 {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNullOrBlank
|
||||
protected CreatorId createdBy;
|
||||
@NotNullOrBlank
|
||||
protected CreatorId createdBy;
|
||||
}
|
||||
|
@ -14,11 +14,11 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
||||
@Getter
|
||||
@Setter
|
||||
public class FU0<Id>
|
||||
extends BaseForm
|
||||
implements BaseFormForUpdateApi<Id> {
|
||||
extends BaseForm
|
||||
implements BaseFormForUpdateApi<Id> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNullOrBlank
|
||||
protected Id id;
|
||||
@NotNullOrBlank
|
||||
protected Id id;
|
||||
}
|
||||
|
@ -15,11 +15,11 @@ import me.chyxion.tigon.format.annotation.EmptyToNull;
|
||||
@Getter
|
||||
@Setter
|
||||
public class FU1<Id>
|
||||
extends FU0<Id> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
extends FU0<Id> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
protected Boolean enabled;
|
||||
@EmptyToNull
|
||||
protected String note;
|
||||
@NotNull
|
||||
protected Boolean enabled;
|
||||
@EmptyToNull
|
||||
protected String note;
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
||||
@Getter
|
||||
@Setter
|
||||
public class FU2<EditorId, Id>
|
||||
extends FU1<Id> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
extends FU1<Id> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNullOrBlank
|
||||
private EditorId updatedBy;
|
||||
@NotNullOrBlank
|
||||
private EditorId updatedBy;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import java.util.List;
|
||||
*/
|
||||
public class ListResult<T>
|
||||
extends ViewModel<List<T>>
|
||||
implements ListResultApi<T> {
|
||||
implements ListResultApi<T> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final String TOTAL_KEY = "total";
|
||||
|
||||
|
@ -27,4 +27,4 @@ public interface ListResultApi<T> extends ViewModelable<List<T>> {
|
||||
* @return this
|
||||
*/
|
||||
ListResultApi<T> setTotal(int total);
|
||||
}
|
||||
}
|
||||
|
@ -13,31 +13,31 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
public class M0<Id> extends BaseModel<Id> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected Id id;
|
||||
protected Id id;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String primaryKeyName() {
|
||||
return ID;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String primaryKeyName() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Id primaryKeyValue() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Id primaryKeyValue() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void primaryKeyValue(Id id) {
|
||||
this.id = id;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void primaryKeyValue(Id id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
@ -15,31 +15,31 @@ import java.util.Date;
|
||||
@Setter
|
||||
public class M1<Id> extends M0<Id> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String DATE_CREATED = "date_created";
|
||||
public static final String DATE_UPDATED = "date_updated";
|
||||
public static final String DATE_CREATED = "date_created";
|
||||
public static final String DATE_UPDATED = "date_updated";
|
||||
|
||||
protected Date dateCreated;
|
||||
protected Date dateUpdated;
|
||||
protected Date dateCreated;
|
||||
protected Date dateUpdated;
|
||||
|
||||
/**
|
||||
* init date created
|
||||
*/
|
||||
@Override
|
||||
public void beforeInsert() {
|
||||
super.beforeInsert();
|
||||
if (dateCreated == null) {
|
||||
dateCreated = new Date();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* init date created
|
||||
*/
|
||||
@Override
|
||||
public void beforeInsert() {
|
||||
super.beforeInsert();
|
||||
if (dateCreated == null) {
|
||||
dateCreated = new Date();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* update date updated
|
||||
*/
|
||||
@Override
|
||||
public void beforeUpdate() {
|
||||
/**
|
||||
* update date updated
|
||||
*/
|
||||
@Override
|
||||
public void beforeUpdate() {
|
||||
super.beforeUpdate();
|
||||
dateUpdated = new Date();
|
||||
}
|
||||
dateUpdated = new Date();
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,11 @@ import lombok.Setter;
|
||||
@Setter
|
||||
public class M2<Id> extends M1<Id> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String ENABLED = "enabled";
|
||||
public static final String NOTE = "note";
|
||||
public static final String ENABLED = "enabled";
|
||||
public static final String NOTE = "note";
|
||||
|
||||
protected boolean enabled;
|
||||
protected String note;
|
||||
protected boolean enabled;
|
||||
protected String note;
|
||||
}
|
||||
|
@ -13,13 +13,13 @@ import lombok.Setter;
|
||||
@Setter
|
||||
@Getter
|
||||
public class M3<UserId, Id>
|
||||
extends M2<Id> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
extends M2<Id> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String CREATED_BY = "created_by";
|
||||
public static final String UPDATED_BY = "updated_by";
|
||||
public static final String CREATED_BY = "created_by";
|
||||
public static final String UPDATED_BY = "updated_by";
|
||||
|
||||
// fields
|
||||
protected UserId createdBy;
|
||||
protected UserId updatedBy;
|
||||
// fields
|
||||
protected UserId createdBy;
|
||||
protected UserId updatedBy;
|
||||
}
|
||||
|
@ -15,59 +15,59 @@ import com.alibaba.fastjson.JSONObject;
|
||||
*/
|
||||
@Getter
|
||||
public class ViewModel<T>
|
||||
implements ViewModelable<T> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
implements ViewModelable<T> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private T data;
|
||||
private Map<String, Object> attrs;
|
||||
private T data;
|
||||
private Map<String, Object> attrs;
|
||||
|
||||
public ViewModel() {
|
||||
}
|
||||
public ViewModel() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data
|
||||
*/
|
||||
public ViewModel(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* @param attrs
|
||||
*/
|
||||
public ViewModel(T data, Map<String, Object> attrs) {
|
||||
this.data = data;
|
||||
this.attrs = attrs;
|
||||
}
|
||||
/**
|
||||
* @param data
|
||||
*/
|
||||
public ViewModel(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data
|
||||
* @param attrs
|
||||
*/
|
||||
public ViewModel(T data, Map<String, Object> attrs) {
|
||||
this.data = data;
|
||||
this.attrs = attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<T> setAttr(String name, Object value) {
|
||||
if (attrs == null) {
|
||||
attrs = new HashMap<String, Object>();
|
||||
}
|
||||
attrs.put(name, value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @param name
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<T> setAttr(String name, Object value) {
|
||||
if (attrs == null) {
|
||||
attrs = new HashMap<String, Object>();
|
||||
}
|
||||
attrs.put(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
*/
|
||||
@Override
|
||||
public <A> A getAttr(String name) {
|
||||
return attrs != null ? (A) attrs.get(name) : null;
|
||||
}
|
||||
public <A> A getAttr(String name) {
|
||||
return attrs != null ? (A) attrs.get(name) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModelable<T> setAttrs(Map<String, Object> attrs) {
|
||||
this.attrs = attrs;
|
||||
this.attrs = attrs;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -81,41 +81,41 @@ public class ViewModel<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* @return map
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> mapRtn = null;
|
||||
if (data != null) {
|
||||
if (data instanceof Map) {
|
||||
mapRtn = (Map<String, Object>) data;
|
||||
}
|
||||
else {
|
||||
if (data instanceof ViewModelable) {
|
||||
mapRtn = new HashMap<String, Object>();
|
||||
mapRtn.put("data", ((ViewModelable) data).toMap());
|
||||
}
|
||||
else {
|
||||
Object jsonData = JSON.toJSON(data);
|
||||
if (jsonData instanceof JSONObject) {
|
||||
mapRtn = (Map<String, Object>) jsonData;
|
||||
}
|
||||
else {
|
||||
mapRtn = new HashMap<String, Object>();
|
||||
mapRtn.put("data", jsonData);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (attrs != null && !attrs.isEmpty()) {
|
||||
mapRtn.putAll(attrs);
|
||||
}
|
||||
}
|
||||
else if (attrs != null) {
|
||||
mapRtn = attrs;
|
||||
}
|
||||
else {
|
||||
mapRtn = new HashMap<String, Object>();
|
||||
}
|
||||
return mapRtn;
|
||||
}
|
||||
}
|
||||
* @return map
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> mapRtn = null;
|
||||
if (data != null) {
|
||||
if (data instanceof Map) {
|
||||
mapRtn = (Map<String, Object>) data;
|
||||
}
|
||||
else {
|
||||
if (data instanceof ViewModelable) {
|
||||
mapRtn = new HashMap<String, Object>();
|
||||
mapRtn.put("data", ((ViewModelable) data).toMap());
|
||||
}
|
||||
else {
|
||||
Object jsonData = JSON.toJSON(data);
|
||||
if (jsonData instanceof JSONObject) {
|
||||
mapRtn = (Map<String, Object>) jsonData;
|
||||
}
|
||||
else {
|
||||
mapRtn = new HashMap<String, Object>();
|
||||
mapRtn.put("data", jsonData);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (attrs != null && !attrs.isEmpty()) {
|
||||
mapRtn.putAll(attrs);
|
||||
}
|
||||
}
|
||||
else if (attrs != null) {
|
||||
mapRtn = attrs;
|
||||
}
|
||||
else {
|
||||
mapRtn = new HashMap<String, Object>();
|
||||
}
|
||||
return mapRtn;
|
||||
}
|
||||
}
|
||||
|
@ -11,15 +11,15 @@ import java.util.Map;
|
||||
*/
|
||||
public interface ViewModelable<T> extends Mappable {
|
||||
|
||||
/**
|
||||
* @return data main data
|
||||
*/
|
||||
T getData();
|
||||
/**
|
||||
* @return data main data
|
||||
*/
|
||||
T getData();
|
||||
|
||||
/**
|
||||
* @param data data to set
|
||||
*/
|
||||
ViewModelable<T> setData(T data);
|
||||
* @param data data to set
|
||||
*/
|
||||
ViewModelable<T> setData(T data);
|
||||
|
||||
/**
|
||||
* @param name attr name
|
||||
|
@ -13,14 +13,14 @@ import me.chyxion.tigon.model.BaseModel;
|
||||
* May 12, 2015 3:00:40 PM
|
||||
*/
|
||||
public class Search implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final List<Criterion> criteria =
|
||||
new LinkedList<Criterion>();
|
||||
private String table;
|
||||
private Integer offset;
|
||||
private Integer limit;
|
||||
private final Map<String, String> orders =
|
||||
private Integer offset;
|
||||
private Integer limit;
|
||||
private final Map<String, String> orders =
|
||||
new LinkedHashMap<String, String>();
|
||||
/**
|
||||
* extended data
|
||||
@ -28,53 +28,53 @@ public class Search implements Serializable {
|
||||
private final Map<String, Object> ext =
|
||||
new HashMap<String, Object>();
|
||||
|
||||
private static final List<SearchProcessor> PROCESSORS;
|
||||
static {
|
||||
List<SearchProcessor> processors = new LinkedList<SearchProcessor>();
|
||||
processors.add(new EqualSearchProcessor());
|
||||
processors.add(new IsNullSearchProcessor());
|
||||
private static final List<SearchProcessor> PROCESSORS;
|
||||
static {
|
||||
List<SearchProcessor> processors = new LinkedList<SearchProcessor>();
|
||||
processors.add(new EqualSearchProcessor());
|
||||
processors.add(new IsNullSearchProcessor());
|
||||
|
||||
processors.add(new InSearchProcessor());
|
||||
processors.add(new NotInSearchProcessor());
|
||||
processors.add(new InSearchProcessor());
|
||||
processors.add(new NotInSearchProcessor());
|
||||
|
||||
processors.add(new NotEqualSearchProcessor());
|
||||
processors.add(new IsNotNullSearchProcessor());
|
||||
processors.add(new NotEqualSearchProcessor());
|
||||
processors.add(new IsNotNullSearchProcessor());
|
||||
|
||||
processors.add(new GtSearchProcessor());
|
||||
processors.add(new GteSearchProcessor());
|
||||
processors.add(new GtSearchProcessor());
|
||||
processors.add(new GteSearchProcessor());
|
||||
|
||||
processors.add(new LtSearchProcessor());
|
||||
processors.add(new LteSearchProcessor());
|
||||
processors.add(new LtSearchProcessor());
|
||||
processors.add(new LteSearchProcessor());
|
||||
|
||||
processors.add(new BetweenSearchProcessor());
|
||||
processors.add(new LikeSearchProcessor());
|
||||
processors.add(new BetweenSearchProcessor());
|
||||
processors.add(new LikeSearchProcessor());
|
||||
|
||||
processors.add(new AndSearchProcessor());
|
||||
processors.add(new OrSearchProcessor());
|
||||
PROCESSORS = Collections.unmodifiableList(processors);
|
||||
processors.add(new AndSearchProcessor());
|
||||
processors.add(new OrSearchProcessor());
|
||||
PROCESSORS = Collections.unmodifiableList(processors);
|
||||
}
|
||||
|
||||
/**
|
||||
* default construct
|
||||
*/
|
||||
public Search() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value id value
|
||||
*/
|
||||
public Search(Object value) {
|
||||
eq(BaseModel.ID, value);
|
||||
}
|
||||
/**
|
||||
* default construct
|
||||
*/
|
||||
public Search() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value id value
|
||||
*/
|
||||
public Search(Object value) {
|
||||
eq(BaseModel.ID, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct by eq
|
||||
* @param col col name
|
||||
* @param value value
|
||||
*/
|
||||
public Search(String col, Object value) {
|
||||
eq(col, value);
|
||||
}
|
||||
/**
|
||||
* construct by eq
|
||||
* @param col col name
|
||||
* @param value value
|
||||
*/
|
||||
public Search(String col, Object value) {
|
||||
eq(col, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* construct by eq
|
||||
@ -94,22 +94,22 @@ public class Search implements Serializable {
|
||||
in(col, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* set table
|
||||
* @param table table
|
||||
* @return this
|
||||
*/
|
||||
public Search table(String table) {
|
||||
this.table = table;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* set table
|
||||
* @param table table
|
||||
* @return this
|
||||
*/
|
||||
public Search table(String table) {
|
||||
this.table = table;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* clear criteria
|
||||
* @return search
|
||||
*/
|
||||
public Search clearCriteria() {
|
||||
criteria.clear();
|
||||
criteria.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -122,14 +122,14 @@ public class Search implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* col eq
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search eq(String col, Object value) {
|
||||
if (value == null) {
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search eq(String col, Object value) {
|
||||
if (value == null) {
|
||||
criteria.add(new Criterion(CriterionType.IS_NULL, col, value));
|
||||
}
|
||||
else if (value instanceof Collection) {
|
||||
@ -141,8 +141,8 @@ public class Search implements Serializable {
|
||||
else {
|
||||
criteria.add(new Criterion(CriterionType.EQ, col, value));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* same as #eq(col, null)
|
||||
@ -150,216 +150,216 @@ public class Search implements Serializable {
|
||||
* @return this
|
||||
*/
|
||||
public Search isNull(String col) {
|
||||
return eq(col, null);
|
||||
return eq(col, null);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* col in values array
|
||||
* @param col col name
|
||||
* @param values values
|
||||
* @return this
|
||||
*/
|
||||
public Search in(String col, Object[] values) {
|
||||
* @param col col name
|
||||
* @param values values
|
||||
* @return this
|
||||
*/
|
||||
public Search in(String col, Object[] values) {
|
||||
criteria.add(new Criterion(CriterionType.IN, col, values));
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* col in values list
|
||||
* @param col col name
|
||||
* @param values values
|
||||
* @return this
|
||||
*/
|
||||
public Search in(String col, Collection<?> values) {
|
||||
* @param col col name
|
||||
* @param values values
|
||||
* @return this
|
||||
*/
|
||||
public Search in(String col, Collection<?> values) {
|
||||
criteria.add(new Criterion(CriterionType.IN, col, values));
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* col like value
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search like(String col, String value) {
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search like(String col, String value) {
|
||||
criteria.add(new Criterion(CriterionType.LIKE, col, value));
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @param wrapValue wrap value with %
|
||||
* @return this
|
||||
*/
|
||||
public Search like(String col, String value, boolean wrapValue) {
|
||||
return like(col, wrapValue ? "%" + value + "%" : value);
|
||||
}
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @param wrapValue wrap value with %
|
||||
* @return this
|
||||
*/
|
||||
public Search like(String col, String value, boolean wrapValue) {
|
||||
return like(col, wrapValue ? "%" + value + "%" : value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param bottom bottom value
|
||||
* @param top top value
|
||||
* @return this
|
||||
*/
|
||||
public Search between(String col, Object bottom, Object top) {
|
||||
/**
|
||||
* @param col col name
|
||||
* @param bottom bottom value
|
||||
* @param top top value
|
||||
* @return this
|
||||
*/
|
||||
public Search between(String col, Object bottom, Object top) {
|
||||
criteria.add(new Criterion(
|
||||
CriterionType.BETWEEN,
|
||||
col,
|
||||
Arrays.asList(bottom, top)));
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search ne(String col, Object value) {
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search ne(String col, Object value) {
|
||||
criteria.add(new Criterion(
|
||||
value != null ? CriterionType.NE :
|
||||
CriterionType.IS_NOT_NULL, col, value));
|
||||
return this;
|
||||
}
|
||||
value != null ? CriterionType.NE :
|
||||
CriterionType.IS_NOT_NULL, col, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* col not null
|
||||
* @param col col
|
||||
* @return search
|
||||
*/
|
||||
public Search notNull(String col) {
|
||||
criteria.add(new Criterion(
|
||||
CriterionType.IS_NOT_NULL, col, (Object) null));
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* col not null
|
||||
* @param col col
|
||||
* @return search
|
||||
*/
|
||||
public Search notNull(String col) {
|
||||
criteria.add(new Criterion(
|
||||
CriterionType.IS_NOT_NULL, col, (Object) null));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param values values
|
||||
* @return this
|
||||
*/
|
||||
public Search notIn(String col, Object[] values) {
|
||||
/**
|
||||
* @param col col name
|
||||
* @param values values
|
||||
* @return this
|
||||
*/
|
||||
public Search notIn(String col, Object[] values) {
|
||||
return notIn(col, Arrays.asList(values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param values values
|
||||
* @return this
|
||||
*/
|
||||
public Search notIn(String col, Collection<?> values) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param values values
|
||||
* @return this
|
||||
*/
|
||||
public Search notIn(String col, Collection<?> values) {
|
||||
criteria.add(new Criterion(CriterionType.NOT_IN, col, values));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search lt(String col, Object value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search lt(String col, Object value) {
|
||||
criteria.add(new Criterion(CriterionType.LT, col, value));
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search lte(String col, Object value) {
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search lte(String col, Object value) {
|
||||
criteria.add(new Criterion(CriterionType.LTE, col, value));
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search gt(String col, Object value) {
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search gt(String col, Object value) {
|
||||
criteria.add(new Criterion(CriterionType.GT, col, value));
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search gte(String col, Object value) {
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search gte(String col, Object value) {
|
||||
criteria.add(new Criterion(CriterionType.GTE, col, value));
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param search search
|
||||
* @return this
|
||||
*/
|
||||
public Search and(Search search) {
|
||||
Assert.notNull(search, "And Search Could Not Be Null");
|
||||
Assert.state(this != search, "And Search Could Not Be Self");
|
||||
criteria.add(new Criterion(CriterionType.AND, search));
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @param search search
|
||||
* @return this
|
||||
*/
|
||||
public Search and(Search search) {
|
||||
Assert.notNull(search, "And Search Could Not Be Null");
|
||||
Assert.state(this != search, "And Search Could Not Be Self");
|
||||
criteria.add(new Criterion(CriterionType.AND, search));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param search search
|
||||
* @return this
|
||||
*/
|
||||
public Search or(Search search) {
|
||||
Assert.notNull(search, "Or Search Could Not Be Null");
|
||||
Assert.state(this != search, "Or Search Could Not Be Self");
|
||||
/**
|
||||
* @param search search
|
||||
* @return this
|
||||
*/
|
||||
public Search or(Search search) {
|
||||
Assert.notNull(search, "Or Search Could Not Be Null");
|
||||
Assert.state(this != search, "Or Search Could Not Be Self");
|
||||
criteria.add(new Criterion(CriterionType.OR, search));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search or(String col, Object value) {
|
||||
return or(new Search(col, value));
|
||||
}
|
||||
/**
|
||||
* @param col col name
|
||||
* @param value value
|
||||
* @return this
|
||||
*/
|
||||
public Search or(String col, Object value) {
|
||||
return or(new Search(col, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @return this
|
||||
*/
|
||||
public Search asc(String col) {
|
||||
return order(col, "asc");
|
||||
}
|
||||
/**
|
||||
* @param col col name
|
||||
* @return this
|
||||
*/
|
||||
public Search asc(String col) {
|
||||
return order(col, "asc");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @return this
|
||||
*/
|
||||
public Search desc(String col) {
|
||||
return order(col, "desc");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offset offset
|
||||
* @return this
|
||||
*/
|
||||
public Search offset(Integer offset) {
|
||||
if (offset != null) {
|
||||
Assert.state(offset >= 0, "Offset May Not Be Negative");
|
||||
}
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @param col col name
|
||||
* @return this
|
||||
*/
|
||||
public Search desc(String col) {
|
||||
return order(col, "desc");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offset offset
|
||||
* @return this
|
||||
*/
|
||||
public Search offset(Integer offset) {
|
||||
if (offset != null) {
|
||||
Assert.state(offset >= 0, "Offset May Not Be Negative");
|
||||
}
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offset offset
|
||||
* @return this
|
||||
*/
|
||||
public Search offset(int offset) {
|
||||
Assert.state(offset >= 0, "Offset May Not Be Negative");
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @param offset offset
|
||||
* @return this
|
||||
*/
|
||||
public Search offset(int offset) {
|
||||
Assert.state(offset >= 0, "Offset May Not Be Negative");
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return offset
|
||||
@ -368,27 +368,27 @@ public class Search implements Serializable {
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param limit limit
|
||||
* @return this
|
||||
*/
|
||||
public Search limit(Integer limit) {
|
||||
if (limit != null) {
|
||||
Assert.state(limit > 0, "Limit May Not Be Negative Or Zero");
|
||||
}
|
||||
this.limit = limit;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @param limit limit
|
||||
* @return this
|
||||
*/
|
||||
public Search limit(Integer limit) {
|
||||
if (limit != null) {
|
||||
Assert.state(limit > 0, "Limit May Not Be Negative Or Zero");
|
||||
}
|
||||
this.limit = limit;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param limit limit
|
||||
* @return this
|
||||
*/
|
||||
public Search limit(int limit) {
|
||||
Assert.state(limit > 0, "Limit May Not Be Negative Or Zero");
|
||||
this.limit = limit;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @param limit limit
|
||||
* @return this
|
||||
*/
|
||||
public Search limit(int limit) {
|
||||
Assert.state(limit > 0, "Limit May Not Be Negative Or Zero");
|
||||
this.limit = limit;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return limit
|
||||
@ -404,13 +404,13 @@ public class Search implements Serializable {
|
||||
return orders;
|
||||
}
|
||||
|
||||
/**
|
||||
* assemble to sql and value list
|
||||
* @return sql and value list
|
||||
*/
|
||||
public List<Object> assemble() {
|
||||
return assemble(false);
|
||||
}
|
||||
/**
|
||||
* assemble to sql and value list
|
||||
* @return sql and value list
|
||||
*/
|
||||
public List<Object> assemble() {
|
||||
return assemble(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if has criterion
|
||||
@ -419,26 +419,26 @@ public class Search implements Serializable {
|
||||
return !criteria.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if has no criterion
|
||||
*/
|
||||
public boolean hasNoCriterion() {
|
||||
return criteria.isEmpty();
|
||||
}
|
||||
/**
|
||||
* @return true if has no criterion
|
||||
*/
|
||||
public boolean hasNoCriterion() {
|
||||
return criteria.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if has order
|
||||
*/
|
||||
public boolean hasOrder() {
|
||||
return !orders.isEmpty();
|
||||
}
|
||||
/**
|
||||
* @return true if has order
|
||||
*/
|
||||
public boolean hasOrder() {
|
||||
return !orders.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if has no order
|
||||
*/
|
||||
public boolean hasNoOrder() {
|
||||
return orders.isEmpty();
|
||||
}
|
||||
/**
|
||||
* @return true if has no order
|
||||
*/
|
||||
public boolean hasNoOrder() {
|
||||
return orders.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* get ext data
|
||||
@ -447,7 +447,7 @@ public class Search implements Serializable {
|
||||
* @return data
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getExt(String name) {
|
||||
public <T> T getExt(String name) {
|
||||
return (T) ext.get(name);
|
||||
}
|
||||
|
||||
@ -458,44 +458,44 @@ public class Search implements Serializable {
|
||||
* @return this
|
||||
*/
|
||||
public Search setExt(String name, Object value) {
|
||||
ext.put(name, value);
|
||||
ext.put(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
// --
|
||||
// private methods
|
||||
// --
|
||||
// private methods
|
||||
|
||||
/**
|
||||
* @param col col name
|
||||
* @param direction direction
|
||||
* @return this
|
||||
*/
|
||||
Search order(String col, String direction) {
|
||||
Assert.hasText(col, "Order Column Could Not Be Blank");
|
||||
orders.put(col, direction);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @param col col name
|
||||
* @param direction direction
|
||||
* @return this
|
||||
*/
|
||||
Search order(String col, String direction) {
|
||||
Assert.hasText(col, "Order Column Could Not Be Blank");
|
||||
orders.put(col, direction);
|
||||
return this;
|
||||
}
|
||||
|
||||
List<Object> assemble(boolean subSearch) {
|
||||
List<Object> result = new LinkedList<Object>();
|
||||
SearchProcessArgs args = new SearchProcessArgs(table, result);
|
||||
List<Object> assemble(boolean subSearch) {
|
||||
List<Object> result = new LinkedList<Object>();
|
||||
SearchProcessArgs args = new SearchProcessArgs(table, result);
|
||||
for (Criterion condition : criteria) {
|
||||
args.setCondition(condition);
|
||||
for (SearchProcessor processor : PROCESSORS) {
|
||||
if (processor.accept(args)) {
|
||||
processor.process(args);
|
||||
break;
|
||||
}
|
||||
if (processor.accept(args)) {
|
||||
processor.process(args);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!args.isHasPrevCol()) {
|
||||
args.setHasPrevCol(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (subSearch && criteria.size() > 1) {
|
||||
result.add(0, new SqlFragment("("));
|
||||
result.add(new SqlFragment(")"));
|
||||
if (subSearch && criteria.size() > 1) {
|
||||
result.add(0, new SqlFragment("("));
|
||||
result.add(new SqlFragment(")"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,10 @@ import org.apache.commons.lang3.StringUtils;
|
||||
*/
|
||||
public class WordUtils {
|
||||
|
||||
/**
|
||||
* split Camel Case
|
||||
* <pre>
|
||||
* nice - [nice]
|
||||
/**
|
||||
* split Camel Case
|
||||
* <pre>
|
||||
* nice - [nice]
|
||||
* World - [World]
|
||||
* MySQL - [My SQL]
|
||||
* HTML - [HTML]
|
||||
@ -25,31 +25,31 @@ public class WordUtils {
|
||||
* 99Roses - [99 Roses]
|
||||
* DO178 - [DO178]
|
||||
* Do178 - [Do178]
|
||||
* </pre>
|
||||
* @param str word
|
||||
* @return split result
|
||||
*/
|
||||
public static String[] splitToWords(String str) {
|
||||
return StringUtils.isNotBlank(str) ?
|
||||
// JSONObject - JSON Object
|
||||
str.split(new StringBuilder("(?<=[A-Z])(?=[A-Z][a-z])")
|
||||
// MySQL - My SQL
|
||||
.append("|(?<=[a-z])(?=[A-Z])")
|
||||
// 99Roses -> 99 Roses
|
||||
.append("|(?<=[^a-zA-Z])(?=[A-Z])")
|
||||
// .append("|(?<=[^A-Z])(?=[A-Z])")
|
||||
// 5s - 5 s
|
||||
// .append("|(?<=[^a-zA-Z])(?=[a-z])")
|
||||
// A3 - A 3 | a3 - a 3
|
||||
// .append("|(?<=[A-Za-z])(?=[^A-Za-z])")
|
||||
.toString()) :
|
||||
new String[]{};
|
||||
}
|
||||
* </pre>
|
||||
* @param str word
|
||||
* @return split result
|
||||
*/
|
||||
public static String[] splitToWords(String str) {
|
||||
return StringUtils.isNotBlank(str) ?
|
||||
// JSONObject - JSON Object
|
||||
str.split(new StringBuilder("(?<=[A-Z])(?=[A-Z][a-z])")
|
||||
// MySQL - My SQL
|
||||
.append("|(?<=[a-z])(?=[A-Z])")
|
||||
// 99Roses -> 99 Roses
|
||||
.append("|(?<=[^a-zA-Z])(?=[A-Z])")
|
||||
// .append("|(?<=[^A-Z])(?=[A-Z])")
|
||||
// 5s - 5 s
|
||||
// .append("|(?<=[^a-zA-Z])(?=[a-z])")
|
||||
// A3 - A 3 | a3 - a 3
|
||||
// .append("|(?<=[A-Za-z])(?=[^A-Za-z])")
|
||||
.toString()) :
|
||||
new String[]{};
|
||||
}
|
||||
|
||||
/**
|
||||
* Join Camel Case Word
|
||||
* <pre>
|
||||
* #convertCamelCase("nice", "_") - [nice]
|
||||
/**
|
||||
* Join Camel Case Word
|
||||
* <pre>
|
||||
* #convertCamelCase("nice", "_") - [nice]
|
||||
* #convertCamelCase("World", "_") - [World]
|
||||
* #convertCamelCase("MySQL", "_") - [My_SQL]
|
||||
* #convertCamelCase("HTML", "_") - [HTML]
|
||||
@ -64,36 +64,36 @@ public class WordUtils {
|
||||
* #convertCamelCase("Do178", "_") - [Do_178]
|
||||
* #convertCamelCase("Do178", "-") - [Do-178]
|
||||
* ...
|
||||
* </pre>
|
||||
* @param str word
|
||||
* @param separator separator
|
||||
* @return split result
|
||||
*/
|
||||
public static String convertCamelCase(String str, String separator) {
|
||||
return StringUtils.join(splitToWords(str), separator);
|
||||
}
|
||||
* </pre>
|
||||
* @param str word
|
||||
* @param separator separator
|
||||
* @return split result
|
||||
*/
|
||||
public static String convertCamelCase(String str, String separator) {
|
||||
return StringUtils.join(splitToWords(str), separator);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* foo_bar - fooBar
|
||||
* foo,bar - fooBar
|
||||
* </pre>
|
||||
* @param str word
|
||||
* @param separator separator
|
||||
* @return split result
|
||||
*/
|
||||
public static String convertToCamelCase(String str, String separator) {
|
||||
String strRtn = null;
|
||||
if (StringUtils.isNotBlank(str)) {
|
||||
StringBuilder sbRtn = new StringBuilder();
|
||||
for (String s : str.split(separator)) {
|
||||
sbRtn.append(StringUtils.capitalize(s));
|
||||
}
|
||||
strRtn = sbRtn.toString();
|
||||
}
|
||||
else {
|
||||
strRtn = str;
|
||||
}
|
||||
return strRtn;
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* foo_bar - fooBar
|
||||
* foo,bar - fooBar
|
||||
* </pre>
|
||||
* @param str word
|
||||
* @param separator separator
|
||||
* @return split result
|
||||
*/
|
||||
public static String convertToCamelCase(String str, String separator) {
|
||||
String strRtn = null;
|
||||
if (StringUtils.isNotBlank(str)) {
|
||||
StringBuilder sbRtn = new StringBuilder();
|
||||
for (String s : str.split(separator)) {
|
||||
sbRtn.append(StringUtils.capitalize(s));
|
||||
}
|
||||
strRtn = sbRtn.toString();
|
||||
}
|
||||
else {
|
||||
strRtn = str;
|
||||
}
|
||||
return strRtn;
|
||||
}
|
||||
}
|
||||
|
@ -18,39 +18,39 @@ import java.util.Arrays;
|
||||
* May 13, 2016 10:45:07 AM
|
||||
*/
|
||||
public class TestDriver {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(TestDriver.class);
|
||||
|
||||
@Test
|
||||
public void run() {
|
||||
M3<String, String> m3 = new M3<String, String>();
|
||||
log.info("M3 [{}].", m3.updateMap());
|
||||
log.info("M3 [{}].", m3.cols());
|
||||
}
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(TestDriver.class);
|
||||
|
||||
@Test
|
||||
public void run() {
|
||||
M3<String, String> m3 = new M3<String, String>();
|
||||
log.info("M3 [{}].", m3.updateMap());
|
||||
log.info("M3 [{}].", m3.cols());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runSearch() {
|
||||
Search search = new Search(1).eq("name", 2).or("gender", "F").or("gender", "M");
|
||||
System.err.println(StringUtils.join(search.assemble(), ""));
|
||||
search = new Search().or(
|
||||
new Search().or("Bar", "Foo")
|
||||
.eq("foo", "bar")
|
||||
.ne("ne_col", "1")
|
||||
.ne("not_null", null)
|
||||
.notNull("not_null2")
|
||||
@Test
|
||||
public void runSearch() {
|
||||
Search search = new Search(1).eq("name", 2).or("gender", "F").or("gender", "M");
|
||||
System.err.println(StringUtils.join(search.assemble(), ""));
|
||||
search = new Search().or(
|
||||
new Search().or("Bar", "Foo")
|
||||
.eq("foo", "bar")
|
||||
.ne("ne_col", "1")
|
||||
.ne("not_null", null)
|
||||
.notNull("not_null2")
|
||||
.or(new Search().eq("sub_or0", 1).eq("sub_or2", 2))
|
||||
.in("in_col", new Object[] {"1", 2, 3})
|
||||
.in("in_col", new Object[] {"1", 2, 3})
|
||||
.like("col_like", "%Shaun%")
|
||||
.or("Or0", "OrValue")
|
||||
.or("Or2", "OrValue2")
|
||||
).eq("name", 2).isNull("gaga");
|
||||
System.err.println(StringUtils.join(search.assemble(), ""));
|
||||
}
|
||||
.or("Or0", "OrValue")
|
||||
.or("Or2", "OrValue2")
|
||||
).eq("name", 2).isNull("gaga");
|
||||
System.err.println(StringUtils.join(search.assemble(), ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runArray() {
|
||||
Object array = new String[] {"1", "2"};
|
||||
System.err.println(Arrays.asList((Object[]) array));
|
||||
new Search().in("foo", new String[]{});
|
||||
}
|
||||
@Test
|
||||
public void runArray() {
|
||||
Object array = new String[] {"1", "2"};
|
||||
System.err.println(Arrays.asList((Object[]) array));
|
||||
new Search().in("foo", new String[]{});
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Properties>
|
||||
<Property name="pattern">%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n</Property>
|
||||
<Property name="log.dir">.logs</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${pattern}" />
|
||||
</Console>
|
||||
<RollingFile name="File"
|
||||
fileName="${log.dir}/${project.artifactId}-test.log"
|
||||
filePattern="${log.dir}/$${date:yyyy-MM}/${project.artifactId}-test-%d{yyyy-MM-dd}-%i.log">
|
||||
<Properties>
|
||||
<Property name="pattern">%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n</Property>
|
||||
<Property name="log.dir">.logs</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${pattern}" />
|
||||
<Policies>
|
||||
</Console>
|
||||
<RollingFile name="File"
|
||||
fileName="${log.dir}/${project.artifactId}-test.log"
|
||||
filePattern="${log.dir}/$${date:yyyy-MM}/${project.artifactId}-test-%d{yyyy-MM-dd}-%i.log">
|
||||
<PatternLayout pattern="${pattern}" />
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="16 MB" />
|
||||
</Policies>
|
||||
<SizeBasedTriggeringPolicy size="16 MB" />
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="32" />
|
||||
</RollingFile>
|
||||
</RollingFile>
|
||||
<!-- appender to send mails asynchronously -->
|
||||
<Async name="AsyncFile">
|
||||
<AppenderRef ref="File" />
|
||||
</Async>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="Console" level="DEBUG" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="Console" level="DEBUG" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?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
|
||||
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-mybatis-redis-cache</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon MyBatis Redis Cache</name>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>tigon-mybatis-redis-cache</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon MyBatis Redis Cache</name>
|
||||
<description>Tigon MyBatis Redis Cache</description>
|
||||
|
||||
<parent>
|
||||
@ -16,7 +16,7 @@
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
@ -25,11 +25,11 @@
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -11,16 +11,16 @@ import org.apache.ibatis.cache.Cache;
|
||||
*/
|
||||
public interface CacheTool {
|
||||
|
||||
/**
|
||||
* clear cache
|
||||
* @param mapper mapper
|
||||
*/
|
||||
void clearCache(Class<?> mapper);
|
||||
|
||||
/**
|
||||
* clear cache
|
||||
* @param mapper mapper
|
||||
* @return cache of mapper
|
||||
*/
|
||||
Cache getCache(Class<?> mapper);
|
||||
/**
|
||||
* clear cache
|
||||
* @param mapper mapper
|
||||
*/
|
||||
void clearCache(Class<?> mapper);
|
||||
|
||||
/**
|
||||
* clear cache
|
||||
* @param mapper mapper
|
||||
* @return cache of mapper
|
||||
*/
|
||||
Cache getCache(Class<?> mapper);
|
||||
}
|
||||
|
@ -15,111 +15,111 @@ import org.springframework.data.redis.core.ValueOperations;
|
||||
* Feb 23, 2016 6:03:39 PM
|
||||
*/
|
||||
public final class RedisCache implements Cache {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(RedisCache.class);
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(RedisCache.class);
|
||||
|
||||
private String id;
|
||||
private RedisTemplate<String, Object> redisTpl;
|
||||
private ValueOperations<String, Object> valueOp;
|
||||
private RedisCacheConfig config;
|
||||
private String id;
|
||||
private RedisTemplate<String, Object> redisTpl;
|
||||
private ValueOperations<String, Object> valueOp;
|
||||
private RedisCacheConfig config;
|
||||
|
||||
/**
|
||||
* construct cache
|
||||
* @param id cache id
|
||||
*/
|
||||
public RedisCache(String id) {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cache Instance ID Could Not Be Null");
|
||||
}
|
||||
log.info("Create Redis Cache [{}].", id);
|
||||
this.id = id;
|
||||
config = RedisCacheConfig.getInstance();
|
||||
redisTpl = config.getRedisTpl();
|
||||
valueOp = redisTpl.opsForValue();
|
||||
}
|
||||
/**
|
||||
* construct cache
|
||||
* @param id cache id
|
||||
*/
|
||||
public RedisCache(String id) {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cache Instance ID Could Not Be Null");
|
||||
}
|
||||
log.info("Create Redis Cache [{}].", id);
|
||||
this.id = id;
|
||||
config = RedisCacheConfig.getInstance();
|
||||
redisTpl = config.getRedisTpl();
|
||||
valueOp = redisTpl.opsForValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public int getSize() {
|
||||
log.debug("Get Cache [{}] Size.", id);
|
||||
return redisTpl.keys(prefixedKey("*")).size();
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public int getSize() {
|
||||
log.debug("Get Cache [{}] Size.", id);
|
||||
return redisTpl.keys(prefixedKey("*")).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void putObject(final Object key, final Object value) {
|
||||
log.debug("Put Object Key [{}], Value [{}].", key, value);
|
||||
valueOp.set(prefixedKey(key), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Object getObject(final Object key) {
|
||||
Object value = valueOp.get(prefixedKey(key));
|
||||
log.debug("Get Object Key [{}], Value [{}].", key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Object removeObject(final Object key) {
|
||||
log.debug("Remove Object Key [{}].", key);
|
||||
redisTpl.delete(prefixedKey(key));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void clear() {
|
||||
log.debug("Clear Cache Key [{}].", id);
|
||||
redisTpl.delete(redisTpl.keys(prefixedKey("*")));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ReadWriteLock getReadWriteLock() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void putObject(final Object key, final Object value) {
|
||||
log.debug("Put Object Key [{}], Value [{}].", key, value);
|
||||
valueOp.set(prefixedKey(key), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Object getObject(final Object key) {
|
||||
Object value = valueOp.get(prefixedKey(key));
|
||||
log.debug("Get Object Key [{}], Value [{}].", key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Object removeObject(final Object key) {
|
||||
log.debug("Remove Object Key [{}].", key);
|
||||
redisTpl.delete(prefixedKey(key));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void clear() {
|
||||
log.debug("Clear Cache Key [{}].", id);
|
||||
redisTpl.delete(redisTpl.keys(prefixedKey("*")));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ReadWriteLock getReadWriteLock() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Redis Cache [" + id + "]";
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Redis Cache [" + id + "]";
|
||||
}
|
||||
|
||||
// --
|
||||
// private methods
|
||||
// --
|
||||
// private methods
|
||||
|
||||
/**
|
||||
* return prefixed cache key
|
||||
* @param key cache key
|
||||
* @return prefixed key
|
||||
*/
|
||||
String prefixedKey(Object key) {
|
||||
return prefix() + String.valueOf(key);
|
||||
}
|
||||
/**
|
||||
* return prefixed cache key
|
||||
* @param key cache key
|
||||
* @return prefixed key
|
||||
*/
|
||||
String prefixedKey(Object key) {
|
||||
return prefix() + String.valueOf(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return cache prefix
|
||||
*/
|
||||
String prefix() {
|
||||
return id + ":";
|
||||
}
|
||||
/**
|
||||
* @return cache prefix
|
||||
*/
|
||||
String prefix() {
|
||||
return id + ":";
|
||||
}
|
||||
}
|
||||
|
@ -12,33 +12,33 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* May 12, 2016 9:02:37 PM
|
||||
*/
|
||||
public class RedisCacheConfig {
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTpl;
|
||||
private static RedisCacheConfig instance;
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTpl;
|
||||
private static RedisCacheConfig instance;
|
||||
|
||||
@PostConstruct
|
||||
void init() {
|
||||
instance = this;
|
||||
}
|
||||
@PostConstruct
|
||||
void init() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return cache instance
|
||||
*/
|
||||
public static RedisCacheConfig getInstance() {
|
||||
return instance;
|
||||
}
|
||||
/**
|
||||
* @return cache instance
|
||||
*/
|
||||
public static RedisCacheConfig getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the redisTpl
|
||||
*/
|
||||
public RedisTemplate<String, Object> getRedisTpl() {
|
||||
return redisTpl;
|
||||
}
|
||||
/**
|
||||
* @return the redisTpl
|
||||
*/
|
||||
public RedisTemplate<String, Object> getRedisTpl() {
|
||||
return redisTpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param redisTpl the redisTpl to set
|
||||
*/
|
||||
public void setRedisTpl(RedisTemplate<String, Object> redisTpl) {
|
||||
this.redisTpl = redisTpl;
|
||||
}
|
||||
/**
|
||||
* @param redisTpl the redisTpl to set
|
||||
*/
|
||||
public void setRedisTpl(RedisTemplate<String, Object> redisTpl) {
|
||||
this.redisTpl = redisTpl;
|
||||
}
|
||||
}
|
||||
|
@ -17,41 +17,41 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* Aug 26, 2015 10:58:58 AM
|
||||
*/
|
||||
public class CacheToolSupport implements CacheTool {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(CacheToolSupport.class);
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(CacheToolSupport.class);
|
||||
|
||||
@Autowired
|
||||
private SqlSessionFactory ssf;
|
||||
private Configuration configuration;
|
||||
@Autowired
|
||||
private SqlSessionFactory ssf;
|
||||
private Configuration configuration;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void clearCache(Class<?> mapper) {
|
||||
log.info("Clear Cache [{}].", mapper);
|
||||
Cache cache = getCache(mapper);
|
||||
if (cache != null) {
|
||||
cache.clear();
|
||||
}
|
||||
else {
|
||||
log.warn("No Cache [{}] Found.", mapper);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void clearCache(Class<?> mapper) {
|
||||
log.info("Clear Cache [{}].", mapper);
|
||||
Cache cache = getCache(mapper);
|
||||
if (cache != null) {
|
||||
cache.clear();
|
||||
}
|
||||
else {
|
||||
log.warn("No Cache [{}] Found.", mapper);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Cache getCache(Class<?> mapper) {
|
||||
return configuration.getCache(mapper.getName());
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Cache getCache(Class<?> mapper) {
|
||||
return configuration.getCache(mapper.getName());
|
||||
}
|
||||
|
||||
// --
|
||||
// private methods
|
||||
// --
|
||||
// private methods
|
||||
|
||||
@PostConstruct
|
||||
void init() {
|
||||
configuration = ssf.getConfiguration();
|
||||
}
|
||||
}
|
||||
@PostConstruct
|
||||
void init() {
|
||||
configuration = ssf.getConfiguration();
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Properties>
|
||||
<Property name="pattern">%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n</Property>
|
||||
<Property name="log.dir">${project.basedir}/.logs</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${pattern}" />
|
||||
</Console>
|
||||
<RollingFile name="File"
|
||||
fileName="${log.dir}/${project.artifactId}-test.log"
|
||||
filePattern="${log.dir}/$${date:yyyy-MM}/${project.artifactId}-test-%d{yyyy-MM-dd}-%i.log">
|
||||
<Properties>
|
||||
<Property name="pattern">%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n</Property>
|
||||
<Property name="log.dir">${project.basedir}/.logs</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${pattern}" />
|
||||
<Policies>
|
||||
</Console>
|
||||
<RollingFile name="File"
|
||||
fileName="${log.dir}/${project.artifactId}-test.log"
|
||||
filePattern="${log.dir}/$${date:yyyy-MM}/${project.artifactId}-test-%d{yyyy-MM-dd}-%i.log">
|
||||
<PatternLayout pattern="${pattern}" />
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="16 MB" />
|
||||
</Policies>
|
||||
<SizeBasedTriggeringPolicy size="16 MB" />
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="32" />
|
||||
</RollingFile>
|
||||
</RollingFile>
|
||||
<!-- appender to send mails asynchronously -->
|
||||
<Async name="AsyncFile">
|
||||
<AppenderRef ref="File" />
|
||||
</Async>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="Console" level="DEBUG" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="Console" level="DEBUG" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
|
@ -4,11 +4,11 @@
|
||||
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-mybatis</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon MyBatis</name>
|
||||
<description>Tigon MyBatis</description>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>tigon-mybatis</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon MyBatis</name>
|
||||
<description>Tigon MyBatis</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
@ -17,20 +17,20 @@
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-model</artifactId>
|
||||
</dependency>
|
||||
<!-- MyBatis -->
|
||||
<dependency>
|
||||
<!-- MyBatis -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
</dependency>
|
||||
<artifactId>mybatis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
@ -42,26 +42,26 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
|
@ -25,11 +25,11 @@ public interface BaseMapper<PrimaryKey, Model extends BaseModel<PrimaryKey>> {
|
||||
String PARAM_COL_KEY = "col";
|
||||
String PARAM_COLS_KEY = "cols";
|
||||
|
||||
/**
|
||||
/**
|
||||
* insert model
|
||||
* @param model model
|
||||
* @return insert result
|
||||
*/
|
||||
* @param model model
|
||||
* @return insert result
|
||||
*/
|
||||
int insert(@Param(PARAM_MODEL_KEY) Model model);
|
||||
|
||||
/**
|
||||
|
@ -9,7 +9,6 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import org.w3c.dom.Document;
|
||||
import javax.xml.transform.*;
|
||||
import java.util.concurrent.*;
|
||||
import org.w3c.dom.DocumentType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -58,96 +57,76 @@ public class TigonSqlSessionFactoryBean extends SqlSessionFactoryBean {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setMapperLocations(final Resource[] mapperLocations) {
|
||||
@Override
|
||||
public void setMapperLocations(final Resource[] mapperLocations) {
|
||||
if (mapperLocations != null && mapperLocations.length > 0) {
|
||||
final ExecutorService updateMapperXmlExeService =
|
||||
Executors.newFixedThreadPool(mapperLocations.length);
|
||||
final List<Future<Resource>> updateMapperXmlFutures =
|
||||
new ArrayList<Future<Resource>>(mapperLocations.length);
|
||||
final XMLMapperEntityResolver xmlMapperEntityResolver = new XMLMapperEntityResolver();
|
||||
final XMLMapperEntityResolver xmlMapperEntityResolver =
|
||||
new XMLMapperEntityResolver();
|
||||
final List<Resource> updatedMapperLocations =
|
||||
new ArrayList<Resource>(mapperLocations.length);
|
||||
// update mapper xml in thread
|
||||
for (final Resource mapperLocation : mapperLocations) {
|
||||
updateMapperXmlFutures.add(updateMapperXmlExeService.submit(new Callable<Resource>() {
|
||||
@Override
|
||||
public Resource call() throws Exception {
|
||||
return updateMapperXml(xmlMapperEntityResolver, mapperLocation);
|
||||
}
|
||||
}));
|
||||
updatedMapperLocations.add(updateMapperXml(xmlMapperEntityResolver, mapperLocation));
|
||||
}
|
||||
|
||||
final List<Resource> updatedMapperLocations =
|
||||
new ArrayList<Resource>(mapperLocations.length);
|
||||
try {
|
||||
for (Future<Resource> future : updateMapperXmlFutures) {
|
||||
updatedMapperLocations.add(future.get());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Update MyBatis Mapper Error Caused", e);
|
||||
}
|
||||
updateMapperXmlExeService.shutdown();
|
||||
super.setMapperLocations(updatedMapperLocations.toArray(mapperLocations));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
|
||||
// this.setMapperLocations();
|
||||
SqlSessionFactory ssf = super.buildSqlSessionFactory();
|
||||
Configuration config = ssf.getConfiguration();
|
||||
config.setMapUnderscoreToCamelCase(true);
|
||||
config.addInterceptor(new KeyGenInterceptor());
|
||||
// tigon mapper
|
||||
Resource mapperLocation =
|
||||
findResource("classpath*:__tigon_mybatis__.xml");
|
||||
XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),
|
||||
config, mapperLocation.toString(), config.getSqlFragments());
|
||||
xmlMapperBuilder.parse();
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
|
||||
SqlSessionFactory ssf = super.buildSqlSessionFactory();
|
||||
Configuration config = ssf.getConfiguration();
|
||||
config.setMapUnderscoreToCamelCase(true);
|
||||
config.addInterceptor(new KeyGenInterceptor());
|
||||
// tigon mapper
|
||||
Resource mapperLocation =
|
||||
findResource("classpath*:__tigon_mybatis__.xml");
|
||||
XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),
|
||||
config, mapperLocation.toString(), config.getSqlFragments());
|
||||
xmlMapperBuilder.parse();
|
||||
return ssf;
|
||||
}
|
||||
|
||||
// --
|
||||
// private methods
|
||||
// --
|
||||
// private methods
|
||||
|
||||
/**
|
||||
* find resource by path
|
||||
* @param path path
|
||||
* @return resource
|
||||
*/
|
||||
private Resource findResource(String path) {
|
||||
Resource resource = null;
|
||||
Resource[] resources = null;
|
||||
try {
|
||||
resources = new PathMatchingResourcePatternResolver()
|
||||
.getResources(path);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Find Resource [" + path + "] Error Caused", e);
|
||||
}
|
||||
if (resources.length == 0) {
|
||||
throw new IllegalStateException(
|
||||
"No Resource [" + path + "] Found");
|
||||
}
|
||||
else if (resources.length == 1) {
|
||||
resource = resources[0];
|
||||
log.info("Resource [{}] Of Path [{}] Found.", resource, path);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Multiple Resources ["
|
||||
+ org.apache.commons.lang3.StringUtils.join(resources, ", ")
|
||||
+ "] Of Path [" + path + "] Found");
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
/**
|
||||
* find resource by path
|
||||
* @param path path
|
||||
* @return resource
|
||||
*/
|
||||
private Resource findResource(String path) {
|
||||
Resource resource = null;
|
||||
Resource[] resources = null;
|
||||
try {
|
||||
resources = new PathMatchingResourcePatternResolver()
|
||||
.getResources(path);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Find Resource [" + path + "] Error Caused", e);
|
||||
}
|
||||
if (resources.length == 0) {
|
||||
throw new IllegalStateException(
|
||||
"No Resource [" + path + "] Found");
|
||||
}
|
||||
else if (resources.length == 1) {
|
||||
resource = resources[0];
|
||||
log.info("Resource [{}] Of Path [{}] Found.", resource, path);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Multiple Resources ["
|
||||
+ org.apache.commons.lang3.StringUtils.join(resources, ", ")
|
||||
+ "] Of Path [" + path + "] Found");
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
private Class<BaseMapper> getMapperClass(String name) {
|
||||
Class<BaseMapper> mapperClassRtn = null;
|
||||
private Class<BaseMapper> getMapperClass(String name) {
|
||||
Class<BaseMapper> mapperClassRtn = null;
|
||||
try {
|
||||
Class<?> classFound = ClassUtils.forName(name,
|
||||
ClassUtils.getDefaultClassLoader());
|
||||
@ -161,128 +140,128 @@ public class TigonSqlSessionFactoryBean extends SqlSessionFactoryBean {
|
||||
return mapperClassRtn;
|
||||
}
|
||||
|
||||
private Transformer newTransformer() {
|
||||
try {
|
||||
return TransformerFactory.newInstance().newTransformer();
|
||||
}
|
||||
catch (TransformerConfigurationException e) {
|
||||
throw new IllegalStateException(
|
||||
"Create XML Transformer Error Caused", e);
|
||||
}
|
||||
}
|
||||
private Transformer newTransformer() {
|
||||
try {
|
||||
return TransformerFactory.newInstance().newTransformer();
|
||||
}
|
||||
catch (TransformerConfigurationException e) {
|
||||
throw new IllegalStateException(
|
||||
"Create XML Transformer Error Caused", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Resource updateMapperXml(
|
||||
private Resource updateMapperXml(
|
||||
final XMLMapperEntityResolver xmlMapperEntityResolver,
|
||||
final Resource mapperLocation) {
|
||||
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
Resource mapperResourceUpdated = null;
|
||||
inputStream = mapperLocation.getInputStream();
|
||||
final XPathParser xPathParser =
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
Resource mapperResourceUpdated = null;
|
||||
inputStream = mapperLocation.getInputStream();
|
||||
final XPathParser xPathParser =
|
||||
new XPathParser(inputStream, false, null, xmlMapperEntityResolver);
|
||||
final String mapperNamespace =
|
||||
final String mapperNamespace =
|
||||
xPathParser.evalString("/mapper/@namespace");
|
||||
|
||||
if (StringUtils.isNotBlank(mapperNamespace)) {
|
||||
final Class<BaseMapper> mapperClass =
|
||||
if (StringUtils.isNotBlank(mapperNamespace)) {
|
||||
final Class<BaseMapper> mapperClass =
|
||||
getMapperClass(mapperNamespace);
|
||||
if (mapperClass != null) {
|
||||
MetaObject metaXpp = SystemMetaObject.forObject(xPathParser);
|
||||
Document doc = (Document) metaXpp.getValue("document");
|
||||
boolean updated = false;
|
||||
for (MapperXmlProcessor mapperXmlProcessor : MAPPER_XML_PROCESSORS) {
|
||||
if (mapperXmlProcessor.accept(mapperClass, xPathParser)) {
|
||||
mapperXmlProcessor.process(mapperClass, doc);
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
if (updated) {
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final DocumentType docType = doc.getDoctype();
|
||||
final Transformer transformer = newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
|
||||
if (mapperClass != null) {
|
||||
MetaObject metaXpp = SystemMetaObject.forObject(xPathParser);
|
||||
Document doc = (Document) metaXpp.getValue("document");
|
||||
boolean updated = false;
|
||||
for (MapperXmlProcessor mapperXmlProcessor : MAPPER_XML_PROCESSORS) {
|
||||
if (mapperXmlProcessor.accept(mapperClass, xPathParser)) {
|
||||
mapperXmlProcessor.process(mapperClass, doc);
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
if (updated) {
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final DocumentType docType = doc.getDoctype();
|
||||
final Transformer transformer = newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
|
||||
docType.getPublicId());
|
||||
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
|
||||
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
|
||||
docType.getSystemId());
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
transformer.transform(new DOMSource(doc), new StreamResult(baos));
|
||||
mapperResourceUpdated = new TigonMapperResource(baos.toByteArray(), mapperLocation);
|
||||
log.info("Tigon MyBatis Mapper [{}] Updated Result [{}].", mapperResourceUpdated, baos);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mapperResourceUpdated != null ? mapperResourceUpdated : mapperLocation;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException(
|
||||
"Read MyBatis Mapper Resource [" + mapperLocation + "] Error Caused", e);
|
||||
}
|
||||
catch (TransformerException e) {
|
||||
throw new IllegalStateException(
|
||||
"Transform MyBatis Mapper Resource [" + mapperLocation + "] Error Caused", e);
|
||||
}
|
||||
finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.warn("Close MyBatis Mapper Resource [{}] Input Stream Error Caused.",
|
||||
mapperLocation, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
transformer.transform(new DOMSource(doc), new StreamResult(baos));
|
||||
mapperResourceUpdated = new TigonMapperResource(baos.toByteArray(), mapperLocation);
|
||||
log.info("Tigon MyBatis Mapper [{}] Updated Result [{}].", mapperResourceUpdated, baos);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mapperResourceUpdated != null ? mapperResourceUpdated : mapperLocation;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException(
|
||||
"Read MyBatis Mapper Resource [" + mapperLocation + "] Error Caused", e);
|
||||
}
|
||||
catch (TransformerException e) {
|
||||
throw new IllegalStateException(
|
||||
"Transform MyBatis Mapper Resource [" + mapperLocation + "] Error Caused", e);
|
||||
}
|
||||
finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.warn("Close MyBatis Mapper Resource [{}] Input Stream Error Caused.",
|
||||
mapperLocation, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class TigonMapperResource extends ByteArrayResource {
|
||||
private final Resource originResource;
|
||||
static class TigonMapperResource extends ByteArrayResource {
|
||||
private final Resource originResource;
|
||||
|
||||
public TigonMapperResource(byte[] byteArray, Resource originResource) {
|
||||
super(byteArray);
|
||||
this.originResource = originResource;
|
||||
}
|
||||
public TigonMapperResource(byte[] byteArray, Resource originResource) {
|
||||
super(byteArray);
|
||||
this.originResource = originResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* for JRebel monitor file
|
||||
*/
|
||||
@Override
|
||||
public URL getURL() throws IOException {
|
||||
return originResource.getURL();
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* for JRebel monitor file
|
||||
*/
|
||||
@Override
|
||||
public URL getURL() throws IOException {
|
||||
return originResource.getURL();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* for JRebel monitor file
|
||||
*/
|
||||
@Override
|
||||
public File getFile() throws IOException {
|
||||
return originResource.getFile();
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* for JRebel monitor file
|
||||
*/
|
||||
@Override
|
||||
public File getFile() throws IOException {
|
||||
return originResource.getFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return originResource.getFilename();
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return originResource.getFilename();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "[TIGON] " + originResource.getDescription();
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "[TIGON] " + originResource.getDescription();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[TIGON] " + originResource.toString();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[TIGON] " + originResource.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC
|
||||
"-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
"-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="Tigon">
|
||||
|
||||
<!-- Search -->
|
||||
<sql id="search">
|
||||
<choose>
|
||||
<sql id="search">
|
||||
<choose>
|
||||
<when test="s instanceof me.chyxion.tigon.mybatis.Search">
|
||||
<if test="s.hasCriterion()">
|
||||
where <include refid="Tigon.assemble" />
|
||||
@ -21,7 +21,7 @@
|
||||
where <include refid="primaryKey" /> = #{s}
|
||||
</when>
|
||||
</choose>
|
||||
</sql>
|
||||
</sql>
|
||||
<!--/ Search -->
|
||||
|
||||
<!-- Search Assemble -->
|
||||
@ -75,7 +75,7 @@
|
||||
<!--/ Search For Count -->
|
||||
|
||||
<!-- Insert -->
|
||||
<sql id="insert">
|
||||
<sql id="insert">
|
||||
insert into <include refid="table" />
|
||||
<choose>
|
||||
<!-- Model -->
|
||||
@ -122,11 +122,11 @@
|
||||
</foreach>
|
||||
</otherwise>
|
||||
</choose>
|
||||
</sql>
|
||||
</sql>
|
||||
<!--/ Insert -->
|
||||
|
||||
<!-- Update -->
|
||||
<sql id="update">
|
||||
<sql id="update">
|
||||
update <include refid="table" />
|
||||
<set>
|
||||
<choose>
|
||||
@ -153,7 +153,7 @@
|
||||
where <include refid="primaryKey" /> = #{__primary_key_value__}
|
||||
</otherwise>
|
||||
</choose>
|
||||
</sql>
|
||||
</sql>
|
||||
<!--/ Update -->
|
||||
|
||||
<!-- Set Cols null -->
|
||||
@ -176,31 +176,31 @@
|
||||
<!--/ Set Cols null -->
|
||||
|
||||
<!-- Delete -->
|
||||
<sql id="delete">
|
||||
delete from
|
||||
<sql id="delete">
|
||||
delete from
|
||||
<include refid="table" />
|
||||
<include refid="Tigon.search" />
|
||||
</sql>
|
||||
<include refid="Tigon.search" />
|
||||
</sql>
|
||||
<!--/ Delete -->
|
||||
|
||||
<!-- Find One -->
|
||||
<sql id="find">
|
||||
<sql id="find">
|
||||
select
|
||||
<include refid="cols" />
|
||||
from
|
||||
<include refid="table" />
|
||||
<include refid="Tigon.search" />
|
||||
</sql>
|
||||
<include refid="Tigon.search" />
|
||||
</sql>
|
||||
<!--/ Find One -->
|
||||
|
||||
<!-- List -->
|
||||
<sql id="list">
|
||||
<sql id="list">
|
||||
select
|
||||
<include refid="cols" />
|
||||
from
|
||||
<include refid="table" />
|
||||
<include refid="Tigon.search" />
|
||||
</sql>
|
||||
<include refid="Tigon.search" />
|
||||
</sql>
|
||||
<!--/ List -->
|
||||
|
||||
<!-- Count -->
|
||||
|
@ -27,50 +27,50 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||
public class AppMapperTest // extends AbstractTransactionalJUnit4SpringContextTests
|
||||
{
|
||||
@Autowired
|
||||
private AppMapper mapper;
|
||||
@Autowired
|
||||
private AppMapper mapper;
|
||||
@Autowired
|
||||
private ActivityMapper activityMapper;
|
||||
|
||||
@Test
|
||||
public void mapperTest() {
|
||||
// String id = String.valueOf(new Date().getTime());
|
||||
// init model
|
||||
@Test
|
||||
public void mapperTest() {
|
||||
// String id = String.valueOf(new Date().getTime());
|
||||
// init model
|
||||
|
||||
App m = newApp();
|
||||
App m2 = newApp();
|
||||
// m.setCreatedBy("chyxion");
|
||||
// mapper.insertApp(Arrays.asList(m, m2));
|
||||
mapper.insert(Arrays.asList(m, m2));
|
||||
App m3 = newApp();
|
||||
mapper.insert(m3);
|
||||
App m4 = newApp();
|
||||
App m5 = newApp();
|
||||
mapper.insert(new App[] {m4, m5});
|
||||
// Assert.assertTrue(mapper.list(null).size() > 0);
|
||||
System.err.println(m);
|
||||
System.err.println(m2);
|
||||
System.err.println(m3);
|
||||
System.err.println(m4);
|
||||
System.err.println(m5);
|
||||
App m = newApp();
|
||||
App m2 = newApp();
|
||||
// m.setCreatedBy("chyxion");
|
||||
// mapper.insertApp(Arrays.asList(m, m2));
|
||||
mapper.insert(Arrays.asList(m, m2));
|
||||
App m3 = newApp();
|
||||
mapper.insert(m3);
|
||||
App m4 = newApp();
|
||||
App m5 = newApp();
|
||||
mapper.insert(new App[] {m4, m5});
|
||||
// Assert.assertTrue(mapper.list(null).size() > 0);
|
||||
System.err.println(m);
|
||||
System.err.println(m2);
|
||||
System.err.println(m3);
|
||||
System.err.println(m4);
|
||||
System.err.println(m5);
|
||||
for (App app : mapper.list(null)) {
|
||||
System.err.println(app);
|
||||
}
|
||||
}
|
||||
|
||||
App newApp() {
|
||||
App m = new App();
|
||||
m.setCreatedBy("donghuang");
|
||||
m.setDateCreated(new Date());
|
||||
m.setName("s");
|
||||
m.setHoldingDate(new Date());
|
||||
m.setEnabled(true);
|
||||
m.setHoldingPlace("s");
|
||||
return m;
|
||||
}
|
||||
App newApp() {
|
||||
App m = new App();
|
||||
m.setCreatedBy("donghuang");
|
||||
m.setDateCreated(new Date());
|
||||
m.setName("s");
|
||||
m.setHoldingDate(new Date());
|
||||
m.setEnabled(true);
|
||||
m.setHoldingPlace("s");
|
||||
return m;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFind() {
|
||||
@Test
|
||||
public void testFind() {
|
||||
App app = mapper.find(1L);
|
||||
System.err.println(app);
|
||||
app = mapper.find(new Search().eq(App.NAME, "s1").desc(App.NAME).offset(0).limit(1));
|
||||
@ -84,7 +84,7 @@ public class AppMapperTest // extends AbstractTransactionalJUnit4SpringContextTe
|
||||
|
||||
@Test
|
||||
public void testCount() {
|
||||
// System.err.println(mapper.count(null));
|
||||
// System.err.println(mapper.count(null));
|
||||
System.err.println(activityMapper.count(new Search(3)));
|
||||
System.err.println(mapper.count(new Search(3)));
|
||||
System.err.println(mapper.count(new Search().gt(App.ID, 1).limit(3).desc(App.NAME)));
|
||||
|
@ -28,7 +28,7 @@ public class Activity extends M3<String, Long> {
|
||||
public static final String HOLDING_PLACE = "holding_place";
|
||||
|
||||
// Properties
|
||||
private String name;
|
||||
private Date holdingDate;
|
||||
private String holdingPlace;
|
||||
private String name;
|
||||
private Date holdingDate;
|
||||
private String holdingPlace;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class App extends M3<String, Long> {
|
||||
public static final String HOLDING_PLACE = "holding_place";
|
||||
|
||||
// Properties
|
||||
private String name;
|
||||
private Date holdingDate;
|
||||
private String holdingPlace;
|
||||
private String name;
|
||||
private Date holdingDate;
|
||||
private String holdingPlace;
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Properties>
|
||||
<Property name="pattern">%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n</Property>
|
||||
<Property name="log.dir">.logs</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${pattern}" />
|
||||
</Console>
|
||||
<RollingFile name="File"
|
||||
fileName="${log.dir}/tigon-mybatis.log"
|
||||
filePattern="${log.dir}/tigon-mybatis-%d{yyyy-MM-dd}-%i.log">
|
||||
<Properties>
|
||||
<Property name="pattern">%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n</Property>
|
||||
<Property name="log.dir">.logs</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${pattern}" />
|
||||
<Policies>
|
||||
</Console>
|
||||
<RollingFile name="File"
|
||||
fileName="${log.dir}/tigon-mybatis.log"
|
||||
filePattern="${log.dir}/tigon-mybatis-%d{yyyy-MM-dd}-%i.log">
|
||||
<PatternLayout pattern="${pattern}" />
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="16 MB" />
|
||||
</Policies>
|
||||
<SizeBasedTriggeringPolicy size="16 MB" />
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="32" />
|
||||
</RollingFile>
|
||||
</RollingFile>
|
||||
<!-- appender to send mails asynchronously -->
|
||||
<Async name="AsyncFile">
|
||||
<AppenderRef ref="File" />
|
||||
</Async>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="Console" level="DEBUG" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="Console" level="DEBUG" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
<configuration>
|
||||
<settings>
|
||||
<!-- 全局映射器启用缓存 -->
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?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
|
||||
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">
|
||||
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
|
||||
init-method="init"
|
||||
@ -11,13 +11,13 @@
|
||||
p:username="${db.user}"
|
||||
p:password="${db.password}"
|
||||
p:maxActive="16" />
|
||||
<!-- MyBatis SqlSessionFactory -->
|
||||
<bean id="sqlSessionFactory"
|
||||
<!-- MyBatis SqlSessionFactory -->
|
||||
<bean id="sqlSessionFactory"
|
||||
class="me.chyxion.tigon.mybatis.TigonSqlSessionFactoryBean"
|
||||
p:dataSource-ref="dataSource"
|
||||
p:mapperLocations="classpath*:mybatis/mappers/*-mapper.xml" />
|
||||
<!-- MyBatis Mappers Auto Scan -->
|
||||
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
|
||||
p:basePackage="me.chyxion.tigon.mybatis.test.mapper"
|
||||
p:sqlSessionFactoryBeanName="sqlSessionFactory" />
|
||||
</beans>
|
||||
p:dataSource-ref="dataSource"
|
||||
p:mapperLocations="classpath*:mybatis/mappers/*-mapper.xml" />
|
||||
<!-- MyBatis Mappers Auto Scan -->
|
||||
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
|
||||
p:basePackage="me.chyxion.tigon.mybatis.test.mapper"
|
||||
p:sqlSessionFactoryBeanName="sqlSessionFactory" />
|
||||
</beans>
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?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: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
|
||||
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">
|
||||
<context:property-placeholder location="classpath:spring/config.properties" />
|
||||
<context:property-placeholder location="classpath:spring/config.properties" />
|
||||
</beans>
|
||||
|
@ -1,50 +1,50 @@
|
||||
<?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
|
||||
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-props-config</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Props Config</name>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>tigon-props-config</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Props Config</name>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<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>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<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>
|
||||
|
@ -16,105 +16,105 @@ import org.slf4j.LoggerFactory;
|
||||
* Oct 13, 2015 11:25:55 AM
|
||||
*/
|
||||
public class PropsConfig {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(PropsConfig.class);
|
||||
public static final Properties CONFIG_PROPS =
|
||||
new Properties();
|
||||
static { load(); }
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(PropsConfig.class);
|
||||
public static final Properties CONFIG_PROPS =
|
||||
new Properties();
|
||||
static { load(); }
|
||||
|
||||
/**
|
||||
* get app (container/tomcat) dir
|
||||
* @return app dir
|
||||
*/
|
||||
public static File getAppDir() {
|
||||
File file = new File(
|
||||
// classes
|
||||
PropsConfig.class.getResource("/").getFile())
|
||||
// WEB-INF
|
||||
.getParentFile()
|
||||
// WebApp
|
||||
.getParentFile()
|
||||
// WebApps
|
||||
.getParentFile()
|
||||
// App
|
||||
.getParentFile();
|
||||
log.info("Get App Dir [{}].", file.getAbsolutePath());
|
||||
return file;
|
||||
}
|
||||
/**
|
||||
* get app (container/tomcat) dir
|
||||
* @return app dir
|
||||
*/
|
||||
public static File getAppDir() {
|
||||
File file = new File(
|
||||
// classes
|
||||
PropsConfig.class.getResource("/").getFile())
|
||||
// WEB-INF
|
||||
.getParentFile()
|
||||
// WebApp
|
||||
.getParentFile()
|
||||
// WebApps
|
||||
.getParentFile()
|
||||
// App
|
||||
.getParentFile();
|
||||
log.info("Get App Dir [{}].", file.getAbsolutePath());
|
||||
return file;
|
||||
}
|
||||
|
||||
// --
|
||||
// private methods
|
||||
// --
|
||||
// private methods
|
||||
|
||||
/**
|
||||
* load system config
|
||||
*/
|
||||
static void load() {
|
||||
InputStream configIn = null;
|
||||
String configPath = "/spring/config.properties";
|
||||
try {
|
||||
log.info("Load Classpath Config [{}].", configPath);
|
||||
configIn = PropsConfig.class
|
||||
.getResourceAsStream(configPath);
|
||||
if (configIn != null) {
|
||||
log.info("Classpath Config [{}] Found.", configPath);
|
||||
CONFIG_PROPS.load(configIn);
|
||||
}
|
||||
else {
|
||||
log.warn("No Classpath Config [{}] Found.", configPath);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Load Classpath Config [{}] Error Caused.", configPath, e);
|
||||
}
|
||||
finally {
|
||||
if (configIn != null) {
|
||||
try {
|
||||
configIn.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.warn("Config Input Stream Close Eroror Caused.");
|
||||
}
|
||||
}
|
||||
}
|
||||
File appDir = getAppDir();
|
||||
// load global config
|
||||
load(appDir.getParentFile());
|
||||
// load app config
|
||||
load(appDir);
|
||||
log.debug("Config Props [{}] Loaded.", CONFIG_PROPS);
|
||||
}
|
||||
/**
|
||||
* load system config
|
||||
*/
|
||||
static void load() {
|
||||
InputStream configIn = null;
|
||||
String configPath = "/spring/config.properties";
|
||||
try {
|
||||
log.info("Load Classpath Config [{}].", configPath);
|
||||
configIn = PropsConfig.class
|
||||
.getResourceAsStream(configPath);
|
||||
if (configIn != null) {
|
||||
log.info("Classpath Config [{}] Found.", configPath);
|
||||
CONFIG_PROPS.load(configIn);
|
||||
}
|
||||
else {
|
||||
log.warn("No Classpath Config [{}] Found.", configPath);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Load Classpath Config [{}] Error Caused.", configPath, e);
|
||||
}
|
||||
finally {
|
||||
if (configIn != null) {
|
||||
try {
|
||||
configIn.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.warn("Config Input Stream Close Eroror Caused.");
|
||||
}
|
||||
}
|
||||
}
|
||||
File appDir = getAppDir();
|
||||
// load global config
|
||||
load(appDir.getParentFile());
|
||||
// load app config
|
||||
load(appDir);
|
||||
log.debug("Config Props [{}] Loaded.", CONFIG_PROPS);
|
||||
}
|
||||
|
||||
static void load(File dir) {
|
||||
// load from custom file
|
||||
File configFile = new File(dir, "config/config.properties");
|
||||
String configPath = configFile.getAbsolutePath();
|
||||
log.info("Load Config From Path [{}].", configPath);
|
||||
if (configFile.exists()) {
|
||||
log.info("Config File [{}] Exists.", configPath);
|
||||
InputStream configIn = null;
|
||||
try {
|
||||
configIn = new FileInputStream(configFile);
|
||||
Properties props = new Properties();
|
||||
props.load(configIn);
|
||||
log.debug("Config Props [{}] Found.", props);
|
||||
CONFIG_PROPS.putAll(props);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Load Config [{}] Error Caused.", configPath, e);
|
||||
}
|
||||
finally {
|
||||
if (configIn != null) {
|
||||
try {
|
||||
configIn.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.warn("Config Input Stream Close Error Caused.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
log.info("Config File [{}] Does Not Exist, Ignore.", configPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
static void load(File dir) {
|
||||
// load from custom file
|
||||
File configFile = new File(dir, "config/config.properties");
|
||||
String configPath = configFile.getAbsolutePath();
|
||||
log.info("Load Config From Path [{}].", configPath);
|
||||
if (configFile.exists()) {
|
||||
log.info("Config File [{}] Exists.", configPath);
|
||||
InputStream configIn = null;
|
||||
try {
|
||||
configIn = new FileInputStream(configFile);
|
||||
Properties props = new Properties();
|
||||
props.load(configIn);
|
||||
log.debug("Config Props [{}] Found.", props);
|
||||
CONFIG_PROPS.putAll(props);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Load Config [{}] Error Caused.", configPath, e);
|
||||
}
|
||||
finally {
|
||||
if (configIn != null) {
|
||||
try {
|
||||
configIn.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.warn("Config Input Stream Close Error Caused.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
log.info("Config File [{}] Does Not Exist, Ignore.", configPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,4 +7,4 @@
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
<context:property-placeholder properties-ref="configProps" />
|
||||
</beans>
|
||||
</beans>
|
||||
|
@ -12,4 +12,4 @@
|
||||
<util:constant id="configProps"
|
||||
static-field="me.chyxion.tigon.propsconfig.PropsConfig.CONFIG_PROPS" />
|
||||
<context:property-placeholder properties-ref="configProps" />
|
||||
</beans>
|
||||
</beans>
|
||||
|
@ -1,22 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="encoding" value="utf-8" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="encoding" value="utf-8" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="file" class="org.apache.log4j.RollingFileAppender">
|
||||
<param name="encoding" value="utf-8" />
|
||||
<param name="MaxFileSize" value="64MB" />
|
||||
<param name="MaxBackupIndex" value="16" />
|
||||
<param name="File" value="E:\\Workspaces\\Eclipse\\FlagInfoEChat\\Commons\\echat-db/.log/echat-db-test.log" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="file" class="org.apache.log4j.RollingFileAppender">
|
||||
<param name="encoding" value="utf-8" />
|
||||
<param name="MaxFileSize" value="64MB" />
|
||||
<param name="MaxBackupIndex" value="16" />
|
||||
<param name="File" value="E:\\Workspaces\\Eclipse\\FlagInfoEChat\\Commons\\echat-db/.log/echat-db-test.log" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<logger name="org.apache">
|
||||
<level value="warn" />
|
||||
@ -28,9 +28,9 @@
|
||||
<appender-ref ref="file" />
|
||||
</logger>
|
||||
|
||||
<root>
|
||||
<level value="debug" />
|
||||
<root>
|
||||
<level value="debug" />
|
||||
<appender-ref ref="console" />
|
||||
<appender-ref ref="file" />
|
||||
</root>
|
||||
<appender-ref ref="file" />
|
||||
</root>
|
||||
</log4j:configuration>
|
||||
|
@ -16,7 +16,7 @@
|
||||
<context:property-placeholder location="classpath:spring/config.properties" />
|
||||
<import resource="classpath:spring/spring-echat-redis.xml" />
|
||||
<bean class="cn.com.flaginfo.web.cache.RedisCacheConfig" />
|
||||
<aop:aspectj-autoproxy proxy-target-class="true" />
|
||||
<aop:aspectj-autoproxy proxy-target-class="true" />
|
||||
<bean id="dataSource"
|
||||
class="com.alibaba.druid.pool.DruidDataSource"
|
||||
init-method="init"
|
||||
@ -25,16 +25,16 @@
|
||||
p:username="${db.user}"
|
||||
p:password="${db.password}"
|
||||
/>
|
||||
<!-- Transaction Manager -->
|
||||
<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
|
||||
<!-- Transaction Manager -->
|
||||
<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
|
||||
p:dataSource-ref="dataSource" />
|
||||
<tx:annotation-driven transaction-manager="transactionManager" />
|
||||
<!-- MyBatis SqlSessionFactory -->
|
||||
<bean id="sqlSessionFactory" class="me.chyxion.tigon.dao.mybatis.SqlSessionFactoryBeanExt"
|
||||
p:dataSource-ref="dataSource"
|
||||
p:configLocation="classpath:mybatis/mybatis-config.xml"
|
||||
p:typeAliasesPackage="${project.groupId}.**.models"
|
||||
p:mapperLocations="classpath*:mybatis/mappers/**/*-mapper.xml">
|
||||
<tx:annotation-driven transaction-manager="transactionManager" />
|
||||
<!-- MyBatis SqlSessionFactory -->
|
||||
<bean id="sqlSessionFactory" class="me.chyxion.tigon.dao.mybatis.SqlSessionFactoryBeanExt"
|
||||
p:dataSource-ref="dataSource"
|
||||
p:configLocation="classpath:mybatis/mybatis-config.xml"
|
||||
p:typeAliasesPackage="${project.groupId}.**.models"
|
||||
p:mapperLocations="classpath*:mybatis/mappers/**/*-mapper.xml">
|
||||
<property name="plugins">
|
||||
<list>
|
||||
<bean class="me.chyxion.tigon.dao.mybatis.pagination.PaginationIntercepter"
|
||||
@ -42,9 +42,9 @@
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
<!-- MyBatis Mapper Auto Scan -->
|
||||
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
|
||||
p:basePackage="${project.groupId}.**.mappers"
|
||||
<!-- MyBatis Mapper Auto Scan -->
|
||||
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
|
||||
p:basePackage="${project.groupId}.**.mappers"
|
||||
p:sqlSessionFactoryBeanName="sqlSessionFactory"
|
||||
/>
|
||||
</beans>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<artifactId>tigon-redis</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Redis</name>
|
||||
<description>Tigon Redis</description>
|
||||
<description>Tigon Redis</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
@ -16,7 +16,7 @@
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
@ -45,22 +45,22 @@
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -8,18 +8,18 @@ package me.chyxion.tigon.redis.pub;
|
||||
* Nov 7, 2015 5:32:36 PM
|
||||
*/
|
||||
public interface PubProducer {
|
||||
String PUB_QUEUE_SUFFIX = "_QUEUE";
|
||||
String MESSAGE_CHANEL = "__PUBLICATION__";
|
||||
String PUB_QUEUE_SUFFIX = "_QUEUE";
|
||||
String MESSAGE_CHANEL = "__PUBLICATION__";
|
||||
|
||||
/**
|
||||
* @param topic topic
|
||||
* @param message message
|
||||
*/
|
||||
void publish(String topic, Object message);
|
||||
/**
|
||||
* @param topic topic
|
||||
* @param message message
|
||||
*/
|
||||
void publish(String topic, Object message);
|
||||
|
||||
/**
|
||||
* @param topic topic
|
||||
* @param message message
|
||||
*/
|
||||
void publish(String topic, String message);
|
||||
/**
|
||||
* @param topic topic
|
||||
* @param message message
|
||||
*/
|
||||
void publish(String topic, String message);
|
||||
}
|
||||
|
@ -14,34 +14,34 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
* Nov 7, 2015 5:07:50 PM
|
||||
*/
|
||||
public class PubProducerSupport
|
||||
implements PubProducer {
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTpl;
|
||||
@Autowired
|
||||
private StringRedisTemplate strRedisTpl;
|
||||
implements PubProducer {
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTpl;
|
||||
@Autowired
|
||||
private StringRedisTemplate strRedisTpl;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void publish(String topic, Object message) {
|
||||
publish(redisTpl, topic, message);
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void publish(String topic, Object message) {
|
||||
publish(redisTpl, topic, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void publish(String topic, String message) {
|
||||
publish(strRedisTpl, topic, message);
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void publish(String topic, String message) {
|
||||
publish(strRedisTpl, topic, message);
|
||||
}
|
||||
|
||||
// --
|
||||
// private methods
|
||||
|
||||
private <T> void publish(
|
||||
RedisTemplate<String, T> redisTpl, String topic, T message) {
|
||||
redisTpl.opsForList().rightPush(topic + PUB_QUEUE_SUFFIX, message);
|
||||
strRedisTpl.convertAndSend(MESSAGE_CHANEL, topic);
|
||||
}
|
||||
// --
|
||||
// private methods
|
||||
|
||||
private <T> void publish(
|
||||
RedisTemplate<String, T> redisTpl, String topic, T message) {
|
||||
redisTpl.opsForList().rightPush(topic + PUB_QUEUE_SUFFIX, message);
|
||||
strRedisTpl.convertAndSend(MESSAGE_CHANEL, topic);
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ import org.junit.Test;
|
||||
*/
|
||||
public class TestDriver {
|
||||
|
||||
@Test
|
||||
public void testHash() {
|
||||
// System.err.println(new AuthConfig().hashPassword("123", "456"));
|
||||
}
|
||||
@Test
|
||||
public void testHash() {
|
||||
// System.err.println(new AuthConfig().hashPassword("123", "456"));
|
||||
}
|
||||
}
|
||||
|
@ -19,15 +19,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration({
|
||||
"classpath:spring/spring-echat-redis.xml",
|
||||
"classpath:spring/spring-redis-test.xml",
|
||||
"classpath:spring/spring-echat-redis.xml",
|
||||
"classpath:spring/spring-redis-test.xml",
|
||||
})
|
||||
public class TestPub {
|
||||
@Autowired
|
||||
private PubProducer pp;
|
||||
@Autowired
|
||||
private PubProducer pp;
|
||||
|
||||
@Test
|
||||
public void testRun() {
|
||||
pp.publish("MESSAGE", "Hello, Redis Pub!" + new Date());
|
||||
}
|
||||
@Test
|
||||
public void testRun() {
|
||||
pp.publish("MESSAGE", "Hello, Redis Pub!" + new Date());
|
||||
}
|
||||
}
|
||||
|
@ -15,14 +15,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration({
|
||||
"classpath:spring/spring-echat-redis.xml",
|
||||
"classpath:spring/spring-redis-test.xml",
|
||||
"classpath:spring/spring-redis-sub-test.xml",
|
||||
"classpath:spring/spring-echat-redis.xml",
|
||||
"classpath:spring/spring-redis-test.xml",
|
||||
"classpath:spring/spring-redis-sub-test.xml",
|
||||
})
|
||||
public class TestSub {
|
||||
|
||||
@Test
|
||||
public void testRun() {
|
||||
new Scanner(System.in).next();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRun() {
|
||||
new Scanner(System.in).next();
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,43 @@
|
||||
<?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
|
||||
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-sequence</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Sequence</name>
|
||||
<description>Tigon Sequence</description>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>tigon-sequence</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Sequence</name>
|
||||
<description>Tigon Sequence</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>bson</artifactId>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
@ -48,5 +48,5 @@
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -8,9 +8,9 @@ package me.chyxion.tigon.sequence;
|
||||
* Nov 23, 2016 3:01:53 PM
|
||||
*/
|
||||
public interface IdSequence {
|
||||
|
||||
/**
|
||||
* @return id
|
||||
*/
|
||||
String get();
|
||||
|
||||
/**
|
||||
* @return id
|
||||
*/
|
||||
String get();
|
||||
}
|
||||
|
@ -12,10 +12,10 @@ import me.chyxion.tigon.sequence.IdSequence;
|
||||
*/
|
||||
public class IdSequenceSupport implements IdSequence {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String get() {
|
||||
return ObjectId.get().toHexString();
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String get() {
|
||||
return ObjectId.get().toHexString();
|
||||
}
|
||||
}
|
||||
|
@ -3,5 +3,5 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean class="me.chyxion.tigon.sequence.support.IdSequenceSupport" />
|
||||
</beans>
|
||||
<bean class="me.chyxion.tigon.sequence.support.IdSequenceSupport" />
|
||||
</beans>
|
||||
|
@ -15,16 +15,16 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration({
|
||||
"classpath*:spring/spring-*.xml",
|
||||
// "classpath*:spring/servlet-spring-*.xml"
|
||||
"classpath*:spring/spring-*.xml",
|
||||
// "classpath*:spring/servlet-spring-*.xml"
|
||||
})
|
||||
public class TestDriver {
|
||||
|
||||
@Autowired
|
||||
private IdSequence idSeq;
|
||||
@Autowired
|
||||
private IdSequence idSeq;
|
||||
|
||||
@Test
|
||||
public void testIdSequence() {
|
||||
System.err.println(idSeq.get());
|
||||
}
|
||||
@Test
|
||||
public void testIdSequence() {
|
||||
System.err.println(idSeq.get());
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Properties>
|
||||
<Property name="pattern">%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n</Property>
|
||||
<Property name="log.dir">.logs</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${pattern}" />
|
||||
</Console>
|
||||
<RollingFile name="File"
|
||||
fileName="${log.dir}/${project.artifactId}-test.log"
|
||||
filePattern="${log.dir}/$${date:yyyy-MM}/${project.artifactId}-test-%d{yyyy-MM-dd}-%i.log">
|
||||
<Properties>
|
||||
<Property name="pattern">%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n</Property>
|
||||
<Property name="log.dir">.logs</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${pattern}" />
|
||||
<Policies>
|
||||
</Console>
|
||||
<RollingFile name="File"
|
||||
fileName="${log.dir}/${project.artifactId}-test.log"
|
||||
filePattern="${log.dir}/$${date:yyyy-MM}/${project.artifactId}-test-%d{yyyy-MM-dd}-%i.log">
|
||||
<PatternLayout pattern="${pattern}" />
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="16 MB" />
|
||||
</Policies>
|
||||
<SizeBasedTriggeringPolicy size="16 MB" />
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="32" />
|
||||
</RollingFile>
|
||||
</RollingFile>
|
||||
<!-- appender to send mails asynchronously -->
|
||||
<Async name="AsyncFile">
|
||||
<AppenderRef ref="File" />
|
||||
</Async>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="Console" level="DEBUG" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="Console" level="DEBUG" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<artifactId>tigon-service-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Service API</name>
|
||||
<description>Tigon Servic API</description>
|
||||
<description>Tigon Servic API</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
@ -16,20 +16,20 @@
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-model</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -16,23 +16,23 @@ import javax.validation.constraints.NotNull;
|
||||
* Jun 21, 2016 10:02:10 AM
|
||||
*/
|
||||
public interface BaseCrudByFormService
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>,
|
||||
FormForCreate extends BaseFormForCreateApi,
|
||||
FormForUpdate extends BaseFormForUpdateApi<PrimaryKey>>
|
||||
extends BaseCrudService<PrimaryKey, Model>,
|
||||
BaseQueryService<PrimaryKey, Model>,
|
||||
BaseDeleteService<PrimaryKey> {
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>,
|
||||
FormForCreate extends BaseFormForCreateApi,
|
||||
FormForUpdate extends BaseFormForUpdateApi<PrimaryKey>>
|
||||
extends BaseCrudService<PrimaryKey, Model>,
|
||||
BaseQueryService<PrimaryKey, Model>,
|
||||
BaseDeleteService<PrimaryKey> {
|
||||
|
||||
/**
|
||||
* @param form form
|
||||
* @return view model
|
||||
*/
|
||||
@NotNull ViewModel<Model> create(@NotNull @Valid FormForCreate form);
|
||||
/**
|
||||
* @param form form
|
||||
* @return view model
|
||||
*/
|
||||
@NotNull ViewModel<Model> create(@NotNull @Valid FormForCreate form);
|
||||
|
||||
/**
|
||||
* @param form form
|
||||
* @return view model
|
||||
*/
|
||||
@NotNull ViewModel<Model> update(@NotNull @Valid FormForUpdate form);
|
||||
/**
|
||||
* @param form form
|
||||
* @return view model
|
||||
*/
|
||||
@NotNull ViewModel<Model> update(@NotNull @Valid FormForUpdate form);
|
||||
|
||||
}
|
||||
|
@ -18,35 +18,35 @@ import org.hibernate.validator.constraints.NotEmpty;
|
||||
* Jun 21, 2016 10:02:10 AM
|
||||
*/
|
||||
public interface BaseCrudService
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>>
|
||||
extends BaseQueryService<PrimaryKey, Model>,
|
||||
BaseDeleteService<PrimaryKey> {
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>>
|
||||
extends BaseQueryService<PrimaryKey, Model>,
|
||||
BaseDeleteService<PrimaryKey> {
|
||||
|
||||
/**
|
||||
* @param model form
|
||||
* @return view model
|
||||
*/
|
||||
@NotNull ViewModel<Model> create(@NotNull Model model);
|
||||
/**
|
||||
* @param model form
|
||||
* @return view model
|
||||
*/
|
||||
@NotNull ViewModel<Model> create(@NotNull Model model);
|
||||
|
||||
/**
|
||||
* create model
|
||||
* @param models model
|
||||
*/
|
||||
Collection<ViewModel<Model>> create(@NotEmpty Collection<Model> models);
|
||||
/**
|
||||
* create model
|
||||
* @param models model
|
||||
*/
|
||||
Collection<ViewModel<Model>> create(@NotEmpty Collection<Model> models);
|
||||
|
||||
/**
|
||||
* @param model model
|
||||
* @return view model
|
||||
*/
|
||||
@NotNull ViewModel<Model> update(@NotNull Model model);
|
||||
/**
|
||||
* @param model model
|
||||
* @return view model
|
||||
*/
|
||||
@NotNull ViewModel<Model> update(@NotNull Model model);
|
||||
|
||||
/**
|
||||
* update model by search
|
||||
* @param model model sample
|
||||
* @param search search
|
||||
* @return updated rows
|
||||
*/
|
||||
int update(@NotNull Model model, @NotNull Search search);
|
||||
/**
|
||||
* update model by search
|
||||
* @param model model sample
|
||||
* @param search search
|
||||
* @return updated rows
|
||||
*/
|
||||
int update(@NotNull Model model, @NotNull Search search);
|
||||
|
||||
/**
|
||||
* update model by primary key
|
||||
@ -56,11 +56,11 @@ public interface BaseCrudService
|
||||
*/
|
||||
int update(@NotEmpty Map<String, ?> model, @NotNullOrBlank PrimaryKey primaryKey);
|
||||
|
||||
/**
|
||||
* update model by search
|
||||
* @param model update map
|
||||
* @param search search
|
||||
* @return updated rows
|
||||
*/
|
||||
int update(@NotEmpty Map<String, ?> model, @NotNull Search search);
|
||||
/**
|
||||
* update model by search
|
||||
* @param model update map
|
||||
* @param search search
|
||||
* @return updated rows
|
||||
*/
|
||||
int update(@NotEmpty Map<String, ?> model, @NotNull Search search);
|
||||
}
|
||||
|
@ -15,15 +15,15 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
||||
@Validated
|
||||
public interface BaseDeleteService<PrimaryKey> {
|
||||
|
||||
/**
|
||||
* delete by search
|
||||
* @param search search
|
||||
*/
|
||||
int delete(@NotNull Search search);
|
||||
|
||||
/**
|
||||
* delete by primaryKey
|
||||
* @param primaryKey primaryKey
|
||||
*/
|
||||
int delete(@NotNullOrBlank PrimaryKey primaryKey);
|
||||
/**
|
||||
* delete by search
|
||||
* @param search search
|
||||
*/
|
||||
int delete(@NotNull Search search);
|
||||
|
||||
/**
|
||||
* delete by primaryKey
|
||||
* @param primaryKey primaryKey
|
||||
*/
|
||||
int delete(@NotNullOrBlank PrimaryKey primaryKey);
|
||||
}
|
||||
|
@ -19,100 +19,100 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank;
|
||||
*/
|
||||
@Validated
|
||||
public interface BaseQueryService<PrimaryKey,
|
||||
Model extends BaseModel<PrimaryKey>>
|
||||
extends BaseService<PrimaryKey, Model> {
|
||||
Model extends BaseModel<PrimaryKey>>
|
||||
extends BaseService<PrimaryKey, Model> {
|
||||
|
||||
/**
|
||||
* find view model by search
|
||||
* @param search search
|
||||
* @return view model
|
||||
*/
|
||||
ViewModel<Model> findViewModel(@NotNull Search search);
|
||||
/**
|
||||
* find view model by search
|
||||
* @param search search
|
||||
* @return view model
|
||||
*/
|
||||
ViewModel<Model> findViewModel(@NotNull Search search);
|
||||
|
||||
/**
|
||||
* find view model by primaryKey
|
||||
* @param primaryKey primaryKey
|
||||
* @return view model
|
||||
*/
|
||||
ViewModel<Model> findViewModel(@NotNull PrimaryKey primaryKey);
|
||||
/**
|
||||
* find view model by primaryKey
|
||||
* @param primaryKey primaryKey
|
||||
* @return view model
|
||||
*/
|
||||
ViewModel<Model> findViewModel(@NotNull PrimaryKey primaryKey);
|
||||
|
||||
/**
|
||||
* list view model
|
||||
* @param search search
|
||||
* @return view model
|
||||
*/
|
||||
@NotNull List<ViewModel<Model>> listViewModels(@NotNull Search search);
|
||||
/**
|
||||
* list view model
|
||||
* @param search search
|
||||
* @return view model
|
||||
*/
|
||||
@NotNull List<ViewModel<Model>> listViewModels(@NotNull Search search);
|
||||
|
||||
/**
|
||||
* list view model page
|
||||
* @param search search
|
||||
* @return view model page
|
||||
*/
|
||||
@NotNull ListResult<ViewModel<Model>> listViewModelsPage(@NotNull Search search);
|
||||
|
||||
/**
|
||||
* find model by primaryKey
|
||||
* @param primaryKey model primaryKey
|
||||
* @return model
|
||||
*/
|
||||
Model find(@NotNullOrBlank PrimaryKey primaryKey);
|
||||
/**
|
||||
* list view model page
|
||||
* @param search search
|
||||
* @return view model page
|
||||
*/
|
||||
@NotNull ListResult<ViewModel<Model>> listViewModelsPage(@NotNull Search search);
|
||||
|
||||
/**
|
||||
* find model by primaryKey
|
||||
* @param primaryKey model primaryKey
|
||||
* @return model
|
||||
*/
|
||||
Model find(@NotNullOrBlank PrimaryKey primaryKey);
|
||||
|
||||
/**
|
||||
* find model by search
|
||||
* @param search search
|
||||
* @return result
|
||||
*/
|
||||
Model find(@NotNull Search search);
|
||||
/**
|
||||
* find model by search
|
||||
* @param search search
|
||||
* @return result
|
||||
*/
|
||||
Model find(@NotNull Search search);
|
||||
|
||||
/**
|
||||
* list by search
|
||||
* @param search search
|
||||
* @return list result
|
||||
*/
|
||||
@NotNull List<Model> list(Search search);
|
||||
/**
|
||||
* list by search
|
||||
* @param search search
|
||||
* @return list result
|
||||
*/
|
||||
@NotNull List<Model> list(Search search);
|
||||
|
||||
/**
|
||||
* list page by search
|
||||
* @param search search
|
||||
* @return list result
|
||||
*/
|
||||
@NotNull ListResult<Model> listPage(@NotNull Search search);
|
||||
/**
|
||||
* list page by search
|
||||
* @param search search
|
||||
* @return list result
|
||||
*/
|
||||
@NotNull ListResult<Model> listPage(@NotNull Search search);
|
||||
|
||||
/**
|
||||
* count by search
|
||||
* @param search search
|
||||
* @return count
|
||||
*/
|
||||
int count(Search search);
|
||||
|
||||
/**
|
||||
* scan model of all
|
||||
* @param scanner scanner
|
||||
*/
|
||||
Model scan(@NotNull Scanner<Model> scanner);
|
||||
|
||||
/**
|
||||
* scan model by search
|
||||
* @param search search
|
||||
* @param scanner scanner
|
||||
*/
|
||||
Model scan(Search search, @NotNull Scanner<Model> scanner);
|
||||
|
||||
/**
|
||||
* scan model by search
|
||||
* @param batchSize fetch model batch size
|
||||
* @param search search
|
||||
* @param scanner scanner
|
||||
*/
|
||||
Model scan(@Min(1) int batchSize, Search search, @NotNull Scanner<Model> scanner);
|
||||
/**
|
||||
* count by search
|
||||
* @param search search
|
||||
* @return count
|
||||
*/
|
||||
int count(Search search);
|
||||
|
||||
/**
|
||||
* scan model of all
|
||||
* @param scanner scanner
|
||||
*/
|
||||
Model scan(@NotNull Scanner<Model> scanner);
|
||||
|
||||
/**
|
||||
* scan model by search
|
||||
* @param search search
|
||||
* @param scanner scanner
|
||||
*/
|
||||
Model scan(Search search, @NotNull Scanner<Model> scanner);
|
||||
|
||||
/**
|
||||
* scan model by search
|
||||
* @param batchSize fetch model batch size
|
||||
* @param search search
|
||||
* @param scanner scanner
|
||||
*/
|
||||
Model scan(@Min(1) int batchSize, Search search, @NotNull Scanner<Model> scanner);
|
||||
|
||||
interface Scanner<T> {
|
||||
|
||||
/**
|
||||
* scan model
|
||||
* @param model model
|
||||
* @return false to break
|
||||
*/
|
||||
boolean run(T model);
|
||||
}
|
||||
interface Scanner<T> {
|
||||
|
||||
/**
|
||||
* scan model
|
||||
* @param model model
|
||||
* @return false to break
|
||||
*/
|
||||
boolean run(T model);
|
||||
}
|
||||
}
|
||||
|
@ -15,17 +15,17 @@ import org.hibernate.validator.constraints.NotEmpty;
|
||||
*/
|
||||
public interface BaseService<PrimaryKey, Model extends BaseModel<PrimaryKey>> {
|
||||
|
||||
/**
|
||||
* model to view model
|
||||
* @param model db model
|
||||
* @return view model
|
||||
*/
|
||||
ViewModel<Model> toViewModel(@NotNull Model model);
|
||||
/**
|
||||
* model to view model
|
||||
* @param model db model
|
||||
* @return view model
|
||||
*/
|
||||
ViewModel<Model> toViewModel(@NotNull Model model);
|
||||
|
||||
/**
|
||||
* model to view model
|
||||
* @param models model
|
||||
* @return view model
|
||||
*/
|
||||
List<ViewModel<Model>> toViewModel(@NotEmpty List<Model> models);
|
||||
/**
|
||||
* model to view model
|
||||
* @param models model
|
||||
* @return view model
|
||||
*/
|
||||
List<ViewModel<Model>> toViewModel(@NotEmpty List<Model> models);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<artifactId>tigon-service-support</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Tigon Service Support</name>
|
||||
<description>Tigon Service Support</description>
|
||||
<description>Tigon Service Support</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
@ -16,7 +16,7 @@
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-service-api</artifactId>
|
||||
@ -79,5 +79,5 @@
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -18,52 +18,52 @@ import me.chyxion.tigon.service.BaseCrudByFormService;
|
||||
*/
|
||||
@Slf4j
|
||||
public class BaseCrudByFormServiceSupport
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>,
|
||||
FormForCreate extends BaseFormForCreateApi,
|
||||
FormForUpdate extends BaseFormForUpdateApi<PrimaryKey>,
|
||||
Mapper extends BaseMapper<PrimaryKey, Model>>
|
||||
extends BaseCrudServiceSupport<PrimaryKey, Model, Mapper>
|
||||
implements BaseCrudByFormService<PrimaryKey, Model, FormForCreate, FormForUpdate> {
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>,
|
||||
FormForCreate extends BaseFormForCreateApi,
|
||||
FormForUpdate extends BaseFormForUpdateApi<PrimaryKey>,
|
||||
Mapper extends BaseMapper<PrimaryKey, Model>>
|
||||
extends BaseCrudServiceSupport<PrimaryKey, Model, Mapper>
|
||||
implements BaseCrudByFormService<PrimaryKey, Model, FormForCreate, FormForUpdate> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> create(FormForCreate form) {
|
||||
log.debug("Create Form [{}].", form);
|
||||
validate(form);
|
||||
return create(form.copy(modelType));
|
||||
}
|
||||
@Override
|
||||
public ViewModel<Model> create(FormForCreate form) {
|
||||
log.debug("Create Form [{}].", form);
|
||||
validate(form);
|
||||
return create(form.copy(modelType));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> update(FormForUpdate form) {
|
||||
validate(form);
|
||||
PrimaryKey primaryKey = form.getId();
|
||||
Model model = find(primaryKey);
|
||||
Assert.state(model != null, "No Model [" + primaryKey + "] Found");
|
||||
return update(form.copy(model));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> update(FormForUpdate form) {
|
||||
validate(form);
|
||||
PrimaryKey primaryKey = form.getId();
|
||||
Model model = find(primaryKey);
|
||||
Assert.state(model != null, "No Model [" + primaryKey + "] Found");
|
||||
return update(form.copy(model));
|
||||
}
|
||||
|
||||
|
||||
// --
|
||||
// private methods
|
||||
// --
|
||||
// private methods
|
||||
|
||||
/**
|
||||
* validate create form
|
||||
* @param form create form
|
||||
*/
|
||||
protected void validate(FormForCreate form) {
|
||||
// For Override
|
||||
}
|
||||
|
||||
/**
|
||||
* validate update form
|
||||
* @param form update form
|
||||
*/
|
||||
protected void validate(FormForUpdate form) {
|
||||
// For Override
|
||||
}
|
||||
/**
|
||||
* validate create form
|
||||
* @param form create form
|
||||
*/
|
||||
protected void validate(FormForCreate form) {
|
||||
// For Override
|
||||
}
|
||||
|
||||
/**
|
||||
* validate update form
|
||||
* @param form update form
|
||||
*/
|
||||
protected void validate(FormForUpdate form) {
|
||||
// For Override
|
||||
}
|
||||
}
|
||||
|
@ -25,38 +25,38 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@Slf4j
|
||||
public class BaseCrudServiceSupport
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>,
|
||||
Mapper extends BaseMapper<PrimaryKey, Model>>
|
||||
extends BaseQueryServiceSupport<PrimaryKey, Model, Mapper>
|
||||
implements BaseCrudService<PrimaryKey, Model> {
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>,
|
||||
Mapper extends BaseMapper<PrimaryKey, Model>>
|
||||
extends BaseQueryServiceSupport<PrimaryKey, Model, Mapper>
|
||||
implements BaseCrudService<PrimaryKey, Model> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int delete(Search search) {
|
||||
return mapper.delete(search);
|
||||
}
|
||||
public int delete(Search search) {
|
||||
return mapper.delete(search);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int delete(PrimaryKey primaryKey) {
|
||||
return mapper.delete(primaryKey);
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int delete(PrimaryKey primaryKey) {
|
||||
return mapper.delete(primaryKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> create(Model model) {
|
||||
beforeInsert(model);
|
||||
mapper.insert(model);
|
||||
afterInsert(model);
|
||||
return toViewModel(model);
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> create(Model model) {
|
||||
beforeInsert(model);
|
||||
mapper.insert(model);
|
||||
afterInsert(model);
|
||||
return toViewModel(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -72,15 +72,15 @@ public class BaseCrudServiceSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> update(Model model) {
|
||||
beforeUpdate(model);
|
||||
mapper.update(model);
|
||||
afterUpdate(model);
|
||||
return toViewModel(model);
|
||||
}
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> update(Model model) {
|
||||
beforeUpdate(model);
|
||||
mapper.update(model);
|
||||
afterUpdate(model);
|
||||
return toViewModel(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -88,7 +88,7 @@ public class BaseCrudServiceSupport
|
||||
@Override
|
||||
@Transactional
|
||||
public int update(@NotNull Model model, @NotNull Search search) {
|
||||
return mapper.update(model, search);
|
||||
return mapper.update(model, search);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,28 +109,28 @@ public class BaseCrudServiceSupport
|
||||
}
|
||||
|
||||
// --
|
||||
// private methods
|
||||
// private methods
|
||||
|
||||
protected void beforeInsert(Model model) {
|
||||
if (idType.equals(String.class) &&
|
||||
StringUtils.isBlank((String) model.primaryKeyValue())) {
|
||||
final String id = idSeq.get();
|
||||
log.debug("Insert Model [{}] Id Is Blank, Generate [{}].", model, id);
|
||||
model.primaryKeyValue((PrimaryKey) id);
|
||||
}
|
||||
// Hook
|
||||
}
|
||||
protected void beforeInsert(Model model) {
|
||||
if (idType.equals(String.class) &&
|
||||
StringUtils.isBlank((String) model.primaryKeyValue())) {
|
||||
final String id = idSeq.get();
|
||||
log.debug("Insert Model [{}] Id Is Blank, Generate [{}].", model, id);
|
||||
model.primaryKeyValue((PrimaryKey) id);
|
||||
}
|
||||
// Hook
|
||||
}
|
||||
|
||||
protected void afterInsert(Model model) {
|
||||
// Hook
|
||||
}
|
||||
protected void afterInsert(Model model) {
|
||||
// Hook
|
||||
}
|
||||
|
||||
|
||||
protected void beforeUpdate(Model model) {
|
||||
// Hook
|
||||
}
|
||||
protected void beforeUpdate(Model model) {
|
||||
// Hook
|
||||
}
|
||||
|
||||
protected void afterUpdate(Model model) {
|
||||
// Hook
|
||||
}
|
||||
protected void afterUpdate(Model model) {
|
||||
// Hook
|
||||
}
|
||||
}
|
||||
|
@ -19,13 +19,13 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
*/
|
||||
@Slf4j
|
||||
public class BaseQueryServiceSupport
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>,
|
||||
Mapper extends BaseMapper<PrimaryKey, Model>>
|
||||
extends BaseServiceSupport<PrimaryKey, Model, Mapper>
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>,
|
||||
Mapper extends BaseMapper<PrimaryKey, Model>>
|
||||
extends BaseServiceSupport<PrimaryKey, Model, Mapper>
|
||||
implements BaseQueryService<PrimaryKey, Model> {
|
||||
|
||||
@Value("${default.query.batch.size:32}")
|
||||
private int scanBatchSize;
|
||||
@Value("${default.query.batch.size:32}")
|
||||
private int scanBatchSize;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -36,15 +36,15 @@ public class BaseQueryServiceSupport
|
||||
return mapper.list(search);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ListResult<Model> listPage(Search search) {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ListResult<Model> listPage(Search search) {
|
||||
log.debug("List Models Page By Search [{}], Using Mapper [{}].", search, mapper);
|
||||
return new ListResult<Model>(mapper.list(search),
|
||||
mapper.count(search));
|
||||
}
|
||||
return new ListResult<Model>(mapper.list(search),
|
||||
mapper.count(search));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -78,101 +78,101 @@ public class BaseQueryServiceSupport
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> findViewModel(Search search) {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> findViewModel(Search search) {
|
||||
log.debug("Find View Model By Search [{}] Using Mapper [{}].", search, mapper);
|
||||
Model model = mapper.find(search);
|
||||
return model != null ? toViewModel(model) : null;
|
||||
}
|
||||
Model model = mapper.find(search);
|
||||
return model != null ? toViewModel(model) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ListResult<ViewModel<Model>> listViewModelsPage(
|
||||
Search search) {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ListResult<ViewModel<Model>> listViewModelsPage(
|
||||
Search search) {
|
||||
log.debug("List View Models Page By Search [{}] Using Mapper [{}].", search, mapper);
|
||||
return new ListResult<ViewModel<Model>>(
|
||||
listViewModels(search),
|
||||
mapper.count(search));
|
||||
}
|
||||
return new ListResult<ViewModel<Model>>(
|
||||
listViewModels(search),
|
||||
mapper.count(search));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<ViewModel<Model>> listViewModels(Search search) {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<ViewModel<Model>> listViewModels(Search search) {
|
||||
log.debug("List View Models By Search [{}] Using Mapper [{}].", search, mapper);
|
||||
return toViewModel(mapper.list(search));
|
||||
}
|
||||
return toViewModel(mapper.list(search));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> findViewModel(PrimaryKey primaryKey) {
|
||||
Model model = mapper.find(primaryKey);
|
||||
return model != null ? toViewModel(model) : null;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> findViewModel(PrimaryKey primaryKey) {
|
||||
Model model = mapper.find(primaryKey);
|
||||
return model != null ? toViewModel(model) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Model find(PrimaryKey primaryKey) {
|
||||
return mapper.find(primaryKey);
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Model find(PrimaryKey primaryKey) {
|
||||
return mapper.find(primaryKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Model scan(Scanner<Model> scanner) {
|
||||
return scan(null, scanner);
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Model scan(Scanner<Model> scanner) {
|
||||
return scan(null, scanner);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Model scan(Search search, Scanner<Model> scanner) {
|
||||
return scan(scanBatchSize(), search, scanner);
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Model scan(Search search, Scanner<Model> scanner) {
|
||||
return scan(scanBatchSize(), search, scanner);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Model scan(int batchSize, Search search, Scanner<Model> scanner) {
|
||||
log.info("Scan Model By Search [{}].", search);
|
||||
int total = mapper.count(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 : mapper.list(
|
||||
search.offset(start)
|
||||
.limit(Math.min(batchSize, total - start)))) {
|
||||
if (scanner.run(model)) {
|
||||
log.info("Model [{}] Found By Scanner.", model);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
log.debug("No Matched Model Found By Scanner.");
|
||||
}
|
||||
else {
|
||||
log.info("No Model To Scan By Search [{}].", search);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Model scan(int batchSize, Search search, Scanner<Model> scanner) {
|
||||
log.info("Scan Model By Search [{}].", search);
|
||||
int total = mapper.count(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 : mapper.list(
|
||||
search.offset(start)
|
||||
.limit(Math.min(batchSize, total - start)))) {
|
||||
if (scanner.run(model)) {
|
||||
log.info("Model [{}] Found By Scanner.", model);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
log.debug("No Matched Model Found By Scanner.");
|
||||
}
|
||||
else {
|
||||
log.info("No Model To Scan By Search [{}].", search);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected int scanBatchSize() {
|
||||
return scanBatchSize;
|
||||
}
|
||||
}
|
||||
protected int scanBatchSize() {
|
||||
return scanBatchSize;
|
||||
}
|
||||
}
|
||||
|
@ -27,76 +27,76 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
@Getter
|
||||
@Setter
|
||||
public class BaseServiceSupport
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>,
|
||||
Mapper extends BaseMapper<PrimaryKey, Model>>
|
||||
implements BaseService<PrimaryKey, Model> {
|
||||
<PrimaryKey, Model extends BaseModel<PrimaryKey>,
|
||||
Mapper extends BaseMapper<PrimaryKey, Model>>
|
||||
implements BaseService<PrimaryKey, Model> {
|
||||
|
||||
@Autowired
|
||||
protected Mapper mapper;
|
||||
@Autowired
|
||||
protected IdSequence idSeq;
|
||||
protected Class<PrimaryKey> idType;
|
||||
protected Class<Model> modelType;
|
||||
@Autowired
|
||||
protected IdSequence idSeq;
|
||||
protected Class<PrimaryKey> idType;
|
||||
protected Class<Model> modelType;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public BaseServiceSupport() {
|
||||
Class<?>[] clazzArr =
|
||||
GenericTypeResolver.resolveTypeArguments(
|
||||
getClass(),
|
||||
BaseServiceSupport.class);
|
||||
idType = (Class<PrimaryKey>) clazzArr[0];
|
||||
modelType = (Class<Model>) clazzArr[1];
|
||||
}
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public BaseServiceSupport() {
|
||||
Class<?>[] clazzArr =
|
||||
GenericTypeResolver.resolveTypeArguments(
|
||||
getClass(),
|
||||
BaseServiceSupport.class);
|
||||
idType = (Class<PrimaryKey>) clazzArr[0];
|
||||
modelType = (Class<Model>) clazzArr[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> toViewModel(Model model) {
|
||||
ViewModel<Model> viewModel =
|
||||
new ViewModel<Model>(model);
|
||||
log.debug("Model [{}] To View Model.", model);
|
||||
processViewModel(viewModel, model);
|
||||
return viewModel;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ViewModel<Model> toViewModel(Model model) {
|
||||
ViewModel<Model> viewModel =
|
||||
new ViewModel<Model>(model);
|
||||
log.debug("Model [{}] To View Model.", model);
|
||||
processViewModel(viewModel, model);
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<ViewModel<Model>> toViewModel(List<Model> models) {
|
||||
List<ViewModel<Model>> viewModels = null;
|
||||
if (models != null && !models.isEmpty()) {
|
||||
viewModels = new ArrayList<ViewModel<Model>>(models.size());
|
||||
for (Model model : models) {
|
||||
viewModels.add(toViewModel(model));
|
||||
}
|
||||
}
|
||||
else {
|
||||
viewModels = Collections.emptyList();
|
||||
}
|
||||
return viewModels;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<ViewModel<Model>> toViewModel(List<Model> models) {
|
||||
List<ViewModel<Model>> viewModels = null;
|
||||
if (models != null && !models.isEmpty()) {
|
||||
viewModels = new ArrayList<ViewModel<Model>>(models.size());
|
||||
for (Model model : models) {
|
||||
viewModels.add(toViewModel(model));
|
||||
}
|
||||
}
|
||||
else {
|
||||
viewModels = Collections.emptyList();
|
||||
}
|
||||
return viewModels;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param model model
|
||||
* @param url url
|
||||
* @return url
|
||||
*/
|
||||
protected String urlCacheClear(M1<PrimaryKey> model, String url) {
|
||||
Date dateUpdated = model.getDateUpdated();
|
||||
return dateUpdated != null ?
|
||||
url + "?_d=" + dateUpdated.getTime() : url;
|
||||
}
|
||||
/**
|
||||
* @param model model
|
||||
* @param url url
|
||||
* @return url
|
||||
*/
|
||||
protected String urlCacheClear(M1<PrimaryKey> model, String url) {
|
||||
Date dateUpdated = model.getDateUpdated();
|
||||
return dateUpdated != null ?
|
||||
url + "?_d=" + dateUpdated.getTime() : url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param viewModel view model
|
||||
* @param model model
|
||||
*/
|
||||
protected void processViewModel(ViewModel<Model> viewModel, Model model) {
|
||||
// For Subclass Override
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param viewModel view model
|
||||
* @param model model
|
||||
*/
|
||||
protected void processViewModel(ViewModel<Model> viewModel, Model model) {
|
||||
// For Subclass Override
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user