mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-05 00:25:32 +08:00
fix(debug): 修复debug消息中耗时计算异常的问题
This commit is contained in:
@@ -10,35 +10,36 @@ import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public abstract class AbstractSQLAction<T> implements SQLAction<T> {
|
||||
|
||||
protected final @NotNull String sqlContent;
|
||||
private final @NotNull SQLManagerImpl sqlManager;
|
||||
private final @NotNull UUID uuid;
|
||||
private final long createTime;
|
||||
private final long createNanoTime;
|
||||
|
||||
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
||||
this(manager, sql, System.currentTimeMillis());
|
||||
this(manager, sql, System.nanoTime());
|
||||
}
|
||||
|
||||
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql, @NotNull UUID uuid) {
|
||||
this(manager, sql, uuid, System.currentTimeMillis());
|
||||
this(manager, sql, uuid, System.nanoTime());
|
||||
}
|
||||
|
||||
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql, long createTime) {
|
||||
this(manager, sql, UUID.randomUUID(), createTime);
|
||||
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql, long createNanoTime) {
|
||||
this(manager, sql, UUID.randomUUID(), createNanoTime);
|
||||
}
|
||||
|
||||
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql,
|
||||
@NotNull UUID uuid, long createTime) {
|
||||
@NotNull UUID uuid, long createNanoTime) {
|
||||
Objects.requireNonNull(manager);
|
||||
Objects.requireNonNull(sql);
|
||||
Objects.requireNonNull(uuid);
|
||||
this.sqlManager = manager;
|
||||
this.sqlContent = sql;
|
||||
this.uuid = uuid;
|
||||
this.createTime = createTime;
|
||||
this.createNanoTime = createNanoTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +54,8 @@ public abstract class AbstractSQLAction<T> implements SQLAction<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCreateTime() {
|
||||
return this.createTime;
|
||||
public long getCreateTime(TimeUnit unit) {
|
||||
return unit.convert(createNanoTime, TimeUnit.NANOSECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PreparedQueryActionImpl extends QueryActionImpl implements Prepared
|
||||
@Override
|
||||
public @NotNull SQLQueryImpl execute() throws SQLException {
|
||||
debugMessage(Collections.singletonList(params));
|
||||
|
||||
|
||||
Connection connection = getManager().getConnection();
|
||||
PreparedStatement preparedStatement;
|
||||
try {
|
||||
@@ -67,12 +67,10 @@ public class PreparedQueryActionImpl extends QueryActionImpl implements Prepared
|
||||
}
|
||||
|
||||
try {
|
||||
long executeTime = System.currentTimeMillis();
|
||||
SQLQueryImpl query = new SQLQueryImpl(
|
||||
getManager(), this,
|
||||
connection, preparedStatement,
|
||||
preparedStatement.executeQuery(),
|
||||
executeTime
|
||||
preparedStatement.executeQuery()
|
||||
);
|
||||
getManager().getActiveQuery().put(getActionUUID(), query);
|
||||
return query;
|
||||
|
||||
@@ -35,12 +35,10 @@ public class QueryActionImpl extends AbstractSQLAction<SQLQuery> implements Quer
|
||||
}
|
||||
|
||||
try {
|
||||
long executeTime = System.currentTimeMillis();
|
||||
SQLQueryImpl query = new SQLQueryImpl(
|
||||
getManager(), this,
|
||||
connection, statement,
|
||||
statement.executeQuery(getSQLContent()),
|
||||
executeTime
|
||||
statement.executeQuery(getSQLContent())
|
||||
);
|
||||
getManager().getActiveQuery().put(getActionUUID(), query);
|
||||
|
||||
|
||||
@@ -8,22 +8,23 @@ import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SQLQueryImpl implements SQLQuery {
|
||||
|
||||
protected final long executeTime;
|
||||
|
||||
protected final SQLManagerImpl sqlManager;
|
||||
final Connection connection;
|
||||
final Statement statement;
|
||||
final ResultSet resultSet;
|
||||
protected final Connection connection;
|
||||
protected final Statement statement;
|
||||
protected final ResultSet resultSet;
|
||||
protected QueryActionImpl queryAction;
|
||||
|
||||
public SQLQueryImpl(
|
||||
SQLManagerImpl sqlManager, QueryActionImpl queryAction,
|
||||
Connection connection, Statement statement, ResultSet resultSet
|
||||
) {
|
||||
this(sqlManager, queryAction, connection, statement, resultSet, System.currentTimeMillis());
|
||||
this(sqlManager, queryAction, connection, statement, resultSet, System.nanoTime());
|
||||
}
|
||||
|
||||
public SQLQueryImpl(
|
||||
@@ -40,8 +41,8 @@ public class SQLQueryImpl implements SQLQuery {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getExecuteTime() {
|
||||
return this.executeTime;
|
||||
public long getExecuteTime(TimeUnit timeUnit) {
|
||||
return timeUnit.convert(this.executeTime, TimeUnit.NANOSECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +74,7 @@ public class SQLQueryImpl implements SQLQuery {
|
||||
|
||||
if (getManager().isDebugMode()) {
|
||||
try {
|
||||
getManager().getDebugHandler().afterQuery(this, getExecuteTime(), System.currentTimeMillis());
|
||||
getManager().getDebugHandler().afterQuery(this, getExecuteTime(TimeUnit.NANOSECONDS), System.nanoTime());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user