package com.capgemini.reports.database.manager;

import com.capgemini.reports.database.javabean.DbCriteria;
import com.capgemini.reports.database.javabean.enumeration.ReportCriteriaEnum;
import org.hibernate.Session;

/** Hibernate manager for DBCriteria JAVA bean. **/
public class MngCriteria extends AbstractHibernateManager<DbCriteria> {

    @Override
    public Class<DbCriteria> getManagedClass() {
        return DbCriteria.class;
    }

    /**
     * Create a new persistent object for criteria.
     */
    public DbCriteria insert(Session session, final ReportCriteriaEnum aCriteriaName, final String aType) {
        DbCriteria theCriteria = new DbCriteria();
        // Set specific attribute values
        theCriteria.setCriteriaName(aCriteriaName.toString());
        theCriteria.setCriteriaType(aType);

        // Persist object
        session.save(theCriteria);
        return theCriteria;
    }

    /**
     * Search query for retrieving Criteria using its name.
     */
    DbCriteria searchByName(Session session, final String aName) {
        return searchBy(session, "criteriaName", aName);
    }
}
