Commit 92e9827a authored by yanzg's avatar yanzg

将源码打包进jar包

parent 92bed357
...@@ -11,7 +11,6 @@ import org.springframework.jdbc.core.RowCallbackHandler; ...@@ -11,7 +11,6 @@ import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.support.rowset.SqlRowSet; import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -69,7 +68,7 @@ public class DbExecuteImpl implements DbExecute { ...@@ -69,7 +68,7 @@ public class DbExecuteImpl implements DbExecute {
* @param <T> 返回的集合的类型 * @param <T> 返回的集合的类型
*/ */
@Override @Override
public <T extends Object> void query(Class<?> targetClass, Class<T> cls, DbRow<T> rowHandle, String sqlName, String sql, Object... paras) { public <T> void query(Class<?> targetClass, Class<T> cls, DbRow<T> rowHandle, String sqlName, String sql, Object... paras) {
SqlInfo sqlInfo = new SqlInfo(targetClass, sqlName, sql, paras); SqlInfo sqlInfo = new SqlInfo(targetClass, sqlName, sql, paras);
executeSql(sqlInfo, (row, start) -> { executeSql(sqlInfo, (row, start) -> {
RowCallbackHandler rowCallbackHandler = rs -> { RowCallbackHandler rowCallbackHandler = rs -> {
...@@ -94,14 +93,11 @@ public class DbExecuteImpl implements DbExecute { ...@@ -94,14 +93,11 @@ public class DbExecuteImpl implements DbExecute {
* @return 集合 * @return 集合
*/ */
@Override @Override
public <T extends Object> List<T> query(Class<?> targetClass, Class<T> cls, String sqlName, String sql, Object... paras) { public <T> List<T> query(Class<?> targetClass, Class<T> cls, String sqlName, String sql, Object... paras) {
SqlInfo sqlInfo = new SqlInfo(targetClass, sqlName, sql, paras); SqlInfo sqlInfo = new SqlInfo(targetClass, sqlName, sql, paras);
Ref<List<T>> ret = new Ref<>(null); Ref<List<T>> ret = new Ref<>(null);
executeSql(sqlInfo, (row, start) -> { executeSql(sqlInfo, (row, start) -> {
ret.value = this.getJdbc().query(sqlInfo.getSql(), sqlInfo.getParas(), AllBeanRowMapper.getInstance(cls, configDb)); ret.value = this.getJdbc().query(sqlInfo.getSql(), sqlInfo.getParas(), AllBeanRowMapper.getInstance(cls, configDb));
if (ret.value == null) {
ret.value = new ArrayList<T>();
}
row.value = ret.value.size(); row.value = ret.value.size();
}); });
return ret.value; return ret.value;
...@@ -151,23 +147,28 @@ public class DbExecuteImpl implements DbExecute { ...@@ -151,23 +147,28 @@ public class DbExecuteImpl implements DbExecute {
* @param sqlFunction 执行函数,传入参数为影响的行数引用和开始执行时间 * @param sqlFunction 执行函数,传入参数为影响的行数引用和开始执行时间
*/ */
private void executeSql(SqlInfo sqlInfo, DbSqlFunction<Ref<Integer>, Long> sqlFunction) { private void executeSql(SqlInfo sqlInfo, DbSqlFunction<Ref<Integer>, Long> sqlFunction) {
Ref<Integer> row = new Ref<>(0); // 开始记录日志
String fullUrl = String.format("Sql:%s:%s", sqlInfo.getTargetClass().getSimpleName(), sqlInfo.getSqlName());
logCountTime.start(fullUrl);
// 开始时间
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
Ref<Integer> row = new Ref<>(0);
sqlInfo.setSql(this.handleParas(sqlInfo.getSql())); sqlInfo.setSql(this.handleParas(sqlInfo.getSql()));
String fullUrl = String.format("Sql:%s:%s", sqlInfo.getTargetClass().getSimpleName(), sqlInfo.getSqlName());
logCountTime.start(fullUrl);
boolean isError = false; boolean isError = false;
try { try {
YzgTimeout.timeOut(sqlInfo.getTargetClass(), sqlInfo.getSqlName(), () -> { YzgTimeout.timeOut(sqlInfo.getTargetClass(), sqlInfo.getSqlName(), () ->
sqlFunction.accept(row, start); sqlFunction.accept(row, start)
}); );
} catch (Exception ex) { } catch (Exception ex) {
isError = true; isError = true;
throw ex; throw ex;
} finally { } finally {
// 写入日志
long time = System.currentTimeMillis() - start; long time = System.currentTimeMillis() - start;
logCountTime.finish(fullUrl, time, isError); logCountTime.finish(fullUrl, time, isError);
// 打印sql语句
printSql.print(sqlInfo, time, row.value); printSql.print(sqlInfo, time, row.value);
} }
} }
......
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