}
@SuppressWarnings({"unchecked"})
public void performCollectionChange(Session session, String entityName, String propertyName, AuditConfiguration auditCfg,
PersistentCollectionChangeData persistentCollectionChangeData, Object revision) {
final QueryBuilder qb = new QueryBuilder(persistentCollectionChangeData.getEntityName(), MIDDLE_ENTITY_ALIAS);
final String originalIdPropName = auditCfg.getAuditEntCfg().getOriginalIdPropName();
final Map<String, Object> originalId = (Map<String, Object>) persistentCollectionChangeData.getData().get(originalIdPropName);
final String revisionFieldName = auditCfg.getAuditEntCfg().getRevisionFieldName();
final String revisionTypePropName = auditCfg.getAuditEntCfg().getRevisionTypePropName();
// Adding a parameter for each id component, except the rev number and type.
for (Map.Entry<String, Object> originalIdEntry : originalId.entrySet()) {
if (!revisionFieldName.equals(originalIdEntry.getKey()) && !revisionTypePropName.equals(originalIdEntry.getKey())) {
qb.getRootParameters().addWhereWithParam(originalIdPropName + "." + originalIdEntry.getKey(),
true, "=", originalIdEntry.getValue());
}
}
final SessionFactoryImplementor sessionFactory = ( (SessionImplementor) session ).getFactory();
final Type propertyType = sessionFactory.getEntityPersister( entityName ).getPropertyType( propertyName );
if ( propertyType.isCollectionType() ) {
CollectionType collectionPropertyType = (CollectionType) propertyType;
// Handling collection of components.
if ( collectionPropertyType.getElementType( sessionFactory ) instanceof ComponentType ) {
// Adding restrictions to compare data outside of primary key.
for ( Map.Entry<String, Object> dataEntry : persistentCollectionChangeData.getData().entrySet() ) {
if ( !originalIdPropName.equals( dataEntry.getKey() ) ) {
qb.getRootParameters().addWhereWithParam( dataEntry.getKey(), true, "=", dataEntry.getValue() );
}
}
}
}
addEndRevisionNullRestriction(auditCfg, qb.getRootParameters());
final List<Object> l = qb.toQuery(session).setLockOptions(LockOptions.UPGRADE).list();
// Update the last revision if one exists.
// HHH-5967: with collections, the same element can be added and removed multiple times. So even if it's an
// ADD, we may need to update the last revision.
if (l.size() > 0) {