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.
Add build-time configuration property quarkus.hibernate-envers.enabled
- Loading branch information
Showing
7 changed files
with
162 additions
and
18 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...in/java/io/quarkus/hibernate/envers/deployment/HibernateEnversAlwaysEnabledProcessor.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,23 @@ | ||
package io.quarkus.hibernate.envers.deployment; | ||
|
||
import io.quarkus.deployment.Feature; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
import io.quarkus.deployment.logging.LogCleanupFilterBuildItem; | ||
|
||
// Executed even if the extension is disabled, see https://github.com/quarkusio/quarkus/pull/26966/ | ||
public final class HibernateEnversAlwaysEnabledProcessor { | ||
|
||
@BuildStep | ||
FeatureBuildItem feature() { | ||
return new FeatureBuildItem(Feature.HIBERNATE_ENVERS); | ||
} | ||
|
||
@BuildStep | ||
void setupLogFilters(BuildProducer<LogCleanupFilterBuildItem> filters) { | ||
filters.produce(new LogCleanupFilterBuildItem("org.hibernate.envers.boot.internal.EnversServiceImpl", | ||
"Envers integration enabled")); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...rc/main/java/io/quarkus/hibernate/envers/deployment/HibernateEnversDisabledProcessor.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,31 @@ | ||
package io.quarkus.hibernate.envers.deployment; | ||
|
||
import java.util.List; | ||
|
||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.BuildSteps; | ||
import io.quarkus.deployment.annotations.ExecutionTime; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.hibernate.envers.HibernateEnversRecorder; | ||
import io.quarkus.hibernate.orm.deployment.PersistenceUnitDescriptorBuildItem; | ||
import io.quarkus.hibernate.orm.deployment.integration.HibernateOrmIntegrationStaticConfiguredBuildItem; | ||
|
||
@BuildSteps(onlyIfNot = HibernateEnversEnabled.class) | ||
public final class HibernateEnversDisabledProcessor { | ||
|
||
@BuildStep | ||
@Record(ExecutionTime.STATIC_INIT) | ||
public void disableHibernateEnvers(HibernateEnversRecorder recorder, | ||
List<PersistenceUnitDescriptorBuildItem> persistenceUnitDescriptorBuildItems, | ||
BuildProducer<HibernateOrmIntegrationStaticConfiguredBuildItem> integrationProducer) { | ||
for (PersistenceUnitDescriptorBuildItem puDescriptor : persistenceUnitDescriptorBuildItems) { | ||
integrationProducer.produce( | ||
new HibernateOrmIntegrationStaticConfiguredBuildItem(HibernateEnversProcessor.HIBERNATE_ENVERS, | ||
puDescriptor.getPersistenceUnitName()) | ||
.setInitListener(recorder.createStaticInitInactiveListener()) | ||
// We don't need XML mapping if Envers is disabled | ||
.setXmlMappingRequired(false)); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ployment/src/main/java/io/quarkus/hibernate/envers/deployment/HibernateEnversEnabled.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,24 @@ | ||
package io.quarkus.hibernate.envers.deployment; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
import io.quarkus.hibernate.envers.HibernateEnversBuildTimeConfig; | ||
|
||
/** | ||
* Supplier that can be used to only run build steps | ||
* if the Hibernate Envers extension is enabled. | ||
*/ | ||
public class HibernateEnversEnabled implements BooleanSupplier { | ||
|
||
private final HibernateEnversBuildTimeConfig config; | ||
|
||
HibernateEnversEnabled(HibernateEnversBuildTimeConfig config) { | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public boolean getAsBoolean() { | ||
return config.enabled; | ||
} | ||
|
||
} |
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
43 changes: 43 additions & 0 deletions
43
...t/java/io/quarkus/hibernate/orm/envers/config/ConfigEnabledFalseAndAuditedEntityTest.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,43 @@ | ||
package io.quarkus.hibernate.orm.envers.config; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import javax.inject.Inject; | ||
import javax.persistence.metamodel.Bindable; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.envers.AuditReaderFactory; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.orm.envers.MyAuditedEntity; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ConfigEnabledFalseAndAuditedEntityTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClass(MyAuditedEntity.class)) | ||
.withConfigurationResource("application.properties") | ||
.overrideConfigKey("quarkus.hibernate-envers.enabled", "false"); | ||
|
||
@Inject | ||
SessionFactory sessionFactory; | ||
|
||
@Test | ||
@SuppressWarnings("rawtypes") | ||
public void test() { | ||
assertThat(sessionFactory.getMetamodel().getEntities()) | ||
.extracting(Bindable::getBindableJavaType) | ||
// In particular this should not contain the revision entity | ||
.containsExactly((Class) MyAuditedEntity.class); | ||
|
||
try (Session session = sessionFactory.openSession()) { | ||
assertThatThrownBy(() -> AuditReaderFactory.get(session).isEntityClassAudited(MyAuditedEntity.class)) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessageContaining("Service is not yet initialized"); | ||
} | ||
} | ||
} |
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
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