strongduanmu commented on code in PR #22029: URL: https://github.com/apache/shardingsphere/pull/22029#discussion_r1017423520
########## proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorFactory.java: ########## @@ -0,0 +1,59 @@ +/* + * 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.proxy.backend.communication; + +import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext; +import org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine; +import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection; +import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus; +import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; +import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement; +import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement; +import org.apache.shardingsphere.transaction.core.TransactionType; + +/** + * Proxy SQL executor factory. + */ +public final class ProxySQLExecutorFactory { + + /** + * Create new instance of Proxy SQL executor. + * + * @param executionContext execution context + * @param databaseCommunicationEngine database communication engine + * @return Proxy SQL executor + */ + public static IProxySQLExecutor newInstance(final ExecutionContext executionContext, final JDBCDatabaseCommunicationEngine databaseCommunicationEngine) { + TransactionStatus transactionStatus = databaseCommunicationEngine.getBackendConnection().getConnectionSession().getTransactionStatus(); + SQLStatement sqlStatement = executionContext.getSqlStatementContext().getSqlStatement(); + IProxySQLExecutor proxySQLExecutor; + if (needAutoTransaction(executionContext, transactionStatus, sqlStatement)) { + proxySQLExecutor = + new ProxySQLExecutorWrapper(databaseCommunicationEngine.getDriverType(), (JDBCBackendConnection) databaseCommunicationEngine.getBackendConnection(), databaseCommunicationEngine); + } else { + proxySQLExecutor = + new ProxySQLExecutor(databaseCommunicationEngine.getDriverType(), (JDBCBackendConnection) databaseCommunicationEngine.getBackendConnection(), databaseCommunicationEngine); + } + return proxySQLExecutor; Review Comment: Please rename proxySQLExecutor to result. ########## proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorFactory.java: ########## @@ -0,0 +1,59 @@ +/* + * 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.proxy.backend.communication; + +import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext; +import org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine; +import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection; +import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus; +import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; +import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement; +import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement; +import org.apache.shardingsphere.transaction.core.TransactionType; + +/** + * Proxy SQL executor factory. + */ +public final class ProxySQLExecutorFactory { + + /** + * Create new instance of Proxy SQL executor. + * + * @param executionContext execution context + * @param databaseCommunicationEngine database communication engine + * @return Proxy SQL executor + */ + public static IProxySQLExecutor newInstance(final ExecutionContext executionContext, final JDBCDatabaseCommunicationEngine databaseCommunicationEngine) { + TransactionStatus transactionStatus = databaseCommunicationEngine.getBackendConnection().getConnectionSession().getTransactionStatus(); + SQLStatement sqlStatement = executionContext.getSqlStatementContext().getSqlStatement(); + IProxySQLExecutor proxySQLExecutor; + if (needAutoTransaction(executionContext, transactionStatus, sqlStatement)) { + proxySQLExecutor = Review Comment: Can we cache the proxySQLExecutor to improve performance? ########## proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java: ########## @@ -127,6 +125,7 @@ public ResponseHeader execute() throws SQLException { if (executionContext.getExecutionUnits().isEmpty()) { return new UpdateResponseHeader(executionContext.getSqlStatementContext().getSqlStatement()); } + IProxySQLExecutor proxySQLExecutor = ProxySQLExecutorFactory.newInstance(executionContext, this); Review Comment: Can we consider jdbc adapter? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
