Example usage for org.hibernate Query setBoolean

List of usage examples for org.hibernate Query setBoolean

Introduction

In this page you can find the example usage for org.hibernate Query setBoolean.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setBoolean(String name, boolean val) 

Source Link

Document

Bind a named boolean-valued parameter.

Usage

From source file:org.sakaiproject.tool.assessment.facade.PublishedAssessmentFacadeQueries.java

License:Educational Community License

public List getNumberOfSubmissionsOfAllAssessmentsByAgent(final String agentId) {
    final String query = "select new AssessmentGradingData(" + " a.publishedAssessmentId, count(a)) "
            + " from AssessmentGradingData as a where a.agentId=? and a.forGrade=?"
            + " group by a.publishedAssessmentId";

    final HibernateCallback hcb = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery(query);
            q.setString(0, agentId);/* www. j av  a  2 s  . co  m*/
            q.setBoolean(1, true);
            return q.list();
        };
    };
    return getHibernateTemplate().executeFind(hcb);
}

From source file:org.sakaiproject.tool.assessment.facade.PublishedAssessmentFacadeQueries.java

License:Educational Community License

public List getNumberOfSubmissionsOfAllAssessmentsByAgent(final String agentId, final String siteId) {

    final ArrayList groupIds = getSiteGroupIdsForSubmittingAgent(agentId, siteId);

    if (groupIds.size() > 0) {
        final String query = "select new AssessmentGradingData(" + " a.publishedAssessmentId, count(a)) "
                + " from AssessmentGradingData as a, AuthorizationData as az "
                + " where a.agentId=:agentId and a.forGrade=:forGrade "
                + " and (az.agentIdString=:siteId or az.agentIdString in (:groupIds)) "
                + " and az.functionId=:functionId and az.qualifierId=a.publishedAssessmentId"
                + " group by a.publishedAssessmentId";

        final HibernateCallback hcb = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query q = session.createQuery(query);
                q.setString("agentId", agentId);
                q.setBoolean("forGrade", true);
                q.setString("siteId", siteId);
                q.setParameterList("groupIds", groupIds);
                q.setString("functionId", "TAKE_PUBLISHED_ASSESSMENT");
                return q.list();
            };/*from  w  ww.  ja  v a  2 s .  c  om*/
        };
        return getHibernateTemplate().executeFind(hcb);
    } else {
        final String query = "select new AssessmentGradingData(" + " a.publishedAssessmentId, count(a)) "
                + " from AssessmentGradingData as a, AuthorizationData as az "
                + " where a.agentId=:agentId and a.forGrade=:forGrade " + " and az.agentIdString=:siteId "
                + " and az.functionId=:functionId and az.qualifierId=a.publishedAssessmentId"
                + " group by a.publishedAssessmentId";

        final HibernateCallback hcb = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query q = session.createQuery(query);
                q.setString("agentId", agentId);
                q.setBoolean("forGrade", true);
                q.setString("siteId", siteId);
                q.setString("functionId", "TAKE_PUBLISHED_ASSESSMENT");
                return q.list();
            };
        };
        return getHibernateTemplate().executeFind(hcb);
    }
}

From source file:org.sakaiproject.tool.assessment.facade.PublishedAssessmentFacadeQueries.java

License:Educational Community License

/**
 * return an array list of the last AssessmentGradingFacade per assessment
 * that a user has submitted for grade./*from  w  w  w .  java2 s.c om*/
 * 
 * @param agentId
 * @param orderBy
 * @param ascending
 * @return
 */
public ArrayList getBasicInfoOfLastSubmittedAssessments(final String agentId, String orderBy,
        boolean ascending) {
    // 1. get total no. of submission per assessment by the given agent
    // HashMap h = getTotalSubmissionPerAssessment(agentId);
    final String query = "select new AssessmentGradingData("
            + " a.assessmentGradingId, p.publishedAssessmentId, p.title, a.agentId,"
            + " a.submittedDate, a.isLate,"
            + " a.forGrade, a.totalAutoScore, a.totalOverrideScore,a.finalScore,"
            + " a.comments, a.status, a.gradedBy, a.gradedDate, a.attemptDate," + " a.timeElapsed) "
            + " from AssessmentGradingData a, PublishedAssessmentData p"
            + " where a.publishedAssessmentId = p.publishedAssessmentId  and a.forGrade=? and a.agentId=?"
            + " order by p.publishedAssessmentId DESC, a.submittedDate DESC";

    /*
     * The sorting for each type will be done in the action listener. if
     * (orderBy.equals(TITLE)) { query += ", p." + orderBy; } else if
     * (!orderBy.equals(SUBMITTED)) { query += ", a." + orderBy; } if
     * (!orderBy.equals(SUBMITTED)) { if (ascending == false) { query += "
     * desc"; } else { query += " asc"; } }
     */

    final HibernateCallback hcb = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery(query);
            q.setBoolean(0, true);
            q.setString(1, agentId);
            return q.list();
        };
    };
    List list = getHibernateTemplate().executeFind(hcb);

    // ArrayList list = (ArrayList) getHibernateTemplate().find(query,
    // new Object[] {agentId}
    // ,
    // new org.hibernate.type.Type[] {Hibernate.STRING});

    ArrayList assessmentList = new ArrayList();
    Long current = new Long("0");
    // Date currentDate = new Date();
    for (int i = 0; i < list.size(); i++) {
        AssessmentGradingData a = (AssessmentGradingData) list.get(i);
        // criteria: only want the most recently submitted assessment from a
        // given user.
        if (!a.getPublishedAssessmentId().equals(current)) {
            current = a.getPublishedAssessmentId();
            AssessmentGradingData f = a;
            assessmentList.add(f);
        }
    }
    return assessmentList;
}

From source file:org.sakaiproject.tool.assessment.facade.PublishedAssessmentFacadeQueries.java

License:Educational Community License

/**
 * Get submission number for the assessment by giving the publishedAssessmentId
 * for assessment deletion safe check// w  w  w. j a  v  a 2s .com
 * @param publishedAssessmentId
 * @return number of submissions
 */
public Integer getTotalSubmissionForEachAssessment(final Long publishedAssessmentId) {
    final String query = "select count(a) from AssessmentGradingData a where a.forGrade=? "
            + " and a.publishedAssessmentId=?";

    final HibernateCallback hcb = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery(query);
            q.setBoolean(0, true);
            q.setLong(1, publishedAssessmentId.longValue());
            return q.list();
        };
    };
    List l = getHibernateTemplate().executeFind(hcb);

    return (Integer) l.get(0);
}

From source file:org.sakaiproject.tool.assessment.facade.PublishedAssessmentFacadeQueries.java

License:Educational Community License

public Integer getTotalSubmission(final String agentId, final Long publishedAssessmentId) {
    final String query = "select count(a) from AssessmentGradingData a where a.forGrade=? "
            + " and a.agentId=? and a.publishedAssessmentId=?";

    final HibernateCallback hcb = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery(query);
            q.setBoolean(0, true);
            q.setString(1, agentId);//from  w  ww.  j av a 2s . c  om
            q.setLong(2, publishedAssessmentId.longValue());
            return q.list();
        };
    };
    List l = getHibernateTemplate().executeFind(hcb);

    // List l = getHibernateTemplate().find(query,
    // new Object[] {agentId,
    // publishedAssessmentId}
    // ,
    // new org.hibernate.type.Type[] {
    // Hibernate.STRING, Hibernate.LONG});
    return (Integer) l.get(0);
}

From source file:org.sakaiproject.tool.assessment.facade.PublishedAssessmentFacadeQueries.java

License:Educational Community License

/**
 * return an array list of the AssessmentGradingData that a user has
 * submitted for grade. one per published assessment, when allAssessments is false,
 * and all submissions per published assessment when allAssesments is true. 
 * If an assessment allows multiple submissions and its grading option is to send highest,
 * then return only the submission with highest finalScore. If an assessment
 * allows multiple submissions and its grading option is to send last, then
 * return only the last submission./*  w  ww  .ja v  a 2 s  . c o  m*/
 * 
 * @param agentId
 * @param siteId
 * @param allAssessments
 * @return
 */
public ArrayList getBasicInfoOfLastOrHighestOrAverageSubmittedAssessmentsByScoringOption(final String agentId,
        final String siteId, boolean allAssessments) {

    // take account of group release
    final ArrayList<String> groupIds = getSiteGroupIdsForSubmittingAgent(agentId, siteId);
    // sorted by submittedData DESC
    final String order_last = " order by p.publishedAssessmentId DESC, a.submittedDate DESC";
    // sorted by finalScore DESC
    final String order_highest = " order by p.publishedAssessmentId DESC, a.finalScore DESC, a.submittedDate DESC";

    List last_list;
    List highest_list;

    // Get total no. of submission per assessment by the given agent
    if (groupIds.size() > 0) {
        final String hql = "select distinct new AssessmentGradingData("
                + " a.assessmentGradingId, p.publishedAssessmentId, p.title, a.agentId,"
                + " a.submittedDate, a.isLate,"
                + " a.forGrade, a.totalAutoScore, a.totalOverrideScore,a.finalScore,"
                + " a.comments, a.status, a.gradedBy, a.gradedDate, a.attemptDate," + " a.timeElapsed) "
                + " from AssessmentGradingData a, PublishedAssessmentData p, AuthorizationData az"
                + " where a.publishedAssessmentId = p.publishedAssessmentId"
                + " and a.forGrade=:forGrade and a.agentId=:agentId"
                + " and (az.agentIdString=:siteId or az.agentIdString in (:groupIds)) "
                + " and az.functionId=:functionId and az.qualifierId=p.publishedAssessmentId"
                + " and (p.status=:activeStatus or p.status=:editStatus) ";

        final HibernateCallback hcb_last = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query q = session.createQuery(hql + order_last);
                q.setBoolean("forGrade", true);
                q.setString("agentId", agentId);
                q.setString("siteId", siteId);
                q.setParameterList("groupIds", groupIds);
                q.setString("functionId", "TAKE_PUBLISHED_ASSESSMENT");
                q.setInteger("activeStatus", 1);
                q.setInteger("editStatus", 3);
                return q.list();
            };
        };

        // this list is sorted by submittedDate desc.
        last_list = getHibernateTemplate().executeFind(hcb_last);

        final HibernateCallback hcb_highest = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query q = session.createQuery(hql + order_highest);
                q.setBoolean("forGrade", true);
                q.setString("agentId", agentId);
                q.setString("siteId", siteId);
                q.setParameterList("groupIds", groupIds);
                q.setString("functionId", "TAKE_PUBLISHED_ASSESSMENT");
                q.setInteger("activeStatus", 1);
                q.setInteger("editStatus", 3);
                return q.list();
            };
        };

        // this list is sorted by finalScore desc.

        highest_list = getHibernateTemplate().executeFind(hcb_highest);
    } else {
        final String hql = "select new AssessmentGradingData("
                + " a.assessmentGradingId, p.publishedAssessmentId, p.title, a.agentId,"
                + " a.submittedDate, a.isLate,"
                + " a.forGrade, a.totalAutoScore, a.totalOverrideScore,a.finalScore,"
                + " a.comments, a.status, a.gradedBy, a.gradedDate, a.attemptDate," + " a.timeElapsed) "
                + " from AssessmentGradingData a, PublishedAssessmentData p, AuthorizationData az"
                + " where a.publishedAssessmentId = p.publishedAssessmentId"
                + " and a.forGrade=:forGrade and a.agentId=:agentId" + " and az.agentIdString=:siteId "
                + " and az.functionId=:functionId and az.qualifierId=p.publishedAssessmentId"
                + " order by p.publishedAssessmentId DESC, a.submittedDate DESC";

        final HibernateCallback hcb_last = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query q = session.createQuery(hql + order_last);
                q.setBoolean("forGrade", true);
                q.setString("agentId", agentId);
                q.setString("siteId", siteId);
                q.setString("functionId", "TAKE_PUBLISHED_ASSESSMENT");
                return q.list();
            };
        };

        // this list is sorted by submittedDate desc.
        last_list = getHibernateTemplate().executeFind(hcb_last);

        final HibernateCallback hcb_highest = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query q = session.createQuery(hql + order_highest);
                q.setBoolean("forGrade", true);
                q.setString("agentId", agentId);
                q.setString("siteId", siteId);
                q.setString("functionId", "TAKE_PUBLISHED_ASSESSMENT");
                return q.list();
            };
        };

        // this list is sorted by finalScore desc.
        highest_list = getHibernateTemplate().executeFind(hcb_highest);
    }

    //getEvaluationModel();
    final String query = "select e.assessment.publishedAssessmentId, e.scoringType, ac.submissionsAllowed  "
            + "from PublishedEvaluationModel e, PublishedAccessControl ac, AuthorizationData az "
            + "where e.assessment.publishedAssessmentId = ac.assessment.publishedAssessmentId "
            + "and az.qualifierId = ac.assessment.publishedAssessmentId and az.agentIdString in (:agentIdString) and az.functionId=:functionId";

    groupIds.add(siteId);

    final HibernateCallback eval_model = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery(query);
            q.setParameterList("agentIdString", groupIds);
            q.setString("functionId", "TAKE_PUBLISHED_ASSESSMENT");
            return q.list();
        };
    };

    List l = getHibernateTemplate().executeFind(eval_model);
    HashMap scoringTypeMap = new HashMap();
    Iterator iter = l.iterator();
    while (iter.hasNext()) {
        Object o[] = (Object[]) iter.next();
        scoringTypeMap.put(o[0], o[1]);
    }

    // The sorting for each column will be done in the action listener.
    ArrayList assessmentList = new ArrayList();
    Long currentid = new Long("0");
    Integer scoringOption = EvaluationModelIfc.LAST_SCORE; // use Last as

    // now go through the last_list, and get the first entry in the list for
    // each publishedAssessment, if
    // not

    for (int i = 0; i < last_list.size(); i++) {
        AssessmentGradingData a = (AssessmentGradingData) last_list.get(i);

        // get the scoring option
        if (scoringTypeMap.get(a.getPublishedAssessmentId()) != null) {
            scoringOption = (Integer) scoringTypeMap.get(a.getPublishedAssessmentId());
        } else {
            // I use Last as default because it is what set above
            scoringOption = EvaluationModelIfc.LAST_SCORE;
        }

        if (EvaluationModelIfc.LAST_SCORE.equals(scoringOption)) {
            if (!a.getPublishedAssessmentId().equals(currentid) || allAssessments) {

                if (!a.getPublishedAssessmentId().equals(currentid)) {
                    a.setIsRecorded(true);
                }
                assessmentList.add(a);
                currentid = a.getPublishedAssessmentId();
            }
        }
    }

    // now go through the highest_list ,and get the first entry in the list
    // for each publishedAssessment.

    currentid = 0L;
    for (int i = 0; i < highest_list.size(); i++) {
        AssessmentGradingData a = (AssessmentGradingData) highest_list.get(i);

        // get the scoring option
        if (scoringTypeMap.get(a.getPublishedAssessmentId()) != null) {
            scoringOption = (Integer) scoringTypeMap.get(a.getPublishedAssessmentId());
        } else {
            // I use Last as default because it is what set above
            scoringOption = EvaluationModelIfc.LAST_SCORE;
        }

        if (EvaluationModelIfc.HIGHEST_SCORE.equals(scoringOption)) {
            if (!a.getPublishedAssessmentId().equals(currentid) || allAssessments) {

                if (!a.getPublishedAssessmentId().equals(currentid)) {
                    a.setIsRecorded(true);
                }
                assessmentList.add(a);
                currentid = a.getPublishedAssessmentId();
            }
        }

        if (EvaluationModelIfc.AVERAGE_SCORE.equals(scoringOption)) {

            assessmentList.add(a);
        }

    }

    return assessmentList;
}

From source file:org.sakaiproject.tool.assessment.facade.PublishedAssessmentFacadeQueries.java

License:Educational Community License

public List getAllAssessmentsGradingDataByAgentAndSiteId(final String agentId, final String siteId) {
    final String query = "select a " + " from AssessmentGradingData as a, AuthorizationData as az "
            + " where a.agentId=:agentId and a.forGrade=:forGrade " + " and az.agentIdString=:siteId "
            + " and az.functionId=:functionId and az.qualifierId=a.publishedAssessmentId";

    final HibernateCallback hcb = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery(query);
            q.setString("agentId", agentId);
            q.setBoolean("forGrade", true);
            q.setString("siteId", siteId);
            q.setString("functionId", "OWN_PUBLISHED_ASSESSMENT");
            return q.list();
        };//from   w ww  . j  ava 2 s. c  o  m
    };
    return getHibernateTemplate().executeFind(hcb);
}

From source file:org.unitime.timetable.model.TimePattern.java

License:Open Source License

public static List<TimePattern> findAll(Long sessionId, Boolean visible) {
    String query = "from TimePattern tp " + "where tp.session.uniqueId=:sessionId";
    if (visible != null)
        query += " and visible=:visible";

    org.hibernate.Session hibSession = new TimePatternDAO().getSession();
    Query q = hibSession.createQuery(query);
    q.setCacheable(true);//from w ww.  jav  a  2s.  c  o m
    q.setLong("sessionId", sessionId.longValue());
    if (visible != null)
        q.setBoolean("visible", visible.booleanValue());

    List<TimePattern> v = q.list();
    Collections.sort(v);
    return v;
}

From source file:org.webcurator.domain.ProfileDAOImpl.java

License:Apache License

/**
 * Get available profiles.//from ww  w  .ja v  a 2  s. c o m
 */
@SuppressWarnings("unchecked")
public List<ProfileDTO> getAvailableProfiles(final Agency anAgency, final int level,
        final Long currentProfileOid) {
    return (List<ProfileDTO>) getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session aSession) throws HibernateException, SQLException {
            Query query = aSession.getNamedQuery(Profile.QRY_GET_AVAIL_DTOS);
            query.setLong("agencyOid", anAgency.getOid());
            query.setInteger("requiredLevel", level);
            query.setBoolean("default", true);
            query.setLong("currentProfileOid", currentProfileOid);
            return query.list();
        }
    });
}

From source file:org.yamj.core.database.dao.StagingDao.java

License:Open Source License

public List<VideoData> findVideoDatas(String baseName, StageDirectory stageDirectory) {
    if (stageDirectory == null) {
        return Collections.emptyList();
    }//from  w ww  . j  ava  2  s.  c  o m

    StringBuilder sb = new StringBuilder();
    sb.append("SELECT distinct vd ");
    sb.append("FROM VideoData vd ");
    sb.append("JOIN vd.mediaFiles mf ");
    sb.append("JOIN mf.stageFiles sf ");
    sb.append("WHERE sf.fileType=:fileType ");
    sb.append("AND mf.extra=:extra ");
    if (baseName != null) {
        sb.append("AND lower(sf.baseName)=:baseName ");
    }
    sb.append("AND sf.stageDirectory=:stageDirectory ");
    sb.append("AND sf.status != :deleted ");

    Query query = currentSession().createQuery(sb.toString());
    query.setParameter("fileType", FileType.VIDEO);
    query.setBoolean("extra", Boolean.FALSE);
    if (baseName != null) {
        query.setString("baseName", baseName.toLowerCase());
    }
    query.setParameter("stageDirectory", stageDirectory);
    query.setParameter("deleted", StatusType.DELETED);
    query.setCacheable(true);
    query.setCacheMode(CacheMode.NORMAL);
    return query.list();
}