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 | 0 | public RiceEntityManagerProxyFactoryBean(String prefix, DataSource datasource) { |
37 | 0 | this.prefix = prefix; |
38 | 0 | this.datasource = datasource; |
39 | 0 | this.moduleJpaEnabledPropertyPrefix = prefix; |
40 | 0 | } |
41 | |
|
42 | 0 | public RiceEntityManagerProxyFactoryBean(String prefix, DataSource datasource, String moduleJpaEnabledPropertyPrefix) { |
43 | 0 | this.prefix = prefix; |
44 | 0 | this.datasource = datasource; |
45 | 0 | this.moduleJpaEnabledPropertyPrefix = moduleJpaEnabledPropertyPrefix; |
46 | 0 | } |
47 | |
|
48 | |
public void afterPropertiesSet() throws Exception { |
49 | 0 | if (OrmUtils.isJpaEnabled(moduleJpaEnabledPropertyPrefix)) { |
50 | 0 | factoryBean = new RiceLocalContainerEntityManagerFactoryBean(prefix, datasource); |
51 | 0 | factoryBean.afterPropertiesSet(); |
52 | |
} |
53 | 0 | } |
54 | |
|
55 | |
public Class getObjectType() { |
56 | 0 | return (factoryBean != null ? factoryBean.getObjectType() : EntityManagerFactory.class); |
57 | |
} |
58 | |
|
59 | |
public Object getObject() throws Exception { |
60 | 0 | return (factoryBean != null ? factoryBean.getObject() : new NullEntityManagerFactory()); |
61 | |
} |
62 | |
|
63 | |
public boolean isSingleton() { |
64 | 0 | return true; |
65 | |
} |
66 | |
|
67 | |
} |