01: /**
02: * EasyBeans
03: * Copyright (C) 2006 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: EasyBeansManagedRuntime.java 1970 2007-10-16 11:49:25Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.persistence.openjpa;
25:
26: import javax.naming.InitialContext;
27: import javax.transaction.TransactionManager;
28:
29: import org.apache.openjpa.ee.AbstractManagedRuntime;
30: import org.apache.openjpa.ee.ManagedRuntime;
31:
32: /**
33: * This class manages the specific features required for OpenJPA : the link to
34: * the Transaction manager.
35: * @author Florent Benoit
36: */
37: public class EasyBeansManagedRuntime extends AbstractManagedRuntime
38: implements ManagedRuntime {
39:
40: /**
41: * JOTM binding in registry.
42: */
43: private static final String JOTM_BINDING = "javax.transaction.UserTransaction";
44:
45: /**
46: * @return the TransactionManager for the managed runtime. This manager is
47: * used to register synchronization listeners, to map transactional
48: * PersistenceManagers to the current transaction, and possibly to
49: * enlist XA resources.
50: * @throws Exception if the transactionManager cannot be found.
51: */
52: public TransactionManager getTransactionManager() throws Exception {
53: return (TransactionManager) new InitialContext()
54: .lookup(JOTM_BINDING);
55: }
56:
57: /**
58: * Returns the Throwable that caused the current transaction to be marked
59: * for rollback, provided that any exists.
60: * @return the Throwable cause, or null if none
61: * @throws Exception if problems
62: */
63: public Throwable getRollbackCause() throws Exception {
64: return null;
65: }
66:
67: /**
68: * Sets the rollback only flag on the current transaction. If the
69: * TransactionManager is capable of tracking the cause of the rollback-only
70: * flag, it will also pass along cause information.
71: * @param cause the Throwable that caused the transaction to be marked for
72: * rollback, or null of none is known
73: * @throws Exception if the transactionManager cannot be found.
74: */
75: public void setRollbackOnly(final Throwable cause) throws Exception {
76: getTransactionManager().getTransaction().setRollbackOnly();
77: }
78:
79: }
|