You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2012/08/04 22:32:10 UTC

git commit: DELTASPIKE-250 cleanup

Updated Branches:
  refs/heads/master 0c4b0f784 -> b0f81e5db


DELTASPIKE-250 cleanup


Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/b0f81e5d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/b0f81e5d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/b0f81e5d

Branch: refs/heads/master
Commit: b0f81e5dbb0ace4a2fc17f1b66d005cf368de6df
Parents: 0c4b0f7
Author: gpetracek <gp...@apache.org>
Authored: Sat Aug 4 21:56:15 2012 +0200
Committer: gpetracek <gp...@apache.org>
Committed: Sat Aug 4 22:23:47 2012 +0200

----------------------------------------------------------------------
 .../EnvironmentAwareTransactionStrategy.java       |   49 ++++++-
 .../SimpleEnvironmentAwareTransactionStrategy.java |   98 ---------------
 2 files changed, 42 insertions(+), 105 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/b0f81e5d/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/EnvironmentAwareTransactionStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/EnvironmentAwareTransactionStrategy.java b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/EnvironmentAwareTransactionStrategy.java
index b4079ab..49fec33 100644
--- a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/EnvironmentAwareTransactionStrategy.java
+++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/EnvironmentAwareTransactionStrategy.java
@@ -26,24 +26,35 @@ import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.Alternative;
 import javax.inject.Inject;
 import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
 import java.lang.annotation.Annotation;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 /**
- * This alternative {@link org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy} uses auto-detection and
- * can be used if different environments (dev., prod.,...) should use different transaction-types.
+ * <p>This alternative {@link org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy} uses auto-detection and
+ * can be used for different (parallel) persistence-units which use different transaction-types or
+ * if different environments (dev., prod.,...) should use different transaction-types.</p>
  *
- * This implementation uses a different approach for the auto-detection which can be used for environments
- * (or producer-constellations) which allow a mixed usage of JTA and RESOURCE_LOCAL.
- * (Within a transactional call it isn't possible to mix different transaction-types.)
+ * <p>This implementation can be used for environments which allow a mixed usage of JTA and RESOURCE_LOCAL.
+ * (Within a transactional call it isn't possible to mix different transaction-types.)</p>
  *
- * @see SimpleEnvironmentAwareTransactionStrategy
+ * <p>Optional:<br/>
+ * E.g. in case of a project-stage based logic
+ * {@link org.apache.deltaspike.core.api.exclude.annotation.Exclude} can be used to switch between different
+ * producer-beans.</p>
+ *
+ * <p>It's a better alternative than extending
+ * {@link BeanManagedUserTransactionStrategy}
+ * (which would lead to an impl. dependency) only for using
+ * {@link org.apache.deltaspike.core.api.exclude.annotation.Exclude} at the custom
+ * {@link org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy}
+ * (or doing a custom veto-extension).</p>
  */
 @Dependent
 @Alternative
 @SuppressWarnings("UnusedDeclaration")
-public class EnvironmentAwareTransactionStrategy extends SimpleEnvironmentAwareTransactionStrategy
+public class EnvironmentAwareTransactionStrategy extends BeanManagedUserTransactionStrategy
 {
     private static final long serialVersionUID = -4432802805095533499L;
 
@@ -98,6 +109,30 @@ public class EnvironmentAwareTransactionStrategy extends SimpleEnvironmentAwareT
         return new JtaAwareEntityManagerEntry(entityManager, qualifier, isTransactionTypeJta);
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void beforeProceed(EntityManagerEntry entityManagerEntry)
+    {
+        //cast without check is valid, because the entry was created by this class - see #createEntityManagerEntry
+        if (((JtaAwareEntityManagerEntry)entityManagerEntry).isTransactionTypeJta())
+        {
+            super.beforeProceed(entityManagerEntry);
+        }
+    }
+
+    @Override
+    protected EntityTransaction getTransaction(EntityManagerEntry entityManagerEntry)
+    {
+        if (((JtaAwareEntityManagerEntry)entityManagerEntry).isTransactionTypeJta())
+        {
+            return super.getTransaction(entityManagerEntry);
+        }
+
+        return entityManagerEntry.getEntityManager().getTransaction();
+    }
+
     @Override
     protected void onCloseTransactionScope()
     {

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/b0f81e5d/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/SimpleEnvironmentAwareTransactionStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/SimpleEnvironmentAwareTransactionStrategy.java b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/SimpleEnvironmentAwareTransactionStrategy.java
deleted file mode 100644
index f691a7b..0000000
--- a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/SimpleEnvironmentAwareTransactionStrategy.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.deltaspike.jpa.impl.transaction;
-
-import org.apache.deltaspike.core.impl.util.JndiUtils;
-import org.apache.deltaspike.jpa.impl.transaction.context.EntityManagerEntry;
-import org.apache.deltaspike.jpa.impl.transaction.context.JtaAwareEntityManagerEntry;
-
-import javax.enterprise.context.Dependent;
-import javax.enterprise.inject.Alternative;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityTransaction;
-import javax.transaction.UserTransaction;
-import java.lang.annotation.Annotation;
-import java.util.logging.Logger;
-
-/**
- * This alternative {@link org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy} uses a simple auto-detection
- * based on a failed JNDI lookup (of java:comp/UserTransaction) and
- * can be used if different environments (dev., prod.,...) should use different transaction-types.
- * It requires additional logic in the producer for the {@link EntityManager} to create the {@link EntityManager}
- * for the correct persistence-unit. In case of a project-stage based logic
- * {@link org.apache.deltaspike.core.api.exclude.annotation.Exclude} can be used to switch between different
- * producer-beans.
- *
- * It's a better alternative than extending
- * {@link BeanManagedUserTransactionStrategy}
- * (which would lead to an impl. dependency) only for using
- * {@link org.apache.deltaspike.core.api.exclude.annotation.Exclude} at the custom
- * {@link org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy}
- * (or doing a custom veto-extension).
- */
-@Dependent
-@Alternative
-@SuppressWarnings("UnusedDeclaration")
-public class SimpleEnvironmentAwareTransactionStrategy extends BeanManagedUserTransactionStrategy
-{
-    private static final long serialVersionUID = -3432802805095533499L;
-
-    private static final Logger LOGGER =
-        Logger.getLogger(SimpleEnvironmentAwareTransactionStrategy.class.getName());
-
-    @Override
-    protected EntityManagerEntry createEntityManagerEntry(
-        EntityManager entityManager, Class<? extends Annotation> qualifier)
-    {
-        try
-        {
-            //just used for detecting the environment (e.g. servlet-container vs. application-server)
-            JndiUtils.lookup(USER_TRANSACTION_JNDI_NAME, UserTransaction.class);
-        }
-        catch (IllegalStateException e)
-        {
-            return new JtaAwareEntityManagerEntry(entityManager, qualifier, false);
-        }
-        return super.createEntityManagerEntry(entityManager, qualifier);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void beforeProceed(EntityManagerEntry entityManagerEntry)
-    {
-        //cast without check is valid, because the entry was created by this class - see #createEntityManagerEntry
-        if (((JtaAwareEntityManagerEntry)entityManagerEntry).isTransactionTypeJta())
-        {
-            super.beforeProceed(entityManagerEntry);
-        }
-    }
-
-    @Override
-    protected EntityTransaction getTransaction(EntityManagerEntry entityManagerEntry)
-    {
-        if (((JtaAwareEntityManagerEntry)entityManagerEntry).isTransactionTypeJta())
-        {
-            return super.getTransaction(entityManagerEntry);
-        }
-
-        return entityManagerEntry.getEntityManager().getTransaction();
-    }
-}