Skip to content

Commit

Permalink
Remove useless RALBackendHandler (#29821)
Browse files Browse the repository at this point in the history
* Remove useless generic type on RuleDefinitionBackendHandler

* Refactor CreateDatabaseRuleRDLExecuteEngine

* Refactor DropDatabaseRuleRDLExecuteEngine

* Remove useless RALBackendHandler

* Refactor QueryableRALBackendHandler

* Refactor QueryableRALBackendHandler

* Refactor CreateDatabaseRuleRDLExecuteEngine
  • Loading branch information
terrymanu authored Jan 23, 2024
1 parent 8b18d4e commit 1a88337
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shardingsphere.proxy.backend.handler.distsql.ral;

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.distsql.handler.type.ral.query.ConnectionSizeAwareQueryableRALExecutor;
import org.apache.shardingsphere.distsql.handler.type.ral.query.DatabaseAwareQueryableRALExecutor;
import org.apache.shardingsphere.distsql.handler.type.ral.query.InstanceContextAwareQueryableRALExecutor;
Expand All @@ -27,6 +28,7 @@
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.handler.distsql.DistSQLBackendHandler;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseCell;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseRow;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
Expand All @@ -47,7 +49,8 @@
*
* @param <T> type of queryable RAL statement
*/
public final class QueryableRALBackendHandler<T extends QueryableRALStatement> implements RALBackendHandler {
@RequiredArgsConstructor
public final class QueryableRALBackendHandler<T extends QueryableRALStatement> implements DistSQLBackendHandler {

private final T sqlStatement;

Expand All @@ -57,12 +60,6 @@ public final class QueryableRALBackendHandler<T extends QueryableRALStatement> i

private MergedResult mergedResult;

@SuppressWarnings("unchecked")
public QueryableRALBackendHandler(final QueryableRALStatement sqlStatement, final ConnectionSession connectionSession) {
this.sqlStatement = (T) sqlStatement;
this.connectionSession = connectionSession;
}

@SuppressWarnings("unchecked")
@Override
public ResponseHeader execute() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.shardingsphere.distsql.statement.ral.UpdatableRALStatement;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.handler.distsql.DistSQLBackendHandler;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
Expand All @@ -36,7 +37,7 @@
* @param <T> type of SQL statement
*/
@RequiredArgsConstructor
public final class UpdatableRALBackendHandler<T extends UpdatableRALStatement> implements RALBackendHandler {
public final class UpdatableRALBackendHandler<T extends UpdatableRALStatement> implements DistSQLBackendHandler {

private final UpdatableRALStatement sqlStatement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.handler.distsql.rdl.rule.database.execute.DatabaseRuleRDLExecuteEngine;
import org.apache.shardingsphere.single.distsql.statement.rdl.LoadSingleTableStatement;
import org.apache.shardingsphere.single.distsql.statement.rdl.SetDefaultSingleTableStorageUnitStatement;

import java.util.Collection;
import java.util.LinkedHashMap;
Expand All @@ -49,17 +47,12 @@ public final class CreateDatabaseRuleRDLExecuteEngine implements DatabaseRuleRDL
@SuppressWarnings("unchecked")
public Collection<MetaDataVersion> execute(final RuleDefinitionStatement sqlStatement, final ShardingSphereDatabase database, final RuleConfiguration currentRuleConfig) {
RuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(currentRuleConfig, sqlStatement);
executor.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig);
ModeContextManager modeContextManager = ProxyContext.getInstance().getContextManager().getInstanceContext().getModeContextManager();
return modeContextManager.alterRuleConfiguration(database.getName(), getToBeCreatedRuleConfiguration(sqlStatement, database, currentRuleConfig, toBeCreatedRuleConfig));
}

private RuleConfiguration getToBeCreatedRuleConfiguration(final RuleDefinitionStatement sqlStatement,
final ShardingSphereDatabase database, final RuleConfiguration currentRuleConfig, final RuleConfiguration toBeCreatedRuleConfig) {
if (sqlStatement instanceof LoadSingleTableStatement || sqlStatement instanceof SetDefaultSingleTableStorageUnitStatement) {
return null == currentRuleConfig ? decorateRuleConfiguration(database, toBeCreatedRuleConfig) : decorateRuleConfiguration(database, currentRuleConfig);
if (null == currentRuleConfig) {
return modeContextManager.alterRuleConfiguration(database.getName(), decorateRuleConfiguration(database, toBeCreatedRuleConfig));
}
return toBeCreatedRuleConfig;
executor.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig);
return modeContextManager.alterRuleConfiguration(database.getName(), decorateRuleConfiguration(database, currentRuleConfig));
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 1a88337

Please sign in to comment.