You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/01/28 09:57:26 UTC

[GitHub] [shardingsphere] jingshanglu commented on a change in pull request #15115: Make It is easy to use with narayana

jingshanglu commented on a change in pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r794357094



##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java
##########
@@ -61,4 +75,102 @@ private TransactionRule getTransactionRule() {
         Optional<TransactionRule> transactionRule = globalRules.stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
         return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build()));
     }
+    
+    private void generateNarayanaConfig(final TransactionRule transactionRule) {
+        Map<Object, Object> result;
+        if (transactionRule.getDefaultType() == TransactionType.XA && transactionRule.getProviderType().equalsIgnoreCase("Narayana")) {
+            result = generateDefaultNarayanaConfig();
+            if (null != transactionRule.getProps()) {
+                swapJdbcStore(transactionRule, result);
+            }
+        } else {
+            return;
+        }
+        String value = narayanaConfigMapToXml((LinkedHashMap<Object, Object>) result);
+        String path = ClassLoader.getSystemResource("").getPath();
+        System.out.println(path);
+        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.");
+        }
+    }

Review comment:
       Config of transaction is `org.apache.shardingsphere.transaction.rule.TransactionRule`, all types of transactions share the `props` field.
   ```
   public final class TransactionRule implements GlobalRule {
       
       private final TransactionType defaultType;
       
       private final String providerType;
       
       private final Properties props; 
       
       public TransactionRule(final TransactionRuleConfiguration ruleConfig) {
           defaultType = TransactionType.valueOf(ruleConfig.getDefaultType().toUpperCase());
           providerType = ruleConfig.getProviderType();
           props = ruleConfig.getProps();
       }
       
       @Override
       public String getType() {
           return TransactionRule.class.getSimpleName();
       }
   }
   ```
   `TransactionContextsBuilder` is the general entry for transaction engine initialization. In `TransactionContextsBuilder`, the transaction engine is initialized according to the configuration.




-- 
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-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org