001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.data.jpa.eclipselink; 017 018import org.eclipse.persistence.transaction.JTATransactionController; 019import org.kuali.rice.core.framework.persistence.jta.Jta; 020 021import javax.transaction.TransactionManager; 022 023/** 024 * An implementation of EclipseLink's {@link org.eclipse.persistence.sessions.ExternalTransactionController} which will 025 * utilize the JTA TransactionManager being used by the KRAD application. 026 * 027 * <p> 028 * It locates this via a call to {@link org.kuali.rice.core.framework.persistence.jta.Jta#getTransactionManager()}. So 029 * the application must ensure that it has configured and setup JTA properly within it's application environment. 030 * </p> 031 * 032 * <p> 033 * The superclass for this class, which is part of EclipseLink, attempts to invoke the 034 * {@link #acquireTransactionManager()} from the default contructor. So an attempt will be made to acquire the JTA 035 * transaction manager as soon as an instance of this object is created. This means that it must be ensured that JPA is 036 * enabled prior to the creation of an instance of this controller class. 037 * </p> 038 * 039 * @author Kuali Rice Team (rice.collab@kuali.org) 040 */ 041public class JtaTransactionController extends JTATransactionController { 042 043 /** 044 * {@inheritDoc} 045 */ 046 @Override 047 protected TransactionManager acquireTransactionManager() throws Exception { 048 if (!Jta.isEnabled()) { 049 throw new IllegalStateException("Attempting to use EclipseLink with JTA, but JTA is not configured properly" 050 + "for this KRAD application!"); 051 } 052 return Jta.getTransactionManager(); 053 } 054 055}