Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support all hibernate-envers configuration options #21872

Merged
merged 2 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ List<AdditionalJpaModelBuildItem> addJpaModelClasses() {
}

@BuildStep
public void registerEnversReflections(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
public void registerEnversReflections(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
HibernateEnversBuildTimeConfig buildTimeConfig) {
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, "org.hibernate.envers.DefaultRevisionEntity"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false,
"org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity"));
reflectiveClass
.produce(new ReflectiveClassBuildItem(false, false, "org.hibernate.tuple.entity.DynamicMapEntityTuplizer"));
reflectiveClass.produce(
new ReflectiveClassBuildItem(false, false, "org.hibernate.tuple.component.DynamicMapComponentTuplizer"));

buildTimeConfig.revisionListener.ifPresent(s -> reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, s)));
buildTimeConfig.auditStrategy.ifPresent(s -> reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, s)));
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.quarkus.hibernate.orm.envers;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;

import org.hibernate.envers.boot.internal.EnversService;
import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration;
import org.hibernate.envers.configuration.internal.GlobalConfiguration;
import org.hibernate.envers.strategy.AuditStrategy;
import org.hibernate.internal.SessionImpl;
import org.hibernate.persister.entity.EntityPersister;

public abstract class AbstractEnversResource {
@Inject
public EntityManager em;

@Inject
public UserTransaction transaction;

public String getDefaultAuditEntityName(Class<?> clazz) {
return clazz.getName() + "_AUD";
}

public EntityPersister getEntityPersister(String entityName) {
return ((SessionImpl) em.getDelegate()).getSessionFactory().getMetamodel().entityPersister(entityName);
}

public AuditEntitiesConfiguration getAuditEntitiesConfiguration() {
return getEnversService().getAuditEntitiesConfiguration();
}

public GlobalConfiguration getGlobalConfiguration() {
return getEnversService().getGlobalConfiguration();
}

public AuditStrategy getAuditStrategy() {
return getEnversService().getAuditStrategy();
}

public EnversService getEnversService() {
return ((((SessionImpl) em.getDelegate()).getFactory().getServiceRegistry())
.getParentServiceRegistry())
.getService(EnversService.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.quarkus.hibernate.orm.envers;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Version;

import org.hibernate.envers.Audited;

@Entity
@Audited
public class MyAuditedVersionEntity {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "myAuditedEntitySeq")
private long id;

private String name;

@Version
private long version;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public long getVersion() {
return version;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.quarkus.hibernate.orm.envers;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.envers.RevisionEntity;
import org.hibernate.envers.RevisionNumber;
import org.hibernate.envers.RevisionTimestamp;

@Entity
@RevisionEntity
public class MyListenerlessRevisionEntity {

@Id
@RevisionNumber
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "myRevisionEntitySeq")
private Long id;

@Temporal(TemporalType.TIMESTAMP)
@RevisionTimestamp
private Date revisionTimestamp;

private String listenerValue;

public Long getId() {
return id;
}

public Date getRevisionTimestamp() {
return revisionTimestamp;
}

public void setRevisionTimestamp(Date revisionTimestamp) {
this.revisionTimestamp = revisionTimestamp;
}

public String getListenerValue() {
return listenerValue;
}

public void setListenerValue(String listenerValue) {
this.listenerValue = listenerValue;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.quarkus.hibernate.orm.envers;

import org.hibernate.envers.RevisionListener;

public class MyListenerlessRevisionListener implements RevisionListener {

@Override
public void newRevision(Object revisionEntity) {
MyListenerlessRevisionEntity.class.cast(revisionEntity).setListenerValue(this.toString());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.hibernate.orm.envers.config;

import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.orm.envers.AbstractEnversResource;
import io.quarkus.hibernate.orm.envers.MyAuditedEntity;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class EnversAllowIdentifierReuseTestCase {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(MyAuditedEntity.class, EnversTestAllowIdentifierReuseResource.class,
AbstractEnversResource.class)
.addAsResource("application-with-allow-identifier-reuse.properties",
"application.properties"));

@Test
public void testValidityStrategyFieldNameOverrides() {
RestAssured.when().get("/envers-allow-identifier-reuse").then()
.body(is("OK"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.quarkus.hibernate.orm.envers.config;

import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.orm.envers.AbstractEnversResource;
import io.quarkus.hibernate.orm.envers.MyAuditedEntity;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class EnversAuditStrategyTestCase {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(MyAuditedEntity.class, EnversTestAuditStrategyResource.class, AbstractEnversResource.class)
.addAsResource("application-with-audit-strategy.properties", "application.properties"));

@Test
public void testAuditStrategy() {
RestAssured.when().get("/envers-audit-strategy").then()
.body(is("OK"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.hibernate.orm.envers.config;

import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.orm.envers.AbstractEnversResource;
import io.quarkus.hibernate.orm.envers.MyAuditedEntity;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class EnversDefaultSchemaCatalogTestCase {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(MyAuditedEntity.class, EnversTestDefaultSchemaCatalogResource.class,
AbstractEnversResource.class)
.addAsResource("application-with-default-schema-catalog.properties",
"application.properties"));

@Test
public void testDefaultSchemaAndCatalog() {
RestAssured.when().get("/envers-default-schema-catalog").then()
.body(is("OK"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.hibernate.orm.envers.config;

import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.orm.envers.AbstractEnversResource;
import io.quarkus.hibernate.orm.envers.MyAuditedVersionEntity;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class EnversDoNotAuditOptimisticLockingFieldTestCase {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(MyAuditedVersionEntity.class, EnversTestDoNotAuditOptimisticLockingFieldResource.class,
AbstractEnversResource.class)
.addAsResource("application-with-do-not-audit-optimistic-locking-field.properties",
"application.properties"));

@Test
public void testDoNotAuditOptimisticLockingFieldAsNonDefault() {
RestAssured.when().get("/envers-do-not-audit-optimistic-locking-field").then()
.body(is("OK"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.hibernate.orm.envers.config;

import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.orm.envers.AbstractEnversResource;
import io.quarkus.hibernate.orm.envers.MyAuditedEntity;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class EnversEmbeddableSetOrdinalFieldNameTestCase {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(MyAuditedEntity.class, EnversTestEmbeddableSetOrdinalFieldNameResource.class,
AbstractEnversResource.class)
.addAsResource("application-with-embeddable-set-ordinal-field-name.properties",
"application.properties"));

@Test
public void testDoNotAuditOptimisticLockingFieldAsNonDefault() {
RestAssured.when().get("/envers-embeddable-set-ordinal-field-name").then()
.body(is("OK"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.hibernate.orm.envers.config;

import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.orm.envers.AbstractEnversResource;
import io.quarkus.hibernate.orm.envers.MyAuditedEntity;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class EnversModifiedColumnNamingStrategyTestCase {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(MyAuditedEntity.class, EnversTestModifiedColumnNamingStrategyResource.class,
AbstractEnversResource.class)
.addAsResource("application-with-modified-column-naming-strategy.properties",
"application.properties"));

@Test
public void testModifiedColumnNamingStrategy() {
RestAssured.when().get("/envers-modified-column-naming-strategy").then()
.body(is("OK"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.hibernate.orm.envers.config;

import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.orm.envers.AbstractEnversResource;
import io.quarkus.hibernate.orm.envers.MyAuditedEntity;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class EnversModifiedFlagsTestCase {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(MyAuditedEntity.class, EnversTestModifiedFlagsResource.class,
AbstractEnversResource.class)
.addAsResource("application-with-modified-flags.properties",
"application.properties"));

@Test
public void testModifiedFlags() {
RestAssured.when().get("/envers-modified-flags").then()
.body(is("OK"));
}
}
Loading