Commit 1c1991d3 authored by yanzg's avatar yanzg

将源码打包进jar包

parent 269ffaa3
......@@ -38,4 +38,12 @@ public class TestRunnableListAuto {
public void test1() {
runTest(false);
}
@Test
public void testLong() {
long day = 1000L * 60 * 60 * 24;
System.out.println(Long.MAX_VALUE);
System.out.println(Long.MAX_VALUE / day + "天");
System.out.println(Long.MAX_VALUE / day / 365 + "年");
}
}
package com.yanzuoguang.db;
import com.yanzuoguang.db.impl.SqlInfo;
/**
* 打印sql语句
*
* @author 颜佐光
*/
public interface DbPrintSql {
/**
* 打印Sql语句
*
* @param sqlInfo Sql语句信息
* @param time Sql语句
* @param row 影响的行数
*/
void printSql(SqlInfo sqlInfo, long time, int row);
}
package com.yanzuoguang.db;
import com.yanzuoguang.db.impl.SqlInfo;
/**
* 排除打印的Sql语句
*
* @author 颜佐光
*/
public interface DbPrintSqlExcept {
/**
* 是否过滤打印的Sql语句
*
* @param sqlInfo Sql语句信息
* @param time Sql语句
* @param row 影响的行数
* @return true = 过滤打印(不打印), false = 打印
*/
boolean isPrintExcept(SqlInfo sqlInfo, long time, int row);
}
......@@ -22,11 +22,11 @@ import java.util.List;
public class DbExecuteImpl implements DbExecute {
private final JdbcTemplate jdbcTemplate;
private final DbPrintSql printSql;
private final DbExecutePrintSql printSql;
private final ConfigDb configDb;
private final LogCountTime logCountTime;
public DbExecuteImpl(JdbcTemplate jdbcTemplate, DbPrintSql printSql, ConfigDb configDb, LogCountTime logCountTime) {
public DbExecuteImpl(JdbcTemplate jdbcTemplate, DbExecutePrintSql printSql, ConfigDb configDb, LogCountTime logCountTime) {
this.jdbcTemplate = jdbcTemplate;
this.printSql = printSql;
this.configDb = configDb;
......
package com.yanzuoguang.db.impl;
import com.yanzuoguang.db.DbPrintSql;
import com.yanzuoguang.db.DbPrintSqlExcept;
import com.yanzuoguang.util.log.Log;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 打印SQL语句日志工具类
*
* @author 颜佐光
*/
@Component
public class DbExecutePrintSql {
private final List<DbPrintSql> dbPrintSqlList;
private final List<DbPrintSqlExcept> dbPrintSqlExceptList;
public DbExecutePrintSql(List<DbPrintSql> dbPrintSqlList, List<DbPrintSqlExcept> dbPrintSqlExceptList) {
this.dbPrintSqlList = dbPrintSqlList;
this.dbPrintSqlExceptList = dbPrintSqlExceptList;
}
/**
* 打印SQL语句
*
* @param sqlInfo sql语句嘻嘻你
* @param time 执行的时间
* @param row SQL语句
*/
public void print(SqlInfo sqlInfo, long time, int row) {
try {
for (DbPrintSqlExcept except : dbPrintSqlExceptList) {
if (except.isPrintExcept(sqlInfo, time, row)) {
return;
}
}
dbPrintSqlList.forEach(k ->
k.printSql(sqlInfo, time, row)
);
} catch (Exception ex) {
Log.error(DbExecutePrintSql.class, ex);
}
}
}
package com.yanzuoguang.db.impl;
import com.yanzuoguang.db.ConfigDb;
import com.yanzuoguang.db.DbPrintSql;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log;
import org.springframework.stereotype.Component;
/**
* 打印SQL语句日志工具类
* 打印Sql语句
*
* @author 颜佐光
*/
@Component
public class DbPrintSql {
public class DbPrintSqlDefault implements DbPrintSql {
private final ConfigDb configDb;
public DbPrintSql(ConfigDb configDb) {
this.configDb = configDb;
@Override
public void printSql(SqlInfo sqlInfo, long time, int row) {
String sql = getStringSql(sqlInfo.getSql(), sqlInfo.getParas());
// 打印SQL语句
String tag = String.format("%d row %d ms %s.%s", row, time, sqlInfo.getTargetClass().getSimpleName(), sqlInfo.getSqlName());
Log.infoTag(DbExecutePrintSql.class, tag, sql);
}
/**
......@@ -59,31 +61,4 @@ public class DbPrintSql {
return sb.toString();
}
/**
* 打印SQL语句
*
* @param sqlInfo sql语句嘻嘻你
* @param time 执行的时间
* @param row SQL语句
*/
public void print(SqlInfo sqlInfo, long time, int row) {
try {
// 日志表忽略打印
if (!configDb.isPrintSql()) {
return;
}
if (!StringHelper.isEmpty(configDb.getPrintSqlFilter())) {
if (sqlInfo.getSql().matches(configDb.getPrintSqlFilter())) {
return;
}
}
String sql = getStringSql(sqlInfo.getSql(), sqlInfo.getParas());
// 打印SQL语句
String tag = String.format("%d row %d ms %s.%s", row, time, sqlInfo.getTargetClass().getSimpleName(), sqlInfo.getSqlName());
Log.infoTag(DbPrintSql.class, tag, sql);
} catch (Exception ex) {
Log.error(DbPrintSql.class, ex);
}
}
}
package com.yanzuoguang.db.impl;
import com.yanzuoguang.db.ConfigDb;
import com.yanzuoguang.db.DbPrintSqlExcept;
import com.yanzuoguang.util.helper.StringHelper;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
/**
* 配置打印过滤
*
* @author 颜佐光
*/
@Component
@Order(-1)
public class DbPrintSqlExceptDefault implements DbPrintSqlExcept {
private final ConfigDb configDb;
public DbPrintSqlExceptDefault(ConfigDb configDb) {
this.configDb = configDb;
}
@Override
public boolean isPrintExcept(SqlInfo sqlInfo, long time, int row) {
// 日志表忽略打印
if (!configDb.isPrintSql()) {
return true;
}
if (StringHelper.isEmpty(configDb.getPrintSqlFilter())) {
return false;
}
return sqlInfo.getSql().matches(configDb.getPrintSqlFilter()) || sqlInfo.getSqlName().matches(configDb.getPrintSqlFilter());
}
}
......@@ -2,18 +2,17 @@ import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.dao.impl.SqlData;
import com.yanzuoguang.dao.impl.TableSqlCache;
import com.yanzuoguang.dao.impl.TableStruct;
import com.yanzuoguang.db.ConfigDb;
import com.yanzuoguang.db.impl.DbPrintSql;
import com.yanzuoguang.db.impl.DbPrintSqlDefault;
import com.yanzuoguang.util.helper.JsonHelper;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
public class TestDbPrintSql {
public class TestDbExecutePrintSql {
@Test
public void test() {
DbPrintSql printSql = new DbPrintSql(new ConfigDb());
DbPrintSqlDefault printSql = new DbPrintSqlDefault();
String stringSql = printSql.getStringSql("select * from where id = ? AND name = ? and removeFlag = 0 ", "1");
System.out.println(stringSql);
}
......
package com.yanzuoguang.mq.dao.impl;
import com.yanzuoguang.db.DbPrintSqlExcept;
import com.yanzuoguang.db.impl.SqlInfo;
import org.springframework.stereotype.Component;
/**
* 过滤Sql语句打印消息
*
* @author 颜佐光
*/
@Component
public class DbPrintExceptByMessage implements DbPrintSqlExcept {
/**
* 当前包的Sql语句不打印
*/
private final Package aPackage = DbPrintExceptByMessage.class.getPackage();
@Override
public boolean isPrintExcept(SqlInfo sqlInfo, long time, int row) {
if (sqlInfo == null || sqlInfo.getTargetClass().getPackage() == aPackage) {
return true;
}
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment