openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1775607 - in /openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta: InterceptorBase.java JtaConfig.java JtaExtension.java
Date Thu, 22 Dec 2016 10:14:45 GMT
Author: rmannibucau
Date: Thu Dec 22 10:14:45 2016
New Revision: 1775607

URL: http://svn.apache.org/viewvc?rev=1775607&view=rev
Log:
small workaround to allow to use jta module without meecrowave but still benefit from it if
there

Added:
    openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/JtaConfig.java
Modified:
    openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/InterceptorBase.java
    openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/JtaExtension.java

Modified: openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/InterceptorBase.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/InterceptorBase.java?rev=1775607&r1=1775606&r2=1775607&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/InterceptorBase.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/InterceptorBase.java
Thu Dec 22 10:14:45 2016
@@ -16,9 +16,6 @@
  */
 package org.apache.meecrowave.jta;
 
-import org.apache.meecrowave.Meecrowave;
-import org.apache.meecrowave.runner.cli.CliOption;
-
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.CDI;
@@ -48,7 +45,7 @@ public abstract class InterceptorBase im
     private transient volatile ConcurrentMap<Method, Boolean> rollback = new ConcurrentHashMap<>();
 
     @Inject
-    private Meecrowave.Builder config;
+    private JtaConfig config;
 
     @Inject
     protected TransactionManager transactionManager;
@@ -77,7 +74,7 @@ public abstract class InterceptorBase im
             }
 
             Exception error = unwrap(e);
-            if (error != null && (!config.getExtension(Jta.class).isHandleExceptionOnlyForClient()
|| isNewTransaction(state))) {
+            if (error != null && (!config.isHandleExceptionOnlyForClient() || isNewTransaction(state)))
{
                 final Method method = ic.getMethod();
                 if (rollback == null) {
                     synchronized (this) {
@@ -235,15 +232,6 @@ public abstract class InterceptorBase im
         }
     }
 
-    public static class Jta {
-        @CliOption(name = "jta-handle-exception-only-for-client", description = "should JTA
exception only be managed by client")
-        private boolean handleExceptionOnlyForClient;
-
-        public boolean isHandleExceptionOnlyForClient() {
-            return handleExceptionOnlyForClient;
-        }
-    }
-
     protected static class State {
         protected final Transaction old;
         protected final Transaction current;

Added: openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/JtaConfig.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/JtaConfig.java?rev=1775607&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/JtaConfig.java
(added)
+++ openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/JtaConfig.java
Thu Dec 22 10:14:45 2016
@@ -0,0 +1,28 @@
+/*
+ * 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.meecrowave.jta;
+
+import org.apache.meecrowave.runner.cli.CliOption;
+
+public class JtaConfig {
+    @CliOption(name = "jta-handle-exception-only-for-client", description = "should JTA exception
only be managed by client")
+    boolean handleExceptionOnlyForClient;
+
+    public boolean isHandleExceptionOnlyForClient() {
+        return handleExceptionOnlyForClient;
+    }
+}

Modified: openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/JtaExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/JtaExtension.java?rev=1775607&r1=1775606&r2=1775607&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/JtaExtension.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-jta/src/main/java/org/apache/meecrowave/jta/JtaExtension.java
Thu Dec 22 10:14:45 2016
@@ -45,6 +45,7 @@ public class JtaExtension implements Ext
     private TransactionContext context;
     private boolean hasManager;
     private boolean hasRegistry;
+    private final JtaConfig config = new JtaConfig();
 
     void register(@Observes final BeforeBeanDiscovery beforeBeanDiscovery, final BeanManager
beanManager) {
         Stream.of(
@@ -63,7 +64,7 @@ public class JtaExtension implements Ext
         }
     }
 
-    void addContext(@Observes final AfterBeanDiscovery afterBeanDiscovery) {
+    void addContextAndBeans(@Observes final AfterBeanDiscovery afterBeanDiscovery, final
BeanManager bm) {
         context = new TransactionContext();
         afterBeanDiscovery.addContext(context);
 
@@ -77,11 +78,14 @@ public class JtaExtension implements Ext
             hasManager = true;
             hasRegistry = true;
         }
+
+        afterBeanDiscovery.addBean(new JtaConfigBean(config));
     }
 
     void init(@Observes final AfterDeploymentValidation afterDeploymentValidation, final
BeanManager bm) {
         if (!hasRegistry && hasManager) {
             afterDeploymentValidation.addDeploymentProblem(new IllegalStateException("You
should produce a TransactionManager and TransactionSynchronizationRegistry"));
+            return;
         }
         final TransactionManager manager = TransactionManager.class.cast(
                 bm.getReference(bm.resolve(bm.getBeans(TransactionManager.class)), TransactionManager.class,
bm.createCreationalContext(null)));
@@ -90,6 +94,15 @@ public class JtaExtension implements Ext
                 TransactionSynchronizationRegistry.class.cast(bm.getReference(bm.resolve(bm.getBeans(TransactionSynchronizationRegistry.class)),
                         TransactionSynchronizationRegistry.class, bm.createCreationalContext(null)));
         context.init(manager, registry);
+
+        try {
+            final Class<?> builder = Thread.currentThread().getContextClassLoader().loadClass("org.apache.meecrowave.Meecrowave$Builder");
+            final JtaConfig ext = JtaConfig.class.cast(builder.getMethod("getExtension",
Class.class).invoke(
+                    bm.getReference(bm.resolve(bm.getBeans(builder)), builder, bm.createCreationalContext(null)),
JtaConfig.class));
+            config.handleExceptionOnlyForClient = ext.handleExceptionOnlyForClient;
+        } catch (final Exception e) {
+            config.handleExceptionOnlyForClient = Boolean.getBoolean("meecrowave.jta.handleExceptionOnlyForClient");
+        }
     }
 
     private static class JtaBean implements Bean<TransactionManager> {
@@ -126,6 +139,71 @@ public class JtaExtension implements Ext
             // no-op
         }
 
+        @Override
+        public Set<Type> getTypes() {
+            return types;
+        }
+
+        @Override
+        public Set<Annotation> getQualifiers() {
+            return qualifiers;
+        }
+
+        @Override
+        public Class<? extends Annotation> getScope() {
+            return ApplicationScoped.class;
+        }
+
+        @Override
+        public String getName() {
+            return null;
+        }
+
+        @Override
+        public Set<Class<? extends Annotation>> getStereotypes() {
+            return Collections.emptySet();
+        }
+
+        @Override
+        public boolean isAlternative() {
+            return false;
+        }
+    }
+
+    private static class JtaConfigBean implements Bean<JtaConfig> {
+        private final JtaConfig config;
+        private final Set<Type> types = new HashSet<>(asList(JtaConfig.class,
Object.class));
+        private final Set<Annotation> qualifiers = new HashSet<>(asList(DefaultLiteral.INSTANCE,
AnyLiteral.INSTANCE));
+
+        private JtaConfigBean(final JtaConfig value) {
+            this.config = value;
+        }
+
+        @Override
+        public Set<InjectionPoint> getInjectionPoints() {
+            return Collections.emptySet();
+        }
+
+        @Override
+        public Class<?> getBeanClass() {
+            return JtaConfig.class;
+        }
+
+        @Override
+        public boolean isNullable() {
+            return false;
+        }
+
+        @Override
+        public JtaConfig create(final CreationalContext<JtaConfig> context) {
+            return config;
+        }
+
+        @Override
+        public void destroy(final JtaConfig instance, final CreationalContext<JtaConfig>
context) {
+            // no-op
+        }
+
         @Override
         public Set<Type> getTypes() {
             return types;



Mime
View raw message