<commit_before><commit_msg>Add AbstractDao to dao<commit_after>package com.hida.dao;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * missing javadocs
 *
 * @author lruffin
 * @param <PK>
 * @param <T>
 */
public abstract class AbstractDao<PK extends Serializable, T> {

    /**
     *      
     */
    private final Class<T> persistentClass;

    /**
     * 
     */
    @SuppressWarnings("unchecked")
    public AbstractDao() {
        this.persistentClass = (Class<T>) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
    }

    /**
     * 
     */
    @Autowired
    private SessionFactory sessionFactory;

    /**
     * 
     * @return 
     */
    protected Session getSession() {
        return sessionFactory.getCurrentSession();
    }

    /**
     * 
     * @param key
     * @return 
     */
    @SuppressWarnings("unchecked")
    public T getByKey(PK key) {
        return (T) getSession().get(persistentClass, key);
    }

    /**
     * 
     * @param entity 
     */
        
    public void persist(T entity) {
        getSession().persist(entity);
    }

    /**
     * 
     * @param entity 
     */
    public void delete(T entity) {
        getSession().delete(entity);
    }

    /**
     * 
     * @return 
     */
    protected Criteria createEntityCriteria() {
        return getSession().createCriteria(persistentClass);
    }

}
{'fraction_non_alphanumeric': 0.12876884422110552, 'fraction_numerical': 0.000628140703517588, 'mean_word_length': 2.2845360824742267, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '1079699', 'n_tokens_mistral': 489, 'n_tokens_neox': 472, 'n_words': 85}