-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QueryableRALExecuteEngine and UpdatableRALExecuteEngine
- Loading branch information
Showing
8 changed files
with
177 additions
and
61 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
...a/org/apache/shardingsphere/distsql/handler/type/ral/query/QueryableRALExecuteEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.distsql.handler.type.ral.query; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.shardingsphere.distsql.handler.type.ral.query.aware.ConnectionSizeAwareQueryableRALExecutor; | ||
import org.apache.shardingsphere.distsql.handler.type.ral.query.aware.DatabaseAwareQueryableRALExecutor; | ||
import org.apache.shardingsphere.distsql.handler.type.ral.query.aware.InstanceContextAwareQueryableRALExecutor; | ||
import org.apache.shardingsphere.distsql.handler.util.DatabaseNameUtils; | ||
import org.apache.shardingsphere.distsql.statement.ral.queryable.QueryableRALStatement; | ||
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; | ||
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; | ||
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; | ||
import org.apache.shardingsphere.mode.manager.ContextManager; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Queryable RAL execute engine. | ||
*/ | ||
@RequiredArgsConstructor | ||
public abstract class QueryableRALExecuteEngine { | ||
|
||
private final QueryableRALStatement sqlStatement; | ||
|
||
private final String currentDatabaseName; | ||
|
||
private final ContextManager contextManager; | ||
|
||
@Getter | ||
private Collection<String> columnNames; | ||
|
||
@Getter | ||
private Collection<LocalDataQueryResultRow> rows; | ||
|
||
/** | ||
* Execute query. | ||
* | ||
*/ | ||
@SuppressWarnings({"unchecked", "rawtypes"}) | ||
public void executeQuery() { | ||
QueryableRALExecutor executor = TypedSPILoader.getService(QueryableRALExecutor.class, sqlStatement.getClass()); | ||
rows = getRows(executor); | ||
columnNames = executor.getColumnNames(); | ||
} | ||
|
||
@SuppressWarnings({"unchecked", "rawtypes"}) | ||
private Collection<LocalDataQueryResultRow> getRows(final QueryableRALExecutor executor) { | ||
if (executor instanceof InstanceContextAwareQueryableRALExecutor) { | ||
((InstanceContextAwareQueryableRALExecutor) executor).setInstanceContext(contextManager.getInstanceContext()); | ||
} | ||
if (executor instanceof DatabaseAwareQueryableRALExecutor) { | ||
((DatabaseAwareQueryableRALExecutor) executor).setDatabase(getDatabase(DatabaseNameUtils.getDatabaseName(sqlStatement, currentDatabaseName))); | ||
} | ||
if (executor instanceof ConnectionSizeAwareQueryableRALExecutor) { | ||
((ConnectionSizeAwareQueryableRALExecutor) executor).setConnectionSize(getConnectionSize()); | ||
} | ||
return executor.getRows(sqlStatement, contextManager.getMetaDataContexts().getMetaData()); | ||
} | ||
|
||
protected abstract ShardingSphereDatabase getDatabase(String databaseName); | ||
|
||
protected abstract int getConnectionSize(); | ||
} |
53 changes: 53 additions & 0 deletions
53
.../org/apache/shardingsphere/distsql/handler/type/ral/update/UpdatableRALExecuteEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.distsql.handler.type.ral.update; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.shardingsphere.distsql.handler.util.DatabaseNameUtils; | ||
import org.apache.shardingsphere.distsql.statement.ral.updatable.UpdatableRALStatement; | ||
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; | ||
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; | ||
|
||
import java.sql.SQLException; | ||
|
||
/** | ||
* Updatable RAL execute engine. | ||
*/ | ||
@RequiredArgsConstructor | ||
public abstract class UpdatableRALExecuteEngine { | ||
|
||
private final UpdatableRALStatement sqlStatement; | ||
|
||
private final String currentDatabaseName; | ||
|
||
/** | ||
* Execute update. | ||
* | ||
* @throws SQLException SQL exception | ||
*/ | ||
@SuppressWarnings({"unchecked", "rawtypes"}) | ||
public void executeUpdate() throws SQLException { | ||
UpdatableRALExecutor executor = TypedSPILoader.getService(UpdatableRALExecutor.class, sqlStatement.getClass()); | ||
if (executor instanceof DatabaseAwareUpdatableRALExecutor) { | ||
((DatabaseAwareUpdatableRALExecutor) executor).setDatabase(getDatabase(DatabaseNameUtils.getDatabaseName(sqlStatement, currentDatabaseName))); | ||
} | ||
executor.executeUpdate(sqlStatement); | ||
} | ||
|
||
protected abstract ShardingSphereDatabase getDatabase(String databaseName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters