Skip to content

Commit

Permalink
Refactor ShardingSphereStatement
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed May 25, 2024
1 parent 9b7b14e commit 77358bc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.shardingsphere.distsql.segment.AlgorithmSegment;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.distsql.handler.update.CreateDefaultShadowAlgorithmExecutor;
import org.apache.shardingsphere.shadow.distsql.segment.ShadowAlgorithmSegment;
import org.apache.shardingsphere.shadow.distsql.statement.CreateDefaultShadowAlgorithmStatement;
Expand All @@ -30,7 +29,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -43,9 +41,6 @@ class CreateDefaultShadowAlgorithmExecutorTest {

private final CreateDefaultShadowAlgorithmExecutor executor = new CreateDefaultShadowAlgorithmExecutor();

@Mock
private ShadowRuleConfiguration currentConfig;

@BeforeEach
void setUp() {
executor.setDatabase(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shardingsphere.infra.expr.espresso;

import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;

import java.util.stream.Stream;
Expand All @@ -25,16 +26,13 @@
* Reflect Value.
* Avoid using JDK21 bytecode during compilation. Refer to `org.graalvm.polyglot.Value`.
*/
@RequiredArgsConstructor
public class ReflectValue {

private static final String VALUE_CLASS_NAME = "org.graalvm.polyglot.Value";

private final Object valueInstance;

public ReflectValue(final Object valueInstance) {
this.valueInstance = valueInstance;
}

/**
* Returns the member with a given identifier or null if the member does not exist.
* @param identifier the member identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.shardingsphere.driver.jdbc.core.statement;

import com.google.common.base.Strings;
import lombok.AccessLevel;
import lombok.Getter;
import org.apache.shardingsphere.driver.executor.DriverExecutor;
Expand All @@ -39,6 +38,7 @@
import org.apache.shardingsphere.infra.connection.kernel.KernelProcessor;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.mysql.type.MySQLDatabaseType;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.exception.dialect.SQLExceptionTransformEngine;
import org.apache.shardingsphere.infra.exception.kernel.syntax.EmptySQLException;
import org.apache.shardingsphere.infra.executor.audit.SQLAuditEngine;
Expand Down Expand Up @@ -159,9 +159,7 @@ public ShardingSphereStatement(final ShardingSphereConnection connection, final

@Override
public ResultSet executeQuery(final String sql) throws SQLException {
if (Strings.isNullOrEmpty(sql)) {
throw new EmptySQLException().toSQLException();
}
ShardingSpherePreconditions.checkNotEmpty(sql, () -> new EmptySQLException().toSQLException());
ResultSet result;
try {
QueryContext queryContext = createQueryContext(sql);
Expand All @@ -170,11 +168,9 @@ public ResultSet executeQuery(final String sql) throws SQLException {
connection.getDatabaseConnectionManager().getConnectionContext().setCurrentDatabase(databaseName);
trafficInstanceId = getInstanceIdAndSet(queryContext).orElse(null);
if (null != trafficInstanceId) {
JDBCExecutionUnit executionUnit = createTrafficExecutionUnit(trafficInstanceId, queryContext);
return executor.getTrafficExecutor().execute(executionUnit, Statement::executeQuery);
return executor.getTrafficExecutor().execute(createTrafficExecutionUnit(trafficInstanceId, queryContext), Statement::executeQuery);
}
useFederation = decide(queryContext,
metaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.getMetaData().getGlobalRuleMetaData());
useFederation = decide(queryContext, metaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.getMetaData().getGlobalRuleMetaData());
if (useFederation) {
return executeFederationQuery(queryContext);
}
Expand Down Expand Up @@ -435,8 +431,7 @@ private boolean execute0(final String sql, final ExecuteCallback executeCallback
JDBCExecutionUnit executionUnit = createTrafficExecutionUnit(trafficInstanceId, queryContext);
return executor.getTrafficExecutor().execute(executionUnit, trafficCallback);
}
useFederation = decide(queryContext,
metaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.getMetaData().getGlobalRuleMetaData());
useFederation = decide(queryContext, metaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.getMetaData().getGlobalRuleMetaData());
if (useFederation) {
ResultSet resultSet = executeFederationQuery(queryContext);
return null != resultSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.shardingsphere.data.pipeline.core.consistencycheck.table.calculator;

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.util.close.QuietlyCloser;

import java.sql.Connection;
Expand All @@ -28,7 +27,6 @@
/**
* Calculation context.
*/
@RequiredArgsConstructor
public final class CalculationContext implements AutoCloseable {

private final AtomicReference<Connection> connection = new AtomicReference<>();
Expand Down

0 comments on commit 77358bc

Please sign in to comment.