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 java.util.Map;
19
20 import org.eclipse.persistence.config.PersistenceUnitProperties;
21 import org.kuali.rice.krad.data.jpa.KradEntityManagerFactoryBean;
22 import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter;
23
24 /**
25 * A KRAD-managed {@link javax.persistence.EntityManagerFactory} factory bean which can be used to configure an
26 * EclipseLink persistence unit using JPA.
27 *
28 * <p>This class inherits the behavior from {@link KradEntityManagerFactoryBean} but adds the following:</p>
29 *
30 * <ul>
31 * <li>Sets the {@link org.springframework.orm.jpa.JpaVendorAdapter} to {@link EclipseLinkJpaVendorAdapter}</li>
32 * <li>Detects if JTA is being used and, if so sets a JPA property value for
33 * {@link PersistenceUnitProperties#TARGET_SERVER} to {@link JtaTransactionController} which allows for
34 * EclipseLink integration with JTA.</li>
35 * <li>Configures an EclipseLink "customizer" which allows for a configurable sequence management strategy</li>
36 * <li>Disables the shared cache (defined by {@link PersistenceUnitProperties#CACHE_SHARED_DEFAULT} by default</li>
37 * </ul>
38 *
39 * @author Kuali Rice Team (rice.collab@kuali.org)
40 */
41 public class KradEclipseLinkEntityManagerFactoryBean extends KradEntityManagerFactoryBean {
42
43 /**
44 * Creates a KRAD-managed {@link javax.persistence.EntityManagerFactory} factory bean.
45 */
46 public KradEclipseLinkEntityManagerFactoryBean() {
47 super.setJpaVendorAdapter(new EclipseLinkJpaVendorAdapter());
48 }
49
50 /**
51 * {@inheritDoc}
52 */
53 @Override
54 protected void loadCustomJpaDefaults(Map<String, String> jpaProperties) {
55 if (getPersistenceUnitManager().getDefaultJtaDataSource() != null
56 && !jpaProperties.containsKey(PersistenceUnitProperties.TARGET_SERVER)) {
57 jpaProperties.put(PersistenceUnitProperties.TARGET_SERVER, JtaTransactionController.class.getName());
58 }
59
60 if (!jpaProperties.containsKey(PersistenceUnitProperties.SESSION_CUSTOMIZER)) {
61 jpaProperties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, KradEclipseLinkCustomizer.class.getName());
62 }
63
64 if (!jpaProperties.containsKey(PersistenceUnitProperties.CACHE_SHARED_DEFAULT)) {
65 jpaProperties.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT, "false");
66 }
67 }
68
69 }