deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-256 optional transaction config
Date Sat, 26 Oct 2013 14:16:22 GMT
Updated Branches:
  refs/heads/master c1c3fa353 -> e49b9d387


DELTASPIKE-256 optional transaction config


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

Branch: refs/heads/master
Commit: e49b9d387c0b868a986a288c9c661d1818b186b1
Parents: c1c3fa3
Author: gpetracek <gpetracek@apache.org>
Authored: Sat Oct 26 16:06:53 2013 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Sat Oct 26 16:08:44 2013 +0200

----------------------------------------------------------------------
 .../jpa/api/transaction/TransactionConfig.java  | 32 +++++++++++++++
 .../BeanManagedUserTransactionStrategy.java     | 41 +++++++++++++++++++-
 2 files changed, 71 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e49b9d38/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/api/transaction/TransactionConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/api/transaction/TransactionConfig.java
b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/api/transaction/TransactionConfig.java
new file mode 100644
index 0000000..5a0f888
--- /dev/null
+++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/api/transaction/TransactionConfig.java
@@ -0,0 +1,32 @@
+/*
+ * 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.api.transaction;
+
+import org.apache.deltaspike.core.api.config.DeltaSpikeConfig;
+
+/**
+ * Optional config for transactions
+ */
+public interface TransactionConfig extends DeltaSpikeConfig
+{
+    /**
+     * @return timeout in seconds or null
+     */
+    Integer getUserTransactionTimeoutInSeconds();
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e49b9d38/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/BeanManagedUserTransactionStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/BeanManagedUserTransactionStrategy.java
b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/BeanManagedUserTransactionStrategy.java
index b814c7f..f08087a 100644
--- a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/BeanManagedUserTransactionStrategy.java
+++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/BeanManagedUserTransactionStrategy.java
@@ -18,8 +18,10 @@
  */
 package org.apache.deltaspike.jpa.impl.transaction;
 
+import org.apache.deltaspike.core.api.provider.BeanProvider;
 import org.apache.deltaspike.core.impl.util.JndiUtils;
 import org.apache.deltaspike.core.util.ExceptionUtils;
+import org.apache.deltaspike.jpa.api.transaction.TransactionConfig;
 import org.apache.deltaspike.jpa.impl.transaction.context.EntityManagerEntry;
 
 import javax.enterprise.context.Dependent;
@@ -51,6 +53,8 @@ public class BeanManagedUserTransactionStrategy extends ResourceLocalTransaction
 
     private static final Logger LOGGER = Logger.getLogger(BeanManagedUserTransactionStrategy.class.getName());
 
+    private transient TransactionConfig transactionConfig;
+
     @Override
     protected EntityManagerEntry createEntityManagerEntry(
         EntityManager entityManager, Class<? extends Annotation> qualifier)
@@ -82,8 +86,41 @@ public class BeanManagedUserTransactionStrategy extends ResourceLocalTransaction
 
     protected Integer getDefaultTransactionTimeoutInSeconds()
     {
-        //override it and provide a custom value - if needed - TODO discuss a type-safe module-config
for DELTASPIKE-256
-        return null;
+        if (this.transactionConfig == null)
+        {
+            lazyInit();
+        }
+
+        return transactionConfig.getUserTransactionTimeoutInSeconds();
+    }
+
+    protected synchronized void lazyInit()
+    {
+        if (this.transactionConfig != null)
+        {
+            return;
+        }
+
+        this.transactionConfig = BeanProvider.getContextualReference(TransactionConfig.class,
true);
+
+        if (this.transactionConfig == null)
+        {
+            this.transactionConfig = createDefaultTransactionConfig();
+        }
+    }
+
+    protected TransactionConfig createDefaultTransactionConfig()
+    {
+        return new TransactionConfig()
+        {
+            private static final long serialVersionUID = -3915439087580270117L;
+
+            @Override
+            public Integer getUserTransactionTimeoutInSeconds()
+            {
+                return null;
+            }
+        };
     }
 
     @Override


Mime
View raw message