terrymanu commented on a change in pull request #15115: URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r802257985
########## File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFactory.java ########## @@ -0,0 +1,49 @@ +/* + * 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.transaction.spi; + +import java.util.Map; +import java.util.ServiceLoader; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Transaction config factory. + */ +public class TransactionConfigFactory { Review comment: Please use final with class if the class not for extension. ########## File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFactory.java ########## @@ -0,0 +1,49 @@ +/* + * 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.transaction.spi; + +import java.util.Map; +import java.util.ServiceLoader; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Transaction config factory. + */ +public class TransactionConfigFactory { + + private static final Map<String, TransactionConfigFacade> SERVICES = new ConcurrentHashMap<>(); + + static { + for (TransactionConfigFacade each : ServiceLoader.load(TransactionConfigFacade.class)) { + SERVICES.put(each.getTransactionType(), each); + } + } Review comment: Please reuse `ShardingSphereServiceLoader` ########## File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFactory.java ########## @@ -0,0 +1,49 @@ +/* + * 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.transaction.spi; + +import java.util.Map; +import java.util.ServiceLoader; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Transaction config factory. + */ +public class TransactionConfigFactory { + + private static final Map<String, TransactionConfigFacade> SERVICES = new ConcurrentHashMap<>(); + + static { + for (TransactionConfigFacade each : ServiceLoader.load(TransactionConfigFacade.class)) { + SERVICES.put(each.getTransactionType(), each); + } + } + + /** + * Get transaction config facade instance. + * + * @param transactionProviderType transaction provider type + * @return transaction config facade + */ + public static TransactionConfigFacade newInstance(final String transactionProviderType) { + if (null != transactionProviderType) { + return SERVICES.get(transactionProviderType); Review comment: It is better to reuse `TypedSPIRegistry` ########## File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFactory.java ########## @@ -0,0 +1,49 @@ +/* + * 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.transaction.spi; + +import java.util.Map; +import java.util.ServiceLoader; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Transaction config factory. + */ +public class TransactionConfigFactory { + + private static final Map<String, TransactionConfigFacade> SERVICES = new ConcurrentHashMap<>(); + + static { + for (TransactionConfigFacade each : ServiceLoader.load(TransactionConfigFacade.class)) { + SERVICES.put(each.getTransactionType(), each); + } + } + + /** + * Get transaction config facade instance. + * + * @param transactionProviderType transaction provider type + * @return transaction config facade + */ + public static TransactionConfigFacade newInstance(final String transactionProviderType) { Review comment: Please use Optional instead of `null` ########## File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFacade.java ########## @@ -0,0 +1,41 @@ +/* + * 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.transaction.spi; + +import org.apache.shardingsphere.transaction.rule.TransactionRule; + +/** + * Transaction config facade. + */ +public interface TransactionConfigFacade { Review comment: It is better to reuse `TypedSPI` ########## File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/java/org/apache/shardingsphere/transaction/xa/narayana/util/NarayanaConfigFacade.java ########## @@ -0,0 +1,144 @@ +/* + * 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.transaction.xa.narayana.util; + +import com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore; +import com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess; +import com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule; +import com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner; +import com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter; +import com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter; +import com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter; +import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule; +import lombok.extern.slf4j.Slf4j; +import org.apache.shardingsphere.transaction.rule.TransactionRule; +import org.apache.shardingsphere.transaction.spi.TransactionConfigFacade; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +@Slf4j +public class NarayanaConfigFacade implements TransactionConfigFacade { + + @Override + public void generate(final TransactionRule transactionRule, final String instanceId) { + if (null == transactionRule) { + return; + } + Map<Object, Object> content; + content = generateDefaultNarayanaConfig(instanceId); + if (null != transactionRule.getProps()) { + swapJdbcStore(transactionRule, content); + } + String value = narayanaConfigMapToXml(content); + String path = ClassLoader.getSystemResource("").getPath(); + try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path, "jbossts-properties.xml"))) { + bufferedWriter.write(value); + bufferedWriter.flush(); + } catch (final IOException ex) { + log.error("generate narayana config file failed."); + } + } + + @Override + public String getTransactionType() { + return "Narayana"; + } + + private static void swapJdbcStore(final TransactionRule transactionRule, final Map<Object, Object> config) { Review comment: Private method should be just next to the method in which it is used -- 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: notifications-unsubscr...@shardingsphere.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org