支持表级配置

This commit is contained in:
iqudoo
2026-04-17 13:15:49 +08:00
parent ac547d2a57
commit a73e969431
5 changed files with 317 additions and 163 deletions

View File

@@ -11,6 +11,7 @@ import org.mybatis.generator.api.dom.xml.Document;
import org.mybatis.generator.api.dom.xml.TextElement;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.config.Context;
import org.mybatis.generator.config.TableConfiguration;
import org.mybatis.generator.internal.util.StringUtility;
import java.util.List;
@@ -54,6 +55,51 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
}
}
private int getIgnorePageSize(IntrospectedTable introspectedTable) {
try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String getIgnorePageSize = tableConfiguration.getProperty("ignorePageSize");
if (getIgnorePageSize != null && !getIgnorePageSize.isEmpty()) {
int value = Integer.parseInt(getIgnorePageSize);
if (value > 0) {
return value;
}
}
} catch (Throwable ignored) {
}
return ignorePageSize;
}
public int getMaxPageSize(IntrospectedTable introspectedTable) {
try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String getMaxPageSize = tableConfiguration.getProperty("maxPageSize");
if (getMaxPageSize != null && !getMaxPageSize.isEmpty()) {
int value = Integer.parseInt(getMaxPageSize);
if (value > 0) {
return value;
}
}
} catch (Throwable ignored) {
}
return maxPageSize;
}
public int getStartPageNum(IntrospectedTable introspectedTable) {
try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String getStartPageNum = tableConfiguration.getProperty("startPageNum");
if (getStartPageNum != null && !getStartPageNum.isEmpty()) {
int value = Integer.parseInt(getStartPageNum);
if (value > 0) {
return value;
}
}
} catch (Throwable ignored) {
}
return startPageNum;
}
@SuppressWarnings("DuplicatedCode")
@Override
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
@@ -65,7 +111,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
"maxPageSize",
JavaVisibility.PROTECTED,
integerType,
this.maxPageSize + ""
getMaxPageSize(introspectedTable) + ""
);
topLevelClass.addField(maxPageSizeField);
@@ -73,7 +119,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
"ignorePageSize",
JavaVisibility.PROTECTED,
integerType,
this.ignorePageSize + ""
getIgnorePageSize(introspectedTable) + ""
);
topLevelClass.addField(ignorePageSizeField);
@@ -81,7 +127,7 @@ public class TapeMybatisGeneratorPlugin extends PluginAdapter {
"startPageNum",
JavaVisibility.PROTECTED,
integerType,
startPageNum + ""
getStartPageNum(introspectedTable) + ""
);
topLevelClass.addField(startPageNumField);

View File

@@ -6,6 +6,7 @@ import org.mybatis.generator.api.*;
import org.mybatis.generator.api.dom.DefaultJavaFormatter;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.config.Context;
import org.mybatis.generator.config.TableConfiguration;
import org.mybatis.generator.internal.util.StringUtility;
import java.io.File;
@@ -66,10 +67,19 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
modelPackage = stringConfig("modelPackage", modelPackage);
}
private boolean isChangeLogEnable() {
private boolean isChangeLogEnable(IntrospectedTable introspectedTable) {
String tableChangeLogEnable = changeLogEnable;
try {
boolean b = Boolean.parseBoolean(changeLogEnable);
if (b && changeLogContextClassName != null && !changeLogContextClassName.isEmpty()) {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String getChangeLogEnable = tableConfiguration.getProperty("changeLogEnable");
if (getChangeLogEnable != null && !getChangeLogEnable.isEmpty()) {
tableChangeLogEnable = getChangeLogEnable;
}
} catch (Throwable ignored) {
}
try {
boolean b = Boolean.parseBoolean(tableChangeLogEnable);
if (b) {
return true;
}
} catch (Throwable ignored) {
@@ -77,9 +87,18 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
return false;
}
private boolean isOptimisticLockEnable() {
private boolean isOptimisticLockEnable(IntrospectedTable introspectedTable) {
String tableOptimisticLockEnable = optimisticLockEnable;
try {
boolean b = Boolean.parseBoolean(optimisticLockEnable);
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String getOptimisticLockEnable = tableConfiguration.getProperty("optimisticLockEnable");
if (getOptimisticLockEnable != null && !getOptimisticLockEnable.isEmpty()) {
tableOptimisticLockEnable = getOptimisticLockEnable;
}
} catch (Throwable ignored) {
}
try {
boolean b = Boolean.parseBoolean(tableOptimisticLockEnable);
if (b) {
return true;
}
@@ -88,6 +107,30 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
return false;
}
public String getSlowQueryLoggerLevel(IntrospectedTable introspectedTable) {
try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String tableSlowQueryLoggerLevel = tableConfiguration.getProperty("slowQueryLoggerLevel");
if (tableSlowQueryLoggerLevel != null && !tableSlowQueryLoggerLevel.isEmpty()) {
return tableSlowQueryLoggerLevel;
}
} catch (Throwable ignored) {
}
return slowQueryLoggerLevel;
}
public String getSlowQueryLoggerTime(IntrospectedTable introspectedTable) {
try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String tableSlowQueryLoggerTime = tableConfiguration.getProperty("slowQueryLoggerTime");
if (tableSlowQueryLoggerTime != null && !tableSlowQueryLoggerTime.isEmpty()) {
return tableSlowQueryLoggerTime;
}
} catch (Throwable ignored) {
}
return slowQueryLoggerTime;
}
private String stringConfig(String key, String defaultValue) {
String v = properties.getProperty(key);
if (StringUtility.stringHasValue(v)) {
@@ -381,7 +424,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addAnnotation("@SuppressWarnings(\"DuplicatedCode\")");
implClass.addAnnotation("@Repository");
addImportPackages(implClass, modelClassName, exampleClassName, mapperClassName, interfaceName);
addImportPackages(implClass, introspectedTable, modelClassName, exampleClassName, mapperClassName, interfaceName);
FullyQualifiedJavaType superInterface = new FullyQualifiedJavaType(facadeRepositoryPackage + "." + interfaceName);
implClass.addSuperInterface(superInterface);
@@ -404,23 +447,23 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
generateFindAnyByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
generateFindValidByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
generateFindTrashByIdMethod(implClass, modelClassName, mapperFieldName, exampleClassName, hasBLOBColumns);
generateInsertMethod(implClass, modelClassName, mapperFieldName, introspectedTable);
generateBatchInsertMethod(implClass, modelClassName, mapperFieldName, introspectedTable);
generateUpdateMethod(implClass, modelClassName, exampleClassName, mapperFieldName, introspectedTable, hasBLOBColumns);
generateUpdateByExampleSelectiveMethod(implClass, modelClassName, exampleClassName, mapperFieldName, introspectedTable, hasBLOBColumns);
generateDeleteByIdMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateDeleteAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateTrashByIdMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateTrashAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateRecoverByIdMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateRecoverAllMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateInsertMethod(implClass, introspectedTable, modelClassName, mapperFieldName);
generateBatchInsertMethod(implClass, introspectedTable, modelClassName, mapperFieldName);
generateUpdateMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateUpdateByExampleSelectiveMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateDeleteByIdMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateDeleteAllMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateTrashByIdMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateTrashAllMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateRecoverByIdMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateRecoverAllMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateFindValidOneMethod(implClass, modelClassName, exampleClassName);
generateFindTrashOneMethod(implClass, modelClassName, exampleClassName);
generateGetValidListMethod(implClass, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateGetTrashListMethod(implClass, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateCountByValidMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateGetValidListMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateGetTrashListMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateCountByValidMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateCountByValidWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateCountByTrashMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateCountByTrashMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateCountByTrashWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
return implClass;
@@ -469,9 +512,9 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
}
}
private void addImportPackages(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperClassName, String interfaceName) {
private void addImportPackages(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperClassName, String interfaceName) {
implClass.addImportedType(new FullyQualifiedJavaType(guidGeneratorClass));
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
implClass.addImportedType(new FullyQualifiedJavaType(changeLogContextClassPackage + "." + changeLogContextClassName));
}
implClass.addImportedType(new FullyQualifiedJavaType(mapperPackage + "." + mapperClassName));
@@ -562,7 +605,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateInsertMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName, IntrospectedTable introspectedTable) {
private void generateInsertMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String mapperFieldName) {
Method method = new Method("insert");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -601,8 +644,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("int count = " + mapperFieldName + ".insert(aDo);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] insert " + modelClassName + " long time\" +");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] insert " + modelClassName + " long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
@@ -613,7 +656,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("record.setDataVersion(aDo.getDataVersion());");
method.addBodyLine("record.setCreateTime(aDo.getCreateTime());");
method.addBodyLine("record.setUpdateTime(aDo.getUpdateTime());");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
method.addBodyLine(" \"insert\", aDo.getGuid(), new HashMap<>());");
}
@@ -623,7 +666,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateBatchInsertMethod(TopLevelClass implClass, String modelClassName, String mapperFieldName, IntrospectedTable introspectedTable) {
private void generateBatchInsertMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String mapperFieldName) {
Method method = new Method("batchInsert");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -668,14 +711,14 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("int count = " + mapperFieldName + ".batchInsert(batch);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] batch insert " + modelClassName + " long time\" +");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] batch insert " + modelClassName + " long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
method.addBodyLine("}");
method.addBodyLine("if (count == batch.size()) {");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
method.addBodyLine("for (" + modelClassName + " aDo : batch) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
method.addBodyLine(" \"batchInsert\", aDo.getGuid(), new HashMap<>());");
@@ -688,8 +731,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateUpdateMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
String mapperFieldName, IntrospectedTable introspectedTable, boolean hasBLOBColumns) {
private void generateUpdateMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName,
String mapperFieldName, boolean hasBLOBColumns) {
Method method = new Method("update");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -702,7 +745,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("if (aDo == null || aDo.getIsDelete() == 1) {");
method.addBodyLine("throw new Throwable(\"Record not found, " + modelClassName + " GUID:\" + record.getGuid());");
method.addBodyLine("}");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
method.addBodyLine("Map<String, Object[]> changeDiff = new HashMap<>();");
}
for (IntrospectedColumn column : introspectedTable.getAllColumns()) {
@@ -715,7 +758,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
continue;
}
method.addBodyLine("if (record." + getterMethod + "() != null) {");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
method.addBodyLine("if (!Objects.equals(record." + getterMethod + "(), aDo." + getterMethod + "())) {");
method.addBodyLine("changeDiff.put(\"" + fieldName + "\", new Object[]{aDo." + getterMethod + "(), record." + getterMethod + "()});");
method.addBodyLine("}");
@@ -724,7 +767,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("}");
}
method.addBodyLine(exampleClassName + " updateWhere = new " + exampleClassName + "();");
if (isOptimisticLockEnable()) {
if (isOptimisticLockEnable(introspectedTable)) {
method.addBodyLine("Integer lockDataVersion = record.getDataVersion();");
method.addBodyLine("if (lockDataVersion == null) {");
method.addBodyLine("lockDataVersion = aDo.getDataVersion();");
@@ -746,13 +789,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
String updateMethod = hasBLOBColumns ? "updateByExampleWithBLOBs" : "updateByExample";
method.addBodyLine("int update = " + mapperFieldName + "." + updateMethod + "(aDo, updateWhere);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] update " + modelClassName + " long time\" +");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] update " + modelClassName + " long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
method.addBodyLine("}");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
method.addBodyLine("if (update > 0 && !changeDiff.isEmpty()) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
method.addBodyLine(" \"update\", aDo.getGuid(), changeDiff);");
@@ -762,8 +805,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateUpdateByExampleSelectiveMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
String mapperFieldName, IntrospectedTable introspectedTable, boolean hasBLOBColumns) {
private void generateUpdateByExampleSelectiveMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName,
String mapperFieldName, boolean hasBLOBColumns) {
Method method = new Method("updateByExampleSelective");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -784,7 +827,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("}");
method.addBodyLine("example = new " + exampleClassName + "();");
method.addBodyLine("example.createCriteria().andGuidIn(guidList);");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
String selectByExampleMethod = hasBLOBColumns ? "selectByExampleWithBLOBs" : "selectByExample";
method.addBodyLine("List<" + modelClassName + "> recordList");
method.addBodyLine(" = " + mapperFieldName + "." + selectByExampleMethod + "(example);");
@@ -807,7 +850,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("diffGroup.put(aDo.getGuid(), changeDiff);");
method.addBodyLine("}");
}
if (isOptimisticLockEnable()) {
if (isOptimisticLockEnable(introspectedTable)) {
method.addBodyLine("// reset data version, with optimistic locking");
method.addBodyLine("record.setDataVersion((int) (new Date().getTime() % 1000));");
}
@@ -821,18 +864,18 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(record, example);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("String exampleString = \"\";");
method.addBodyLine("if (example.getWhereString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] updateByExampleSelective " + modelClassName + " long time\" +");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] updateByExampleSelective " + modelClassName + " long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
method.addBodyLine("}");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
method.addBodyLine("if (update > 0) {");
method.addBodyLine("for (Map.Entry<Long, Map<String, Object[]>> diffEntry : diffGroup.entrySet()) {");
method.addBodyLine("if (diffEntry.getValue() != null && !diffEntry.getValue().isEmpty()) {");
@@ -846,7 +889,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateDeleteByIdMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
private void generateDeleteByIdMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("deleteById");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -863,8 +906,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("}");
method.addBodyLine(exampleClassName + " updateWhere");
method.addBodyLine(" = new " + exampleClassName + "();");
method.addBodyLine("Integer lockDataVersion = aDo.getDataVersion();");
if (isOptimisticLockEnable()) {
if (isOptimisticLockEnable(introspectedTable)) {
method.addBodyLine("Integer lockDataVersion = aDo.getDataVersion();");
method.addBodyLine("updateWhere.createCriteria()");
method.addBodyLine(" .andGuidEqualTo(aDo.getGuid())");
method.addBodyLine(" .andDataVersionEqualTo(lockDataVersion);");
@@ -879,13 +922,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(aDo, updateWhere);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] deleteById " + modelClassName + " long time\" +");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] deleteById " + modelClassName + " long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
method.addBodyLine("}");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
method.addBodyLine("if (update > 0) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
method.addBodyLine(" \"deleteById\", aDo.getGuid(), new HashMap<>());");
@@ -895,7 +938,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateTrashByIdMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
private void generateTrashByIdMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("trashById");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -910,8 +953,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine(exampleClassName + " updateWhere");
method.addBodyLine(" = new " + exampleClassName + "();");
method.addBodyLine("Integer lockDataVersion = aDo.getDataVersion();");
if (isOptimisticLockEnable()) {
if (isOptimisticLockEnable(introspectedTable)) {
method.addBodyLine("Integer lockDataVersion = aDo.getDataVersion();");
method.addBodyLine("updateWhere.createCriteria()");
method.addBodyLine(" .andGuidEqualTo(aDo.getGuid())");
method.addBodyLine(" .andDataVersionEqualTo(lockDataVersion);");
@@ -927,13 +970,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(aDo, updateWhere);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] trashById " + modelClassName + " long time\" +");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] trashById " + modelClassName + " long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
method.addBodyLine("}");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
method.addBodyLine("if (update > 0) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
method.addBodyLine(" \"trashById\", aDo.getGuid(), new HashMap<>());");
@@ -943,7 +986,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateRecoverByIdMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
private void generateRecoverByIdMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("recoverById");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -961,8 +1004,8 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine(exampleClassName + " updateWhere");
method.addBodyLine(" = new " + exampleClassName + "();");
method.addBodyLine("Integer lockDataVersion = aDo.getDataVersion();");
if (isOptimisticLockEnable()) {
if (isOptimisticLockEnable(introspectedTable)) {
method.addBodyLine("Integer lockDataVersion = aDo.getDataVersion();");
method.addBodyLine("updateWhere.createCriteria()");
method.addBodyLine(" .andGuidEqualTo(aDo.getGuid())");
method.addBodyLine(" .andDataVersionEqualTo(lockDataVersion);");
@@ -977,13 +1020,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(aDo, updateWhere);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] recoverById " + modelClassName + " long time\" +");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] recoverById " + modelClassName + " long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
method.addBodyLine("}");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
method.addBodyLine("if (update > 0) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
method.addBodyLine(" \"recoverById\", aDo.getGuid(), new HashMap<>());");
@@ -993,7 +1036,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateDeleteAllMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
private void generateDeleteAllMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("deleteAll");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -1016,7 +1059,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("example = new " + exampleClassName + "();");
method.addBodyLine("example.createCriteria().andGuidIn(guidList);");
method.addBodyLine(modelClassName + " " + lowerFirst(modelClassName) + " = new " + modelClassName + "();");
if (isOptimisticLockEnable()) {
if (isOptimisticLockEnable(introspectedTable)) {
method.addBodyLine("// reset data version, with optimistic locking");
method.addBodyLine(lowerFirst(modelClassName) + ".setDataVersion((int) (new Date().getTime() % 1000));");
}
@@ -1026,13 +1069,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] deleteAll " + modelClassName + " long time\" +");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] deleteAll " + modelClassName + " long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
method.addBodyLine("}");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
method.addBodyLine("if (update > 0) {");
method.addBodyLine("for (Long guid : guidList) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
@@ -1044,7 +1087,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateTrashAllMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
private void generateTrashAllMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("trashAll");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -1063,7 +1106,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("example = new " + exampleClassName + "();");
method.addBodyLine("example.createCriteria().andGuidIn(guidList);");
method.addBodyLine(modelClassName + " " + lowerFirst(modelClassName) + " = new " + modelClassName + "();");
if (isOptimisticLockEnable()) {
if (isOptimisticLockEnable(introspectedTable)) {
method.addBodyLine("// reset data version, with optimistic locking");
method.addBodyLine(lowerFirst(modelClassName) + ".setDataVersion((int) (new Date().getTime() % 1000));");
}
@@ -1074,13 +1117,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] trashAll " + modelClassName + " long time\" +");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] trashAll " + modelClassName + " long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
method.addBodyLine("}");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
method.addBodyLine("if (update > 0) {");
method.addBodyLine("for (Long guid : guidList) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
@@ -1092,7 +1135,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateRecoverAllMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
private void generateRecoverAllMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("recoverAll");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -1111,7 +1154,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("example = new " + exampleClassName + "();");
method.addBodyLine("example.createCriteria().andGuidIn(guidList);");
method.addBodyLine(modelClassName + " " + lowerFirst(modelClassName) + " = new " + modelClassName + "();");
if (isOptimisticLockEnable()) {
if (isOptimisticLockEnable(introspectedTable)) {
method.addBodyLine("// reset data version, with optimistic locking");
method.addBodyLine(lowerFirst(modelClassName) + ".setDataVersion((int) (new Date().getTime() % 1000));");
}
@@ -1122,13 +1165,13 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("int update = " + mapperFieldName + ".updateByExampleSelective(" + lowerFirst(modelClassName) + ", example);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] recoverAll " + modelClassName + " long time\" +");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] recoverAll " + modelClassName + " long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
method.addBodyLine(");");
method.addBodyLine("}");
if (isChangeLogEnable()) {
if (isChangeLogEnable(introspectedTable)) {
method.addBodyLine("if (update > 0) {");
method.addBodyLine("for (Long guid : guidList) {");
method.addBodyLine(changeLogContextClassName + ".addLog(\"" + modelClassName + "\",");
@@ -1177,7 +1220,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateGetValidListMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
private void generateGetValidListMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName,
String mapperFieldName, boolean hasBLOBColumns) {
Method method = new Method("getValidList");
method.addAnnotation("@Override");
@@ -1198,7 +1241,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("return new ArrayList<>();");
method.addBodyLine("}");
method.addBodyLine("long findPrimaryKeyTime = new Date().getTime() - startTime;");
method.addBodyLine("if (findPrimaryKeyTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("if (findPrimaryKeyTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("String exampleString = \"\";");
method.addBodyLine("if (example.getWhereString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
@@ -1209,7 +1252,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("if (example.getLimitString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " valid list primary key long time\" +");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " valid list primary key long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + findPrimaryKeyTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
@@ -1233,7 +1276,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("result = " + mapperFieldName + ".selectByExample(example);");
}
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("String exampleString = \"\";");
method.addBodyLine("if (example.getWhereString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
@@ -1244,7 +1287,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("if (example.getLimitString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " valid list long time\" +");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " valid list long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
@@ -1254,7 +1297,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateGetTrashListMethod(TopLevelClass implClass, String modelClassName, String exampleClassName,
private void generateGetTrashListMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName,
String mapperFieldName, boolean hasBLOBColumns) {
Method method = new Method("getTrashList");
method.addAnnotation("@Override");
@@ -1275,7 +1318,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("return new ArrayList<>();");
method.addBodyLine("}");
method.addBodyLine("long findPrimaryKeyTime = new Date().getTime() - startTime;");
method.addBodyLine("if (findPrimaryKeyTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("if (findPrimaryKeyTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("String exampleString = \"\";");
method.addBodyLine("if (example.getWhereString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
@@ -1286,7 +1329,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("if (example.getLimitString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " trash list primary key long time\" +");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " trash list primary key long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + findPrimaryKeyTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
@@ -1310,7 +1353,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("result = " + mapperFieldName + ".selectByExample(example);");
}
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("String exampleString = \"\";");
method.addBodyLine("if (example.getWhereString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
@@ -1321,7 +1364,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("if (example.getLimitString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " trash list long time\" +");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " trash list long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
@@ -1331,7 +1374,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateCountByValidMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
private void generateCountByValidMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("countByValid");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -1345,7 +1388,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("String exampleString = \"\";");
method.addBodyLine("if (example.getWhereString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
@@ -1353,7 +1396,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("if (example.getOrderByClause() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> order by: \" + example.getOrderByClause();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " valid count long time\" +");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " valid count long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
@@ -1381,7 +1424,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
implClass.addMethod(method);
}
private void generateCountByTrashMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
private void generateCountByTrashMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("countByTrash");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -1395,7 +1438,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("String exampleString = \"\";");
method.addBodyLine("if (example.getWhereString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
@@ -1403,7 +1446,7 @@ public class TapeRepositoryGeneratorPlugin extends PluginAdapter {
method.addBodyLine("if (example.getOrderByClause() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> order by: \" + example.getOrderByClause();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " trash count long time\" +");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " trash count long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");

View File

@@ -9,6 +9,7 @@ import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.DefaultJavaFormatter;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.config.Context;
import org.mybatis.generator.config.TableConfiguration;
import org.mybatis.generator.internal.util.StringUtility;
import java.io.File;
@@ -71,6 +72,30 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
return defaultValue;
}
public String getSlowQueryLoggerLevel(IntrospectedTable introspectedTable) {
try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String tableSlowQueryLoggerLevel = tableConfiguration.getProperty("slowQueryLoggerLevel");
if (tableSlowQueryLoggerLevel != null && !tableSlowQueryLoggerLevel.isEmpty()) {
return tableSlowQueryLoggerLevel;
}
} catch (Throwable ignored) {
}
return slowQueryLoggerLevel;
}
public String getSlowQueryLoggerTime(IntrospectedTable introspectedTable) {
try {
TableConfiguration tableConfiguration = introspectedTable.getTableConfiguration();
String tableSlowQueryLoggerTime = tableConfiguration.getProperty("slowQueryLoggerTime");
if (tableSlowQueryLoggerTime != null && !tableSlowQueryLoggerTime.isEmpty()) {
return tableSlowQueryLoggerTime;
}
} catch (Throwable ignored) {
}
return slowQueryLoggerTime;
}
/**
* 核心方法:仅为视图表生成 RepoView 代码
*/
@@ -102,6 +127,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
// 3. 生成视图Repo实现类
TopLevelClass repoImpl = generateRepoViewImpl(
introspectedTable,
repoImplName,
repoInterfaceName,
domainObjectName,
@@ -179,6 +205,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
* 生成视图Repo实现类逻辑不变仅适配新接口
*/
private TopLevelClass generateRepoViewImpl(
IntrospectedTable introspectedTable,
String implClassName,
String interfaceName,
String modelClassName,
@@ -215,8 +242,8 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
implClass.addField(mapperField);
generateFindOneMethod(implClass, modelClassName, exampleClassName);
generateGetListMethod(implClass, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateCountMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
generateGetListMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName, hasBLOBColumns);
generateCountMethod(implClass, introspectedTable, modelClassName, exampleClassName, mapperFieldName);
generateCountWithPageMethod(implClass, modelClassName, exampleClassName, mapperFieldName);
return implClass;
@@ -268,7 +295,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
/**
* 生成getList方法
*/
private void generateGetListMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName, boolean hasBLOBColumns) {
private void generateGetListMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName, boolean hasBLOBColumns) {
Method method = new Method("getList");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -288,7 +315,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
method.addBodyLine("result = " + mapperFieldName + ".selectByExample(example);");
}
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("String exampleString = \"\";");
method.addBodyLine("if (example.getWhereString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
@@ -299,7 +326,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
method.addBodyLine("if (example.getLimitString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> limit: \" + example.getLimitString();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " view list long time\" +");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " view list long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");
@@ -312,7 +339,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
/**
* 生成count方法
*/
private void generateCountMethod(TopLevelClass implClass, String modelClassName, String exampleClassName, String mapperFieldName) {
private void generateCountMethod(TopLevelClass implClass, IntrospectedTable introspectedTable, String modelClassName, String exampleClassName, String mapperFieldName) {
Method method = new Method("count");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
@@ -325,7 +352,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
method.addBodyLine("long startTime = new Date().getTime();");
method.addBodyLine("long count = " + mapperFieldName + ".countByExample(example);");
method.addBodyLine("long useTime = new Date().getTime() - startTime;");
method.addBodyLine("if (useTime > " + slowQueryLoggerTime + ") {");
method.addBodyLine("if (useTime > " + getSlowQueryLoggerTime(introspectedTable) + ") {");
method.addBodyLine("String exampleString = \"\";");
method.addBodyLine("if (example.getWhereString() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> where: \" + example.getWhereString();");
@@ -333,7 +360,7 @@ public class TapeRepoviewGeneratorPlugin extends PluginAdapter {
method.addBodyLine("if (example.getOrderByClause() != null) {");
method.addBodyLine("exampleString += \"\\n\\t|-> order by: \" + example.getOrderByClause();");
method.addBodyLine("}");
method.addBodyLine("LOGGER." + slowQueryLoggerLevel + "(\"[SQL] select " + modelClassName + " view count long time\" +");
method.addBodyLine("LOGGER." + getSlowQueryLoggerLevel(introspectedTable) + "(\"[SQL] select " + modelClassName + " view count long time\" +");
method.addBodyLine(" \"\\n\\t|-> use time\" + useTime + \"ms\" +");
method.addBodyLine(" exampleString +");
method.addBodyLine(" \"\\n\\t|-----------------------------------\"");