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.pentaho.cdf.comments.CommentsEngine.java

License:Open Source License

public JSONObject list(String page, int firstResult, int maxResults, boolean isDeleted, boolean isArchived,
        String user) throws JSONException, InvalidCdfOperationException, PluginHibernateException {
    logger.debug("Listing messages");

    if (StringUtils.isEmpty(page)) {
        logger.error("Parameter 'page' is not optional");
        throw new InvalidCdfOperationException("Page cannot be null");
    }/*from  w w  w  .ja  v  a2  s  . c o  m*/

    final String queryName;

    if (isDeleted || isArchived) {
        queryName = "getCommentsByPageWhere";
    } else {
        queryName = "getCommentsByPage"; // default query
    }

    logger.debug("Adding comment");
    Session session = getSession();

    Query query = session.getNamedQuery("org.pentaho.cdf.comments.CommentEntry." + queryName);
    query.setString("page", page);

    if (isDeleted || isArchived) {
        query.setBoolean("deleted", isDeleted);
        query.setBoolean("archived", isArchived);
    }

    query.setFirstResult(firstResult < 0 ? 0 : firstResult); // default 0
    query.setMaxResults(maxResults < 0 ? 20 : maxResults); // default 20

    // Get it and build the tree

    @SuppressWarnings("unchecked")
    List<CommentEntry> comments = query.list();

    JSONArray jsonArray = new JSONArray();
    for (CommentEntry comment : comments) {
        JSONObject commentJson = commentToJson(comment, user);
        jsonArray.put(commentJson);
    }

    return JsonUtil.makeJsonSuccessResponse(jsonArray);
}

From source file:org.sakaiproject.profile2.dao.impl.ProfileDaoImpl.java

License:Educational Community License

/**
  * {@inheritDoc}//from   w w  w  .j  a va2 s .  c  om
  */
public List<String> getRequestedConnectionUserIdsForUser(final String userId) {

    //get friends of this user [and map it automatically to the Friend object]
    //updated: now just returns a List of Strings
    HibernateCallback hcb = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {

            Query q = session.getNamedQuery(QUERY_GET_FRIEND_REQUESTS_FOR_USER);
            q.setParameter(USER_UUID, userId, Hibernate.STRING);
            q.setBoolean("false", Boolean.FALSE);
            //q.setResultTransformer(Transformers.aliasToBean(Friend.class));

            return q.list();
        }
    };

    return (List<String>) getHibernateTemplate().executeFind(hcb);
}

From source file:org.sakaiproject.profile2.dao.impl.ProfileDaoImpl.java

License:Educational Community License

/**
  * {@inheritDoc}//from   w  w w  . jav  a 2s.c o  m
  */
public List<String> getConfirmedConnectionUserIdsForUser(final String userId) {

    //get 
    HibernateCallback hcb = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {

            Query q = session.getNamedQuery(QUERY_GET_CONFIRMED_FRIEND_USERIDS_FOR_USER);
            q.setParameter(USER_UUID, userId, Hibernate.STRING);
            q.setBoolean("true", Boolean.TRUE);
            return q.list();
        }
    };

    return (List<String>) getHibernateTemplate().executeFind(hcb);
}

From source file:org.sakaiproject.profile2.dao.impl.ProfileDaoImpl.java

License:Educational Community License

/**
  * {@inheritDoc}/*from ww w  . j av a 2 s. c o m*/
  */
public int getAllUnreadMessagesCount(final String userId) {

    HibernateCallback hcb = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {

            Query q = session.getNamedQuery(QUERY_GET_ALL_UNREAD_MESSAGES_COUNT);
            q.setParameter(UUID, userId, Hibernate.STRING);
            q.setBoolean("false", Boolean.FALSE);
            return q.uniqueResult();
        }
    };

    return ((Integer) getHibernateTemplate().execute(hcb)).intValue();
}

From source file:org.sakaiproject.profile2.dao.impl.ProfileDaoImpl.java

License:Educational Community License

/**
  * {@inheritDoc}//  w  w w  .j  av  a  2 s.  c o  m
  */
public int getThreadsWithUnreadMessagesCount(final String userId) {

    HibernateCallback hcb = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {

            Query q = session.getNamedQuery(QUERY_GET_THREADS_WITH_UNREAD_MESSAGES_COUNT);
            q.setParameter(UUID, userId, Hibernate.STRING);
            q.setBoolean("false", Boolean.FALSE);
            return q.uniqueResult();
        }
    };

    return ((Integer) getHibernateTemplate().execute(hcb)).intValue();
}

From source file:org.sakaiproject.sgs2.server.GroovyShellManagerImpl.java

License:Educational Community License

@SuppressWarnings("unchecked")
public List<String> getFavorite(final String userId) {

    List<String> scriptNames = (List<String>) getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(final Session session) throws HibernateException, SQLException {
            final Query q = session.createQuery(
                    "select name from Script as S where S.userId = :userId and S.favorite = :favorite order by S.actionDate desc");
            q.setString("userId", userId);
            q.setBoolean("favorite", Boolean.TRUE);
            return q.list();
        }//  w  ww  .jav  a2  s  .c o  m
    });

    if (null == scriptNames) {
        return new ArrayList<String>();
    } else {
        return scriptNames;
    }
}

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

License:Educational Community License

public List getTotalScores(final String publishedId, String which, final boolean getSubmittedOnly) {
    try {/*from ww  w  .  j  a va  2  s.  c  o  m*/
        // sectionSet of publishedAssessment is defined as lazy loading in
        // Hibernate OR map, so we need to initialize them. Unfortunately our
        // spring-1.0.2.jar does not support HibernateTemplate.intialize(Object)
        // so we need to do it ourselves
        //PublishedAssessmentData assessment =PersistenceService.getInstance().getPublishedAssessmentFacadeQueries().loadPublishedAssessment(new Long(publishedId));
        //HashSet sectionSet = PersistenceService.getInstance().getPublishedAssessmentFacadeQueries().getSectionSetForAssessment(assessment);
        //assessment.setSectionSet(sectionSet);
        // proceed to get totalScores
        //      Object[] objects = new Object[2];
        //      objects[0] = new Long(publishedId);
        //      objects[1] = new Boolean(true);
        //      Type[] types = new Type[2];
        //      types[0] = Hibernate.LONG;
        //      types[1] = Hibernate.BOOLEAN;

        final HibernateCallback hcb = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query q = null;
                if (getSubmittedOnly) {
                    q = session.createQuery("from AssessmentGradingData a where a.publishedAssessmentId=? "
                            + "and a.forGrade=? "
                            + "order by a.agentId ASC, a.finalScore DESC, a.submittedDate DESC");
                    q.setLong(0, Long.parseLong(publishedId));
                    q.setBoolean(1, true);
                } else {
                    q = session.createQuery("from AssessmentGradingData a where a.publishedAssessmentId=? "
                            + "and (a.forGrade=? or (a.forGrade=? and a.status=?)) "
                            + "order by a.agentId ASC, a.finalScore DESC, a.submittedDate DESC");

                    q.setLong(0, Long.parseLong(publishedId));
                    q.setBoolean(1, true);
                    q.setBoolean(2, false);
                    q.setInteger(3, AssessmentGradingData.NO_SUBMISSION.intValue());
                }
                return q.list();
            };
        };
        List list = getHibernateTemplate().executeFind(hcb);

        //      List list = getHibernateTemplate().find(
        //            "from AssessmentGradingData a where a.publishedAssessmentId=? and a.forGrade=? order by agentId ASC, finalScore DESC, submittedDate DESC", 
        //            objects, types);

        // last submission
        if (which.equals(EvaluationModelIfc.LAST_SCORE.toString())) {
            final HibernateCallback hcb2 = new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException, SQLException {
                    Query q = null;
                    if (getSubmittedOnly) {
                        q = session.createQuery("from AssessmentGradingData a where a.publishedAssessmentId=? "
                                + "and a.forGrade=? " + "order by a.agentId ASC, a.submittedDate DESC");
                        q.setLong(0, Long.parseLong(publishedId));
                        q.setBoolean(1, true);
                    } else {
                        q = session.createQuery("from AssessmentGradingData a where a.publishedAssessmentId=? "
                                + "and (a.forGrade=? or (a.forGrade=? and a.status=?)) "
                                + "order by a.agentId ASC, a.submittedDate DESC");
                        q.setLong(0, Long.parseLong(publishedId));
                        q.setBoolean(1, true);
                        q.setBoolean(2, false);
                        q.setInteger(3, AssessmentGradingData.NO_SUBMISSION.intValue());
                    }
                    return q.list();
                };
            };
            list = getHibernateTemplate().executeFind(hcb2);

            //         list = getHibernateTemplate().find(
            //            "from AssessmentGradingData a where a.publishedAssessmentId=? and a.forGrade=? order by agentId ASC, submittedDate DESC", 
            //            objects, types);
        }

        if (which.equals(EvaluationModelIfc.ALL_SCORE.toString())
                || which.equals(EvaluationModelIfc.AVERAGE_SCORE.toString())) {
            return list;
        } else {
            // only take highest or latest
            Iterator items = list.iterator();
            ArrayList newlist = new ArrayList();
            String agentid = null;
            AssessmentGradingData data = (AssessmentGradingData) items.next();
            // daisyf add the following line on 12/15/04
            data.setPublishedAssessmentId(Long.valueOf(publishedId));
            agentid = data.getAgentId();
            newlist.add(data);
            while (items.hasNext()) {
                while (items.hasNext()) {
                    data = (AssessmentGradingData) items.next();
                    if (!data.getAgentId().equals(agentid)) {
                        agentid = data.getAgentId();
                        newlist.add(data);
                        break;
                    }
                }
            }
            return newlist;
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
        return new ArrayList();
    }
}

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

License:Educational Community License

@SuppressWarnings("unchecked")
public List getAllSubmissions(final String publishedId) {
    //      Object[] objects = new Object[1];
    //      objects[0] = new Long(publishedId);
    //      Type[] types = new Type[1];
    //      types[0] = Hibernate.LONG;

    final HibernateCallback hcb = new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery(
                    "from AssessmentGradingData a where a.publishedAssessmentId=? and a.forGrade=?");
            q.setLong(0, Long.parseLong(publishedId));
            q.setBoolean(1, true);
            return q.list();
        };// www  .  ja  v a  2 s. co m
    };
    return getHibernateTemplate().executeFind(hcb);

    //      List list = getHibernateTemplate().find("from AssessmentGradingData a where a.publishedAssessmentId=? and a.forGrade=1", objects, types);
    //      return list;
}

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

License:Educational Community License

/**
 * This returns a hashmap of all the latest item entries, keyed by
 * item id for easy retrieval.//w  w  w .  j  a  v a  2  s. com
 * return (Long publishedItemId, ArrayList itemGradingData)
 */
public HashMap getLastItemGradingData(final Long publishedId, final String agentId) {
    try {
        //      Object[] objects = new Object[2];
        //      objects[0] = publishedId;
        //      objects[1] = agentId;
        //      Type[] types = new Type[2];
        //      types[0] = Hibernate.LONG;
        //      types[1] = Hibernate.STRING;

        final HibernateCallback hcb = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                // I am debating should I use (a.forGrade=false and a.status=NO_SUBMISSION)
                // or attemptDate is not null
                Query q = session.createQuery("from AssessmentGradingData a where a.publishedAssessmentId=? "
                        + "and a.agentId=? and a.forGrade=? and a.status<>? "
                        + "order by a.submittedDate DESC");
                q.setLong(0, publishedId.longValue());
                q.setString(1, agentId);
                q.setBoolean(2, false);
                q.setInteger(3, AssessmentGradingData.NO_SUBMISSION.intValue());
                return q.list();
            };
        };
        List scores = getHibernateTemplate().executeFind(hcb);

        //      ArrayList scores = (ArrayList) getHibernateTemplate().find("from AssessmentGradingData a where a.publishedAssessmentId=? and a.agentId=? order by submittedDate DESC", objects, types);
        HashMap map = new HashMap();
        if (scores.isEmpty())
            return new HashMap();
        AssessmentGradingData gdata = (AssessmentGradingData) scores.toArray()[0];
        // initialize itemGradingSet
        gdata.setItemGradingSet(getItemGradingSet(gdata.getAssessmentGradingId()));
        if (gdata.getForGrade().booleanValue())
            return new HashMap();
        Iterator iter = gdata.getItemGradingSet().iterator();
        while (iter.hasNext()) {
            ItemGradingData data = (ItemGradingData) iter.next();
            ArrayList thisone = (ArrayList) map.get(data.getPublishedItemId());
            if (thisone == null)
                thisone = new ArrayList();
            thisone.add(data);
            map.put(data.getPublishedItemId(), thisone);
        }
        return map;
    } catch (Exception e) {
        e.printStackTrace();
        return new HashMap();
    }
}

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

License:Educational Community License

public HashMap getSubmitData(final Long publishedId, final String agentId, final Integer scoringoption,
        final Long assessmentGradingId) {
    try {//  w  ww. j  a  v  a 2 s . c  om
        //      Object[] objects = new Object[3];
        //      objects[0] = publishedId;
        //      objects[1] = agentId;
        //      objects[2] = new Boolean(true);
        //      Type[] types = new Type[3];
        //      types[0] = Hibernate.LONG;
        //      types[1] = Hibernate.STRING;
        //      types[2] = Hibernate.BOOLEAN;

        final HibernateCallback hcb = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                log.debug("scoringoption = " + scoringoption);
                if (EvaluationModelIfc.LAST_SCORE.equals(scoringoption)) {
                    // last submission
                    Query q = null;
                    if (assessmentGradingId == null) {
                        q = session.createQuery(
                                "from AssessmentGradingData a where a.publishedAssessmentId=? and a.agentId=? and a.forGrade=? order by a.submittedDate DESC");
                        q.setLong(0, publishedId.longValue());
                        q.setString(1, agentId);
                        q.setBoolean(2, true);
                    } else {
                        q = session.createQuery("from AssessmentGradingData a where a.assessmentGradingId=? ");
                        q.setLong(0, assessmentGradingId.longValue());
                    }
                    return q.list();
                } else {
                    //highest submission
                    Query q1 = null;
                    if (assessmentGradingId == null) {
                        q1 = session.createQuery(
                                "from AssessmentGradingData a where a.publishedAssessmentId=? and a.agentId=? and a.forGrade=? order by a.finalScore DESC, a.submittedDate DESC");
                        q1.setLong(0, publishedId.longValue());
                        q1.setString(1, agentId);
                        q1.setBoolean(2, true);
                    } else {
                        q1 = session.createQuery("from AssessmentGradingData a where a.assessmentGradingId=? ");
                        q1.setLong(0, assessmentGradingId.longValue());
                    }
                    return q1.list();
                }
            };
        };
        List scores = getHibernateTemplate().executeFind(hcb);

        //      ArrayList scores = (ArrayList) getHibernateTemplate().find("from AssessmentGradingData a where a.publishedAssessmentId=? and a.agentId=? and a.forGrade=? order by submittedDate DESC", objects, types);
        HashMap map = new HashMap();
        if (scores.isEmpty())
            return new HashMap();
        AssessmentGradingData gdata = (AssessmentGradingData) scores.toArray()[0];
        HashMap attachmentMap = getItemGradingAttachmentMapByAssessmentGradingId(
                gdata.getAssessmentGradingId());
        gdata.setItemGradingSet(getItemGradingSet(gdata.getAssessmentGradingId()));
        Iterator iter = gdata.getItemGradingSet().iterator();
        while (iter.hasNext()) {
            ItemGradingData data = (ItemGradingData) iter.next();
            if (attachmentMap.get(data.getItemGradingId()) != null) {
                data.setItemGradingAttachmentList(
                        (ArrayList<ItemGradingAttachment>) attachmentMap.get(data.getItemGradingId()));
            } else {
                data.setItemGradingAttachmentList(new ArrayList<ItemGradingAttachment>());
            }

            ArrayList thisone = (ArrayList) map.get(data.getPublishedItemId());
            if (thisone == null)
                thisone = new ArrayList();
            thisone.add(data);
            map.put(data.getPublishedItemId(), thisone);
        }
        return map;
    } catch (Exception e) {
        e.printStackTrace();
        return new HashMap();
    }
}