mirror of
https://gitee.com/jmix/cuba.git
synced 2024-11-30 18:27:56 +08:00
- Entities moved to separate jar
- System properties to point to persistence.xml
This commit is contained in:
parent
2fac72e270
commit
e71cd19f39
@ -7,6 +7,7 @@
|
||||
|
||||
<property name="module.name" value="core"/>
|
||||
<property name="module.jar" value="20-cuba-core.jar"/>
|
||||
<property name="module.intf.jar" value="cuba-core-intf.jar"/>
|
||||
|
||||
<import file="${root.dir}/build-inc.xml"/>
|
||||
<property file="${root.dir}/build.properties"/>
|
||||
@ -24,7 +25,9 @@
|
||||
<path id="test-compile-cp">
|
||||
<fileset refid="common-lib-fs"/>
|
||||
<fileset refid="server-lib-fs"/>
|
||||
<fileset refid="test-lib-fs"/>
|
||||
<!--<fileset refid="chile-jars"/>-->
|
||||
<pathelement location="${prod.out.dir}/${module.name}"/>
|
||||
</path>
|
||||
|
||||
<path id="enhance-cp">
|
||||
@ -43,4 +46,23 @@
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="build-module" depends="compile-module">
|
||||
<echo>==> building ${project.dir} ${module.name}</echo>
|
||||
<mkdir dir="${build.dir}"/>
|
||||
<jar basedir="${prod.out.dir}/${module.name}" destfile="${build.dir}/${module.jar}">
|
||||
<exclude name="**/entity/*"/>
|
||||
</jar>
|
||||
<jar basedir="${prod.out.dir}/${module.name}" destfile="${build.dir}/${module.intf.jar}">
|
||||
<include name="**/entity/*"/>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="deploy-module" depends="base.deploy-module">
|
||||
<copy file="${build.dir}/${module.intf.jar}" todir="${jboss.dir}/server/default/deploy"/>
|
||||
</target>
|
||||
|
||||
<target name="undeploy-module" depends="base.undeploy-module">
|
||||
<delete file="${jboss.dir}/server/default/deploy/${module.intf.jar}"/>
|
||||
</target>
|
||||
|
||||
</project>
|
16
modules/core/src/com/haulmont/cuba/core/CubaProperties.java
Normal file
16
modules/core/src/com/haulmont/cuba/core/CubaProperties.java
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Konstantin Krivopustov
|
||||
* Created: 05.11.2008 17:35:03
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.core;
|
||||
|
||||
public class CubaProperties
|
||||
{
|
||||
public static final String PERSISTENCE_XML = "cuba.PersistenceXml";
|
||||
public static final String PERSISTENCE_UNIT = "cuba.PersistenceUnit";
|
||||
}
|
@ -9,6 +9,8 @@
|
||||
*/
|
||||
package com.haulmont.cuba.core;
|
||||
|
||||
import com.haulmont.cuba.core.entity.BaseEntity;
|
||||
|
||||
public interface EntityManagerAdapter
|
||||
{
|
||||
void persist(BaseEntity entity);
|
||||
|
@ -7,7 +7,7 @@
|
||||
* Created: 31.10.2008 16:51:51
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.core;
|
||||
package com.haulmont.cuba.core.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -9,7 +9,7 @@
|
||||
*/
|
||||
package com.haulmont.cuba.core.entity;
|
||||
|
||||
import com.haulmont.cuba.core.BaseEntity;
|
||||
import com.haulmont.cuba.core.entity.BaseEntity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
@ -11,7 +11,7 @@ package com.haulmont.cuba.core.impl;
|
||||
|
||||
import org.apache.openjpa.persistence.OpenJPAEntityManager;
|
||||
import com.haulmont.cuba.core.EntityManagerAdapter;
|
||||
import com.haulmont.cuba.core.BaseEntity;
|
||||
import com.haulmont.cuba.core.entity.BaseEntity;
|
||||
|
||||
public class EntityManagerAdapterImpl implements EntityManagerAdapter
|
||||
{
|
||||
|
@ -11,6 +11,7 @@ package com.haulmont.cuba.core.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
|
||||
import org.apache.openjpa.persistence.OpenJPAPersistence;
|
||||
|
||||
@ -25,6 +26,7 @@ import com.haulmont.cuba.core.impl.EntityManagerFactoryAdapterImpl;
|
||||
import com.haulmont.cuba.core.PersistenceProvider;
|
||||
import com.haulmont.cuba.core.EntityManagerFactoryAdapter;
|
||||
import com.haulmont.cuba.core.EntityManagerAdapter;
|
||||
import com.haulmont.cuba.core.CubaProperties;
|
||||
|
||||
public class ManagedPersistenceProvider implements PersistenceProvider
|
||||
{
|
||||
@ -50,8 +52,18 @@ public class ManagedPersistenceProvider implements PersistenceProvider
|
||||
synchronized (mutex) {
|
||||
if (!emfInitialized) {
|
||||
log.debug("Creating new EntityManagerFactory");
|
||||
|
||||
String xmlPath = System.getProperty(CubaProperties.PERSISTENCE_XML);
|
||||
if (StringUtils.isBlank(xmlPath))
|
||||
xmlPath = "META-INF/cuba-persistence.xml";
|
||||
String unitName = System.getProperty(CubaProperties.PERSISTENCE_UNIT);
|
||||
if (StringUtils.isBlank(unitName))
|
||||
unitName = "cuba";
|
||||
log.debug(String.format("Using persistence unit %s from %s", unitName, xmlPath));
|
||||
|
||||
OpenJPAEntityManagerFactory jpaFactory =
|
||||
OpenJPAPersistence.createEntityManagerFactory("cuba", "META-INF/cuba-persistence.xml");
|
||||
OpenJPAPersistence.createEntityManagerFactory(unitName, xmlPath);
|
||||
|
||||
EntityManagerFactoryAdapter emf = new EntityManagerFactoryAdapterImpl(jpaFactory);
|
||||
try {
|
||||
log.debug("Binding new EntityManagerFactory to JNDI context " + EMF_JNDI_NAME);
|
||||
|
Loading…
Reference in New Issue
Block a user