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 java.util.Map;
019
020import org.eclipse.persistence.config.PersistenceUnitProperties;
021import org.kuali.rice.krad.data.jpa.KradEntityManagerFactoryBean;
022import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter;
023
024/**
025 * A KRAD-managed {@link javax.persistence.EntityManagerFactory} factory bean which can be used to configure an
026 * EclipseLink persistence unit using JPA.
027 *
028 * <p>This class inherits the behavior from {@link KradEntityManagerFactoryBean} but adds the following:</p>
029 *
030 * <ul>
031 *     <li>Sets the {@link org.springframework.orm.jpa.JpaVendorAdapter} to {@link EclipseLinkJpaVendorAdapter}</li>
032 *     <li>Detects if JTA is being used and, if so sets a JPA property value for
033 *         {@link PersistenceUnitProperties#TARGET_SERVER} to {@link JtaTransactionController} which allows for
034 *         EclipseLink integration with JTA.</li>
035 *     <li>Configures an EclipseLink "customizer" which allows for a configurable sequence management strategy</li>
036 *     <li>Disables the shared cache (defined by {@link PersistenceUnitProperties#CACHE_SHARED_DEFAULT} by default</li>
037 * </ul>
038 *
039 * @author Kuali Rice Team (rice.collab@kuali.org)
040 */
041public class KradEclipseLinkEntityManagerFactoryBean extends KradEntityManagerFactoryBean {
042
043    /**
044     * Creates a KRAD-managed {@link javax.persistence.EntityManagerFactory} factory bean.
045     */
046    public KradEclipseLinkEntityManagerFactoryBean() {
047        super.setJpaVendorAdapter(new EclipseLinkJpaVendorAdapter());
048    }
049
050    /**
051     * {@inheritDoc}
052     */
053    @Override
054    protected void loadCustomJpaDefaults(Map<String, String> jpaProperties) {
055                if (getPersistenceUnitManager().getDefaultJtaDataSource() != null
056                                && !jpaProperties.containsKey(PersistenceUnitProperties.TARGET_SERVER)) {
057            jpaProperties.put(PersistenceUnitProperties.TARGET_SERVER, JtaTransactionController.class.getName());
058        }
059
060                if (!jpaProperties.containsKey(PersistenceUnitProperties.SESSION_CUSTOMIZER)) {
061                        jpaProperties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, KradEclipseLinkCustomizer.class.getName());
062                }
063
064                if (!jpaProperties.containsKey(PersistenceUnitProperties.CACHE_SHARED_DEFAULT)) {
065                        jpaProperties.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT, "false");
066                }
067    }
068
069}