org.hibernate.Query.setParameterList() - java examples

Here are the examples of the java api org.hibernate.Query.setParameterList() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

87 Examples 7

18 View Complete Implementation : PermissionLevelManagerImpl.java
Copyright Educational Community License v2.0
Author : sakaiproject
private List queryWithParameterList(Query query, String queryParamName, List fullList) {
    // sql has a limit for the size of a parameter list, so we may need to cycle
    // through with sublists
    List queryResultList = new ArrayList();
    if (fullList.size() < MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST) {
        query.setParameterList(queryParamName, fullList);
        queryResultList = query.list();
    } else {
        // if there are more than MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST, we need to do multiple queries
        int begIndex = 0;
        int endIndex = 0;
        while (begIndex < fullList.size()) {
            endIndex = begIndex + MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST;
            if (endIndex > fullList.size()) {
                endIndex = fullList.size();
            }
            List tempSubList = new ArrayList();
            tempSubList.addAll(fullList.subList(begIndex, endIndex));
            query.setParameterList(queryParamName, tempSubList);
            queryResultList.addAll(query.list());
            begIndex = endIndex;
        }
    }
    return queryResultList;
}

17 View Complete Implementation : TransformerImpl.java
Copyright GNU Lesser General Public License v3.0
Author : robeio
public void setParameter(Query query, String key, Object value) {
    if (value instanceof Collection) {
        query.setParameterList(key, (Collection) value);
    } else {
        query.setParameter(key, value);
    }
}

17 View Complete Implementation : HibernateUtil.java
Copyright Apache License 2.0
Author : querydsl
private static void setValue(Query query, String key, Object val) {
    if (val instanceof Collection<?>) {
        query.setParameterList(key, (Collection<?>) val);
    } else if (val instanceof Object[] && !BUILT_IN.contains(val.getClreplaced())) {
        query.setParameterList(key, (Object[]) val);
    } else if (val instanceof Number && TYPES.containsKey(val.getClreplaced())) {
        query.setParameter(key, val, getType(val.getClreplaced()));
    } else {
        query.setParameter(key, val);
    }
}

17 View Complete Implementation : HibernateTemplate.java
Copyright Apache License 2.0
Author : banq
/**
 * Apply the given name parameter to the given Query object.
 *
 * @param queryObject
 *            the Query object
 * @param paramName
 *            the name of the parameter
 * @param value
 *            the value of the parameter
 * @throws HibernateException
 *             if thrown by the Query object
 */
protected void applyNamedParameterToQuery(Query queryObject, String paramName, Object value) throws HibernateException {
    if (value instanceof Collection) {
        queryObject.setParameterList(paramName, (Collection) value);
    } else if (value instanceof Object[]) {
        queryObject.setParameterList(paramName, (Object[]) value);
    } else {
        queryObject.setParameter(paramName, value);
    }
}

17 View Complete Implementation : HibernateTemplate.java
Copyright Apache License 2.0
Author : langtianya
/**
 * Apply the given name parameter to the given Query object.
 * @param queryObject the Query object
 * @param paramName the name of the parameter
 * @param value the value of the parameter
 * @throws HibernateException if thrown by the Query object
 */
protected void applyNamedParameterToQuery(Query queryObject, String paramName, Object value) throws HibernateException {
    if (value instanceof Collection) {
        queryObject.setParameterList(paramName, (Collection<?>) value);
    } else if (value instanceof Object[]) {
        queryObject.setParameterList(paramName, (Object[]) value);
    } else {
        queryObject.setParameter(paramName, value);
    }
}

17 View Complete Implementation : ItemDaoImpl.java
Copyright Apache License 2.0
Author : openequella
private void setParams(Query q, final Map<String, Object> ps) {
    for (Map.Entry<String, Object> entry : ps.entrySet()) {
        String key = entry.getKey();
        Object obj = entry.getValue();
        if (obj instanceof Collection<?>) {
            q.setParameterList(key, (Collection<?>) obj);
        } else {
            q.setParameter(key, obj);
        }
    }
}

16 View Complete Implementation : UserDaoImpl.java
Copyright Apache License 2.0
Author : Anstoner
@Override
public void idenreplacedyPost(List<Long> userIds, boolean idenreplacedy) {
    String substm = "+ 1";
    if (!idenreplacedy) {
        substm = "- 1";
    }
    Query query = createSQLQuery("update mto_users set posts = posts " + substm + " where id in (:ids)");
    query.setParameterList("ids", userIds);
    query.executeUpdate();
}

16 View Complete Implementation : UserDaoImpl.java
Copyright Apache License 2.0
Author : Anstoner
@Override
public void idenreplacedyComment(List<Long> userIds, boolean idenreplacedy) {
    String substm = "+ 1";
    if (!idenreplacedy) {
        substm = "- 1";
    }
    Query query = createSQLQuery("update mto_users set comments = comments " + substm + " where id in (:ids)");
    query.setParameterList("ids", userIds);
    query.executeUpdate();
}

16 View Complete Implementation : UserDaoImpl.java
Copyright Apache License 2.0
Author : Anstoner
@Override
public void idenreplacedyFollow(List<Long> userIds, boolean idenreplacedy) {
    String substm = "+ 1";
    if (!idenreplacedy) {
        substm = "- 1";
    }
    Query query = createSQLQuery("update mto_users set follows = follows " + substm + " where id in (:ids)");
    query.setParameterList("ids", userIds);
    query.executeUpdate();
}

16 View Complete Implementation : UserDaoImpl.java
Copyright Apache License 2.0
Author : Anstoner
@Override
public void idenreplacedyFans(List<Long> userIds, boolean idenreplacedy) {
    String substm = "+ 1";
    if (!idenreplacedy) {
        substm = "- 1";
    }
    Query query = createSQLQuery("update mto_users set fans = fans " + substm + " where id in (:ids)");
    query.setParameterList("ids", userIds);
    query.executeUpdate();
}

16 View Complete Implementation : UserDaoImpl.java
Copyright Apache License 2.0
Author : Anstoner
@Override
public void idenreplacedyFavors(List<Long> userIds, boolean idenreplacedy) {
    String substm = "+ 1";
    if (!idenreplacedy) {
        substm = "- 1";
    }
    Query query = createSQLQuery("update mto_users set favors = favors " + substm + " where id in (:ids)");
    query.setParameterList("ids", userIds);
    query.executeUpdate();
}

16 View Complete Implementation : Finder.java
Copyright GNU General Public License v2.0
Author : caipiao
/**
 * 将finder中的参数设置到query中。
 *
 * @param query
 */
public Query setParamsToQuery(Query query) {
    if (params != null) {
        for (int i = 0; i < params.size(); i++) {
            if (types.get(i) == null) {
                query.setParameter(params.get(i), values.get(i));
            } else {
                query.setParameter(params.get(i), values.get(i), types.get(i));
            }
        }
    }
    if (paramsList != null) {
        for (int i = 0; i < paramsList.size(); i++) {
            if (typesList.get(i) == null) {
                query.setParameterList(paramsList.get(i), valuesList.get(i));
            } else {
                query.setParameterList(paramsList.get(i), valuesList.get(i), typesList.get(i));
            }
        }
    }
    if (paramsArray != null) {
        for (int i = 0; i < paramsArray.size(); i++) {
            if (typesArray.get(i) == null) {
                query.setParameterList(paramsArray.get(i), valuesArray.get(i));
            } else {
                query.setParameterList(paramsArray.get(i), valuesArray.get(i), typesArray.get(i));
            }
        }
    }
    return query;
}

16 View Complete Implementation : BaseDaoImpl.java
Copyright Apache License 2.0
Author : SoftwareKing
// 设置查询条件
private void setAliasParameter(Query query, Map<String, Object> alias) {
    if (alias != null) {
        Set<String> keys = alias.keySet();
        for (String key : keys) {
            Object val = alias.get(key);
            if (val instanceof Collection) {
                // 查询条件是列表
                query.setParameterList(key, (Collection) val);
            } else {
                query.setParameter(key, val);
            }
        }
    }
}

16 View Complete Implementation : HibernateVulnerabilityFilterDao.java
Copyright Mozilla Public License 2.0
Author : secdec
private List<Map<String, Object>> runInnerMapQuery(List<Integer> filteredSeverities, List<Integer> filteredVulnerabilities, Clreplaced<?> targetClreplaced) {
    String clreplacedName = targetClreplaced.getName();
    String hql = "select new map (" + "count(*) as total, " + "closeMap.scan.id as scanId) " + "from " + clreplacedName + " closeMap ";
    String filteredIDClause = getIgnoredIdHQL(filteredSeverities, filteredVulnerabilities);
    if (filteredIDClause != null) {
        hql += "where vulnerability.id not in " + filteredIDClause;
    }
    hql += "group by closeMap.scan.id";
    Query query = sessionFactory.getCurrentSession().createQuery(hql);
    if (!filteredSeverities.isEmpty()) {
        query.setParameterList("filteredSeverities", filteredSeverities);
    }
    if (!filteredVulnerabilities.isEmpty()) {
        query.setParameterList("filteredVulnerabilities", filteredVulnerabilities);
    }
    Object idsMap = query.list();
    return (List<Map<String, Object>>) idsMap;
}

16 View Complete Implementation : CommentDaoImpl.java
Copyright Apache License 2.0
Author : Anstoner
@Override
public int deleteByIds(Collection<Long> ids) {
    Query query = createQuery("delete from CommentPO where id in (:ids)");
    query.setParameterList("ids", ids);
    return query.executeUpdate();
}

16 View Complete Implementation : QueryBuilder.java
Copyright Apache License 2.0
Author : slyak
public static void setParams(Query query, Object beanOrMap) {
    String[] nps = query.getNamedParameters();
    if (nps != null) {
        Map<String, Object> params = toParams(beanOrMap);
        for (String key : nps) {
            Object arg = params.get(key);
            if (arg == null) {
                query.setParameter(key, null);
            } else if (arg.getClreplaced().isArray()) {
                query.setParameterList(key, (Object[]) arg);
            } else if (arg instanceof Collection) {
                query.setParameterList(key, ((Collection) arg));
            } else if (arg.getClreplaced().isEnum()) {
                query.setParameter(key, ((Enum) arg).ordinal());
            } else {
                query.setParameter(key, arg);
            }
        }
    }
}

15 View Complete Implementation : UMLSDaoImpl.java
Copyright Apache License 2.0
Author : apache
private void updateNames(String queryName, List<String> subList, Map<String, String> names) {
    Query q = sessionFactory.getCurrentSession().getNamedQuery(queryName);
    q.setParameterList("cuis", subList);
    @SuppressWarnings("unchecked")
    List<Object[]> listCuiName = q.list();
    for (Object[] cuiName : listCuiName) {
        names.put((String) cuiName[0], (String) cuiName[1]);
    }
}

15 View Complete Implementation : BaseDao.java
Copyright MIT License
Author : cjbi
@SuppressWarnings("rawtypes")
private void setAliasParameter(Query query, Map<String, Object> alias) {
    if (alias != null) {
        Set<String> keys = alias.keySet();
        for (String key : keys) {
            Object val = alias.get(key);
            if (val instanceof Collection) {
                // 查询条件是列表
                query.setParameterList(key, (Collection) val);
            } else {
                query.setParameter(key, val);
            }
        }
    }
}

15 View Complete Implementation : UserRoleDAOImpl.java
Copyright Mozilla Public License 2.0
Author : openelisglobal
public boolean userInRole(String userId, Collection<String> roleNames) throws LIMSRuntimeException {
    boolean inRole;
    try {
        String sql = "select count(*) from system_user_role sur " + "join system_role as sr on sr.id = sur.role_id " + "where sur.system_user_id = :userId and sr.name in (:roleNames)";
        Query query = HibernateUtil.getSession().createSQLQuery(sql);
        query.setInteger("userId", Integer.parseInt(userId));
        query.setParameterList("roleNames", roleNames);
        int result = ((BigInteger) query.uniqueResult()).intValue();
        inRole = result != 0;
    } catch (HibernateException he) {
        LogEvent.logError("UserRoleDAOImpl", "userInRole()", he.toString());
        throw new LIMSRuntimeException("Error in UserRoleDAOImpl userInRole()", he);
    }
    return inRole;
}

15 View Complete Implementation : CourseManagementServiceHibernateImpl.java
Copyright Educational Community License v2.0
Author : sakaiproject
public boolean isEnrolled(final String userId, final Set<String> enrollmentSetEids) {
    HibernateCallback hc = session -> {
        Query q = session.getNamedQuery("countEnrollments");
        q.setParameter("userId", userId);
        q.setParameterList("enrollmentSetEids", enrollmentSetEids);
        return q.iterate().next();
    };
    int i = ((Number) getHibernateTemplate().execute(hc)).intValue();
    if (log.isDebugEnabled())
        log.debug(userId + " is enrolled in " + i + " of these " + enrollmentSetEids.size() + " EnrollmentSets");
    return i > 0;
}

15 View Complete Implementation : SecobjprivilegeDao.java
Copyright GNU General Public License v2.0
Author : scoophealth
public List<Secobjprivilege> getByRoles(List<String> roles) {
    String queryString = "from Secobjprivilege obj where obj.roleusergroup IN (:roles)";
    List<Secobjprivilege> results = new ArrayList<Secobjprivilege>();
    Session session = getSession();
    try {
        Query q = session.createQuery(queryString);
        q.setParameterList("roles", roles);
        results = q.list();
    } finally {
        this.releaseSession(session);
    }
    return results;
}

14 View Complete Implementation : VMIDao.java
Copyright Apache License 2.0
Author : grycap
/**
 * Get a List<VMI> according to the specified HQL query.
 * The VMIs must include the specified applications.
 * @param hqlQuery
 * @return The List<VMI>
 */
public List<VMI> getAllVMIByQuery(String hqlQuery, String[] appNames) {
    Query q = getSessionFactory().getCurrentSession().createQuery(hqlQuery);
    if (appNames != null) {
        q.setParameterList("apps", appNames);
        q.setInteger("apps_count", appNames.length);
    }
    List<VMI> l = q.list();
    return l;
}

14 View Complete Implementation : OrderDAO.java
Copyright GNU Affero General Public License v3.0
Author : LibrePlan
/**
 * If user has permissions over all orders it returns <code>null</code>.
 * Otherwise, it returns the list of orders identifiers for which the user has read permissions.
 */
private List<Long> getOrdersIdsByReadAuthorization(User user) {
    if (user.isInRole(UserRole.ROLE_SUPERUSER) || user.isInRole(UserRole.ROLE_READ_ALL_PROJECTS) || user.isInRole(UserRole.ROLE_EDIT_ALL_PROJECTS)) {
        return null;
    } else {
        String strQuery = "SELECT oa.order.id " + "FROM OrderAuthorization oa " + "WHERE oa.user = :user ";
        if (!user.getProfiles().isEmpty()) {
            strQuery += "OR oa.profile IN (:profiles) ";
        }
        Query query = getSession().createQuery(strQuery);
        query.setParameter("user", user);
        if (!user.getProfiles().isEmpty()) {
            query.setParameterList("profiles", user.getProfiles());
        }
        return query.list();
    }
}

14 View Complete Implementation : OrderDAO.java
Copyright GNU Affero General Public License v3.0
Author : LibrePlan
@Override
@Transactional(readOnly = true)
public List<Task> getFilteredTask(List<OrderElement> orderElements, List<Criterion> criterions) {
    if (orderElements == null || orderElements.isEmpty()) {
        return new ArrayList<>();
    }
    String strQuery = "SELECT taskSource.task " + "FROM OrderElement orderElement, TaskSource taskSource, Task task " + "LEFT OUTER JOIN taskSource.schedulingData.orderElement taskSourceOrderElement " + "LEFT OUTER JOIN taskSource.task taskElement " + "WHERE taskSourceOrderElement.id = orderElement.id " + "AND taskElement.id = task.id  AND orderElement IN (:orderElements) ";
    // Set Criterions
    if (criterions != null && !criterions.isEmpty()) {
        strQuery += " AND (EXISTS (FROM task.resourceAllocations as allocation, GenericResourceAllocation as generic " + " WHERE generic.id = allocation.id " + " AND EXISTS( FROM generic.criterions criterion WHERE criterion IN (:criterions))))";
    }
    // Order by
    strQuery += "ORDER BY task.name";
    // Set parameters
    Query query = getSession().createQuery(strQuery);
    query.setParameterList("orderElements", orderElements);
    if (criterions != null && !criterions.isEmpty()) {
        query.setParameterList("criterions", Criterion.withAllDescendants(criterions));
    }
    return query.list();
}

14 View Complete Implementation : OrderElementDAO.java
Copyright GNU Affero General Public License v3.0
Author : LibrePlan
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public Set<String> getAllCodesExcluding(List<OrderElement> orderElements) {
    String strQuery = "SELECT order.infoComponent.code FROM OrderElement order ";
    final List<Long> ids = getNoEmptyIds(orderElements);
    if (!ids.isEmpty()) {
        strQuery += "WHERE order.id NOT IN (:ids)";
    }
    Query query = getSession().createQuery(strQuery);
    if (!ids.isEmpty()) {
        query.setParameterList("ids", ids);
    }
    return new HashSet<>(query.list());
}

14 View Complete Implementation : QualityFormDAO.java
Copyright GNU Affero General Public License v3.0
Author : LibrePlan
@Override
public void checkHasTasks(QualityForm qualityForm) throws ValidationException {
    String queryString = "FROM TaskQualityForm taskQualityForm JOIN taskQualityForm.qualityForm tq WHERE tq IN (:qualityForms)";
    Query query = getSession().createQuery(queryString);
    query.setParameterList("qualityForms", Collections.singleton(qualityForm));
    if (!query.list().isEmpty()) {
        throw ValidationException.invalidValueException("Cannot delete quality form. It is being used at this moment by some task.", qualityForm);
    }
}

14 View Complete Implementation : ProfileDAO.java
Copyright GNU Affero General Public License v3.0
Author : LibrePlan
@Override
public void checkHasUsers(Profile profile) throws ValidationException {
    // Query against a collection of elements
    // http://community.jboss.org/message/353859#353859
    Query query = getSession().createQuery("FROM User user JOIN user.profiles up WHERE up IN (:profiles)");
    query.setParameterList("profiles", Collections.singleton(profile));
    if (!query.list().isEmpty()) {
        throw ValidationException.invalidValueException("Cannot delete profile. It is being used at this moment by some users.", profile);
    }
}

14 View Complete Implementation : PatientDAOImpl.java
Copyright Mozilla Public License 2.0
Author : openelisglobal
public List<String> getPatientIdenreplacedyBySampleStatusIdAndProject(List<Integer> inclusiveStatusIdList, String project) throws LIMSRuntimeException {
    boolean useIdList = inclusiveStatusIdList != null && inclusiveStatusIdList.size() > 0;
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append("select COALESCE(pat.national_id, pat.external_id) as subjectNo from clinlims.sample s ");
    sqlBuilder.append("join clinlims.sample_projects sp on sp.samp_id = s.id ");
    sqlBuilder.append("join clinlims.project p on sp.proj_id = p.id ");
    sqlBuilder.append("join clinlims.sample_human sh on sh.samp_id = s.id ");
    sqlBuilder.append("join clinlims.patient pat on pat.id = sh.patient_id  ");
    sqlBuilder.append("where p.name = :project ");
    if (useIdList) {
        sqlBuilder.append("and s.status_id in(:statusIdList) ");
    }
    try {
        Query query = HibernateUtil.getSession().createSQLQuery(sqlBuilder.toString());
        if (useIdList) {
            query.setParameterList("statusIdList", inclusiveStatusIdList);
        }
        query.setString("project", project);
        List<String> subjectList = query.list();
        closeSession();
        return subjectList;
    } catch (Exception e) {
        handleException(e, "getPatientIdenreplacedyBySampleStatusIdAndProject");
    }
    return new ArrayList<String>();
}

14 View Complete Implementation : ResultDAOImpl.java
Copyright Mozilla Public License 2.0
Author : openelisglobal
@SuppressWarnings("unchecked")
public List<Result> getResultsForreplacedysisIdList(List<Integer> replacedysisIdList) throws LIMSRuntimeException {
    if (replacedysisIdList.isEmpty()) {
        return null;
    }
    String sql = "from Result r where r.replacedysis IN (:replacedysisList)";
    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setParameterList("replacedysisList", replacedysisIdList);
        List<Result> resultList = query.list();
        closeSession();
        return resultList;
    } catch (HibernateException e) {
        handleException(e, "getResultsForreplacedysisIdList");
    }
    return null;
}

14 View Complete Implementation : PrivacyManagerImpl.java
Copyright Educational Community License v2.0
Author : sakaiproject
private List<PrivacyRecord> getPrivacyByContextAndTypeAndUserIds(final String contextId, final String recordType, final List userIds) {
    if (contextId == null || recordType == null || userIds == null) {
        throw new IllegalArgumentException("Null Argument in getPrivacyByContextAndTypeAndUserIds");
    }
    HibernateCallback<List<PrivacyRecord>> hcb = session -> {
        Query q = session.getNamedQuery(QUERY_BY_CONTEXT__TYPE_IDLIST);
        q.setString(CONTEXT_ID, contextId);
        q.setString(RECORD_TYPE, recordType);
        q.setParameterList("userIds", userIds);
        return q.list();
    };
    return getHibernateTemplate().execute(hcb);
}

13 View Complete Implementation : HibernatePatientDAO.java
Copyright Apache License 2.0
Author : isstac
/**
 * @param attributes attributes on a Person or Patient object. similar to: [gender, givenName,
 *                   middleName, familyName]
 * @return           list of patients that match other patients
 * @see org.openmrs.api.db.PatientDAO#getDuplicatePatientsByAttributes(java.util.List)
 */
@SuppressWarnings("unchecked")
@Override
public List<Patient> getDuplicatePatientsByAttributes(List<String> attributes) {
    List<Patient> patients = new ArrayList<>();
    List<Integer> patientIds = new ArrayList<>();
    if (!attributes.isEmpty()) {
        String sqlString = getDuplicatePatientsSQLString(attributes);
        if (sqlString != null) {
            SQLQuery sqlquery = sessionFactory.getCurrentSession().createSQLQuery(sqlString);
            patientIds = sqlquery.list();
            if (!patientIds.isEmpty()) {
                Query query = sessionFactory.getCurrentSession().createQuery("from Patient p1 where p1.patientId in (:ids)");
                query.setParameterList("ids", patientIds);
                patients = query.list();
            }
        }
    }
    sortDuplicatePatients(patients, patientIds);
    return patients;
}

13 View Complete Implementation : WorkerDAO.java
Copyright GNU Affero General Public License v3.0
Author : LibrePlan
@Override
@Transactional(readOnly = true)
public List<Object[]> getWorkingHoursGroupedPerWorker(List<String> workerCodes, Date startingDate, Date endingDate) {
    String strQuery = "SELECT worker.code, SUM(wrl.effort) " + "FROM Worker worker, WorkReportLine wrl " + "LEFT OUTER JOIN wrl.resource resource " + "WHERE resource.id = worker.id ";
    // Set date range
    if (startingDate != null && endingDate != null) {
        strQuery += "AND wrl.date BETWEEN :startingDate AND :endingDate ";
    }
    if (startingDate != null && endingDate == null) {
        strQuery += "AND wrl.date >= :startingDate ";
    }
    if (startingDate == null && endingDate != null) {
        strQuery += "AND wrl.date <= :endingDate ";
    }
    // Set workers
    if (workerCodes != null && !workerCodes.isEmpty()) {
        strQuery += "AND worker.code IN (:workerCodes) ";
    }
    // Group by
    strQuery += "GROUP BY worker.code ";
    // Order by
    strQuery += "ORDER BY worker.code";
    // Set parameters
    Query query = getSession().createQuery(strQuery);
    if (startingDate != null) {
        query.setParameter("startingDate", startingDate);
    }
    if (endingDate != null) {
        query.setParameter("endingDate", endingDate);
    }
    if (workerCodes != null && !workerCodes.isEmpty()) {
        query.setParameterList("workerCodes", workerCodes);
    }
    // Get result
    return query.list();
}

13 View Complete Implementation : SampleDAOImpl.java
Copyright Mozilla Public License 2.0
Author : openelisglobal
// ==============================================================
@Override
public List getSamplesByStatusAndDomain(List statuses, String domain) throws LIMSRuntimeException {
    List list = new Vector();
    try {
        String sql = "from Sample s where status in (:param1) and domain = :param2";
        org.hibernate.Query query = HibernateUtil.getSession().createQuery(sql);
        query.setParameterList("param1", statuses);
        query.setParameter("param2", domain);
        list = query.list();
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
    } catch (Exception e) {
        // bugzilla 2154
        LogEvent.logError("SampleDAOImpl", "getAllSampleByStatusAndDomain()", e.toString());
        throw new LIMSRuntimeException("Error in Sample getAllSampleByStatusAndDomain()", e);
    }
    return list;
}

13 View Complete Implementation : SampleItemDAOImpl.java
Copyright Mozilla Public License 2.0
Author : openelisglobal
@Override
public List<SampleItem> getSampleItemsBySampleIdAndStatus(String id, Set<Integer> includedStatusList) throws LIMSRuntimeException {
    if (includedStatusList.isEmpty()) {
        return new ArrayList<SampleItem>();
    }
    try {
        String sql = "from SampleItem sampleItem where sampleItem.sample.id = :sampleId and sampleItem.statusId in ( :statusIds ) order by sampleItem.sortOrder";
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setInteger("sampleId", Integer.parseInt(id));
        query.setParameterList("statusIds", includedStatusList);
        @SuppressWarnings("unchecked")
        List<SampleItem> list = query.list();
        closeSession();
        return list;
    } catch (HibernateException he) {
        handleException(he, "getSampleItemsBySampleIdAndStatus");
    }
    return null;
}

13 View Complete Implementation : AssignmentPeerAssessmentServiceImpl.java
Copyright Educational Community License v2.0
Author : sakaiproject
public List<Peerreplacedessmenreplacedem> getPeerreplacedessmenreplacedems(final Collection<String> submissionsIds, Integer scaledFactor) {
    List<Peerreplacedessmenreplacedem> listPeerreplacedessmenreplacedem = new ArrayList<>();
    if (submissionsIds == null || submissionsIds.size() == 0) {
        // return an empty list
        return listPeerreplacedessmenreplacedem;
    }
    HibernateCallback<List<Peerreplacedessmenreplacedem>> hcb = session -> {
        Query q = session.getNamedQuery("findPeerreplacedessmenreplacedemsBySubmissions");
        q.setParameterList("submissionIds", submissionsIds);
        return q.list();
    };
    listPeerreplacedessmenreplacedem = getHibernateTemplate().execute(hcb);
    for (Peerreplacedessmenreplacedem item : listPeerreplacedessmenreplacedem) {
        item.setScaledFactor(scaledFactor);
    }
    return listPeerreplacedessmenreplacedem;
}

13 View Complete Implementation : PrivacyManagerImpl.java
Copyright Educational Community License v2.0
Author : sakaiproject
private List<PrivacyRecord> getViewableStateList(final String contextId, final Boolean viewable, final String recordType, final List userIds) {
    if (contextId == null || viewable == null || recordType == null || userIds == null) {
        throw new IllegalArgumentException("Null Argument in getViewableStateList");
    }
    HibernateCallback<List<PrivacyRecord>> hcb = session -> {
        Query q = session.getNamedQuery(QUERY_BY_CONTEXT_VIEWABLE_TYPE_IDLIST);
        q.setString(CONTEXT_ID, contextId);
        q.setBoolean(VIEWABLE, viewable);
        q.setString(RECORD_TYPE, recordType);
        q.setParameterList("userIds", userIds);
        return q.list();
    };
    return getHibernateTemplate().execute(hcb);
}

13 View Complete Implementation : ActionFactory.java
Copyright GNU General Public License v2.0
Author : spacewalkproject
/**
 * Delete the server actions replacedociated with the given set of parent actions.
 * @param parentActions Set of parent actions.
 */
public static void deleteServerActionsByParent(Set parentActions) {
    Session session = HibernateFactory.getSession();
    Query serverActionsToDelete = session.getNamedQuery("ServerAction.deleteByParentActions");
    serverActionsToDelete.setParameterList("actions", parentActions);
    serverActionsToDelete.executeUpdate();
}

13 View Complete Implementation : HistoryApplication.java
Copyright GNU Affero General Public License v3.0
Author : headsupdev
public List<Event> getEvents(long before, List<String> types, int count) {
    if (types == null || types.size() == 0) {
        return new LinkedList<Event>();
    }
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();
    Query q = session.createQuery("from StoredEvent e where e.clreplaced in (:types) and e.time < :before and (id.project.disabled is null or id.project.disabled = false) order by time desc");
    q.setParameterList("types", types);
    q.setTimestamp("before", new Date(before));
    q.setMaxResults(count);
    return q.list();
}

12 View Complete Implementation : ClassifierEvaluationDaoImpl.java
Copyright Apache License 2.0
Author : apache
public Map<String, FeatureRank> getFeatureRanks(Set<String> featureNames, String corpusName, String featureSetName, String label, String evaluationType, Integer foldId, double param1, String param2) {
    Query q = prepareUniqueFeatureEvalQuery(corpusName, featureSetName, label, evaluationType, foldId, param1, param2, "getFeatureRankEvaluations");
    q.setParameterList("featureNames", featureNames);
    @SuppressWarnings("unchecked")
    List<FeatureRank> featureRanks = q.list();
    Map<String, FeatureRank> frMap = new HashMap<String, FeatureRank>(featureRanks.size());
    for (FeatureRank fr : featureRanks) frMap.put(fr.getFeatureName(), fr);
    return frMap;
}

12 View Complete Implementation : HistoryApplication.java
Copyright GNU Affero General Public License v3.0
Author : headsupdev
public List<Event> getEventsForProject(Project project, long before, List<String> types, int count) {
    if (types == null || types.size() == 0) {
        return new LinkedList<Event>();
    }
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();
    Query q = session.createQuery("from StoredEvent e where e.clreplaced in (:types) and project.id = :pid and e.time < :before order by time desc");
    q.setParameterList("types", types);
    q.setString("pid", project.getId());
    q.setTimestamp("before", new Date(before));
    q.setMaxResults(count);
    return q.list();
}

12 View Complete Implementation : HibernateProgramWorkflowDAO.java
Copyright Apache License 2.0
Author : isstac
/**
 * @see org.openmrs.api.db.ProgramWorkflowDAO#getPatientPrograms(org.openmrs.Cohort,
 *      java.util.Collection)
 */
@Override
@SuppressWarnings("unchecked")
public List<PatientProgram> getPatientPrograms(Cohort cohort, Collection<Program> programs) {
    String hql = "from PatientProgram ";
    if (cohort != null || programs != null) {
        hql += "where ";
    }
    if (cohort != null) {
        hql += "patient.patientId in (:patientIds) ";
    }
    if (programs != null) {
        if (cohort != null) {
            hql += "and ";
        }
        hql += " program in (:programs)";
    }
    hql += " order by patient.patientId, dateEnrolled";
    Query query = sessionFactory.getCurrentSession().createQuery(hql);
    if (cohort != null) {
        query.setParameterList("patientIds", cohort.getMemberIds());
    }
    if (programs != null) {
        query.setParameterList("programs", programs);
    }
    return query.list();
}

12 View Complete Implementation : OrderDAO.java
Copyright GNU Affero General Public License v3.0
Author : LibrePlan
private List<Long> getOrdersIdsUnscheduled(Date startDate, Date endDate) {
    String strQuery = "SELECT s.orderElement.id " + "FROM SchedulingDataForVersion s " + "WHERE s.schedulingStateType = :type";
    Query query = getSession().createQuery(strQuery);
    query.setParameter("type", SchedulingState.Type.NO_SCHEDULED);
    List<Long> ordersIdsUnscheduled = query.list();
    if (ordersIdsUnscheduled.isEmpty()) {
        return Collections.emptyList();
    }
    String strQueryDates = "SELECT o.id " + "FROM Order o " + "WHERE o.id IN (:ids) ";
    if (startDate != null) {
        strQueryDates += "AND o.initDate >= :startDate ";
    }
    if (endDate != null) {
        strQueryDates += "AND o.initDate <= :endDate ";
    }
    Query queryDates = getSession().createQuery(strQueryDates);
    if (startDate != null) {
        queryDates.setParameter("startDate", startDate);
    }
    if (endDate != null) {
        queryDates.setParameter("endDate", endDate);
    }
    queryDates.setParameterList("ids", ordersIdsUnscheduled);
    return queryDates.list();
}

12 View Complete Implementation : NoteDAOImpl.java
Copyright Mozilla Public License 2.0
Author : openelisglobal
@Override
@SuppressWarnings("unchecked")
public List<Note> getNotesChronologicallyByRefIdAndRefTableAndType(String objectId, String tableId, List<String> filter) throws LIMSRuntimeException {
    String sql = "FROM Note n where n.referenceId = :refId and n.referenceTableId = :tableId and n.noteType in ( :filter ) order by n.lastupdated asc";
    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setInteger("refId", Integer.parseInt(objectId));
        query.setInteger("tableId", Integer.parseInt(tableId));
        query.setParameterList("filter", filter);
        List<Note> noteList = query.list();
        closeSession();
        return noteList;
    } catch (HibernateException e) {
        handleException(e, "getNotesChronologicallyByRefIdAndRefTable");
    }
    return null;
}

12 View Complete Implementation : PanelItemDAOImpl.java
Copyright Mozilla Public License 2.0
Author : openelisglobal
@SuppressWarnings("unchecked")
@Override
public List<PanelItem> getPanelItemsForPanelAndItemList(String panelId, List<Integer> testList) throws LIMSRuntimeException {
    String sql = "From PanelItem pi where pi.panel.id = :panelId and pi.test.id in (:testList)";
    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setInteger("panelId", Integer.parseInt(panelId));
        query.setParameterList("testList", testList);
        List<PanelItem> items = query.list();
        closeSession();
        return items;
    } catch (HibernateException e) {
        handleException(e, "getPanelItemsFromPanelAndItemList");
    }
    return null;
}

12 View Complete Implementation : ResultDAOImpl.java
Copyright Mozilla Public License 2.0
Author : openelisglobal
@SuppressWarnings("unchecked")
public Result getResultForreplacedyteInreplacedysisSet(String replacedyteId, List<Integer> replacedysisIDList) throws LIMSRuntimeException {
    try {
        String sql = "from Result r where r.replacedyte = :replacedyteId and r.replacedysis in (:replacedysisIdList)";
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setInteger("replacedyteId", Integer.parseInt(replacedyteId));
        query.setParameterList("replacedysisIdList", replacedysisIDList);
        List<Result> results = query.list();
        closeSession();
        if (results.size() > 0) {
            return results.get(0);
        }
    } catch (Exception e) {
        handleException(e, "getResultForreplacedyteInreplacedysisSet");
    }
    return null;
}

12 View Complete Implementation : SampleDAOImpl.java
Copyright Mozilla Public License 2.0
Author : openelisglobal
@Override
@SuppressWarnings("unchecked")
public List<Sample> getSamplesByProjectAndStatusIDAndAccessionRange(List<Integer> inclusiveProjectIdList, List<Integer> inclusiveStatusIdList, String minAccession, String maxAccession) throws LIMSRuntimeException {
    String sql = "from Sample s where s.statusId in (:statusList) and " + "s.accessionNumber >= :minAccess and s.accessionNumber <= :maxAccess and " + "s.id in (select sp.sample.id from SampleProject sp where sp.project.id in (:projectId))";
    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setParameterList("statusList", inclusiveStatusIdList);
        query.setParameterList("projectId", inclusiveProjectIdList);
        query.setString("minAccess", minAccession);
        query.setString("maxAccess", maxAccession);
        List<Sample> sampleList = query.list();
        closeSession();
        return sampleList;
    } catch (HibernateException e) {
        handleException(e, "getSamplesByProjectAndStatusIDAndAccessionRange");
    }
    return null;
}

12 View Complete Implementation : SynopticMsgcntrManagerImpl.java
Copyright Educational Community License v2.0
Author : sakaiproject
public List<SynopticMsgcntrItem> getSiteSynopticMsgcntrItems(final List<String> userIds, final String siteId) {
    if (userIds == null || userIds.size() == 0) {
        return new ArrayList<SynopticMsgcntrItem>();
    }
    HibernateCallback<List<SynopticMsgcntrItem>> hcb = session -> {
        List rtn = new ArrayList();
        Query q = session.getNamedQuery(QUERY_SITE_SYNOPTIC_ITEMS);
        q.setParameter("siteId", siteId, StringType.INSTANCE);
        for (int initIndex = 0; initIndex < userIds.size(); initIndex += ORACLE_IN_CLAUSE_SIZE_LIMIT) {
            q.setParameterList("userIds", userIds.subList(initIndex, Math.min(initIndex + ORACLE_IN_CLAUSE_SIZE_LIMIT, userIds.size())));
            rtn.addAll(q.list());
        }
        return rtn;
    };
    return getHibernateTemplate().execute(hcb);
}

11 View Complete Implementation : ClassifierEvaluationDaoImpl.java
Copyright Apache License 2.0
Author : apache
public Map<String, Double> getFeatureRankEvaluations(Set<String> featureNames, String corpusName, String featureSetName, String label, String evaluationType, Integer foldId, double param1, String param2) {
    Query q = prepareUniqueFeatureEvalQuery(corpusName, featureSetName, label, evaluationType, foldId, param1, param2, "getFeatureRankEvaluations");
    q.setParameterList("featureNames", featureNames);
    List<FeatureRank> featureRanks = q.list();
    Map<String, Double> evalMap = new HashMap<String, Double>(featureRanks.size());
    for (FeatureRank fr : featureRanks) evalMap.put(fr.getFeatureName(), fr.getEvaluation());
    return evalMap;
}

11 View Complete Implementation : HibernateCalendarStore.java
Copyright Apache License 2.0
Author : Jasig
/* This method initializes the calendar tables for the user.  It adds calendar replacedociations that were not present
   * last time this was run if the user has access to the calendar.
   *
   * NOTE:  This method should be synchronized to prevent duplicate rows of data that might occur when a user
   * logs in and there are multiple calendar portlets on the home page.  Multiple render threads
   * could execute this method simultaneously and cause calendars to be replacedociated more than once.
   *
   * @see org.jasig.portlet.calendar.dao.CalendarStore#initCalendar(java.lang.String, java.util.Set)
   */
public synchronized void initCalendar(String subscribeId, Set<String> roles) {
    try {
        // if the user doesn't have any roles, we don't have any
        // chance of getting predefined calendars, so just go ahead
        // and return
        if (roles.isEmpty())
            return;
        String query = "from PredefinedCalendarDefinition pcd where pcd.id in " + "(select distinct def.id from PredefinedCalendarDefinition def " + "left join def.defaultRoles role where " + ":subscribeId not in (select config.subscribeId " + "from def.userConfigurations config)";
        if (roles.size() > 0) {
            query = query.concat("and role in (:roles)");
        }
        query = query.concat(")");
        Query q = this.getSession().createQuery(query);
        q.setString("subscribeId", subscribeId);
        if (roles.size() > 0)
            q.setParameterList("roles", roles);
        @SuppressWarnings("unchecked")
        List<PredefinedCalendarDefinition> defs = q.list();
        for (PredefinedCalendarDefinition def : defs) {
            PredefinedCalendarConfiguration config = new PredefinedCalendarConfiguration();
            config.setCalendarDefinition(def);
            config.setSubscribeId(subscribeId);
            storeCalendarConfiguration(config);
        }
    } catch (HibernateException ex) {
        throw convertHibernateAccessException(ex);
    }
}

11 View Complete Implementation : OrderDAO.java
Copyright GNU Affero General Public License v3.0
Author : LibrePlan
/**
 * If user has permissions over all orders and not filters are preplaceded it returns <code>null</code>.
 * Otherwise, it returns the list of orders
 * identifiers for which the user has read permissions and the filters preplaced.
 */
private List<Long> getOrdersIdsFiltered(User user, List<Label> labels, List<Criterion> criteria, ExternalCompany customer, OrderStatusEnum state, Boolean excludeFinishedProject) {
    List<Long> ordersIdsByReadAuthorization = getOrdersIdsByReadAuthorization(user);
    String strQuery = "SELECT o.id ";
    strQuery += "FROM Order o ";
    String where = "";
    String whereFinal = "";
    if (labels != null && !labels.isEmpty()) {
        for (int i = 0; i < labels.size(); i++) {
            if (where.isEmpty()) {
                where += "WHERE ";
            } else {
                where += "AND ";
            }
            where += ":label" + i + " IN elements(o.labels) ";
        }
    }
    if (criteria != null && !criteria.isEmpty()) {
        strQuery += "JOIN o.criterionRequirements cr ";
        if (where.isEmpty()) {
            where += "WHERE ";
        } else {
            where += "AND ";
        }
        where += "cr.criterion IN (:criteria) ";
        where += "AND cr.clreplaced = DirectCriterionRequirement ";
        whereFinal += "GROUP BY o.id ";
        whereFinal += "HAVING count(o.id) = :criteriaSize ";
    }
    if (customer != null) {
        if (where.isEmpty()) {
            where += "WHERE ";
        } else {
            where += "AND ";
        }
        where += "o.customer = :customer ";
    }
    if (state != null) {
        if (where.isEmpty()) {
            where += "WHERE ";
        } else {
            where += "AND ";
        }
        where += "o.state = :state ";
    }
    if (excludeFinishedProject != null && excludeFinishedProject == true) {
        if (where.isEmpty()) {
            where += "WHERE ";
        } else {
            where += "AND ";
        }
        where += "o.state <> '" + OrderStatusEnum.FINISHED.getIndex() + "'";
    }
    // If not restrictions by labels, criteria, customer or state
    if (where.isEmpty()) {
        return ordersIdsByReadAuthorization;
    }
    if (ordersIdsByReadAuthorization != null && !ordersIdsByReadAuthorization.isEmpty()) {
        if (where.isEmpty()) {
            where += "WHERE ";
        } else {
            where += "AND ";
        }
        where += "o.id IN (:ids) ";
    }
    strQuery += where + whereFinal;
    Query query = getSession().createQuery(strQuery);
    if (labels != null && !labels.isEmpty()) {
        int i = 0;
        for (Label label : labels) {
            query.setParameter("label" + i, label);
            i++;
        }
    }
    if (criteria != null && !criteria.isEmpty()) {
        query.setParameterList("criteria", criteria);
        query.setParameter("criteriaSize", (long) criteria.size());
    }
    if (customer != null) {
        query.setParameter("customer", customer);
    }
    if (state != null) {
        query.setParameter(STATE_PARAMETER, state);
    }
    if (ordersIdsByReadAuthorization != null && !ordersIdsByReadAuthorization.isEmpty()) {
        query.setParameterList("ids", ordersIdsByReadAuthorization);
    }
    return query.list();
}