quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

Implement per persistence unit configuration for Hibernate Envers

Open gsmet opened this issue 2 years ago • 2 comments

Hibernate Envers actually has the existing infrastructure to do so as we implement the active boolean per persistence unit but all the rest of the config is still global. We should move everything to the persistence unit specific config, adjust HibernateEnversRecorder#contributeBootProperties() to target per PU config for all properties and it would probably work. If we're lucky.

We also need a proper test for that new feature.

Typically, we want to be able to do:

quarkus.hibernate-envers.db1.store-data-at-delete=true
quarkus.hibernate-envers.db1.audit-table-suffix=_aud
quarkus.hibernate-envers.db1.revision-field-name=rev
quarkus.hibernate-envers.db1.revision-type-field-name=revtype
quarkus.hibernate-envers.db1.audit-strategy=org.hibernate.envers.strategy.ValidityAuditStrategy
quarkus.hibernate-envers.db1.audit-strategy-validity-end-rev-field-name=revend
quarkus.hibernate-envers.db1.audit-strategy-validity-store-revend-timestamp=true
quarkus.hibernate-envers.db1.audit-strategy-validity-revend-timestamp-field-name=revend_tstmp

quarkus.hibernate-envers.db2.audit-table-suffix=_aud
quarkus.hibernate-envers.db2.revision-field-name=revision_id
quarkus.hibernate-envers.db2.revision-type-field-name=revtype
quarkus.hibernate-envers.db2.do-not-audit-optimistic-locking-field=false
quarkus.hibernate-envers.db2.store-data-at-delete=true

Discussed in https://github.com/quarkusio/quarkus/discussions/27971

Originally posted by Traivor September 15, 2022 It doesn't appear that the hibernate-envers plugin supports configuration on a persistence unit basis. Am I reading things right? Are there any plans to support this?

Alternatively, would passing envers properties via the new quarkus.hibernate-orm."unit-name".unsupported-properties property work?

gsmet avatar Sep 21 '22 14:09 gsmet

/cc @Sanne, @yrodiere

quarkus-bot[bot] avatar Sep 21 '22 14:09 quarkus-bot[bot]

@tmihalac I wonder if you would be interested in taking this one?

gsmet avatar Sep 21 '22 14:09 gsmet

@tmihalac I wonder if you would be interested in taking this one?

Yes I will take it.

tmihalac avatar Sep 29 '22 05:09 tmihalac

@gsmet How do I add the properties to the config per persistence unit in HibernateEnversRecorder#contributeBootProperties()?

How do I change HibernateEnversProcessor#registerEnversReflections() in regards to the config ?

tmihalac avatar Sep 29 '22 07:09 tmihalac

@tmihalac the properties at the root of HibernateEnversBuildTimeConfig will need to be migrated to HibernateEnversBuildTimeConfigPersistenceUnit.

and then I would say you already have the general idea in contributeBootProperties given it's implemented for the one property in HibernateEnversBuildTimeConfigPersistenceUnit.

As for HibernateEnversProcessor#registerEnversReflections() you will have to go through the properties of the default persistence unit and the named ones and register all that's necessary.

Is it clear enough?

gsmet avatar Sep 29 '22 08:09 gsmet

In general I understood that, but how do I differentiate the properties of each PersistenceUnit? can you give me an example ? what is the xxx in this case the same as it is today ? addConfig(propertyCollector, xxx, config.storeDataAtDelete);

tmihalac avatar Sep 29 '22 09:09 tmihalac

It's not exactly obvious but the propertyCollector is specific to the current persistence unit so you just have to push things there from the puConfig you get from the config.

gsmet avatar Sep 29 '22 09:09 gsmet

As for HibernateEnversProcessor#registerEnversReflections() you will have to go through the properties of the default persistence unit and the named ones and register all that's necessary.

What do you mean ?

tmihalac avatar Sep 29 '22 10:09 tmihalac

Typically that this:

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

will need to be done for all the PUs once these properties are moved to PU-specific properties.

gsmet avatar Sep 29 '22 11:09 gsmet