#898: AuftragsCacheService.kt

projectforge-business/src/main/kotlin/org/projectforge/business/fibu/AuftragsCacheService.kt Type: Spring Service · Purpose: Fast tuple-based database queries for order data · Package: org.projectforge.business.fibu
Source path: projectforge-business/src/main/kotlin/org/projectforge/business/fibu/AuftragsCacheService.kt 167 lines · 135 code · 25 comments · 7 blank
Purpose: Provides high-performance read-only database access for orders (AuftragDO), order positions (AuftragsPositionDO), and payment schedules (PaymentScheduleDO) using native JPQL tuple queries. Avoids full entity hydration and lazy-loading overhead by selecting only the columns needed for list rendering and cache population.

Architecture & Design

Service Declaration

The class is annotated with @Service and depends on PfPersistenceService via @Autowired. All methods use runIsolatedReadOnly to execute queries in a fresh persistence context, preventing pollution of the caller's session cache.

DependencyTypeRole
PfPersistenceServiceFrameworkProvides isolated read-only JPA contexts for fast tuple queries

Methods

selectAuftragsList(): List<AuftragDO>

Returns all orders (including deleted) with a curated column set. Maps each Tuple to a partially-populated AuftragDO using TupleUtils getter helpers. Foreign keys (kundeId, projektId, contactPersonId) are resolved via em.getReference() to avoid additional queries — Hibernate returns a lazy proxy without hitting the database.

selectNonDeletedAuftragsPositions(): List<AuftragsPositionDO>

Returns non-deleted order positions. Similar tuple mapping pattern with an additional performance optimization: bemerkung (comment) is abbreviated to 30 characters via abbreviate(30), reducing memory footprint for list views. The task reference (taskId) creates a stub TaskDO with only the ID set.

selectNonDeletedPaymentSchedules(): List<PaymentScheduleDO>

Returns non-deleted payment schedules, creating stub AuftragDO objects (ID-only) for the foreign key reference auftragId.

Query Definitions (Companion Object)

Three JPQL queries are defined as private val constants in the companion object, using ${AuftragDO::class.simpleName} interpolation for type-safe entity references:

ConstantTarget EntityFilter
SELECT_ORDERSAuftragDONone (all records, including deleted)
SELECT_POSITIONSAuftragsPositionDOWHERE deleted = false
SELECT_PAYMENTS_SCHEDULESPaymentScheduleDOWHERE deleted = false

Performance Strategy

Related Classes

Git History

868d6abb7 2025 -> 2026
49b1d6b8d Forecast and orderbook: forecast-Type for orders/positions added (current month or following month)
7163b8c4e WIP: Order book snapshots, ForecastExport fixed (customer and project name were missing)
63081666f Source file headers: 2024-> 2025.
ae2c04ee0 Migration stuff in progress... (all tests of all packages: OK).
89ea9a532 Migration stuff in progress... (all tests of all packages: OK).