View Javadoc

1   /**
2    * Copyright 2005-2013 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.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   * @author Kuali Rice Team (rice.collab@kuali.org)
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  }