ppalaga commented on a change in pull request #1411:
URL: https://github.com/apache/camel-quarkus/pull/1411#discussion_r444015392



##########
File path: 
extensions/jta/deployment/src/main/java/org/apache/camel/quarkus/component/jta/deployment/JtaProcessor.java
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.camel.quarkus.component.jta.deployment;
+
+import com.arjuna.ats.internal.arjuna.utils.SocketProcessId;
+import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
+import io.quarkus.deployment.Capabilities;
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import org.apache.camel.quarkus.component.jta.MandatoryJtaTransactionPolicy;
+import org.apache.camel.quarkus.component.jta.NestedJtaTransactionPolicy;
+import org.apache.camel.quarkus.component.jta.NeverJtaTransactionPolicy;
+import org.apache.camel.quarkus.component.jta.NotSupportedJtaTransactionPolicy;
+import org.apache.camel.quarkus.component.jta.RequiredJtaTransactionPolicy;
+import org.apache.camel.quarkus.component.jta.RequiresNewJtaTransactionPolicy;
+import org.apache.camel.quarkus.component.jta.SupportsJtaTransactionPolicy;
+
+class JtaProcessor {
+
+    private static final String FEATURE = "camel-jta";
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep
+    void transactedPolicy(
+            BuildProducer<AdditionalBeanBuildItem> additionalBeans,
+            Capabilities capabilities) {
+        if (capabilities.isCapabilityPresent(Capabilities.TRANSACTIONS)) {
+            AdditionalBeanBuildItem.Builder builder = 
AdditionalBeanBuildItem.builder();
+            builder.addBeanClass(RequiredJtaTransactionPolicy.class);
+            builder.addBeanClass(RequiresNewJtaTransactionPolicy.class);
+            builder.addBeanClass(MandatoryJtaTransactionPolicy.class);
+            builder.addBeanClass(NestedJtaTransactionPolicy.class);
+            builder.addBeanClass(NeverJtaTransactionPolicy.class);
+            builder.addBeanClass(NotSupportedJtaTransactionPolicy.class);
+            builder.addBeanClass(SupportsJtaTransactionPolicy.class);
+
+            additionalBeans.produce(builder.build());
+        }
+    }
+
+    @BuildStep

Review comment:
       ```suggestion
       @BuildStep // TODO remove this BuildStep when 
https://github.com/quarkusio/quarkus/issues/10180 gets resolved
   ```

##########
File path: extensions/jta/runtime/pom.xml
##########
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.camel.quarkus</groupId>
+        <artifactId>camel-quarkus-jta-parent</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>camel-quarkus-jta</artifactId>
+    <name>Camel Quarkus :: JTA :: Runtime</name>
+    <description>Using Camel with JTA Transaction Manager</description>

Review comment:
       ```suggestion
       <description>Enclose Camel routes in distributed transactions using Java 
Transaction API (JTA) and Narayana transaction manager</description>
   ```
   
   If you like/accept the above proposal, please regenerate the docs.

##########
File path: 
extensions/jta/runtime/src/main/java/org/apache/camel/quarkus/component/jta/TransactionalJtaTransactionPolicy.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.camel.quarkus.component.jta;
+
+import javax.inject.Inject;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.apache.camel.CamelException;
+import org.apache.camel.jta.JtaTransactionPolicy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Helper methods for transaction handling
+ */
+public abstract class TransactionalJtaTransactionPolicy extends 
JtaTransactionPolicy {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(TransactionalJtaTransactionPolicy.class);
+
+    @Inject
+    TransactionManager transactionManager;
+
+    protected void runWithTransaction(final Runnable runnable, final boolean 
isNew) throws Throwable {
+        if (isNew) {
+            begin();
+        }
+        try {
+            runnable.run();
+        } catch (Throwable e) {
+            rollback(isNew);
+            throw e;
+        }
+        if (isNew) {
+            commit();
+        }
+    }
+
+    private void begin() throws Exception {
+        transactionManager.begin();
+    }
+
+    private void commit() throws Exception {
+        try {
+            transactionManager.commit();
+        } catch (HeuristicMixedException | HeuristicRollbackException | 
RollbackException | SystemException e) {
+            throw new CamelException("Unable to commit transaction", e);
+        } catch (Exception | Error e) {
+            rollback(true);
+            throw e;
+        }
+    }
+
+    protected void rollback(boolean isNew) throws Exception {
+        try {
+            if (isNew) {
+                transactionManager.rollback();
+            } else {
+                transactionManager.setRollbackOnly();
+            }
+        } catch (Throwable e) {
+            LOG.warn("Could not rollback transaction!", e);
+        }
+    }
+
+    protected Transaction suspendTransaction() throws Exception {
+        return transactionManager.suspend();
+    }
+
+    protected void resumeTransaction(final Transaction suspendedTransaction) {
+        if (suspendedTransaction == null) {
+            return;
+        }
+
+        try {
+            transactionManager.resume(suspendedTransaction);
+        } catch (Throwable e) {
+            LOG.warn("Could not resume transaction!", e);
+        }
+    }
+
+    protected boolean hasActiveTransaction() throws Exception {
+        return transactionManager.getStatus() != Status.STATUS_MARKED_ROLLBACK
+                && transactionManager.getStatus() != 
Status.STATUS_NO_TRANSACTION;
+    }

Review comment:
       I guess we do not want end users to override these methods or even call 
them directly? Hence we should perhaps make them package visible and `final`? 
Maybe the subclasses of `TransactionalJtaTransactionPolicy` could be made 
`final` too?

##########
File path: 
integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaRoutes.java
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.camel.quarkus.component.jta.it;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class JtaRoutes extends RouteBuilder {
+    @Override
+    public void configure() throws Exception {
+        from("direct:test")
+                .transacted().transform().constant("Hello World");

Review comment:
       Do not see any coverage for the individual various TransactionPolicies. 
Would it be hard to add a test route per policy?




----------------------------------------------------------------
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.

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


Reply via email to