forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow skipping of persistence.xml parsing
Fixes quarkusio#6805
- Loading branch information
Showing
2 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,7 +128,7 @@ | |
* @author Sanne Grinovero <[email protected]> | ||
*/ | ||
public final class HibernateOrmProcessor { | ||
|
||
public static final String SKIP_PARSE_PERSISTENCE_XML = "SKIP_PARSE_PERSISTENCE_XML"; | ||
public static final String HIBERNATE_ORM_CONFIG_PREFIX = "quarkus.hibernate-orm."; | ||
public static final String NO_SQL_LOAD_SCRIPT_FILE = "no-file"; | ||
|
||
|
@@ -176,9 +176,11 @@ List<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles(LaunchModeBuil | |
@BuildStep | ||
public void parsePersistenceXmlDescriptors( | ||
BuildProducer<PersistenceXmlDescriptorBuildItem> persistenceXmlDescriptorBuildItemBuildProducer) { | ||
List<ParsedPersistenceXmlDescriptor> explicitDescriptors = QuarkusPersistenceXmlParser.locatePersistenceUnits(); | ||
for (ParsedPersistenceXmlDescriptor desc : explicitDescriptors) { | ||
persistenceXmlDescriptorBuildItemBuildProducer.produce(new PersistenceXmlDescriptorBuildItem(desc)); | ||
if (!"true".equals(System.getProperty(SKIP_PARSE_PERSISTENCE_XML, "false"))) { | ||
List<ParsedPersistenceXmlDescriptor> explicitDescriptors = QuarkusPersistenceXmlParser.locatePersistenceUnits(); | ||
for (ParsedPersistenceXmlDescriptor desc : explicitDescriptors) { | ||
persistenceXmlDescriptorBuildItemBuildProducer.produce(new PersistenceXmlDescriptorBuildItem(desc)); | ||
} | ||
} | ||
} | ||
|
||
|
51 changes: 51 additions & 0 deletions
51
...rm/deployment/src/test/java/io/quarkus/hibernate/orm/ExcludePersistenceXmlConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.quarkus.hibernate.orm; | ||
|
||
import javax.enterprise.inject.Instance; | ||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
|
||
import io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.hibernate.orm.enhancer.Address; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ExcludePersistenceXmlConfigTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest(). | ||
setBeforeAllCustomizer(() -> System.setProperty(HibernateOrmProcessor.SKIP_PARSE_PERSISTENCE_XML, "true")). | ||
setAfterAllCustomizer(() -> System.getProperties().remove(HibernateOrmProcessor.SKIP_PARSE_PERSISTENCE_XML)). | ||
setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(Address.class) | ||
.addAsManifestResource("META-INF/some-persistence.xml", "persistence.xml") | ||
.addAsResource("application.properties")); | ||
|
||
@Inject | ||
EntityManager entityManager; | ||
|
||
@Inject | ||
Instance<EntityManager> entityManagers; | ||
|
||
@Test | ||
public void testPersistenceAndConfigTest() { | ||
// We have an entity manager | ||
Assertions.assertNotNull(entityManager); | ||
// We have exactly one entity manager | ||
Assertions.assertEquals(false, entityManagers.isAmbiguous()); | ||
Arc.container().requestContext().activate(); | ||
try { | ||
// it is the default entity manager from application.properties, not templatePU from the persistence.xml | ||
Assertions.assertEquals("default", | ||
entityManager.getEntityManagerFactory().getProperties().get("hibernate.ejb.persistenceUnitName")); | ||
} finally { | ||
Arc.container().requestContext().deactivate(); | ||
} | ||
} | ||
|
||
} |