<commit_before>package org.synyx.urlaubsverwaltung.core.application.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import org.synyx.urlaubsverwaltung.core.application.domain.Application;
import org.synyx.urlaubsverwaltung.core.application.domain.ApplicationStatus;
import org.synyx.urlaubsverwaltung.core.application.domain.DayLength;
import org.synyx.urlaubsverwaltung.core.application.domain.VacationType;
import org.synyx.urlaubsverwaltung.core.person.Person;

import java.util.Date;
import java.util.List;


/**
 * Repository for {@link Application} entities.
 *
 * @author  <NAME> - <EMAIL>
 */
public interface ApplicationDAO extends JpaRepository<Application, Integer> {

    @Query("select max(id) from Application x where x.person = ?1 and x.status = ?2")
    int getIdOfLatestApplication(Person person, ApplicationStatus status);


    @Query(
        "select x from Application x where (x.startDate between ?1 and ?2) or (x.endDate between ?1 and ?2) or (x.startDate < ?1 and x.endDate > ?2) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsForACertainTime(Date startDate, Date endDate);


    @Query(
        "select x from Application x "
        + "where x.status = ?3 and ((x.startDate between ?1 and ?2) or (x.endDate between ?1 and ?2) "
        + "or (x.startDate < ?1 and x.endDate > ?2)) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsForACertainTimeAndState(Date startDate, Date endDate, ApplicationStatus status);


    @Query(
        "select x from Application x "
        + "where x.person = ?3 and ((x.startDate between ?1 and ?2) or (x.endDate between ?1 and ?2) "
        + "or (x.startDate < ?1 and x.endDate > ?2)) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsForACertainTimeAndPerson(Date startDate, Date endDate, Person person);


    @Query(
        "select x from Application x "
        + "where x.person = ?3 and x.status = ?4 and ((x.startDate between ?1 and ?2) or (x.endDate between ?1 and ?2) "
        + "or (x.startDate < ?1 and x.endDate > ?2)) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsForACertainTimeAndPersonAndState(Date startDate, Date endDate, Person person,
        ApplicationStatus status);


    @Query(
        "select x from Application x where x.person = ?1 "
        + "and ((x.startDate between ?2 and ?3) and (x.endDate between ?2 and ?3)) "
        + "and x.vacationType = ?4 "
        + "and (x.status = ?5 or x.status = ?6) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsBetweenTwoMilestones(Person person, Date firstMilestone, Date lastMilestone,
        VacationType type, ApplicationStatus waitingState, ApplicationStatus allowedState);


    @Query(
        "select x from Application x where x.person = ?1 "
        + "and ((x.startDate < ?2) and (x.endDate between ?2 and ?3)) "
        + "and x.vacationType = ?4 "
        + "and (x.status = ?5 or x.status = ?6) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsBeforeFirstMilestone(Person person, Date firstMilestone, Date lastMilestone,
        VacationType type, ApplicationStatus cancelledState, ApplicationStatus allowedState);


    @Query(
        "select x from Application x where x.person = ?1 "
        + "and ((x.startDate between ?2 and ?3) and (x.endDate > ?3)) "
        + "and x.vacationType = ?4 "
        + "and (x.status = ?5 or x.status = ?6) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsAfterLastMilestone(Person person, Date firstMilestone, Date lastMilestone,
        VacationType type, ApplicationStatus cancelledState, ApplicationStatus allowedState);


    @Query(
        "select x from Application x where ((x.startDate between ?1 and ?2) or (x.endDate between ?1 and ?2) or (x.startDate < ?1 and x.endDate > ?2)) "
        + "and x.person = ?3 and (x.status = 0 or x.status = 1) and x.howLong = ?4 order by x.startDate"
    )
    List<Application> getRelevantActiveApplicationsByPeriodAndDayLength(Date startDate, Date endDate, Person person,
        DayLength length);


    @Query(
        "select x from Application x where ((x.startDate between ?1 and ?2) or (x.endDate between ?1 and ?2) or (x.startDate < ?1 and x.endDate > ?2)) "
        + "and x.person = ?3 and (x.status = 0 or x.status = 1) order by x.startDate"
    )
    List<Application> getRelevantActiveApplicationsByPeriodForEveryDayLength(Date startDate, Date endDate,
        Person person);


    // ONLY FOR JMX

    @Query(
        "select count(x) from Application x where x.status = ?1 and ((x.startDate between ?2 and ?3) or (x.endDate between ?2 and ?3)) "
        + "order by x.startDate"
    )
    long countApplicationsInStateAndYear(ApplicationStatus state, Date firstDayOfYear, Date lastDayOfYear);


    @Query(
        "select x from Application x where x.status = ?1 and ((x.startDate between ?2 and ?3) or (x.endDate between ?2 and ?3)) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsByStateAndYear(ApplicationStatus state, Date firstDayOfYear, Date lastDayOfYear);
}<commit_msg>Fix DAO query with deprecated application for leave state<commit_after>package org.synyx.urlaubsverwaltung.core.application.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import org.synyx.urlaubsverwaltung.core.application.domain.Application;
import org.synyx.urlaubsverwaltung.core.application.domain.ApplicationStatus;
import org.synyx.urlaubsverwaltung.core.application.domain.DayLength;
import org.synyx.urlaubsverwaltung.core.application.domain.VacationType;
import org.synyx.urlaubsverwaltung.core.person.Person;

import java.util.Date;
import java.util.List;


/**
 * Repository for {@link Application} entities.
 *
 * @author  <NAME> - <EMAIL>
 */
public interface ApplicationDAO extends JpaRepository<Application, Integer> {

    @Query("select max(id) from Application x where x.person = ?1 and x.status = ?2")
    int getIdOfLatestApplication(Person person, ApplicationStatus status);


    @Query(
        "select x from Application x where (x.startDate between ?1 and ?2) or (x.endDate between ?1 and ?2) or (x.startDate < ?1 and x.endDate > ?2) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsForACertainTime(Date startDate, Date endDate);


    @Query(
        "select x from Application x "
        + "where x.status = ?3 and ((x.startDate between ?1 and ?2) or (x.endDate between ?1 and ?2) "
        + "or (x.startDate < ?1 and x.endDate > ?2)) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsForACertainTimeAndState(Date startDate, Date endDate, ApplicationStatus status);


    @Query(
        "select x from Application x "
        + "where x.person = ?3 and ((x.startDate between ?1 and ?2) or (x.endDate between ?1 and ?2) "
        + "or (x.startDate < ?1 and x.endDate > ?2)) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsForACertainTimeAndPerson(Date startDate, Date endDate, Person person);


    @Query(
        "select x from Application x "
        + "where x.person = ?3 and x.status = ?4 and ((x.startDate between ?1 and ?2) or (x.endDate between ?1 and ?2) "
        + "or (x.startDate < ?1 and x.endDate > ?2)) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsForACertainTimeAndPersonAndState(Date startDate, Date endDate, Person person,
        ApplicationStatus status);


    @Query(
        "select x from Application x where x.person = ?1 "
        + "and ((x.startDate between ?2 and ?3) and (x.endDate between ?2 and ?3)) "
        + "and x.vacationType = ?4 "
        + "and (x.status = ?5 or x.status = ?6) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsBetweenTwoMilestones(Person person, Date firstMilestone, Date lastMilestone,
        VacationType type, ApplicationStatus waitingState, ApplicationStatus allowedState);


    @Query(
        "select x from Application x where x.person = ?1 "
        + "and ((x.startDate < ?2) and (x.endDate between ?2 and ?3)) "
        + "and x.vacationType = ?4 "
        + "and (x.status = ?5 or x.status = ?6) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsBeforeFirstMilestone(Person person, Date firstMilestone, Date lastMilestone,
        VacationType type, ApplicationStatus cancelledState, ApplicationStatus allowedState);


    @Query(
        "select x from Application x where x.person = ?1 "
        + "and ((x.startDate between ?2 and ?3) and (x.endDate > ?3)) "
        + "and x.vacationType = ?4 "
        + "and (x.status = ?5 or x.status = ?6) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsAfterLastMilestone(Person person, Date firstMilestone, Date lastMilestone,
        VacationType type, ApplicationStatus cancelledState, ApplicationStatus allowedState);


    @Query(
        "select x from Application x where ((x.startDate between ?1 and ?2) or (x.endDate between ?1 and ?2) or (x.startDate < ?1 and x.endDate > ?2)) "
        + "and x.person = ?3 and (x.status = 'WAITING' or x.status = 'ALLOWED') and x.howLong = ?4 order by x.startDate"
    )
    List<Application> getRelevantActiveApplicationsByPeriodAndDayLength(Date startDate, Date endDate, Person person,
        DayLength length);


    @Query(
        "select x from Application x where ((x.startDate between ?1 and ?2) or (x.endDate between ?1 and ?2) or (x.startDate < ?1 and x.endDate > ?2)) "
        + "and x.person = ?3 and (x.status = 'WAITING' or x.status = 'ALLOWED') order by x.startDate"
    )
    List<Application> getRelevantActiveApplicationsByPeriodForEveryDayLength(Date startDate, Date endDate,
        Person person);


    // ONLY FOR JMX

    @Query(
        "select count(x) from Application x where x.status = ?1 and ((x.startDate between ?2 and ?3) or (x.endDate between ?2 and ?3)) "
        + "order by x.startDate"
    )
    long countApplicationsInStateAndYear(ApplicationStatus state, Date firstDayOfYear, Date lastDayOfYear);


    @Query(
        "select x from Application x where x.status = ?1 and ((x.startDate between ?2 and ?3) or (x.endDate between ?2 and ?3)) "
        + "order by x.startDate"
    )
    List<Application> getApplicationsByStateAndYear(ApplicationStatus state, Date firstDayOfYear, Date lastDayOfYear);
}
{'fraction_non_alphanumeric': 0.11311102690413036, 'fraction_numerical': 0.014967790829859795, 'mean_word_length': 3.2211115553778487, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4673663', 'n_tokens_mistral': 3367, 'n_tokens_neox': 3262, 'n_words': 980}