<commit_before>package utils;

import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import java.util.List;

public class SimpleQuery<T> {
    private EntityManager em;
    private CriteriaBuilder builder;
    private CriteriaQuery<T> query;
    private Root<T> from;

    public SimpleQuery(EntityManager em, Class<T> model) {
        this.em = em;
        builder = em.getCriteriaBuilder();
        query = builder.createQuery(model);
        from = query.from(model);

        query = query.select(from);
    }

    public SimpleQuery<T> orderByAsc(String field) {
        query = query.orderBy(builder.asc(from.get(field)));
        return this;
    }

    public SimpleQuery<T> orderByDesc(String field) {
        query = query.orderBy(builder.desc(from.get(field)));
        return this;
    }

    public List<T> getResultList() {
        return em.createQuery(query).getResultList();
    }
}
<commit_msg>Where statement for SimpleQuery<commit_after>package utils;

import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import javax.persistence.metamodel.SingularAttribute;
import java.util.List;

public class SimpleQuery<T> {
    private EntityManager em;
    private CriteriaBuilder builder;
    private CriteriaQuery<T> query;
    private Root<T> from;

    public SimpleQuery(EntityManager em, Class<T> model) {
        this.em = em;
        builder = em.getCriteriaBuilder();
        query = builder.createQuery(model);
        from = query.from(model);

        query = query.select(from);
    }

    public SimpleQuery<T> orderByAsc(String field) {
        query = query.orderBy(builder.asc(from.get(field)));
        return this;
    }

    public SimpleQuery<T> orderByDesc(String field) {
        query = query.orderBy(builder.desc(from.get(field)));
        return this;
    }

    public SimpleQuery<T> where(String attribute, Object value) {
        query = query.where(builder.equal(from.get(attribute), value));
        return this;
    }

    public List<T> getResultList() {
        return em.createQuery(query).getResultList();
    }
}

{'fraction_non_alphanumeric': 0.10803802938634399, 'fraction_numerical': 0.0, 'mean_word_length': 3.3433395872420264, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '7360054', 'n_tokens_mistral': 666, 'n_tokens_neox': 662, 'n_words': 142}