#997: Kost2Dao.kt

projectforge-business/src/main/kotlin/org/projectforge/business/fibu/kost/Kost2Dao.kt Type: DAO / Service · Purpose: Data access for Kost2 cost center entities · Source: projectforge-business/src/main/kotlin/org/projectforge/business/fibu/kost/Kost2Dao.kt 218 lines · 149 code · 47 comments · 22 blank
Spring @Service managing persistence operations for Kost2DO entities. Extends BaseDao to provide CRUD, search, and validation logic. Handles project linkage, cost type assignment, uniqueness enforcement, and post-save cache updates.

Key Methods

MethodDescription
setProjekt(kost2, projektId)Links a Kost2 to a Projekt and copies its nummernkreis/bereich/teilbereich
setKost2Art(kost2, kost2ArtId)Sets the Kost2Art (cost type) on a Kost2 entry
getKost2(kostString)Looks up Kost2 by formatted string (e.g. "5.123.45.67")
getKost2(nk, b, tb, art)Looks up Kost2 by individual numeric components
getActiveKost2(nk, b, tb)Returns active Kost2 entries for a given 6-digit prefix
getActiveKost2(projekt)Convenience: active Kost2 entries for a project

Select / Filtering Architecture

The select(filter) override performs a two-phase query:

  1. Database query: Uses QueryFilter with a join on kost2Art, ordered by all numeric components
  2. In-memory filtering: Filters by effectiveKostentraegerStatus (which may inherit ENDED status from the linked project). Supports: ACTIVE, NONACTIVE, ENDED, NOT_ENDED, and ALL

Validation (onInsertOrModify)

Dependencies

Source Code (abridged)

@Service
open class Kost2Dao : BaseDao<Kost2DO>(Kost2DO::class.java) {
    @Autowired private lateinit var projektDao: ProjektDao
    @Autowired private lateinit var kost2ArtDao: Kost2ArtDao
    @Autowired private lateinit var kostCache: KostCache

    override fun select(filter: BaseSearchFilter): List<Kost2DO> {
        val myFilter = if (filter is KostFilter) filter else KostFilter(filter)
        val queryFilter = QueryFilter(myFilter).apply { createJoin("kost2Art") }
        val allKost2 = select(queryFilter)
        return when {
            myFilter.isActive -> allKost2.filter {
                it.effectiveKostentraegerStatus == ACTIVE || it.effectiveKostentraegerStatus == null
            }
            myFilter.isNonActive -> allKost2.filter { it.effectiveKostentraegerStatus == NONACTIVE }
            myFilter.isEnded -> allKost2.filter { it.effectiveKostentraegerStatus == ENDED }
            myFilter.isNotEnded -> allKost2.filter { it.effectiveKostentraegerStatus != ENDED }
            else -> allKost2
        }
    }
}

Git History

868d6abb7 2025 -> 2026
8239a53ee Kost2: Virtuelle Status-Vererbung von ProjektDO implementiert
63081666f Source file headers: 2024-> 2025.
770891c57 Bugfix CandH:CollectionHandler
d394f410f Migration stuff (all tests OK).
d67bce18b Migration stuff in progress...
5989b32fd BaseDao: onChangeLister refactored.
1b50060c3 BaseDao: get->find, save->insert, getList->select, load->select
3aeda5ef5 Big change: InTrans removed, PfPersistenceContext as ThreadLocal.
85b4e1175 PfPersistenceService: query -> executeQuery.
b095e6f7d Big change of Transaction handling.
4c04cfd65 MAJOR-CHANGE! Integer id's to Long id's.
5bafe7941 @Repository -> @Service. @Transactional removed.
f2f7cff74 Migration stuff in progress... (file created)