#1269: CollectionHandler.kt

projectforge-business/src/main/kotlin/org/projectforge/framework/persistence/candh/CollectionHandler.kt Copy-and-History Handler (Collections), projectforge-business/src/main/kotlin/org/projectforge/framework/persistence/candh/CollectionHandler.kt 334 lines · 252 code · 72 comments · 10 blank
Handles mutable collections (TreeSet, ArrayList, HashSet, PersistentSet, PersistentList) in the CandH framework. Compares src and dest collections to detect added, removed, and kept entries. Supports deep copy of collection entries (when managed by owner entity via @PersistenceBehavior(autoUpdateCollectionEntries=true)), soft-delete via @SoftDeleteCollection, and history tracking for collection changes.

Architecture

Collection Management Detection

collectionManagedBySrcClazz() returns true when:

Key Features

FeatureDescription
Diff EngineUses CollectionUtils.compareCollections() to separate added/removed/kept entries
Soft Delete@SoftDeleteCollection marks entries as deleted instead of removing them, preserving history and avoiding unique constraint violations
Entry ReactivationDetects re-added soft-deleted entries and reactivates them
Deep CopyWhen autoUpdateCollectionEntries=true, uses copyValues() recursively on kept entries to detect nested modifications
Collection InstantiationAuto-creates matching collection type (TreeSet->TreeSet, HashSet->HashSet, ArrayList->ArrayList) when dest is null

Companion: New Entry History

writeInsertHistoryEntriesForNewCollectionEntries() recursively walks merged collections to create history entries for newly inserted child entities (whose IDs were null before merge). Handles nested collection hierarchies (e.g. invoice → positions → cost assignments).

Git History

868d6abb7 2025 -> 2026
a77a6570f WIP: Import of creditor invoices
e8a5e51d4 WIP: Import of creditor invoices
2d25df051 User comments on changes: users/groups: clone comments also for history entries
6a32032d6 Hibernate.isInitialized(obj) -> HibernateUtils.isFullyInitialized(obj)