AuftragsRechnungCache.ktRechnungPosInfo) to their associated order positions and orders. This enables fast lookups for the order book to display which invoices are linked to each order, and for the invoice view to show which orders are covered. Handles a cyclic dependency with AuftragsCache by running both caches twice on initialization (a "ready" flag mechanism).
Extends AbstractCache, which provides the refresh()/setExpired()/forceReload() lifecycle. Registered as a Spring @Component.
| Dependency | Type | Role |
|---|---|---|
AuftragsCache | Component | Provides order-to-position mapping; mutual refresh during init |
RechnungCache | Component | Provides RechnungInfo and RechnungPosInfo objects |
RechnungDao | DAO | Registered for BaseDOModifiedListener to invalidate cache on invoice changes |
RechnungJdbcService | Service | Fast JDBC query for invoice-position-to-order-position assignments |
| Map | Key | Value | Purpose |
|---|---|---|---|
invoicePositionMapByAuftragId | Long (order ID) | MutableSet<Long> (invoice position IDs) | Lookup invoice position IDs by order |
invoicePositionMapByAuftragsPositionId | Long (order position ID) | MutableSet<RechnungPosInfo> | Lookup invoice positions by order position |
invoicePositionMapByRechnungId | Long (invoice ID) | MutableSet<RechnungPosInfo> | Lookup order-related invoice positions by invoice |
@PostConstruct init() registers two listeners:
rechnungListener — a BaseDOModifiedListener<RechnungDO> that calls setExpired() whenever an invoice is inserted or modified. This ensures the cache stays fresh when invoices are created, edited, or deleted.auftragsCacheListener — a CacheListener registered on AuftragsCache. Implements the mutual-refresh pattern: when AuftragsCache finishes its refresh, this listener detects it and triggers a second refresh cycle for both caches to resolve cross-references.AuftragsCache and AuftragsRechnungCache depend on each other's data. The solution uses a ready flag:
AuftragsCache.refresh() runs — this cache's data is still emptyonAfterCacheRefresh fires, sets ready = true, unregisters the listenerAuftragsRechnungCache.forceReload() runs — now has AuftragsCache data availableAuftragsCache.forceReload() runs again — now has this cache's data availablegetRechnungsPosInfoByAuftragId(auftragId: Long?): List<RechnungPosInfo>?Returns invoice positions assigned to a given order. Results are sorted by invoice number, then position number. Returns null if auftragId is null. Calls checkRefresh() to trigger lazy cache population if needed.
getRechnungsPosInfosByAuftragsPositionId(auftragsPositionId: Long?): Set<RechnungPosInfo>?Returns invoice positions assigned to a specific order position. Returns null for null input.
refresh() queries rechnungJdbcService.selectRechnungsPositionenWithAuftragPosition() for the raw JDBC result set (faster than JPA for this bulk operation), then:
TreeSet-backed maps (auto-sorted) for each dimensionWhen any RechnungDO is inserted or modified, rechnungListener calls setExpired(). The next call to a public getter method will trigger checkRefresh() → refresh(), lazily rebuilding the cache mapping.
AuftragsCache — mutual refresh partner; provides getOrderInfoByPositionId()RechnungCache — provides getRechnungInfo() and ensureRechnungPosInfo()RechnungJdbcService — raw JDBC query for performanceRechnungPosInfo — value object representing an invoice position in the cacheAbstractCache — base class providing checkRefresh()/setExpired()/forceReload()868d6abb7 2025 -> 2026 51d352133 AuftragsCache / AuftragsRechnungsCache handling refactored (cyclic usage resolved by running caches twice on initialization) 63081666f Source file headers: 2024-> 2025. 22ccc4877 WIP: Scripting 884ff2c70 Debug message added (missing debitor invoices in orders in production only). c9508769a Clone of invoices. d02c8a770 Migration stuff in progress... ff2cc4cfa Migration stuff in progress... (all tests of all packages: OK). f31e8064e Migration stuff in progress... 2e9839891 Migration stuff in progress... 973fbf518 Migration stuff in progress... ba2479571 Migration stuff in progress... b3293f0cc PersistenceService/Context: stats handling improved. b47c21af6 Refactored caching and calculations with invoices (not yet finished)