EN · DE · RU · FR · ES

#413: KontoDao.java

projectforge-business/src/main/java/org/projectforge/business/fibu/KontoDao.java Type: Java · Role: Data Access Object · Source: projectforge-business/src/main/java/org/projectforge/business/fibu/KontoDao.java 85 lines · 49 code · 26 comments · 10 blank
Data Access Object for Konto entities. Extends BaseDao to provide CRUD operations, Hibernate Search queries, and business-logic-level data access.

Code Structure

Package: org.projectforge.business.fibu

Classes: KontoDao

Extends: BaseDao

Methods (5): afterInsertOrModify, getKonto, newInstance, getKontoCache, onInsertOrModify

Fields (2): USER_RIGHT_ID, kontoCache

Imports: 8 packages

Source Code (abridged)

package org.projectforge.business.fibu;

import kotlin.Pair;
import org.jetbrains.annotations.NotNull;
import org.projectforge.business.user.UserRightId;
import org.projectforge.common.i18n.UserException;
import org.projectforge.framework.access.OperationType;
import org.projectforge.framework.persistence.api.BaseDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class KontoDao extends BaseDao<KontoDO> {
    public static final UserRightId USER_RIGHT_ID = UserRightId.FIBU_ACCOUNTS;

    @Autowired
    private KontoCache kontoCache;

    public KontoDao() {
        super(KontoDO.class);
        userRightId = USER_RIGHT_ID;
    }

    @Override
    public void afterInsertOrModify(@NotNull final KontoDO obj, final OperationType operationType) {
        getKontoCache().refresh();
    }

    public KontoDO getKonto(final Integer kontonummer) {
        if (kontonummer == null) {
            return null;
        }
        return persistenceService.selectNamedSingleResult(
                KontoDO.FIND_BY_NUMMER,
                KontoDO.class,
                new Pair<>("nummer", kontonummer));
    }

    @NotNull
    @Override
    public KontoDO newInstance() {
        return new KontoDO();
    }

    /**
     * @return the kontoCache
     */
    public KontoCache getKontoCache() {
        return kontoCache;
    }

    @Override
    public void onInsertOrModify(final KontoDO obj, final OperationType operationType) {
        if (obj.getNummer() != null && obj.getNummer() > 0) {
            KontoDO existingAccount = getKonto(obj.getNummer());
            //Insert case
            if (existingAccount != null && (obj.getId() == null || !obj.getId().equals(existingAccount.getId()))) {
                throw new UserException("fibu.konto.validate.duplicate");
            }
        }
    }
}

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
5989b32fd BaseDao: mechanism of onChangeLister refactored.
1b50060c3 BaseDao: renamed: get -> find, save -> insert, getList -> select, load -> select
3aeda5ef5 Big change: all save|update|...InTrans renamed (InTrans removed). PfPesistenceContext as param not needed anymore (ThreadLocal is used instead). (all tests of all packages: OK).