コード例 #1
0
ファイル: Finder.java プロジェクト: kevonz/saas-cms
 /**
  * 将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;
 }
コード例 #2
0
 private void setQuery(Query query, final Map<String, Object> paramMap) {
   if (paramMap == null || paramMap.isEmpty()) {
     return;
   }
   for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
     Object v = entry.getValue();
     if (v instanceof Object[]) {
       query.setParameterList(entry.getKey(), (Object[]) v);
     } else if (v instanceof Collection) {
       query.setParameterList(entry.getKey(), (Collection<?>) v);
     } else {
       query.setParameter(entry.getKey(), v);
     }
   }
 }
コード例 #3
0
 public List<SalFixOnline> getFixOnlines(Map qo) {
   StringBuilder sb = new StringBuilder();
   sb.append("select sfo from SalFixOnline sfo").append(" left outer join fetch sfo.id.item si");
   String fetch = (String) qo.get(Constants.PARAM_FETCH);
   if (fetch != null) {
     String[] fetchs = fetch.split(",");
     for (int i = 0; i < fetchs.length; i++)
       sb.append(" left outer join fetch sfo.").append(fetchs[i].trim());
   }
   sb.append(" where 1 = 1");
   if (qo != null) {
     if (qo.containsKey("branch.id")) sb.append(" and sfo.id.branch.id = :branchId");
     if (qo.containsKey("depart.id")) sb.append(" and sfo.id.depart.id = :departId");
     if (qo.containsKey("person.id")) sb.append(" and sfo.id.person.id = :personId");
     if (qo.containsKey("persons")
         && qo.get("persons") != null
         && ((List) qo.get("persons")).size() > 0)
       sb.append(" and sfo.id.person.id in (:persons)");
     if (qo.containsKey("items") && qo.get("items") != null && ((List) qo.get("items")).size() > 0)
       sb.append(" and sfo.id.item.id in (:items)");
     if (qo.containsKey("onDate_from")) sb.append(" and sfo.id.onDate >= :onDate_from");
     if (qo.containsKey("onDate_to")) sb.append(" and sfo.id.onDate <= :onDate_to");
     if (qo.containsKey("downDate_from")) sb.append(" and sfo.downDate >= :downDate_from");
     if (qo.containsKey("downDate_to")) sb.append(" and sfo.downDate <= :downDate_to");
   }
   sb.append(" order by sfo.id.person.workerId, sfo.id.depart.id, si.no");
   Query q = getSession().createQuery(sb.toString());
   if (qo != null) {
     if (qo.containsKey("branch.id")) q.setParameter("branchId", qo.get("branch.id"));
     if (qo.containsKey("depart.id")) q.setParameter("departId", qo.get("depart.id"));
     if (qo.containsKey("person.id")) q.setParameter("personId", qo.get("person.id"));
     if (qo.containsKey("persons")
         && qo.get("persons") != null
         && ((List) qo.get("persons")).size() > 0)
       q.setParameterList("persons", (List) qo.get("persons"));
     if (qo.containsKey("items") && qo.get("items") != null && ((List) qo.get("items")).size() > 0)
       q.setParameterList("items", (List) qo.get("items"));
     if (qo.containsKey("onDate_from"))
       q.setParameter("onDate_from", ObjectUtil.toCalendar(qo.get("onDate_from")));
     if (qo.containsKey("onDate_to"))
       q.setParameter("onDate_to", ObjectUtil.toCalendar(qo.get("onDate_to")));
     if (qo.containsKey("downDate_from"))
       q.setParameter("downDate_from", ObjectUtil.toCalendar(qo.get("downDate_from")));
     if (qo.containsKey("downDate_to"))
       q.setParameter("downDate_to", ObjectUtil.toCalendar(qo.get("downDate_to")));
   }
   return (List<SalFixOnline>) q.list();
 }
コード例 #4
0
 public List<SalFactD> getFactDetails(Map qo) {
   StringBuilder sb = new StringBuilder();
   sb.append("select sfd from SalFactD sfd")
       .append(" left outer join fetch sfd.id.fact sf")
       .append(" left outer join fetch sfd.id.item si")
       .append(" left outer join fetch sfd.person p")
       .append(" where 1 = 1");
   if (qo != null) {
     if (qo.containsKey("branch.id")) sb.append(" and sf.id.branch.id = :branchId");
     if (qo.containsKey("fact.no")) sb.append(" and sf.id.no = :factNo");
     if (qo.containsKey("depart.id")) sb.append(" and sf.depart.id = :departId");
     if (qo.containsKey("person.id")) sb.append(" and sfd.person.id = :personId");
     if (qo.containsKey("persons")
         && qo.get("persons") != null
         && ((List) qo.get("persons")).size() > 0) sb.append(" and sfd.person.id in (:persons)");
   }
   sb.append(" order by sf.id.branch.id, sf.depart.id, sf.id.no, sfd.id.no, si.no");
   Query q = getSession().createQuery(sb.toString());
   if (qo != null) {
     if (qo.containsKey("branch.id")) q.setParameter("branchId", qo.get("branch.id"));
     if (qo.containsKey("fact.no")) q.setParameter("factNo", qo.get("fact.no"));
     if (qo.containsKey("depart.id")) q.setParameter("departId", qo.get("depart.id"));
     if (qo.containsKey("person.id")) q.setParameter("personId", qo.get("person.id"));
     if (qo.containsKey("persons")
         && qo.get("persons") != null
         && ((List) qo.get("persons")).size() > 0)
       q.setParameterList("persons", (List) qo.get("persons"));
   }
   return (List<SalFactD>) q.list();
 }
コード例 #5
0
  @Override
  public List<MenuItem> getMenuItems(
      List<Integer> roleIds, Integer sequence, String parentMenuUid) {
    String hql =
        "SELECT distinct menuItem FROM MenuItem menuItem join menuItem.menu.menuRoleAssocs menuRoleAssoc  WHERE 1=1 ";
    if (roleIds != null) {
      hql += " AND menuRoleAssoc.role.roleId IN ( :roleIds )";
    }
    if (parentMenuUid != null) {
      hql += " AND menuItem.parentMenuUid =:parentMenuUid";
    }
    if (sequence != null) {
      hql += " AND menuItem.sequence =:sequence";
    }
    if (parentMenuUid == null) {
      hql += " AND menuItem.parentMenuUid is null";
    }
    hql += " ORDER BY menuItem.sequence";

    Query query = getSession().createQuery(hql);
    if (roleIds != null) {
      query.setParameterList("roleIds", roleIds);
    }
    if (parentMenuUid != null) {
      query.setParameter("parentMenuUid", parentMenuUid);
    }
    if (sequence != null) {
      query.setParameter("sequence", sequence);
    }
    return query.list();
  }
  /**
   * Binds a parameter value to a query parameter.
   *
   * @param parameter the report parameter
   */
  protected void setParameter(JRValueParameter parameter) {
    String hqlParamName = getHqlParameterName(parameter.getName());
    Class<?> clazz = parameter.getValueClass();
    Object parameterValue = parameter.getValue();

    if (log.isDebugEnabled()) {
      log.debug(
          "Parameter " + hqlParamName + " of type " + clazz.getName() + ": " + parameterValue);
    }

    Type type = hibernateTypeMap.get(clazz);

    if (type != null) {
      query.setParameter(hqlParamName, parameterValue, type);
    } else if (Collection.class.isAssignableFrom(clazz)) {
      query.setParameterList(hqlParamName, (Collection<?>) parameterValue);
    } else {
      if (session.getSessionFactory().getClassMetadata(clazz)
          != null) // param type is a hibernate mapped entity
      {
        query.setEntity(hqlParamName, parameterValue);
      } else // let hibernate try to guess the type
      {
        query.setParameter(hqlParamName, parameterValue);
      }
    }
  }
コード例 #7
0
ファイル: DbHelper.java プロジェクト: Yogitha6/Campus-Talk
 public List<User> getUserSearchResults(int topicId) {
   // TODO Auto-generated method stub
   List<User> userArr = new ArrayList<User>();
   Session session = sessionFactory.openSession();
   Transaction tx = null;
   try {
     tx = session.beginTransaction();
     Query query1 = session.createQuery("select userId from UserTopic where topicId = :topicId");
     query1.setString("topicId", String.valueOf(topicId));
     Query query2 = session.createQuery("from User where userId in (:userList)");
     query2.setParameterList("userList", query1.list());
     userArr = query2.list();
     /*for(Topic topic : topicArr){
     	System.out.println("Topic Description----"+topic.getTopicDescription());
     	System.out.println("Topic Id----"+topic.getTopicId());
     }*/
   } catch (HibernateException e) {
     if (tx != null) {
       tx.rollback();
       e.printStackTrace();
     }
   } finally {
     session.close();
   }
   return userArr;
 }
コード例 #8
0
ファイル: BaseDao.java プロジェクト: artyama/jeesite
 /**
  * 设置查询参数
  *
  * @param query
  * @param parameter
  */
 private void setParameter(Query query, Parameter parameter) {
   if (parameter != null) {
     Set<String> keySet = parameter.keySet();
     for (String string : keySet) {
       Object value = parameter.get(string);
       // 这里考虑传入的参数是什么类型,不同类型使用的方法不同
       if (value instanceof Collection<?>) {
         query.setParameterList(string, (Collection<?>) value);
       } else if (value instanceof Object[]) {
         query.setParameterList(string, (Object[]) value);
       } else {
         query.setParameter(string, value);
       }
     }
   }
 }
コード例 #9
0
ファイル: OauthRepository.java プロジェクト: jyotisingh/gocd
 private <T> void deleteEntitiesByUserIds(
     Class<? extends OauthDomainEntity<T>> type, Session session, List<String> userIds) {
   Query query =
       session.createQuery(
           String.format("DELETE FROM %s WHERE userId IN (:userIds)", type.getSimpleName()));
   query.setParameterList("userIds", userIds);
   query.executeUpdate();
 }
コード例 #10
0
  @Override
  @SuppressWarnings("unchecked")
  public Collection<OrganisationUnit> getByNames(Collection<String> names) {
    Query query = getQuery("from OrganisationUnit where name in :names");
    query.setParameterList("names", names);

    return query.list();
  }
コード例 #11
0
 private List<?> executeNamedQuery(GetDataAvailabilityRequest req, Session session) {
   final boolean features = req.isSetFeaturesOfInterest();
   final boolean observableProperties = req.isSetObservedProperties();
   final boolean procedures = req.isSetProcedures();
   String namedQueryName = null;
   Map<String, Collection<String>> parameter = Maps.newHashMap();
   // all
   if (features && observableProperties && procedures) {
     namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_FEATURES_PROCEDURES_OBSERVED_PROPERTIES;
     parameter.put(FEATURES, req.getFeaturesOfInterest());
     parameter.put(OBSERVABLE_PROPERTIES, req.getObservedProperties());
     parameter.put(PROCEDURES, req.getProcedures());
   }
   // observableProperties and procedures
   else if (!features && observableProperties && procedures) {
     namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_PROCEDURES_OBSERVED_PROPERTIES;
     parameter.put(OBSERVABLE_PROPERTIES, req.getObservedProperties());
     parameter.put(PROCEDURES, req.getProcedures());
   }
   // only observableProperties
   else if (!features && observableProperties && !procedures) {
     namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_OBSERVED_PROPERTIES;
     parameter.put(OBSERVABLE_PROPERTIES, req.getObservedProperties());
   }
   // only procedures
   else if (!features && !observableProperties && procedures) {
     namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_PROCEDURES;
     parameter.put(PROCEDURES, req.getProcedures());
   }
   // features and observableProperties
   else if (features && observableProperties && !procedures) {
     namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_FEATURES_OBSERVED_PROPERTIES;
     parameter.put(FEATURES, req.getFeaturesOfInterest());
     parameter.put(OBSERVABLE_PROPERTIES, req.getObservedProperties());
   }
   // features and procedures
   else if (features && !observableProperties && procedures) {
     namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_FEATURES_PROCEDURES;
     parameter.put(FEATURES, req.getFeaturesOfInterest());
     parameter.put(PROCEDURES, req.getProcedures());
   }
   // only features
   else if (features && !observableProperties && procedures) {
     namedQueryName = SQL_QUERY_GET_DATA_AVAILABILITY_FOR_FEATURES;
     parameter.put(FEATURES, req.getFeaturesOfInterest());
   }
   if (StringHelper.isNotEmpty(namedQueryName)) {
     Query namedQuery = session.getNamedQuery(namedQueryName);
     for (String key : parameter.keySet()) {
       namedQuery.setParameterList(key, parameter.get(key));
     }
     LOGGER.debug(
         "QUERY getProceduresForFeatureOfInterest(feature) with NamedQuery: {}", namedQuery);
     namedQuery.setResultTransformer(new DataAvailabilityTransformer(session));
     return namedQuery.list();
   }
   return Lists.newLinkedList();
 }
コード例 #12
0
 public List<EgActiondetails> getEgActiondetailsFilterBy(
     final ArrayList<String> actionType, final String moduleType) {
   final Query qry =
       getCurrentSession()
           .createQuery(
               "from EgActiondetails ad where ad.actiontype in (:actionType) and ad.moduletype=:moduleType order by lastmodifieddate");
   qry.setParameterList("actionType", actionType);
   qry.setString("moduleType", moduleType);
   return qry.list();
 }
コード例 #13
0
 @SuppressWarnings("unchecked")
 public List<HTextFlow> findByIdList(List<Long> idList) {
   if (idList == null || idList.isEmpty()) {
     return new ArrayList<HTextFlow>();
   }
   Query query = getSession().createQuery("FROM HTextFlow WHERE id in (:idList)");
   query.setParameterList("idList", idList);
   // caching could be expensive for long idLists
   query.setCacheable(false).setComment("TextFlowDAO.getByIdList");
   return query.list();
 }
コード例 #14
0
 private Query getNamedQueryWithParams(final String namedQuery, final Object... params) {
   final Query q = getSession().getNamedQuery(namedQuery);
   int index = 0;
   for (final Object param : params) {
     if (param instanceof Collection)
       q.setParameterList(String.valueOf("param_" + index), (Collection) param);
     else q.setParameter(index, param);
     index++;
   }
   return q;
 }
コード例 #15
0
ファイル: BaseDao.java プロジェクト: winhell/newTemplate
  public List<T> findInCollectionByPage(
      final String hql, final List value, final int offset, final int pageSize)
      throws HibernateException {

    Query query = getSession().createQuery(hql);
    if (null != value) {
      query.setParameterList("paraList", value);
    }
    if (offset > 1) return query.setFirstResult(offset).setMaxResults(pageSize).list();
    else return query.list();
  }
コード例 #16
0
ファイル: QualityFormDAO.java プロジェクト: Kuew/libreplan
 @Override
 public void checkHasTasks(QualityForm qualityForm) throws ValidationException {
   Query query =
       getSession()
           .createQuery(
               "FROM TaskQualityForm taskQualityForm JOIN taskQualityForm.qualityForm tq WHERE tq IN (:qualityForms)");
   query.setParameterList("qualityForms", Collections.singleton(qualityForm));
   if (!query.list().isEmpty()) {
     throw ValidationException.invalidValue(
         "Cannot delete quality form. It is being used at this moment by some task.", qualityForm);
   }
 }
コード例 #17
0
  @SuppressWarnings("unchecked")
  public List<Permission> getPermissionsByIds(Integer[] ids) {
    if (ids != null && ids.length > 0) {
      Session session = sessionFactory.getCurrentSession();
      String select = "SELECT p " + "FROM Permission p " + "WHERE p.id IN (:ids)";
      Query query = session.createQuery(select);
      query.setParameterList("ids", ids);

      return (List<Permission>) query.list();
    }

    return new ArrayList<Permission>();
  }
コード例 #18
0
  public List<SalFactD> getSelectedSalFactDs(Map qo) {
    StringBuilder sb = new StringBuilder();
    sb.append("select s, p.depart from SalFactD s")
        .append(" left outer join fetch s.id.fact")
        .append(" left outer join fetch s.id.fact.depart")
        .append(" left outer join fetch s.id.fact.issuer")
        .append(" left outer join fetch s.id.item")
        .append(" left outer join fetch s.person")
        .append(", PsnOnline p")
        .append(" where 1=1")
        .append(" and s.id.fact.id.branch.id = p.branch.id")
        .append(" and s.person.id = p.person.id")
        .append(" and p.onDate <= s.id.fact.issueDate")
        .append(" and p.downDate >= s.id.fact.issueDate");
    if (qo != null) {
      if (qo.containsKey("branch.id")) sb.append(" and s.id.fact.id.branch.id = :bid");
      if (qo.containsKey("date_from") && qo.get("date_from") != null)
        sb.append(" and s.id.fact.issueDate >= :from");
      if (qo.containsKey("date_to") && qo.get("date_to") != null)
        sb.append(" and s.id.fact.issueDate <= :end");
      if (qo.containsKey("items.id")) sb.append(" and s.id.item.id in (:items)");
    }
    sb.append(
        " order by s.id.fact.depart.id, p.depart.id, s.person.workerId, s.id.fact.id.no, s.id.item.id");
    Query q = getSession().createQuery(sb.toString());
    if (qo != null) {
      if (qo.containsKey("branch.id")) q.setParameter("bid", qo.get("branch.id"));
      if (qo.containsKey("date_from") && qo.get("date_from") != null)
        q.setParameter("from", ObjectUtil.toCalendar(qo.get("date_from")));
      if (qo.containsKey("date_to") && qo.get("date_to") != null)
        q.setParameter("end", ObjectUtil.toCalendar(qo.get("date_to")));
      if (qo.containsKey("items.id")) {
        List<SalItem> list = (List<SalItem>) qo.get("items.id");
        List<Integer> items = new ArrayList<Integer>();
        for (SalItem item : list) {
          if (items.indexOf(item.getId()) == -1) items.add(item.getId());
        }
        q.setParameterList("items", items);
      }
    }

    List l = q.list();
    List<SalFactD> ret = new ArrayList<SalFactD>();
    for (int i = 0; i < l.size(); i++) {
      Object[] obj = (Object[]) l.get(i);
      SalFactD sal = (SalFactD) obj[0];
      sal.getPerson().setDepart((Department) obj[1]);
      ret.add(sal);
    }
    return ret;
  }
コード例 #19
0
ファイル: DaoUtils.java プロジェクト: yycdaizi/bwt4
  /**
   * @param query
   * @param paramName
   * @param value
   * @param type
   * @throws HibernateException
   */
  public static void applyNamedParameterToQuery(
      Query query, String paramName, Object value, Type type) throws HibernateException {

    if (value instanceof Collection<?>) {
      if (type != null) {
        query.setParameterList(paramName, (Collection<?>) value, type);
      } else {
        query.setParameterList(paramName, (Collection<?>) value);
      }
    } else if (value instanceof Object[]) {
      if (type != null) {
        query.setParameterList(paramName, (Object[]) value, type);
      } else {
        query.setParameterList(paramName, (Object[]) value);
      }
    } else {
      if (type != null) {
        query.setParameter(paramName, value, type);
      } else {
        query.setParameter(paramName, value);
      }
    }
  }
コード例 #20
0
ファイル: BaseDAO.java プロジェクト: brucevsked/vskeddemolist
 private Query createQuery(
     String queryString, Map<String, Object> params, int startRow, int pageSize) {
   Query query = getSession().createQuery(queryString);
   if (params != null) {
     for (Map.Entry<String, Object> entry : params.entrySet()) {
       String paramName = entry.getKey();
       Object obj = entry.getValue();
       log.info("DAO:set param:" + paramName + " with value:" + obj);
       if (obj instanceof List) {
         query.setParameterList(paramName, (Collection) obj);
       } else if (obj instanceof Object[]) {
         query.setParameterList(paramName, (Object[]) obj);
       } else {
         query.setParameter(paramName, obj);
       }
     }
   }
   query.setCacheable(true);
   if (pageSize != -1) {
     query.setFirstResult(startRow).setMaxResults(pageSize);
   }
   return query;
 }
コード例 #21
0
 /** {@inheritDoc} */
 public TypedQuery<X> setParameter(String name, Object value) {
   try {
     if (value instanceof Collection) {
       query.setParameterList(name, (Collection) value);
     } else {
       query.setParameter(name, value);
     }
     registerParameterBinding(getParameter(name), value);
     return this;
   } catch (QueryParameterException e) {
     throw new IllegalArgumentException(e);
   } catch (HibernateException he) {
     throw getEntityManager().convert(he);
   }
 }
コード例 #22
0
ファイル: GenericDao.java プロジェクト: jekay100/J2EENote
 @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);
       }
     }
   }
 }
コード例 #23
0
  public List<Object[]> getTextFlowAndTarget(List<Long> idList, Long localeId) {
    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder
        .append("from HTextFlow tf ")
        .append("left join tf.targets tft with tft.locale.id =:localeId ")
        .append("where tf.id in (:idList)");

    Query q = getSession().createQuery(queryBuilder.toString());
    q.setParameterList("idList", idList);
    q.setParameter("localeId", localeId);
    q.setCacheable(true);
    q.setComment("TextFlowTargetDAO.getTextFlowTarget");

    return q.list();
  }
コード例 #24
0
  @SuppressWarnings("unchecked")
  @Override
  public List<GarantieBeneficiaireDto> getListeBeneficiairesFromContrats(
      List<Long> listeUidContrats, Long uidAssure, boolean filtrerContratEnCOurs) {
    final StringBuffer requete =
        new StringBuffer("select uidBeneficiaire, contrat.id, role.id, role.libelle ");
    requete.append("from Garantie where ");
    if (listeUidContrats != null && listeUidContrats.size() > 0) {
      requete.append("contrat.id in (:listeUidContrats) and ");
    }
    if (filtrerContratEnCOurs) {
      requete.append("statut.id = :idStatutGarantieEnCours and ");
    }
    requete.append("contrat.isVisible = true and isVisible = true and ");
    requete.append("uidAssure = :uidAssure order by statut.ordre, role.ordre");
    final Query query = createQuery(requete.toString());
    if (listeUidContrats != null && listeUidContrats.size() > 0) {
      query.setParameterList("listeUidContrats", listeUidContrats);
    }
    if (filtrerContratEnCOurs) {
      query.setLong("idStatutGarantieEnCours", adherentMappingService.getIdStatutGarantieEnCours());
    }

    query.setLong("uidAssure", uidAssure);
    final List<Object[]> listResult = query.list();
    final List<GarantieBeneficiaireDto> listeBeneficiaires =
        new ArrayList<GarantieBeneficiaireDto>();
    final List<IdsBeneficiaireContrat> listeIdsBenefsContrats =
        new ArrayList<IdsBeneficiaireContrat>();
    if (listResult != null && listResult.size() > 0) {
      for (Object[] result : listResult) {
        final Long idBenef = (Long) result[0];
        final Long idContrat = (Long) result[1];
        final IdsBeneficiaireContrat idBenefContrat = new IdsBeneficiaireContrat();
        idBenefContrat.setIdBenef(idBenef);
        idBenefContrat.setIdContrat(idContrat);
        if (!listeIdsBenefsContrats.contains(idBenefContrat)) {
          final GarantieBeneficiaireDto benef = new GarantieBeneficiaireDto();
          benef.setIdBenef(idBenef);
          benef.setIdContrat(idContrat);
          benef.setRole(new IdentifiantLibelleDto((Long) result[2], String.valueOf(result[3])));
          listeBeneficiaires.add(benef);
          listeIdsBenefsContrats.add(idBenefContrat);
        }
      }
    }
    return listeBeneficiaires;
  }
コード例 #25
0
  public BigDecimal getAggregateBill(Set<Integer> conceptIds, Date date) {
    // TODO add date condition !!!
    if (conceptIds == null || conceptIds.size() == 0) {
      return null;
    }
    Date to = DateUtils.addDate(date, 1);
    //			Date from = DateUtils.addDate(date, 0);

    String str =
        "select  sum(bill.actualAmount) from  PatientServiceBillItem as bill right join bill.service as service  "
            + " where service.conceptId in  (:conceptIds) and bill.createdDate >= :from and bill.createdDate < :to";
    Query query = sessionFactory.getCurrentSession().createQuery(str);
    query.setParameterList("conceptIds", conceptIds);
    query.setParameter("from", date);
    query.setParameter("to", to);
    return (BigDecimal) query.uniqueResult();
  }
コード例 #26
0
ファイル: BlogDAO.java プロジェクト: subaochen/seam
  private void bindBlogEntryWhereClause(
      Query query,
      WikiDirectory startDir,
      WikiDocument ignoreDoc,
      Integer year,
      Integer month,
      Integer day,
      String tag) {
    query.setParameterList("directoryIDs", wikiNodeDAO.findWikiDirectoryTreeIDs(startDir));
    query.setParameter("currentAccessLevel", currentAccessLevel);

    if (ignoreDoc != null && ignoreDoc.getId() != null) query.setParameter("ignoreDoc", ignoreDoc);
    if (tag != null && tag.length() > 0) query.setParameter("tag", tag);
    if (year != null) query.setParameter("limitYear", year);
    if (month != null) query.setParameter("limitMonth", month);
    if (day != null) query.setParameter("limitDay", day);
  }
コード例 #27
0
ファイル: GenericDao.java プロジェクト: ghost25/jadysjoy
 private void setNamedParams(String[] namedParameters, Object[] queryArgs, Query namedQuery) {
   // Set parameter. Use custom Hibernate Type if necessary
   if (queryArgs != null) {
     for (int i = 0; i < queryArgs.length; i++) {
       Object arg = queryArgs[i];
       Type argType = getArgumentTypeFactory().getArgumentType(arg);
       if (argType != null) {
         namedQuery.setParameter(namedParameters[i], arg, argType);
       } else {
         if (arg instanceof Collection) {
           namedQuery.setParameterList(namedParameters[i], (Collection) arg);
         } else {
           namedQuery.setParameter(namedParameters[i], arg);
         }
       }
     }
   }
 }
コード例 #28
0
ファイル: CommonDAO.java プロジェクト: hymer/site
 protected void setParameter(Query query, String paramName, Object paramValue) {
   if (paramValue instanceof String) {
     query.setString(paramName, (String) paramValue);
   } else if (paramValue instanceof Integer) {
     query.setInteger(paramName, (Integer) paramValue);
   } else if (paramValue instanceof Long) {
     query.setLong(paramName, (Long) paramValue);
   } else if (paramValue instanceof Double) {
     query.setDouble(paramName, (Double) paramValue);
   } else if (paramValue instanceof Boolean) {
     query.setBoolean(paramName, (Boolean) paramValue);
   } else if (paramValue instanceof Date) {
     // TODO 难道这是bug 使用setParameter不行??
     query.setTimestamp(paramName, (Date) paramValue);
   } else if (paramValue instanceof Collection) {
     query.setParameterList(paramName, (Collection<?>) paramValue);
   } else {
     query.setParameter(paramName, paramValue);
   }
 }
コード例 #29
0
  public void getSeveralToysWithINoption() {

    Session session = sf.getCurrentSession();
    session.beginTransaction();

    List queryParamIdList = new ArrayList();

    queryParamIdList.add(5);
    queryParamIdList.add(6);

    Query query = session.createQuery("from Toy where id IN (:IdList)");
    query.setMaxResults(3);
    // query.setFirstResult(index);
    query.setParameterList("IdList", queryParamIdList);

    List<Toy> toys = query.list();

    for (Toy t : toys) {
      System.out.println(t.getName());
    }
  }
コード例 #30
0
 @SuppressWarnings("unchecked")
 public Double getTicketPrice(List<TripBean> trips) {
   List<Double> result = null;
   Query query = null;
   String queryString = null;
   Session session = null;
   // get the current session
   session = sessionFactory.getCurrentSession();
   try {
     // perform database access (query, insert, update, etc) here
     queryString =
         "SELECT SUM(tar.fare) FROM TariffViewBean AS tar INNER JOIN tar.segment.routeDetails as rds INNER JOIN rds.trips AS trp INNER JOIN trp.busStatus.bus AS bus WHERE trp IN (:trips) AND tar.busType = bus.busType AND tar.validFrom <= trp.departureTime AND (tar.validTo > trp.departureTime OR tar.validTo = null)";
     query = session.createQuery(queryString);
     query.setParameterList("trips", trips);
     result = query.list();
   } catch (HibernateException e) {
     exceptionHandling(e, session);
   }
   // return result, if needed
   return result == null || result.size() <= 0 ? null : result.get(0);
 }