<commit_before>package com.gmail.mariska.martin.mtginventory.db;

import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Root;

import com.gmail.mariska.martin.mtginventory.db.model.CardMovement;
import com.gmail.mariska.martin.mtginventory.db.model.CardMovementType;
import com.gmail.mariska.martin.mtginventory.utils.Utils;

/**
 * Pro praci s pohyby cen karet
 * 
 * @author MAR
 * 
 */
public class CardMovementDao extends AbstractDao<CardMovement> implements IDao<CardMovement> {
    private EntityManager em;

    public CardMovementDao(EntityManager em) {
        super(CardMovement.class, em);
        this.em = em;
    }

    public List<CardMovement> getByType(CardMovementType type) {
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<CardMovement> q = cb.createQuery(CardMovement.class);
        Root<CardMovement> from = q.from(CardMovement.class);
        return em.createQuery(q.select(from)
                .where(cb.equal(from.<CardMovementType> get(CardMovement.PROPS.type.toString()), type))
                .orderBy(getDefaultOrder(cb, from)))
                .getResultList();
    }

    @Override
    public List<Order> getDefaultOrder(CriteriaBuilder cb, Root<CardMovement> from) {
        return Arrays.asList(cb.desc(from.get(CardMovement.PROPS.day.toString())),
                cb.desc(from.get(CardMovement.PROPS.gainPercentage.toString())));
    }

    /**
     * Smaze vsechny pohyby cen a vrati pocet smazanych
     * 
     * @return
     */
    public int deleteAllByType(CardMovementType type) {
        Query q = em.createQuery("DELETE FROM CardMovement cm WHERE cm.type = :cmType");
        q.setParameter("cmType", type);
        return q.executeUpdate();<commit_msg>delete movements to typed query<commit_after>package com.gmail.mariska.martin.mtginventory.db;

import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Root;

import com.gmail.mariska.martin.mtginventory.db.model.CardMovement;
import com.gmail.mariska.martin.mtginventory.db.model.CardMovementType;
import com.gmail.mariska.martin.mtginventory.utils.Utils;

/**
 * Pro praci s pohyby cen karet
 * 
 * @author MAR
 * 
 */
public class CardMovementDao extends AbstractDao<CardMovement> implements IDao<CardMovement> {
    private EntityManager em;

    public CardMovementDao(EntityManager em) {
        super(CardMovement.class, em);
        this.em = em;
    }

    public List<CardMovement> getByType(CardMovementType type) {
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<CardMovement> q = cb.createQuery(CardMovement.class);
        Root<CardMovement> from = q.from(CardMovement.class);
        return em.createQuery(q.select(from)
                .where(cb.equal(from.<CardMovementType> get(CardMovement.PROPS.type.toString()), type))
                .orderBy(getDefaultOrder(cb, from)))
                .getResultList();
    }

    @Override
    public List<Order> getDefaultOrder(CriteriaBuilder cb, Root<CardMovement> from) {
        return Arrays.asList(cb.desc(from.get(CardMovement.PROPS.day.toString())),
                cb.desc(from.get(CardMovement.PROPS.gainPercentage.toString())));
    }

    /**
     * Smaze vsechny pohyby cen a vrati pocet smazanych
     * 
     * @return
     */
    public int deleteAllByType(CardMovementType type) {
        TypedQuery<CardMovement> q = em.createQuery("DELETE FROM CardMovement cm WHERE cm.type = :cmType", CardMovement.class);
        q.setParameter("cmType", type);
        return q.executeUpdate();
{'fraction_non_alphanumeric': 0.10987684134267085, 'fraction_numerical': 0.0, 'mean_word_length': 3.6591676040494936, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '7323369', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1284, 'n_words': 226}