<commit_before>package com.saviour.poweryoga.crudfacade;

import com.saviour.poweryoga.model.Faculty;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.persistence.EntityExistsException;
import javax.persistence.PersistenceException;
import javax.persistence.TransactionRequiredException;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;

/**
 * CRUD facade
 *
 * @author TalakB
 * @version 0.0.1
 */
@Component
public class CRUDFacadeImpl<T> extends CRUDEntityFacade<T> {

    //  private transient final Class entityClass;
    @Resource(name = "sessionFactory")
    private SessionFactory sessionFactory;

    private boolean operationSuccessful;

    /**
     *
     * @param entity
     * @return
     * @throws EntityExistsException
     * @throws IllegalStateException
     * @throws IllegalArgumentException
     * @throws TransactionRequiredException
     */
    @Override
    public T create(T entity) throws EntityExistsException,
            IllegalStateException, IllegalArgumentException,
            TransactionRequiredException {
        try {
            sessionFactory.getCurrentSession().persist(entity);
            // manager.flush();
            return entity;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    /**
     *
     * @param primaryKey
     * @return
     * @throws IllegalStateException
     * @throws IllegalArgumentException
     */
    @Override
    public T read(final Serializable primaryKey, Class entClass) throws IllegalStateException,
            IllegalArgumentException {
        return (T) sessionFactory.getCurrentSession().get(entClass, primaryKey);
    }

    /**
     *
     * @param entity
     * @return
     * @throws IllegalStateException
     * @throws IllegalArgumentException
     * @throws TransactionRequiredException
     */
    @Override
    public boolean update(final T entity) throws IllegalStateException,
            IllegalArgumentException, TransactionRequiredException {
        try {
            sessionFactory.getCurrentSession().update(entity);
            operationSuccessful = true;
        } catch (Exception ex) {

        }
        return operationSuccessful;
    }

    /**
     *
     * @param entity
     * @return
     * @throws IllegalStateException
     * @throws IllegalArgumentException
     * @throws TransactionRequiredException
     * @throws PersistenceException
     */
    @Override
    public boolean delete(final T entity) throws IllegalStateException,
            IllegalArgumentException, TransactionRequiredException,
            PersistenceException {
        try {
            sessionFactory.getCurrentSession().delete(entity);
            operationSuccessful = true;
        } catch (Exception ex) {

        }
        return operationSuccessful;

    }

    /**
     * named query without parameter
     *
     * @param queryName
     * @return
     */
    @Override
    public List findWithNamedQuery(String queryName) {
        Query query = sessionFactory.openSession().getNamedQuery(queryName);
        return query.list();
    }

    /**
     * named query with limited number of results
     *
     * @param queryName
     * @param resultLimit
     * @return
     */
    @Override
    public List findWithNamedQuery(String queryName, int resultLimit) {
        Query query = sessionFactory.openSession().getNamedQuery(queryName);
        return query.list();
    }

    /**
     * named query with parameters
     *
     * @param namedQueryName
     * @param parameters
     * @return
     */
    @Override
    public List findWithNamedQuery(String namedQueryName, Map<String, String> parameters) {
        //  Set parameters = parameters.entrySet();
        Query query = sessionFactory.openSession().getNamedQuery(namedQueryName);

        for (Map.Entry<String, String> entry : parameters.entrySet()) {
            query.setParameter(entry.getKey(), entry.getValue());
        }

        return query.list();
    }

    /**
     * named query with parameters and limited number of results
     *
     * @param namedQueryName
     * @param parameters
     * @param resultLimit
     * @return
     */
    @Override
    public List findWithNamedQuery(String namedQueryName, Map<String, String> parameters, int resultLimit) {
        try {
            Query query = sessionFactory.openSession().getNamedQuery(namedQueryName);

            for (Map.Entry<String, String> entry : parameters.entrySet()) {
                query.setParameter(entry.getKey(), entry.getValue());
            }

            return query.list().subList(0, resultLimit - 1);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    @Override
    public Object findWithNativeQuery(String nativeQuery) {
        try {
            Query query = sessionFactory.openSession().createSQLQuery(nativeQuery);
            Object result = query.uniqueResult();

            return result;
        } catch (HibernateException hibernateException) {
            hibernateException.printStackTrace();
            return null;
        }

    }

}<commit_msg>Modifications on CRUDFacade try...catch results.<commit_after>package com.saviour.poweryoga.crudfacade;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.persistence.EntityExistsException;
import javax.persistence.PersistenceException;
import javax.persistence.TransactionRequiredException;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;

/**
 * CRUD facade
 *
 * @author TalakB
 * @version 0.0.1
 */
@Component
public class CRUDFacadeImpl<T> extends CRUDEntityFacade<T> {

    //  private transient final Class entityClass;
    @Resource(name = "sessionFactory")
    private SessionFactory sessionFactory;

    private boolean operationSuccessful;

    /**
     * Persist an entity.
     *
     * @param entity
     * @return
     * @throws EntityExistsException
     * @throws IllegalStateException
     * @throws IllegalArgumentException
     * @throws TransactionRequiredException
     */
    @Override
    public T create(T entity) throws EntityExistsException,
            IllegalStateException, IllegalArgumentException,
            TransactionRequiredException {
        try {
            sessionFactory.getCurrentSession().persist(entity);
            return entity;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    /**
     * Find by Id (Primary key).
     *
     * @param primaryKey
     * @return
     * @throws IllegalStateException
     * @throws IllegalArgumentException
     */
    @Override
    public T read(final Serializable primaryKey, Class entClass) throws IllegalStateException,
            IllegalArgumentException {
        try {
            return (T) sessionFactory.getCurrentSession().get(entClass, primaryKey);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;

        }
    }

    /**
     * Update an entity.
     *
     * @param entity
     * @return
     * @throws IllegalStateException
     * @throws IllegalArgumentException
     * @throws TransactionRequiredException
     */
    @Override
    public boolean update(final T entity) throws IllegalStateException,
            IllegalArgumentException, TransactionRequiredException {
        try {
            sessionFactory.getCurrentSession().update(entity);
            operationSuccessful = true;
        } catch (Exception ex) {
            ex.printStackTrace();
            operationSuccessful = false;

        }
        return operationSuccessful;
    }

    /**
     * Delete an entity.
     *
     * @param entity
     * @return
     * @throws IllegalStateException
     * @throws IllegalArgumentException
     * @throws TransactionRequiredException
     * @throws PersistenceException
     */
    @Override
    public boolean delete(final T entity) throws IllegalStateException,
            IllegalArgumentException, TransactionRequiredException,
            PersistenceException {
        try {
            sessionFactory.getCurrentSession().delete(entity);
            operationSuccessful = true;
        } catch (Exception ex) {
            ex.printStackTrace();
            operationSuccessful = false;

        }
        return operationSuccessful;

    }

    /**
     * Named query without parameter
     *
     * @param queryName
     * @return
     */
    @Override
    public List findWithNamedQuery(String queryName) {
        try {
            Query query = sessionFactory.openSession().getNamedQuery(queryName);
            List qResult = query.list();
            if (!qResult.isEmpty()) {
                return qResult;
            } else {
                return null;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    /**
     * Named query with limited number of results
     *
     * @param queryName
     * @param resultLimit
     * @return
     */
    @Override
    public List findWithNamedQuery(String queryName, int resultLimit) {
        try {
            Query query = sessionFactory.openSession().getNamedQuery(queryName);
            List qResult = query.list();
            if (!qResult.isEmpty()) {
                return qResult;
            } else {
                return null;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    /**
     * named query with parameters
     *
     * @param namedQueryName
     * @param parameters
     * @return
     */
    @Override
    public List findWithNamedQuery(String namedQueryName, Map<String, String> parameters) {
        try {
            //  Set parameters = parameters.entrySet();
            Query query = sessionFactory.openSession().getNamedQuery(namedQueryName);

            for (Map.Entry<String, String> entry : parameters.entrySet()) {
                query.setParameter(entry.getKey(), entry.getValue());
            }
            List qResult = query.list();
            if (!qResult.isEmpty()) {
                return qResult;
            } else {
                return null;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }

    }

    /**
     * named query with parameters and limited number of results
     *
     * @param namedQueryName
     * @param parameters
     * @param resultLimit
     * @return
     */
    @Override
    public List findWithNamedQuery(String namedQueryName, Map<String, String> parameters, int resultLimit) {
        try {
            Query query = sessionFactory.openSession().getNamedQuery(namedQueryName);

            for (Map.Entry<String, String> entry : parameters.entrySet()) {
                query.setParameter(entry.getKey(), entry.getValue());
            }
            List qResult = query.list().subList(0, resultLimit - 1);
            if (!qResult.isEmpty()) {
                return qResult;
            } else {
                return null;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    /**
     * Send native query. The result type depends on the type of query that is sent to mySQL.
     * @param nativeQuery
     * @return 
     */
    @Override
    public Object findWithNativeQuery(String nativeQuery) {
        try {
            Query query = sessionFactory.openSession().createSQLQuery(nativeQuery);
            Object result = query.uniqueResult();
            return result;
        } catch (HibernateException hibernateException) {
            hibernateException.printStackTrace();
            return null;
        }

    }

}
{'fraction_non_alphanumeric': 0.08785294361182412, 'fraction_numerical': 0.0008280202036929701, 'mean_word_length': 2.164265129682997, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7394311', 'n_tokens_mistral': 2984, 'n_tokens_neox': 2924, 'n_words': 709}