Return-Path: X-Original-To: apmail-deltaspike-commits-archive@www.apache.org Delivered-To: apmail-deltaspike-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3596917229 for ; Thu, 3 Sep 2015 16:36:50 +0000 (UTC) Received: (qmail 94954 invoked by uid 500); 3 Sep 2015 16:36:50 -0000 Delivered-To: apmail-deltaspike-commits-archive@deltaspike.apache.org Received: (qmail 94924 invoked by uid 500); 3 Sep 2015 16:36:50 -0000 Mailing-List: contact commits-help@deltaspike.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltaspike.apache.org Delivered-To: mailing list commits@deltaspike.apache.org Received: (qmail 94915 invoked by uid 99); 3 Sep 2015 16:36:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Sep 2015 16:36:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EE399DFF70; Thu, 3 Sep 2015 16:36:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gpetracek@apache.org To: commits@deltaspike.apache.org Message-Id: <1abee24737614d75a0b9dffb6e3a1905@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: deltaspike git commit: DELTASPIKE-986 support for jta outside of ee-servers Date: Thu, 3 Sep 2015 16:36:49 +0000 (UTC) Repository: deltaspike Updated Branches: refs/heads/master 249f12de0 -> b61c4e4e1 DELTASPIKE-986 support for jta outside of ee-servers Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/b61c4e4e Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/b61c4e4e Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/b61c4e4e Branch: refs/heads/master Commit: b61c4e4e1da1bb38bc047865426a380deefe8e0b Parents: 249f12d Author: gpetracek Authored: Thu Sep 3 18:03:08 2015 +0200 Committer: gpetracek Committed: Thu Sep 3 18:36:19 2015 +0200 ---------------------------------------------------------------------- .../jpa/api/config/base/JpaBaseConfig.java | 38 +++++++++++++ .../BeanManagedUserTransactionStrategy.java | 3 +- .../ManagedUserTransactionResolver.java | 35 ++++++++++++ .../transaction/UserTransactionResolver.java | 56 +++++++++++++++----- .../META-INF/apache-deltaspike.properties | 19 +++++++ 5 files changed, 138 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b61c4e4e/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/api/config/base/JpaBaseConfig.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/api/config/base/JpaBaseConfig.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/api/config/base/JpaBaseConfig.java new file mode 100644 index 0000000..7ffaaaf --- /dev/null +++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/api/config/base/JpaBaseConfig.java @@ -0,0 +1,38 @@ +/* + * 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.config.base; + +import org.apache.deltaspike.core.api.config.ConfigResolver; +import org.apache.deltaspike.core.api.config.base.DeltaSpikeBaseConfig; + +public interface JpaBaseConfig extends DeltaSpikeBaseConfig +{ + interface UserTransaction + { + String JNDI_NAME = ConfigResolver.resolve("deltaspike.jpa.user-transaction.jndi-name") + .withCurrentProjectStage(true) + .withDefault("java:comp/UserTransaction") + .getValue(); + + Integer TIMEOUT_IN_SECONDS = ConfigResolver.resolve("deltaspike.jpa.user-transaction.timeout_in_seconds") + .as(Integer.class) + .withCurrentProjectStage(true) + .getValue(); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b61c4e4e/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 e5af662..baad16b 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 @@ -22,6 +22,7 @@ import org.apache.deltaspike.core.api.provider.BeanProvider; import org.apache.deltaspike.core.api.provider.DependentProvider; import org.apache.deltaspike.core.impl.util.JndiUtils; import org.apache.deltaspike.core.util.ExceptionUtils; +import org.apache.deltaspike.jpa.api.config.base.JpaBaseConfig; import org.apache.deltaspike.jpa.api.transaction.TransactionConfig; import org.apache.deltaspike.jpa.impl.transaction.context.EntityManagerEntry; @@ -130,7 +131,7 @@ public class BeanManagedUserTransactionStrategy extends ResourceLocalTransaction @Override public Integer getUserTransactionTimeoutInSeconds() { - return null; + return JpaBaseConfig.UserTransaction.TIMEOUT_IN_SECONDS; } }; } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b61c4e4e/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ManagedUserTransactionResolver.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ManagedUserTransactionResolver.java b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ManagedUserTransactionResolver.java new file mode 100644 index 0000000..d6657c0 --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ManagedUserTransactionResolver.java @@ -0,0 +1,35 @@ +/* + * 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 javax.annotation.Resource; +import javax.transaction.UserTransaction; + +//we need to keep it separated, +//because the injection of UserTransaction might fail with an exception (see DELTASPIKE-986) +public class ManagedUserTransactionResolver +{ + @Resource + private UserTransaction userTransaction; + + public UserTransaction resolveUserTransaction() + { + return userTransaction; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b61c4e4e/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/UserTransactionResolver.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/UserTransactionResolver.java b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/UserTransactionResolver.java index 92a734a..3760054 100644 --- a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/UserTransactionResolver.java +++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/UserTransactionResolver.java @@ -18,10 +18,14 @@ */ package org.apache.deltaspike.jpa.impl.transaction; +import org.apache.deltaspike.core.api.provider.BeanProvider; +import org.apache.deltaspike.core.api.provider.DependentProvider; import org.apache.deltaspike.core.impl.util.JndiUtils; +import org.apache.deltaspike.jpa.api.config.base.JpaBaseConfig; -import javax.annotation.Resource; import javax.enterprise.context.Dependent; +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; import javax.transaction.UserTransaction; import java.io.Serializable; @@ -30,28 +34,56 @@ import java.io.Serializable; @Dependent public class UserTransactionResolver implements Serializable { - protected static final String USER_TRANSACTION_JNDI_NAME = "java:comp/UserTransaction"; - private static final long serialVersionUID = -1432802805095533499L; - @Resource - private UserTransaction userTransaction; + @Inject + private BeanManager beanManager; public UserTransaction resolveUserTransaction() { - if (userTransaction != null) + UserTransaction userTransaction; + + try { - return userTransaction; + DependentProvider provider = + BeanProvider.getDependent(this.beanManager, ManagedUserTransactionResolver.class); + + userTransaction = provider.get().resolveUserTransaction(); + + provider.destroy(); + } + catch (Throwable t) + { + //it was just a try + userTransaction = null; } - try + if (userTransaction != null) { - return JndiUtils.lookup(USER_TRANSACTION_JNDI_NAME, UserTransaction.class); + return userTransaction; } - catch (Exception e) + + String jndiName = JpaBaseConfig.UserTransaction.JNDI_NAME; + + String[] jndiNames = jndiName.split(","); + + for (String currentJndiName : jndiNames) { - // do nothing it was just a try - return null; + try + { + userTransaction = JndiUtils.lookup(currentJndiName, UserTransaction.class); + + if (userTransaction != null) + { + break; + } + } + catch (Exception e) + { + userTransaction = null; + } } + + return userTransaction; } } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b61c4e4e/deltaspike/modules/jpa/impl/src/main/resources/META-INF/apache-deltaspike.properties ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/main/resources/META-INF/apache-deltaspike.properties b/deltaspike/modules/jpa/impl/src/main/resources/META-INF/apache-deltaspike.properties new file mode 100644 index 0000000..e9d3afe --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/main/resources/META-INF/apache-deltaspike.properties @@ -0,0 +1,19 @@ +# 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. + +deltaspike_ordinal=50 +deltaspike.jpa.user-transaction.jndi-name=java:comp/UserTransaction,java:/jboss/UserTransaction