From 6cdb70137aec289bb2b3ed495230f34aac55230a Mon Sep 17 00:00:00 2001 From: homedirectory Date: Mon, 13 Jan 2025 10:24:49 +0200 Subject: [PATCH] #2349 Generate companions for synthetic audit-entities --- .../audit/AuditEntityCompanionGeneratorImpl.java | 14 ++++++++++++++ .../platform/audit/AuditEntityGeneratorImpl.java | 1 + .../companion/EntityCompanionGeneratorImpl.java | 7 +++++-- .../audit/IAuditEntityCompanionGenerator.java | 4 ++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/platform-dao/src/main/java/ua/com/fielden/platform/audit/AuditEntityCompanionGeneratorImpl.java b/platform-dao/src/main/java/ua/com/fielden/platform/audit/AuditEntityCompanionGeneratorImpl.java index a3dfd02d84..f868987f30 100644 --- a/platform-dao/src/main/java/ua/com/fielden/platform/audit/AuditEntityCompanionGeneratorImpl.java +++ b/platform-dao/src/main/java/ua/com/fielden/platform/audit/AuditEntityCompanionGeneratorImpl.java @@ -3,6 +3,7 @@ import jakarta.inject.Singleton; import net.bytebuddy.ByteBuddy; import net.bytebuddy.description.annotation.AnnotationDescription; +import ua.com.fielden.platform.dao.CommonEntityDao; import ua.com.fielden.platform.entity.annotation.EntityType; @Singleton @@ -35,4 +36,17 @@ public Class generateCompanionForAuditProp(final Class generateCompanionForSynAuditEntity(final Class type) { + return new ByteBuddy() + .subclass(CommonEntityDao.class) + .name(type.getCanonicalName() + "Dao") + .annotateType(AnnotationDescription.Builder.ofType(EntityType.class) + .define("value", type) + .build()) + .make() + .load(type.getClassLoader()) + .getLoaded(); + } + } diff --git a/platform-dao/src/main/java/ua/com/fielden/platform/audit/AuditEntityGeneratorImpl.java b/platform-dao/src/main/java/ua/com/fielden/platform/audit/AuditEntityGeneratorImpl.java index 57a947541c..2d7e52dd99 100644 --- a/platform-dao/src/main/java/ua/com/fielden/platform/audit/AuditEntityGeneratorImpl.java +++ b/platform-dao/src/main/java/ua/com/fielden/platform/audit/AuditEntityGeneratorImpl.java @@ -449,6 +449,7 @@ private JavaFile generateSyn_( builder.addAnnotation(synAuditFor(auditedEntityType)); builder.addAnnotation(javaPoet.getAnnotation(SkipVerification.class)); builder.addAnnotation(javaPoet.getAnnotation(SkipEntityRegistration.class)); + builder.addAnnotation(javaPoet.getAnnotation(CompanionIsGenerated.class)); // Declare key member "auditedEntity", common to all audit-entity type versions. final var auditedEntityProp = propertyBuilder(AbstractSynAuditEntity.AUDITED_ENTITY, auditedEntityType) diff --git a/platform-dao/src/main/java/ua/com/fielden/platform/companion/EntityCompanionGeneratorImpl.java b/platform-dao/src/main/java/ua/com/fielden/platform/companion/EntityCompanionGeneratorImpl.java index 9b24f3d887..816292a2fe 100644 --- a/platform-dao/src/main/java/ua/com/fielden/platform/companion/EntityCompanionGeneratorImpl.java +++ b/platform-dao/src/main/java/ua/com/fielden/platform/companion/EntityCompanionGeneratorImpl.java @@ -4,12 +4,12 @@ import jakarta.inject.Singleton; import ua.com.fielden.platform.audit.AbstractAuditEntity; import ua.com.fielden.platform.audit.AbstractAuditProp; +import ua.com.fielden.platform.audit.AbstractSynAuditEntity; import ua.com.fielden.platform.audit.IAuditEntityCompanionGenerator; import ua.com.fielden.platform.entity.AbstractEntity; import ua.com.fielden.platform.entity.exceptions.InvalidArgumentException; -import static ua.com.fielden.platform.audit.AuditUtils.isAuditEntityType; -import static ua.com.fielden.platform.audit.AuditUtils.isAuditPropEntityType; +import static ua.com.fielden.platform.audit.AuditUtils.*; @Singleton final class EntityCompanionGeneratorImpl implements IEntityCompanionGenerator { @@ -29,6 +29,9 @@ public Class generateCompanion(final Class type) { else if (isAuditPropEntityType(type)) { return auditCoGenerator.generateCompanionForAuditProp((Class) type); } + else if (isSynAuditEntityType(type)) { + return auditCoGenerator.generateCompanionForSynAuditEntity((Class) type); + } // Support for other kinds of generated companions should be added here diff --git a/platform-pojo-bl/src/main/java/ua/com/fielden/platform/audit/IAuditEntityCompanionGenerator.java b/platform-pojo-bl/src/main/java/ua/com/fielden/platform/audit/IAuditEntityCompanionGenerator.java index 3194cf6332..035eb95c31 100644 --- a/platform-pojo-bl/src/main/java/ua/com/fielden/platform/audit/IAuditEntityCompanionGenerator.java +++ b/platform-pojo-bl/src/main/java/ua/com/fielden/platform/audit/IAuditEntityCompanionGenerator.java @@ -1,5 +1,7 @@ package ua.com.fielden.platform.audit; +import ua.com.fielden.platform.entity.AbstractEntity; + /** * This interface defines the generator of audit-entity companion object types. */ @@ -17,4 +19,6 @@ public interface IAuditEntityCompanionGenerator { */ Class generateCompanionForAuditProp(Class type); + Class generateCompanionForSynAuditEntity(Class type); + }