Skip to content

Commit

Permalink
#2349 Generate companions for synthetic audit-entities
Browse files Browse the repository at this point in the history
  • Loading branch information
homedirectory committed Jan 13, 2025
1 parent 10089ac commit 6cdb701
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,4 +36,17 @@ public Class<?> generateCompanionForAuditProp(final Class<? extends AbstractAudi
.getLoaded();
}

@Override
public Class<?> generateCompanionForSynAuditEntity(final Class<? extends AbstractSynAuditEntity> 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -29,6 +29,9 @@ public Class<?> generateCompanion(final Class<? extends AbstractEntity> type) {
else if (isAuditPropEntityType(type)) {
return auditCoGenerator.generateCompanionForAuditProp((Class<? extends AbstractAuditProp>) type);
}
else if (isSynAuditEntityType(type)) {
return auditCoGenerator.generateCompanionForSynAuditEntity((Class<? extends AbstractSynAuditEntity>) type);
}

// Support for other kinds of generated companions should be added here

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -17,4 +19,6 @@ public interface IAuditEntityCompanionGenerator {
*/
Class<?> generateCompanionForAuditProp(Class<? extends AbstractAuditProp> type);

Class<?> generateCompanionForSynAuditEntity(Class<? extends AbstractSynAuditEntity> type);

}

0 comments on commit 6cdb701

Please sign in to comment.