Example usage for org.hibernate Query setParameterList

List of usage examples for org.hibernate Query setParameterList

Introduction

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

Prototype

Query<R> setParameterList(int position, Object[] values);

Source Link

Usage

From source file:de.decidr.model.commands.workflowmodel.GetWorkflowParticipationStateCommand.java

License:Apache License

/**
 * Returns all users that are known to the system using the current set of
 * usernames and emails.//from   ww w .  ja  v  a 2  s  . c  o m
 * 
 * @param session
 *            current Hibernate session
 * @return list of known users
 */
@SuppressWarnings("unchecked")
private List<User> getKnownUsers(Session session) {
    /*
     * Workaround for "empty parameter list bug":
     * 
     * using setParameterList with a null value or an empty list results in
     * a QuerySyntaxException.
     */
    List<String> nonEmptyEmails;
    if ((emails == null) || emails.isEmpty()) {
        nonEmptyEmails = new LinkedList<String>();
        // this must not be a valid email address
        nonEmptyEmails.add("");
    } else {
        nonEmptyEmails = emails;
    }

    List<String> nonEmptyUsernames;
    if ((usernames == null) || usernames.isEmpty()) {
        nonEmptyUsernames = new LinkedList<String>();
        // this must not be a valid username
        nonEmptyUsernames.add("");
    } else {
        nonEmptyUsernames = usernames;
    }

    List<Long> nonEmptyUserIds;
    if ((userIds == null) || userIds.isEmpty()) {
        nonEmptyUserIds = new LinkedList<Long>();
        // this must not be a valid user ID
        nonEmptyUserIds.add(UserRole.UNKNOWN_USER_ID);
    } else {
        nonEmptyUserIds = userIds;
    }

    String hql = "select distinct u " + "from User as u left join fetch u.userProfile "
            + "where (u.email in (:emails)) or " + "(u.userProfile.username in (:usernames)) or "
            + "(u.id in (:userIds))";

    Query q = session.createQuery(hql);

    q.setParameterList("emails", nonEmptyEmails);
    q.setParameterList("usernames", nonEmptyUsernames);
    q.setParameterList("userIds", nonEmptyUserIds);

    return q.list();
}

From source file:de.fhdo.gui.admin.modules.collaboration.SvAssignmentDetails.java

License:Apache License

public SvAssignmentDetails() {
    Map args = Executions.getCurrent().getArg();

    svAssignmentData = (SvAssignmentData) args.get("svAssignmentData");

    //Prepare Data
    Set<SvAssignmentData> userData = new HashSet<SvAssignmentData>();
    Set<SvAssignmentData> choosenUserData = new HashSet<SvAssignmentData>();

    Session hb_session_kollab = de.fhdo.collaboration.db.HibernateUtil.getSessionFactory().openSession();
    //hb_session_kollab.getTransaction().begin();

    try {/*  w w  w  .  j a  va 2 s .c o m*/

        if (!newEntry) {
            //Load User Info here
            //1.GetGroupMembers
            String hqlTermUser = "select distinct cu from Collaborationuser cu join fetch cu.organisation o join fetch cu.assignedTerms a where cu.enabled=:enabled and a.classId=:classId";
            Query qTermUser = hb_session_kollab.createQuery(hqlTermUser);
            qTermUser.setParameter("enabled", true);
            qTermUser.setParameter("classId", svAssignmentData.getClassId());
            List<Collaborationuser> cuList = qTermUser.list();

            for (Collaborationuser cu : cuList) {
                SvAssignmentData dgui = new SvAssignmentData(cu.getId(), cu.getFirstName(), cu.getName(),
                        cu.getOrganisation().getOrganisation());
                choosenUserData.add(dgui);
            }
        }
        //2.GetNotGroupMembers
        String hqlNotMembers = "select distinct cu from Collaborationuser cu join fetch cu.organisation o join fetch cu.roles r where cu.enabled=:enabled AND deleted=0 ";
        hqlNotMembers += " and r.name in (:nameList)";
        Query qNotMembers = hb_session_kollab.createQuery(hqlNotMembers);
        qNotMembers.setParameter("enabled", true);
        ArrayList<String> nameList = new ArrayList<String>();
        nameList.add(CODES.ROLE_INHALTSVERWALTER);
        nameList.add(CODES.ROLE_ADMIN); //=> Darf sowieso alles sehen
        qNotMembers.setParameterList("nameList", nameList);
        List<Collaborationuser> cuNotMemberList = qNotMembers.list();

        for (Collaborationuser cu : cuNotMemberList) {
            SvAssignmentData dgui = new SvAssignmentData(cu.getId(), cu.getFirstName(), cu.getName(),
                    cu.getOrganisation().getOrganisation());
            boolean member = false;

            if (!newEntry) {
                for (SvAssignmentData info : choosenUserData) {
                    if (dgui.getCollaborationuserId() == info.getCollaborationuserId()) {
                        member = true;
                    }
                }
            }
            if (!member) {
                userData.add(dgui);
            }
        }
    } catch (Exception e) {
        logger.error("[" + this.getClass().getCanonicalName() + "] Fehler bei DualList preparation(): "
                + e.getMessage());
    } finally {
        hb_session_kollab.close();
    }

    Executions.getCurrent().setAttribute("userData", userData);
    Executions.getCurrent().setAttribute("choosenUserData", choosenUserData);
}

From source file:de.fhg.fokus.hss.db.op.DSAI_IMPU_DAO.java

License:Open Source License

/**
 *
 * <p>//from  w w w.jav a2s  . co m
 * Method developed by Instrumentacion y Componentes S.A (Inycom) (ims at inycom dot es)
 * to return IMPUs attached to the DSAI that, as well, have in their SPs at least one of the IFCs from ifc_list
 *
 * @param session   Hibernate session
 * @param id_dsai   DSAI identifier
 * @param ifc_list   list of IFCs
 * @return
 */

public static List get_IMPU_by_DSAI_for_IFC_list(Session session, int id_dsai, List ifc_list) {

    Query query;
    query = session.createSQLQuery("Select distinct i.* FROM sp_ifc s, impu i, dsai_impu di"
            + " where di.id_dsai=? and i.id=di.id_impu" + " and i.id_sp=s.id_sp and s.id_ifc in (:ifc_list)")
            .addEntity(IMPU.class);
    query.setInteger(0, id_dsai);
    query.setParameterList("ifc_list", ifc_list);

    return query.list();
}

From source file:de.fhg.fokus.hss.db.op.IFC_DAO.java

License:Open Source License

/**
  * This method returns all iFCs associated to the same AS as the iFCs given
  * <p>// w  ww . j a  v a 2s  .c o m
  * Method developed by Instrumentacion y Componentes S.A (Inycom) (ims at inycom dot es) to support the
  * DSAI Information Element
  *
  * @param session   Hiberntate session
  * @param list_ifc   lisf of IFCs
  * @return List of IFCs
  */
public static List get_all_by_Same_AS_ID(Session session, List list_ifc) {

    List list_as = new ArrayList();

    Iterator it = list_ifc.iterator();
    IFC ifc = null;
    while (it.hasNext()) {
        ifc = (IFC) it.next();
        Integer as = (Integer) ifc.getId_application_server();
        if (list_as.contains(as)) {
        } else {
            list_as.add(as);
        }
    }
    if (list_as.isEmpty()) {
        Query query2 = null;
        query2 = session.createSQLQuery("select distinct (ifc.id_application_server) from ifc");
        list_as = query2.list();
    }
    Query query = null;
    query = session.createSQLQuery("select * from ifc where id_application_server in (:list_as)")
            .addEntity(IFC.class);
    query.setParameterList("list_as", list_as);

    return query.list();
}

From source file:de.fhg.fokus.hss.db.op.IMPU_DAO.java

License:Open Source License

/**
 * This method returns all IMPUs attached to the iFCs given.
 * <p>//w ww.  j  a v  a  2  s. co m
 * Method developed by Instrumentacion y Componentes S.A (Inycom) (ims at inycom dot es) to support the DSAI Information Element
 *
 * @param session Hibernate session
 * @param ifc_list List of IFC
 * @return List impu
 */
public static List get_all_IMPU_for_IFC_list(Session session, List ifc_list) {

    List ifc_lista = new ArrayList();
    for (int i = 0; i < ifc_list.size(); i++) {
        IFC ifc = (IFC) ifc_list.get(i);
        ifc_lista.add(ifc.getId());
    }

    if (ifc_lista.isEmpty()) {
        return null;
    }

    Query query = null;
    query = session.createSQLQuery(
            "select distinct IMPU.* from impu IMPU, sp_ifc SP_IFC, ifc IFC where SP_IFC.id_sp=IMPU.id_sp and SP_IFC.id_ifc=IFC.id and IFC.id in (:ifc_lista)")
            .addEntity(IMPU.class);
    query.setParameterList("ifc_lista", ifc_lista);

    return query.list();
}

From source file:de.innovationgate.webgate.api.jdbc.HibernateResultSet.java

License:Open Source License

public static void injectQueryParams(Query hibQuery, Map map) throws WGAPIException {

    if (map == null || map.size() == 0) {
        return;/*from   ww w . ja v  a2 s  .co m*/
    }

    String[] pNames = hibQuery.getNamedParameters();
    for (int i = 0; i < pNames.length; i++) {
        String pName = pNames[i];
        Object value = map.get(pName);
        if (value != null) {
            if (value instanceof WGDocument) {
                value = ((WGDocument) value).getNativeObject();
            }
            if (value instanceof Double) {
                hibQuery.setDouble(pName, (Double) value);
            } else if (value instanceof Collection<?>) {
                hibQuery.setParameterList(pName, (Collection<?>) value);
            } else {
                hibQuery.setParameter(pName, value);
            }
        }
    }

}

From source file:de.innovationgate.webgate.api.jdbc.WGDatabaseImpl.java

License:Open Source License

public List<WGRelationData> getIncomingRelations(Object structKey, String language, String contentClass,
        String relName, String relGroupName, Boolean includeUnreleased, WGColumnSet order)
        throws WGAPIException {
    if (_ddlVersion < WGDatabase.CSVERSION_WGA5) {
        return Collections.emptyList();
    }/*from  ww  w  . ja va  2 s .c o m*/

    StringBuffer hql = new StringBuffer(
            "select relation from ContentRelation as relation where relation.targetstructentry = :structkey and relation.targetlanguage = :language and relation.parentcontent.status in (:states)");
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("structkey", structKey);
    parameters.put("language", language);

    if (relName != null) {
        hql.append(" and relation.name = :relname");
        parameters.put("relname", relName);
    }

    if (relGroupName != null) {
        hql.append(" and relation.group = :relgroup");
        parameters.put("relgroup", relGroupName);
    }

    if (contentClass != null) {
        hql.append(" and relation.parentcontent.contentclass = :sourceclass");
        parameters.put("sourceclass", contentClass);
    }

    if (order != null) {
        hql.append(" order by ");
        hql.append(buildHqlContentOrderClause("relation.parentcontent", order, parameters));
    }

    Query query = getSession().createQuery(hql.toString());
    for (Map.Entry<String, Object> param : parameters.entrySet()) {
        query.setParameter(param.getKey(), param.getValue());
    }

    if (includeUnreleased) {
        query.setParameterList("states",
                new Object[] { WGContent.STATUS_DRAFT, WGContent.STATUS_REVIEW, WGContent.STATUS_RELEASE });
    } else {
        query.setParameterList("states", new Object[] { WGContent.STATUS_RELEASE });
    }

    /*
    Criteria crit = getSession().createCriteria(ContentRelation.class);
    crit.add(Restrictions.eq("targetstructentry", structKey));
    crit.add(Restrictions.eq("targetlanguage", language));
    crit.setFetchMode("parentcontent", FetchMode.SELECT);
            
    if (includeUnreleased) {
    crit.createCriteria("parentcontent").add(Restrictions.in("status", new Object[] {WGContent.STATUS_DRAFT, WGContent.STATUS_REVIEW, WGContent.STATUS_RELEASE}));
    }
    else {
    crit.createCriteria("parentcontent").add(Restrictions.eq("status", WGContent.STATUS_RELEASE));
    }*/

    List<WGRelationData> incoming = new ArrayList();

    for (ContentRelation rel : (List<ContentRelation>) query.list()) {
        WGRelationData relData = createWGRelationData(rel);
        incoming.add(relData);
    }

    return incoming;

}

From source file:de.iteratec.iteraplan.persistence.dao.TimeseriesDAO.java

License:Open Source License

private Integer updateWithNamedQuery(final String queryName, final String parameterName,
        final Object parameter) {
    HibernateCallback<Integer> callback = new HibernateCallback<Integer>() {
        public Integer doInHibernate(Session session) {
            Query queryObject = session.getNamedQuery(queryName);
            if (parameter instanceof Collection) {
                queryObject.setParameterList(parameterName, (Collection) parameter);
            } else {
                queryObject.setParameter(parameterName, parameter);
            }/*from w ww .  j  a va2 s.co  m*/
            return Integer.valueOf(queryObject.executeUpdate());
        }
    };

    return getHibernateTemplate().execute(callback);
}

From source file:de.unisb.cs.st.javalanche.mutation.results.persistence.QueryManager.java

License:Open Source License

/**
 * Query the database for mutations with the given ids.
 * /* w w  w  .j  av a2  s. co  m*/
 * @param ids
 *            The ids that are used to query.
 * @return Return a list of mutations with the given ids.
 */
public static List<Mutation> getMutationsByIds(Long[] ids) {
    Session session = openSession();
    Transaction tx = session.beginTransaction();

    Query query = session.createQuery("FROM Mutation m  WHERE m.id IN (:ids)");
    query.setParameterList("ids", ids);
    List<Mutation> results = query.list();
    int flushCount = 0;
    for (Mutation m : results) {
        m.loadAll();
        flushCount++;
        // if (flushCount % 10 == 0) {
        // session.flush();
        // session.clear();
        // }
    }
    tx.commit();
    session.close();
    return results;
}

From source file:de.unisb.cs.st.javalanche.mutation.util.ResultDeleter.java

License:Open Source License

/**
 * Deletes results for mutations with given ids.
 * /*from   w  ww . ja  v  a 2s  .c  om*/
 * @param ids
 *            ids of the mutations for which the result is deleted.
 */
private static void deleteMutationResults(List<Long> ids) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    Query q = session.createQuery("FROM Mutation WHERE mutationResult IS NOT NULL AND id IN (:idList)");
    q.setParameterList("idList", ids);
    deleteResults(session, q);
    tx.commit();
    session.close();
}