1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.app.persistence.jpa;
17
18 import org.kuali.rice.core.framework.persistence.jpa.NullEntityManagerFactory;
19 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
20 import org.springframework.beans.factory.FactoryBean;
21 import org.springframework.beans.factory.InitializingBean;
22
23 import javax.persistence.EntityManagerFactory;
24 import javax.sql.DataSource;
25
26
27
28
29 public class RiceEntityManagerProxyFactoryBean implements FactoryBean, InitializingBean {
30
31 private RiceLocalContainerEntityManagerFactoryBean factoryBean;
32 private String prefix;
33 private DataSource datasource;
34 private String moduleJpaEnabledPropertyPrefix;
35
36 public RiceEntityManagerProxyFactoryBean(String prefix, DataSource datasource) {
37 this.prefix = prefix;
38 this.datasource = datasource;
39 this.moduleJpaEnabledPropertyPrefix = prefix;
40 }
41
42 public RiceEntityManagerProxyFactoryBean(String prefix, DataSource datasource, String moduleJpaEnabledPropertyPrefix) {
43 this.prefix = prefix;
44 this.datasource = datasource;
45 this.moduleJpaEnabledPropertyPrefix = moduleJpaEnabledPropertyPrefix;
46 }
47
48 public void afterPropertiesSet() throws Exception {
49 if (OrmUtils.isJpaEnabled(moduleJpaEnabledPropertyPrefix)) {
50 factoryBean = new RiceLocalContainerEntityManagerFactoryBean(prefix, datasource);
51 factoryBean.afterPropertiesSet();
52 }
53 }
54
55 public Class getObjectType() {
56 return (factoryBean != null ? factoryBean.getObjectType() : EntityManagerFactory.class);
57 }
58
59 public Object getObject() throws Exception {
60 return (factoryBean != null ? factoryBean.getObject() : new NullEntityManagerFactory());
61 }
62
63 public boolean isSingleton() {
64 return true;
65 }
66
67 }