diff --git a/modules/core/build.xml b/modules/core/build.xml index af8211fd74..b86f9f6f52 100644 --- a/modules/core/build.xml +++ b/modules/core/build.xml @@ -7,6 +7,7 @@ + @@ -24,7 +25,9 @@ + + @@ -43,4 +46,23 @@ + + ==> building ${project.dir} ${module.name} + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/core/test/META-INF/cuba-persistence.xml b/modules/core/src/META-INF/cuba-persistence.xml similarity index 100% rename from modules/core/test/META-INF/cuba-persistence.xml rename to modules/core/src/META-INF/cuba-persistence.xml diff --git a/modules/core/src/com/haulmont/cuba/core/CubaProperties.java b/modules/core/src/com/haulmont/cuba/core/CubaProperties.java new file mode 100644 index 0000000000..bfc2b07318 --- /dev/null +++ b/modules/core/src/com/haulmont/cuba/core/CubaProperties.java @@ -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"; +} diff --git a/modules/core/src/com/haulmont/cuba/core/EntityManagerAdapter.java b/modules/core/src/com/haulmont/cuba/core/EntityManagerAdapter.java index 1898c812a9..e438577714 100644 --- a/modules/core/src/com/haulmont/cuba/core/EntityManagerAdapter.java +++ b/modules/core/src/com/haulmont/cuba/core/EntityManagerAdapter.java @@ -9,6 +9,8 @@ */ package com.haulmont.cuba.core; +import com.haulmont.cuba.core.entity.BaseEntity; + public interface EntityManagerAdapter { void persist(BaseEntity entity); diff --git a/modules/core/src/com/haulmont/cuba/core/BaseEntity.java b/modules/core/src/com/haulmont/cuba/core/entity/BaseEntity.java similarity index 85% rename from modules/core/src/com/haulmont/cuba/core/BaseEntity.java rename to modules/core/src/com/haulmont/cuba/core/entity/BaseEntity.java index dbd09044cf..7816eb3546 100644 --- a/modules/core/src/com/haulmont/cuba/core/BaseEntity.java +++ b/modules/core/src/com/haulmont/cuba/core/entity/BaseEntity.java @@ -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; diff --git a/modules/core/src/com/haulmont/cuba/core/entity/Server.java b/modules/core/src/com/haulmont/cuba/core/entity/Server.java index 667d63456e..623e478619 100644 --- a/modules/core/src/com/haulmont/cuba/core/entity/Server.java +++ b/modules/core/src/com/haulmont/cuba/core/entity/Server.java @@ -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; diff --git a/modules/core/src/com/haulmont/cuba/core/impl/EntityManagerAdapterImpl.java b/modules/core/src/com/haulmont/cuba/core/impl/EntityManagerAdapterImpl.java index 5edb7c6f60..c57c682b9a 100644 --- a/modules/core/src/com/haulmont/cuba/core/impl/EntityManagerAdapterImpl.java +++ b/modules/core/src/com/haulmont/cuba/core/impl/EntityManagerAdapterImpl.java @@ -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 { diff --git a/modules/core/src/com/haulmont/cuba/core/impl/ManagedPersistenceProvider.java b/modules/core/src/com/haulmont/cuba/core/impl/ManagedPersistenceProvider.java index 2d83957221..0dcb0464ad 100644 --- a/modules/core/src/com/haulmont/cuba/core/impl/ManagedPersistenceProvider.java +++ b/modules/core/src/com/haulmont/cuba/core/impl/ManagedPersistenceProvider.java @@ -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);