Skip to content

Commit

Permalink
feat: 5.0.4 预发发布
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Apr 6, 2023
1 parent b564626 commit dd15c53
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion mybatis-agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ allprojects {


group 'com.plugins.mybatislog.agent'
version '1.0.20'
version '1.0.21'

java {
sourceCompatibility = "1.8"
Expand Down
Binary file removed mybatis-agent/libs/mybatis-plugin-1.0.0.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ public void patchJavaParameters(Executor executor, RunProfile configuration, Jav
final JavaSdkVersion javaSdkVersion = JavaSdkVersion.fromVersionString("17");
if (null != javaSdkVersion && version.compareTo(javaSdkVersion) >= 0) {
final ArrayList<String> addOpens = Config.Idea.getAddOpens();
vmParametersList.addAll(addOpens);
for (String opens : addOpens) {
vmParametersList.addParametersString(opens);
}
}
vmParametersList.prepend("-javaagent:" + agentCoreJarPath);
//
//vmParametersList.addParametersString("-javaagent:\"" + agentCoreJarPath + "\"");
//vmParametersList.addNotEmptyProperty("guide-idea-plugin-probe.projectId", runConfiguration.getProject().getLocationHash());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static String getJarPathByStartWith() {
if ("lib".equals(listFile.getName())) {
final File[] fileslib = listFile.listFiles();
for (File file : fileslib) {
if ("mybatis-agent-1.0.20-all.jar".equals(file.getName())) {
if ("mybatis-agent-1.0.21-all.jar".equals(file.getName())) {
return file.toPath().toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ public static void prints(Project project, String currentLine) {
final SqlVO sqlVO = restoreSql(currentLine);
if (null != sqlVO) {
final String completesql = sqlVO.getCompleteSql().replaceAll("\t|\r|\n", "");
//final String originalSql = sqlVO.getOriginalSql().replaceAll("\t|\r|\n", "");
final String id = sqlVO.getId();
final String parameter = sqlVO.getParameter();
final Integer total = sqlVO.getTotal();
//序号
PrintlnUtil.println(project, Config.SQL_START_LINE + id + "\n", ConsoleViewContentType.USER_INPUT);
PrintlnUtil.printlnSqlType(project, Config.SQL_MIDDLE_LINE, completesql + "\n");
//PrintlnUtil.printlnSqlType(project, Config.SQL_MIDDLE_LINE, originalSql + "\n");
PrintlnUtil.printlnSqlType(project, Config.SQL_MIDDLE_LINE, parameter + "\n");
PrintlnUtil.printlnSqlType(project, Config.SQL_MIDDLE_LINE, "total:" + total + "\n");
PrintlnUtil.println(project, Config.SQL_END_LINE + "\n", ConsoleViewContentType.USER_INPUT);
Expand Down
2 changes: 1 addition & 1 deletion mybatis-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ allprojects {
}

group 'com.plugins.mybatislog.plugin'
version '1.0.0'
version '1.0.1'

java {
sourceCompatibility = "1.8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@

import java.lang.reflect.Field;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.*;


/**
Expand All @@ -45,15 +42,13 @@ public class LogInterceptor implements Interceptor {
*/
private static final Integer ARGSNUMBER = 2;

public static Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd HH:mm:ss")
public static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss")
//当Map的key为复杂对象时,需要开启该方法
.enableComplexMapKeySerialization()
//当字段值为空或null时,依然对该字段进行转换
.serializeNulls()
//防止特殊字符出现乱码
.disableHtmlEscaping()
.create();
.disableHtmlEscaping().create();


@Override
Expand All @@ -73,12 +68,8 @@ public Object intercept(Invocation invocation) throws Throwable {
BoundSql boundSql = mappedStatement.getBoundSql(parameter);
Configuration configuration = mappedStatement.getConfiguration();
// 通过配置信息和BoundSql对象来生成带值得sql语句
String sql = getCompleteSql(configuration, boundSql, originalSql);
final SqlVO sqlVO = new SqlVO().setId(mappedStatement.getId())
.setCompleteSql(sql)
.setParameter(gson.toJson(parameter))
.setTotal(size)
.setOriginalSql(originalSql);
final Pair<String, List<Map<String, ?>>> completeSql = getCompleteSql(configuration, boundSql, originalSql);
final SqlVO sqlVO = new SqlVO().setId(mappedStatement.getId()).setCompleteSql(completeSql.getValue0()).setParameter(gson.toJson(completeSql.getValue1())).setTotal(size).setOriginalSql(originalSql);
final String json = gson.toJson(sqlVO);
System.out.println("==> SQLStructure: " + json);
}
Expand All @@ -102,23 +93,31 @@ private Pair<MappedStatement, Object> getArgs(Invocation invocation) {
* @param originalSql sql
* @return String
*/
private String getCompleteSql(Configuration configuration, BoundSql boundSql, String originalSql) {
private Pair<String, List<Map<String, ?>>> getCompleteSql(Configuration configuration, BoundSql boundSql, String originalSql) {
Object parameterObject = boundSql.getParameterObject();
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
List<Map<String, ?>> keyvalue = new ArrayList<Map<String, ?>>();
if (parameterMappings.size() > 0 && parameterObject != null) {
MetaObject metaObject = configuration.newMetaObject(parameterObject);
for (ParameterMapping parameterMapping : parameterMappings) {
String propertyName = parameterMapping.getProperty();
final HashMap<String, Object> stringObjectHashMap = new HashMap<>();
if (metaObject.hasGetter(propertyName)) {
Object obj = metaObject.getValue(propertyName);
originalSql = originalSql.replaceFirst("#\\{" + propertyName + "}", getParameterValue(obj));
final String parameterValue = getParameterValue(obj);
stringObjectHashMap.put(propertyName, parameterValue);
keyvalue.add(stringObjectHashMap);
originalSql = originalSql.replaceFirst("#\\{" + propertyName + "}", parameterValue);
} else if (boundSql.hasAdditionalParameter(propertyName)) {
Object obj = boundSql.getAdditionalParameter(propertyName);
originalSql = originalSql.replaceFirst("#\\{" + propertyName + "}", getParameterValue(obj));
final String parameterValue = getParameterValue(obj);
stringObjectHashMap.put(propertyName, parameterValue);
keyvalue.add(stringObjectHashMap);
originalSql = originalSql.replaceFirst("#\\{" + propertyName + "}", parameterValue);
}
}
}
return originalSql.replaceAll("[\\s]+", " ");
return Pair.with(originalSql.replaceAll("[\\s]+", " "), keyvalue);
}


Expand Down Expand Up @@ -213,6 +212,7 @@ public Object plugin(Object target) {
}

@Override
public void setProperties(Properties properties) {}
public void setProperties(Properties properties) {
}

}

0 comments on commit dd15c53

Please sign in to comment.