Skip to content

Commit

Permalink
Refactor TrafficExecutorCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Jun 1, 2024
1 parent ae8eb76 commit eb58f47
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public ResultSet executeQuery(final ShardingSphereDatabase database, final Query
}

private TrafficExecutorCallback<ResultSet> getTrafficExecuteQueryCallback(final String jdbcDriverType) {
return JDBCDriverType.STATEMENT.equals(jdbcDriverType) ? Statement::executeQuery : ((statement, sql) -> ((PreparedStatement) statement).executeQuery());
return JDBCDriverType.STATEMENT.equals(jdbcDriverType) ? ((sql, statement) -> statement.executeQuery(sql)) : ((sql, statement) -> ((PreparedStatement) statement).executeQuery());
}

private ExecuteQueryCallback getExecuteQueryCallback(final ShardingSphereDatabase database, final QueryContext queryContext, final String jdbcDriverType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public int executeUpdate() throws SQLException {
handleAutoCommit(queryContext.getSqlStatementContext().getSqlStatement());
ShardingSphereDatabase database = metaData.getDatabase(databaseName);
final int result = executor.executeUpdate(database, queryContext, createDriverExecutionPrepareEngine(database),
(statement, sql) -> ((PreparedStatement) statement).executeUpdate(), null, (StatementReplayCallback<PreparedStatement>) this::replay);
(sql, statement) -> ((PreparedStatement) statement).executeUpdate(), null, (StatementReplayCallback<PreparedStatement>) this::replay);
for (Statement each : executor.getStatements()) {
statements.add((PreparedStatement) each);
}
Expand Down Expand Up @@ -289,7 +289,7 @@ public boolean execute() throws SQLException {
QueryContext queryContext = createQueryContext();
handleAutoCommit(queryContext.getSqlStatementContext().getSqlStatement());
ShardingSphereDatabase database = metaData.getDatabase(databaseName);
final boolean result = executor.executeAdvance(database, queryContext, createDriverExecutionPrepareEngine(database), (statement, sql) -> ((PreparedStatement) statement).execute(),
final boolean result = executor.executeAdvance(database, queryContext, createDriverExecutionPrepareEngine(database), (sql, statement) -> ((PreparedStatement) statement).execute(),
null, (StatementReplayCallback<PreparedStatement>) this::replay);
for (Statement each : executor.getStatements()) {
statements.add((PreparedStatement) each);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> createDriver
@Override
public int executeUpdate(final String sql) throws SQLException {
try {
return executeUpdate(sql, (actualSQL, statement) -> statement.executeUpdate(actualSQL), Statement::executeUpdate);
return executeUpdate(sql, (actualSQL, statement) -> statement.executeUpdate(actualSQL), (actualSQL, statement) -> statement.executeUpdate(actualSQL));
// CHECKSTYLE:OFF
} catch (final RuntimeException ex) {
// CHECKSTYLE:ON
Expand All @@ -169,7 +169,7 @@ public int executeUpdate(final String sql, final int autoGeneratedKeys) throws S
}
try {
return executeUpdate(sql, (actualSQL, statement) -> statement.executeUpdate(actualSQL, autoGeneratedKeys),
(statement, actualSQL) -> statement.executeUpdate(actualSQL, autoGeneratedKeys));
(actualSQL, statement) -> statement.executeUpdate(actualSQL, autoGeneratedKeys));
// CHECKSTYLE:OFF
} catch (final RuntimeException ex) {
// CHECKSTYLE:ON
Expand All @@ -184,7 +184,7 @@ public int executeUpdate(final String sql, final int autoGeneratedKeys) throws S
public int executeUpdate(final String sql, final int[] columnIndexes) throws SQLException {
returnGeneratedKeys = true;
try {
return executeUpdate(sql, (actualSQL, statement) -> statement.executeUpdate(actualSQL, columnIndexes), (statement, actualSQL) -> statement.executeUpdate(actualSQL, columnIndexes));
return executeUpdate(sql, (actualSQL, statement) -> statement.executeUpdate(actualSQL, columnIndexes), (actualSQL, statement) -> statement.executeUpdate(actualSQL, columnIndexes));
// CHECKSTYLE:OFF
} catch (final RuntimeException ex) {
// CHECKSTYLE:ON
Expand All @@ -199,7 +199,7 @@ public int executeUpdate(final String sql, final int[] columnIndexes) throws SQL
public int executeUpdate(final String sql, final String[] columnNames) throws SQLException {
returnGeneratedKeys = true;
try {
return executeUpdate(sql, (actualSQL, statement) -> statement.executeUpdate(actualSQL, columnNames), (statement, actualSQL) -> statement.executeUpdate(actualSQL, columnNames));
return executeUpdate(sql, (actualSQL, statement) -> statement.executeUpdate(actualSQL, columnNames), (actualSQL, statement) -> statement.executeUpdate(actualSQL, columnNames));
// CHECKSTYLE:OFF
} catch (final RuntimeException ex) {
// CHECKSTYLE:ON
Expand Down Expand Up @@ -228,7 +228,7 @@ private int executeUpdate(final String sql, final ExecuteUpdateCallback updateCa
@Override
public boolean execute(final String sql) throws SQLException {
try {
return execute0(sql, (actualSQL, statement) -> statement.execute(actualSQL), Statement::execute);
return execute0(sql, (actualSQL, statement) -> statement.execute(actualSQL), (actualSQL, statement) -> statement.execute(actualSQL));
// CHECKSTYLE:OFF
} catch (final SQLException ex) {
// CHECKSTYLE:ON
Expand All @@ -243,7 +243,7 @@ public boolean execute(final String sql, final int autoGeneratedKeys) throws SQL
if (RETURN_GENERATED_KEYS == autoGeneratedKeys) {
returnGeneratedKeys = true;
}
return execute0(sql, (actualSQL, statement) -> statement.execute(actualSQL, autoGeneratedKeys), (statement, actualSQL) -> statement.execute(actualSQL, autoGeneratedKeys));
return execute0(sql, (actualSQL, statement) -> statement.execute(actualSQL, autoGeneratedKeys), (actualSQL, statement) -> statement.execute(actualSQL, autoGeneratedKeys));
// CHECKSTYLE:OFF
} catch (final SQLException ex) {
// CHECKSTYLE:ON
Expand All @@ -256,7 +256,7 @@ public boolean execute(final String sql, final int autoGeneratedKeys) throws SQL
public boolean execute(final String sql, final int[] columnIndexes) throws SQLException {
try {
returnGeneratedKeys = true;
return execute0(sql, (actualSQL, statement) -> statement.execute(actualSQL, columnIndexes), (statement, actualSQL) -> statement.execute(actualSQL, columnIndexes));
return execute0(sql, (actualSQL, statement) -> statement.execute(actualSQL, columnIndexes), (actualSQL, statement) -> statement.execute(actualSQL, columnIndexes));
// CHECKSTYLE:OFF
} catch (final SQLException ex) {
// CHECKSTYLE:ON
Expand All @@ -269,7 +269,7 @@ public boolean execute(final String sql, final int[] columnIndexes) throws SQLEx
public boolean execute(final String sql, final String[] columnNames) throws SQLException {
try {
returnGeneratedKeys = true;
return execute0(sql, (actualSQL, statement) -> statement.execute(actualSQL, columnNames), (statement, actualSQL) -> statement.execute(actualSQL, columnNames));
return execute0(sql, (actualSQL, statement) -> statement.execute(actualSQL, columnNames), (actualSQL, statement) -> statement.execute(actualSQL, columnNames));
// CHECKSTYLE:OFF
} catch (final SQLException ex) {
// CHECKSTYLE:ON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public interface TrafficExecutorCallback<T> {
/**
* Execute.
*
* @param statement statement
* @param sql SQL
* @param statement statement
* @return execution result
* @throws SQLException SQL exception
*/
T execute(Statement statement, String sql) throws SQLException;
T execute(String sql, Statement statement) throws SQLException;
}

0 comments on commit eb58f47

Please sign in to comment.