Skip to content

Commit

Permalink
Fix code format (apache#20943)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Sep 12, 2022
1 parent f769cbf commit f9a68a9
Show file tree
Hide file tree
Showing 90 changed files with 154 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public final class ShadowConfiguration {
userIdInsertProps.setProperty("operation", "insert");
userIdInsertProps.setProperty("column", "user_id");
userIdInsertProps.setProperty("value", "1");
return new AlgorithmConfiguration("VALUE_MATCH", userIdInsertProps));
return new AlgorithmConfiguration("VALUE_MATCH", userIdInsertProps);
}

// ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public final class MySQLComStmtExecutePacket extends MySQLCommandPacket {
@Getter
private final List<MySQLPreparedStatementParameterType> newParameterTypes;

public MySQLComStmtExecutePacket(final MySQLPacketPayload payload, final int parameterCount) throws SQLException {
public MySQLComStmtExecutePacket(final MySQLPacketPayload payload, final int parameterCount) {
super(MySQLCommandPacketType.COM_STMT_EXECUTE);
this.payload = payload;
statementId = payload.readInt4();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setUp() {
@Test
public void assertNotDMLStatementCheck() {
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(DDLStatement.class));
asserCheckResult(shardingAuditAlgorithm.check(sqlStatementContext, Collections.emptyList(), mock(Grantee.class), database), true, "");
assertCheckResult(shardingAuditAlgorithm.check(sqlStatementContext, Collections.emptyList(), mock(Grantee.class), database), true, "");
verify(database, times(0)).getRuleMetaData();
}

Expand All @@ -73,15 +73,15 @@ public void assertAllBroadcastTablesCheck() {
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(DMLStatement.class));
when(database.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.singletonList(rule)));
when(rule.isAllBroadcastTables(sqlStatementContext.getTablesContext().getTableNames())).thenReturn(true);
asserCheckResult(shardingAuditAlgorithm.check(sqlStatementContext, Collections.emptyList(), mock(Grantee.class), database), true, "");
assertCheckResult(shardingAuditAlgorithm.check(sqlStatementContext, Collections.emptyList(), mock(Grantee.class), database), true, "");
}

@Test
public void assertNotAllShardingTablesCheck() {
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(DMLStatement.class));
when(database.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.singletonList(rule)));
when(rule.isAllBroadcastTables(sqlStatementContext.getTablesContext().getTableNames())).thenReturn(false);
asserCheckResult(shardingAuditAlgorithm.check(sqlStatementContext, Collections.emptyList(), mock(Grantee.class), database), true, "");
assertCheckResult(shardingAuditAlgorithm.check(sqlStatementContext, Collections.emptyList(), mock(Grantee.class), database), true, "");
}

@Test
Expand All @@ -90,10 +90,10 @@ public void assertEmptyShardingConditionsCheck() {
when(database.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.singletonList(rule)));
when(rule.isAllBroadcastTables(sqlStatementContext.getTablesContext().getTableNames())).thenReturn(false);
when(rule.isShardingTable("t_order")).thenReturn(true);
asserCheckResult(shardingAuditAlgorithm.check(sqlStatementContext, Collections.emptyList(), mock(Grantee.class), database), false, "Not allow DML operation without sharding conditions");
assertCheckResult(shardingAuditAlgorithm.check(sqlStatementContext, Collections.emptyList(), mock(Grantee.class), database), false, "Not allow DML operation without sharding conditions");
}

private void asserCheckResult(final SQLCheckResult checkResult, final boolean isPassed, final String errorMessage) {
private void assertCheckResult(final SQLCheckResult checkResult, final boolean isPassed, final String errorMessage) {
assertThat(checkResult.isPassed(), is(isPassed));
assertThat(checkResult.getErrorMessage(), is(errorMessage));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public final class UUIDKeyGenerateAlgorithmTest {

@Test
public void assertGenerateKey() {
assertThat(((String) uuidKeyGenerateAlgorithm.generateKey()).length(), is(32));
assertThat(uuidKeyGenerateAlgorithm.generateKey().length(), is(32));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,27 @@ public void setUp() {
@Test
public void assertCheckSQLStatementPass() {
when(rule.getAuditors().get("auditor_1").check(sqlStatementContext, parameters, grantee, databases.get("foo_db"))).thenReturn(new SQLCheckResult(true, ""));
asserCheckResult(checker.check(sqlStatementContext, Collections.emptyList(), grantee, "foo_db", databases, rule), true, "");
assertCheckResult(checker.check(sqlStatementContext, Collections.emptyList(), grantee, "foo_db", databases, rule), true, "");
verify(rule.getAuditors().get("auditor_1"), times(1)).check(sqlStatementContext, parameters, grantee, databases.get("foo_db"));
}

@Test
public void assertSQCheckPassByDisableAuditNames() {
when(rule.getAuditors().get("auditor_1").check(sqlStatementContext, parameters, grantee, databases.get("foo_db"))).thenReturn(new SQLCheckResult(false, ""));
when(auditStrategy.isAllowHintDisable()).thenReturn(true);
asserCheckResult(checker.check(sqlStatementContext, Collections.emptyList(), grantee, "foo_db", databases, rule), true, "");
assertCheckResult(checker.check(sqlStatementContext, Collections.emptyList(), grantee, "foo_db", databases, rule), true, "");
verify(rule.getAuditors().get("auditor_1"), times(0)).check(sqlStatementContext, parameters, grantee, databases.get("foo_db"));
}

@Test
public void assertSQLCheckNotPass() {
when(rule.getAuditors().get("auditor_1").check(sqlStatementContext, parameters, grantee, databases.get("foo_db")))
.thenReturn(new SQLCheckResult(false, "Not allow DML operation without sharding conditions"));
asserCheckResult(checker.check(sqlStatementContext, Collections.emptyList(), grantee, "foo_db", databases, rule), false, "Not allow DML operation without sharding conditions");
assertCheckResult(checker.check(sqlStatementContext, Collections.emptyList(), grantee, "foo_db", databases, rule), false, "Not allow DML operation without sharding conditions");
verify(rule.getAuditors().get("auditor_1"), times(1)).check(sqlStatementContext, parameters, grantee, databases.get("foo_db"));
}

private void asserCheckResult(final SQLCheckResult checkResult, final boolean isPassed, final String errorMessage) {
private void assertCheckResult(final SQLCheckResult checkResult, final boolean isPassed, final String errorMessage) {
assertThat(checkResult.isPassed(), is(isPassed));
assertThat(checkResult.getErrorMessage(), is(errorMessage));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ public static ShardingSphereDatabase create(final String name, final DatabaseTyp
* @param name system database name
* @param protocolType protocol database type
* @return system database meta data
* @throws SQLException SQL exception
*/
public static ShardingSphereDatabase create(final String name, final DatabaseType protocolType) throws SQLException {
public static ShardingSphereDatabase create(final String name, final DatabaseType protocolType) {
DatabaseConfiguration databaseConfig = new DataSourceProvidedDatabaseConfiguration(new LinkedHashMap<>(), new LinkedList<>());
return create(name, protocolType, databaseConfig, new LinkedList<>(), SystemSchemaBuilder.build(name, protocolType));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@

package org.apache.shardingsphere.infra.fixture;

import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;

public final class FixtureRuleDefinitionUpdater implements RuleDefinitionUpdater<FixtureRuleStatement, FixtureRuleConfiguration> {

@Override
public void checkSQLStatement(final ShardingSphereDatabase database, final FixtureRuleStatement sqlStatement, final FixtureRuleConfiguration currentRuleConfig) throws DistSQLException {
public void checkSQLStatement(final ShardingSphereDatabase database, final FixtureRuleStatement sqlStatement, final FixtureRuleConfiguration currentRuleConfig) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void assertAddDatabase() throws SQLException {
ResourceHeldRule<?> databaseResourceHeldRule = mock(ResourceHeldRule.class);
ResourceHeldRule<?> globalResourceHeldRule = mock(ResourceHeldRule.class);
ShardingSphereDatabase database = mockDatabase(resource, dataSource, databaseResourceHeldRule);
try (MockedStatic<ShardingSphereDatabase> mockedStatic = mockStatic(ShardingSphereDatabase.class);) {
try (MockedStatic<ShardingSphereDatabase> mockedStatic = mockStatic(ShardingSphereDatabase.class)) {
DatabaseType databaseType = mock(DatabaseType.class);
mockedStatic.when(() -> ShardingSphereDatabase.create("foo_db", databaseType)).thenReturn(database);
Map<String, ShardingSphereDatabase> databases = new HashMap<>(Collections.singletonMap("foo_db", database));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.apache.shardingsphere.test.mock.MockedDataSource;
import org.junit.Test;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Collections;

import static org.junit.Assert.assertTrue;
Expand All @@ -30,7 +28,7 @@ public final class ShardingSphereResourceTest {

@SuppressWarnings("BusyWait")
@Test
public void assertClose() throws SQLException, IOException, InterruptedException {
public void assertClose() throws InterruptedException {
MockedDataSource dataSource = new MockedDataSource();
new ShardingSphereResource(Collections.singletonMap("foo_ds", dataSource)).close(dataSource);
while (!dataSource.isClosed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.AlterIndexStatementHandler;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Optional;

Expand All @@ -41,7 +40,7 @@ public final class AlterIndexStatementSchemaRefresher implements MetaDataRefresh

@Override
public Optional<MetaDataRefreshedEvent> refresh(final ShardingSphereDatabase database, final Collection<String> logicDataSourceNames,
final String schemaName, final AlterIndexStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
final String schemaName, final AlterIndexStatement sqlStatement, final ConfigurationProperties props) {
Optional<IndexSegment> renameIndex = AlterIndexStatementHandler.getRenameIndexSegment(sqlStatement);
if (!sqlStatement.getIndex().isPresent() || !renameIndex.isPresent()) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterSchemaStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.AlterSchemaStatementHandler;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Optional;

Expand All @@ -39,7 +38,7 @@ public final class AlterSchemaStatementSchemaRefresher implements MetaDataRefres

@Override
public Optional<MetaDataRefreshedEvent> refresh(final ShardingSphereDatabase database, final Collection<String> logicDataSourceNames,
final String schemaName, final AlterSchemaStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
final String schemaName, final AlterSchemaStatement sqlStatement, final ConfigurationProperties props) {
Optional<String> renameSchemaName = AlterSchemaStatementHandler.getRenameSchema(sqlStatement).map(optional -> optional.getValue().toLowerCase());
if (!renameSchemaName.isPresent()) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.shardingsphere.infra.metadata.database.schema.util.IndexMetaDataUtil;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Optional;

Expand All @@ -38,7 +37,7 @@ public final class CreateIndexStatementSchemaRefresher implements MetaDataRefres

@Override
public Optional<MetaDataRefreshedEvent> refresh(final ShardingSphereDatabase database, final Collection<String> logicDataSourceNames,
final String schemaName, final CreateIndexStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
final String schemaName, final CreateIndexStatement sqlStatement, final ConfigurationProperties props) {
String indexName = null != sqlStatement.getIndex() ? sqlStatement.getIndex().getIndexName().getIdentifier().getValue()
: IndexMetaDataUtil.getGeneratedLogicIndexName(sqlStatement.getColumns());
if (Strings.isNullOrEmpty(indexName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.CreateSchemaStatementHandler;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Optional;

Expand All @@ -38,7 +37,7 @@ public final class CreateSchemaStatementSchemaRefresher implements MetaDataRefre

@Override
public Optional<MetaDataRefreshedEvent> refresh(final ShardingSphereDatabase database, final Collection<String> logicDataSourceNames,
final String schemaName, final CreateSchemaStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
final String schemaName, final CreateSchemaStatement sqlStatement, final ConfigurationProperties props) {
Optional<IdentifierValue> schema = sqlStatement.getSchemaName().isPresent() ? sqlStatement.getSchemaName() : CreateSchemaStatementHandler.getUsername(sqlStatement);
if (!schema.isPresent()) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.DropIndexStatementHandler;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
Expand All @@ -43,7 +42,7 @@ public final class DropIndexStatementSchemaRefresher implements MetaDataRefreshe

@Override
public Optional<MetaDataRefreshedEvent> refresh(final ShardingSphereDatabase database, final Collection<String> logicDataSourceNames,
final String schemaName, final DropIndexStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
final String schemaName, final DropIndexStatement sqlStatement, final ConfigurationProperties props) {
DropIndexEvent event = new DropIndexEvent();
for (IndexSegment each : sqlStatement.getIndexes()) {
String actualSchemaName = each.getOwner().map(optional -> optional.getIdentifier().getValue().toLowerCase()).orElse(schemaName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropSchemaStatement;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;

import java.sql.SQLException;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.LinkedList;
Expand All @@ -40,7 +39,7 @@ public final class DropSchemaStatementSchemaRefresher implements MetaDataRefresh

@Override
public Optional<MetaDataRefreshedEvent> refresh(final ShardingSphereDatabase database, final Collection<String> logicDataSourceNames,
final String schemaName, final DropSchemaStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
final String schemaName, final DropSchemaStatement sqlStatement, final ConfigurationProperties props) {
Collection<String> tobeRemovedTables = new LinkedHashSet<>();
Collection<String> tobeRemovedSchemas = new LinkedHashSet<>();
Collection<String> schemaNames = getSchemaNames(sqlStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Optional;

Expand All @@ -37,7 +36,7 @@ public final class DropTableStatementSchemaRefresher implements MetaDataRefreshe

@Override
public Optional<MetaDataRefreshedEvent> refresh(final ShardingSphereDatabase database, final Collection<String> logicDataSourceNames,
final String schemaName, final DropTableStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
final String schemaName, final DropTableStatement sqlStatement, final ConfigurationProperties props) {
SchemaAlteredEvent event = new SchemaAlteredEvent(database.getName(), schemaName);
sqlStatement.getTables().forEach(each -> {
database.getSchema(schemaName).removeTable(each.getTableName().getIdentifier().getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropViewStatement;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Optional;

Expand All @@ -38,7 +37,7 @@ public final class DropViewStatementSchemaRefresher implements MetaDataRefresher

@Override
public Optional<MetaDataRefreshedEvent> refresh(final ShardingSphereDatabase database, final Collection<String> logicDataSourceNames,
final String schemaName, final DropViewStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
final String schemaName, final DropViewStatement sqlStatement, final ConfigurationProperties props) {
SchemaAlteredEvent event = new SchemaAlteredEvent(database.getName(), schemaName);
sqlStatement.getViews().forEach(each -> {
ShardingSphereSchema schema = database.getSchema(schemaName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.vertx.VertxQueryResult;
import org.apache.shardingsphere.infra.executor.sql.execute.result.update.UpdateResult;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -41,7 +40,7 @@
public final class VertxExecutorCallback implements ExecutorCallback<VertxExecutionUnit, Future<ExecuteResult>> {

@Override
public Collection<Future<ExecuteResult>> execute(final Collection<VertxExecutionUnit> inputs, final boolean isTrunkThread, final Map<String, Object> dataMap) throws SQLException {
public Collection<Future<ExecuteResult>> execute(final Collection<VertxExecutionUnit> inputs, final boolean isTrunkThread, final Map<String, Object> dataMap) {
List<Future<ExecuteResult>> result = new ArrayList<>(inputs.size());
for (VertxExecutionUnit each : inputs) {
Future<RowSet<Row>> future = each.getStorageResource().compose(preparedQuery -> preparedQuery.execute(Tuple.from(each.getExecutionUnit().getSqlUnit().getParameters())));
Expand Down
Loading

0 comments on commit f9a68a9

Please sign in to comment.