Skip to content

Commit

Permalink
#2349 Ensure AbstractAuditEntity.auditedEntity is the first key member
Browse files Browse the repository at this point in the history
  • Loading branch information
homedirectory committed Dec 21, 2024
1 parent df52ef6 commit 842ebe3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private JavaFile generateAuditEntity(
// By virtue of its name, this property's accessor and setter implement abstract methods in the base type
final var auditedEntityTitle = TitlesDescsGetter.getEntityTitle(type);
final var auditedEntityProp = propertyBuilder(AUDITED_ENTITY, type)
.addAnnotation(AnnotationSpecs.compositeKeyMember(AbstractAuditEntity.NEXT_COMPOSITE_KEY_MEMBER))
.addAnnotation(AnnotationSpecs.compositeKeyMember(AbstractAuditEntity.AUDITED_ENTITY_KEY_MEMBER_ORDER))
.addAnnotation(javaPoet.getAnnotation(MapTo.class))
.addAnnotation(javaPoet.getAnnotation(Required.class))
.addAnnotation(javaPoet.getAnnotation(Final.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ public abstract class AbstractAuditEntity<E extends AbstractEntity<?>> extends A
*/
public static final String CHANGED_PROPS = "changedProps";

static final int NEXT_COMPOSITE_KEY_MEMBER = 2;
/**
* The composite key order that must be specified by the {@link #AUDITED_ENTITY} property.
*/
// Placing this property first ensures that its column comes first in the multi-column unique index that is always
// generated for composite keys, which improves performance because the first column in such an index is searchable.
static final int AUDITED_ENTITY_KEY_MEMBER_ORDER = 1;

/**
* Getter for property {@link #AUDITED_ENTITY}.
Expand All @@ -73,7 +78,7 @@ public abstract class AbstractAuditEntity<E extends AbstractEntity<?>> extends A
@IsProperty
@MapTo
@Title(value = "Audited entity version", desc = "Version of the entity for which this audit record was created.")
@CompositeKeyMember(1)
@CompositeKeyMember(2)
private Long auditedVersion;

@IsProperty
Expand Down

0 comments on commit 842ebe3

Please sign in to comment.