View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.data.jpa.eclipselink;
17  
18  import org.eclipse.persistence.transaction.JTATransactionController;
19  import org.kuali.rice.core.framework.persistence.jta.Jta;
20  
21  import javax.transaction.TransactionManager;
22  
23  /**
24   * An implementation of EclipseLink's {@link org.eclipse.persistence.sessions.ExternalTransactionController} which will
25   * utilize the JTA TransactionManager being used by the KRAD application.
26   *
27   * <p>
28   * It locates this via a call to {@link org.kuali.rice.core.framework.persistence.jta.Jta#getTransactionManager()}.  So
29   * the application must ensure that it has configured and setup JTA properly within it's application environment.
30   * </p>
31   *
32   * <p>
33   * The superclass for this class, which is part of EclipseLink, attempts to invoke the
34   * {@link #acquireTransactionManager()} from the default contructor. So an attempt will be made to acquire the JTA
35   * transaction manager as soon as an instance of this object is created. This means that it must be ensured that JPA is
36   * enabled prior to the creation of an instance of this controller class.
37   * </p>
38   *
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   */
41  public class JtaTransactionController extends JTATransactionController {
42  
43      /**
44       * {@inheritDoc}
45       */
46      @Override
47      protected TransactionManager acquireTransactionManager() throws Exception {
48          if (!Jta.isEnabled()) {
49              throw new IllegalStateException("Attempting to use EclipseLink with JTA, but JTA is not configured properly"
50                      + "for this KRAD application!");
51          }
52          return Jta.getTransactionManager();
53      }
54  
55  }