aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1695851 - /aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/EMFTracker.java
Date Fri, 14 Aug 2015 09:31:58 GMT
Author: cschneider
Date: Fri Aug 14 09:31:58 2015
New Revision: 1695851

URL: http://svn.apache.org/r1695851
Log:
Safeguard if getProperties fails

Modified:
    aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/EMFTracker.java

Modified: aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/EMFTracker.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/EMFTracker.java?rev=1695851&r1=1695850&r2=1695851&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/EMFTracker.java
(original)
+++ aries/trunk/jpa/jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/EMFTracker.java
Fri Aug 14 09:31:58 2015
@@ -37,6 +37,8 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.coordinator.Coordinator;
 import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Tracks EntityManagerFactory services and publishes a Supplier<EntityManager> for
each.
@@ -45,6 +47,7 @@ import org.osgi.util.tracker.ServiceTrac
  */
 @SuppressWarnings("rawtypes")
 public class EMFTracker extends ServiceTracker {
+    private static Logger LOG = LoggerFactory.getLogger(EMFTracker.class);
 
     private Coordinator coordinator;
 
@@ -89,13 +92,15 @@ public class EMFTracker extends ServiceT
      * @return
      */
     private PersistenceUnitTransactionType getTransactionType(EntityManagerFactory emf) {
-        PersistenceUnitTransactionType transactionType = (PersistenceUnitTransactionType)
emf.getProperties()
-        		.get(PersistenceUnitTransactionType.class.getName());
-        if(transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL) {
-        	return PersistenceUnitTransactionType.RESOURCE_LOCAL;
-        } else {
-        	return PersistenceUnitTransactionType.JTA;
+        try {
+            PersistenceUnitTransactionType transactionType = (PersistenceUnitTransactionType)
emf.getProperties().get(PersistenceUnitTransactionType.class.getName());
+            if (transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL) {
+                return PersistenceUnitTransactionType.RESOURCE_LOCAL;
+            }
+        } catch (Exception e) {
+            LOG.warn("Error while determining the transaction type. Falling back to JTA.",
e);
         }
+        return PersistenceUnitTransactionType.JTA;
     }
 
     private Dictionary<String, String> getEmSupplierProps(String unitName) {



Mime
View raw message