<commit_before>/**
 * $Id$
 * $URL$
 * EvaluationDaoImpl.java - evaluation - Aug 21, 2006 12:07:31 AM - azeckoski
 **************************************************************************
 * Copyright (c) 2008 Centre for Applied Research in Educational Technologies, University of Cambridge
 * Licensed under the Educational Community License version 1.0
 * 
 * A copy of the Educational Community License has been included in this 
 * distribution and is available at: http://www.opensource.org/licenses/ecl1.php
 *
 * <NAME> (<EMAIL>) (<EMAIL>) (<EMAIL>)
 */

package org.sakaiproject.evaluation.dao;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import org.sakaiproject.evaluation.constant.EvalConstants;
import org.sakaiproject.evaluation.logic.EvalEvaluationService;
import org.sakaiproject.evaluation.model.EvalAdhocGroup;
import org.sakaiproject.evaluation.model.EvalAnswer;
import org.sakaiproject.evaluation.model.EvalAssignGroup;
import org.sakaiproject.evaluation.model.EvalAssignUser;
import org.sakaiproject.evaluation.model.EvalEvaluation;
import org.sakaiproject.evaluation.model.EvalItem;
import org.sakaiproject.evaluation.model.EvalItemGroup;
import org.sakaiproject.evaluation.model.EvalLock;
import org.sakaiproject.evaluation.model.EvalResponse;
import org.sakaiproject.evaluation.model.EvalScale;
import org.sakaiproject.evaluation.model.EvalTemplate;
import org.sakaiproject.evaluation.model.EvalTemplateItem;
import org.sakaiproject.evaluation.utils.ArrayUtils;
import org.sakaiproject.evaluation.utils.ComparatorsUtils;
import org.sakaiproject.evaluation.utils.EvalUtils;
import org.sakaiproject.genericdao.api.search.Restriction;
import org.sakaiproject.genericdao.api.search.Search;
import org.sakaiproject.genericdao.hibernate.HibernateGeneralGenericDao;

/**
 * This is the more specific Evaluation data access interface,
 * it should contain specific DAO methods, the generic ones
 * are included from the GenericDao already<br/>
 * This is now isolated to the logic layer only to ensure there is no access from the outside<br/>
 * <br/>
 * <b>LOCKING methods note:</b><br/>
 * The locking logic is designed to make it easier to know if an entity should or should not be changed or removed<br/> 
 * Locked entities can never be removed via the APIs and should not be removed with direct access to the DB<br/>
 * Locking handled as indicated here:<br/>
 * http://bugs.sakaiproject.org/confluence/display/EVALSYS/Evaluation+Implementation<br/>
 * <br/>
 * This is a BOTTOM level service and should depend on no other services
 * 
 * @author <NAME> (<EMAIL>)
 */
public class EvaluationDaoImpl extends HibernateGeneralGenericDao implements EvaluationDao {

    private static Log log = LogFactory.getLog(EvaluationDaoImpl.class);

    public void init() {
        log.debug("init");
    }

    /* (non-Javadoc)
     * @see org.sakaiproject.evaluation.dao.EvaluationDao#forceCommit()
     */
    public void forceCommit() {
        getSession().getTransaction().commit();
    }

    /* (non-Javadoc)
     * @see org.sakaiproject.evaluation.dao.EvaluationDao#forceRollback()
     */
    public void forceRollback() {
        getSession().getTransaction().rollback();
    }

    public void fixupDatabase() {
        // fix up some of the null fields
        long count = 0;
        count = countBySearch(EvalEvaluation.class, new Search("studentViewResults","", Restriction.NULL) );
        if (count > 0) {<commit_msg>EVALSYS-916 Fixed up the status handling code some more, adjustments<commit_after>/**
 * $Id$
 * $URL$
 * EvaluationDaoImpl.java - evaluation - Aug 21, 2006 12:07:31 AM - azeckoski
 **************************************************************************
 * Copyright (c) 2008 Centre for Applied Research in Educational Technologies, University of Cambridge
 * Licensed under the Educational Community License version 1.0
 * 
 * A copy of the Educational Community License has been included in this 
 * distribution and is available at: http://www.opensource.org/licenses/ecl1.php
 *
 * <NAME> (<EMAIL>) (<EMAIL>) (<EMAIL>)
 */

package org.sakaiproject.evaluation.dao;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import org.sakaiproject.evaluation.constant.EvalConstants;
import org.sakaiproject.evaluation.logic.EvalEvaluationService;
import org.sakaiproject.evaluation.model.EvalAdhocGroup;
import org.sakaiproject.evaluation.model.EvalAnswer;
import org.sakaiproject.evaluation.model.EvalAssignGroup;
import org.sakaiproject.evaluation.model.EvalAssignUser;
import org.sakaiproject.evaluation.model.EvalEvaluation;
import org.sakaiproject.evaluation.model.EvalItem;
import org.sakaiproject.evaluation.model.EvalItemGroup;
import org.sakaiproject.evaluation.model.EvalLock;
import org.sakaiproject.evaluation.model.EvalResponse;
import org.sakaiproject.evaluation.model.EvalScale;
import org.sakaiproject.evaluation.model.EvalTemplate;
import org.sakaiproject.evaluation.model.EvalTemplateItem;
import org.sakaiproject.evaluation.utils.ArrayUtils;
import org.sakaiproject.evaluation.utils.ComparatorsUtils;
import org.sakaiproject.evaluation.utils.EvalUtils;
import org.sakaiproject.genericdao.api.search.Restriction;
import org.sakaiproject.genericdao.api.search.Search;
import org.sakaiproject.genericdao.hibernate.HibernateGeneralGenericDao;
import org.springframework.dao.DataAccessResourceFailureException;

/**
 * This is the more specific Evaluation data access interface,
 * it should contain specific DAO methods, the generic ones
 * are included from the GenericDao already<br/>
 * This is now isolated to the logic layer only to ensure there is no access from the outside<br/>
 * <br/>
 * <b>LOCKING methods note:</b><br/>
 * The locking logic is designed to make it easier to know if an entity should or should not be changed or removed<br/> 
 * Locked entities can never be removed via the APIs and should not be removed with direct access to the DB<br/>
 * Locking handled as indicated here:<br/>
 * http://bugs.sakaiproject.org/confluence/display/EVALSYS/Evaluation+Implementation<br/>
 * <br/>
 * This is a BOTTOM level service and should depend on no other services
 * 
 * @author <NAME> (<EMAIL>)
 */
public class EvaluationDaoImpl extends HibernateGeneralGenericDao implements EvaluationDao {

    private static Log log = LogFactory.getLog(EvaluationDaoImpl.class);

    public void init() {
        log.debug("init");
    }

    /* (non-Javadoc)
     * @see org.sakaiproject.evaluation.dao.EvaluationDao#forceCommit()
     */
    public void forceCommit() {
        try {
            if (! getSession().getTransaction().isActive()) {
                getSession().getTransaction().begin();
            }
            getSession().getTransaction().commit();
        } catch (Exception e) {
            log.warn("unable to commit transaction: "+e,e);
        }
    }

    /* (non-Javadoc)
     * @see org.sakaiproject.evaluation.dao.EvaluationDao#forceRollback()
     */
    public void forceRollback() {
        try {
            getSession().getTransaction().rollback();
        } catch (Exception e) {
            log.warn("unable to rollback transaction: "+e,e);
        }
    }

    public void fixupDatabase() {
        // fix up some of the null fields
        long count = 0;
        count = countBySearch(EvalEvaluation.class, new Search("studentViewResults","", Restriction.NULL) );
        if (count > 0) {
{'fraction_non_alphanumeric': 0.11791569086651053, 'fraction_numerical': 0.005269320843091335, 'mean_word_length': 4.475, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6079373', 'n_tokens_mistral': 2613, 'n_tokens_neox': 2432, 'n_words': 622}