public void update(NormalDiscount normalDiscount, int normalId) {
    try {

      System.out.println("更新daoimpl");
      System.out.println("normId" + normalDiscount.getNormalId());
      String hql =
          "update NormalDiscount cu set cu.discountName=?,cu.type=?,cu.discountBase=?,cu.baseQty=?,cu.discountRate=?,cu.activity=? where cu.normalId=?";
      Session session = sessionFactory.getCurrentSession();
      Query query = session.createQuery(hql);
      query.setString(0, normalDiscount.getDiscountName());
      query.setString(1, normalDiscount.getType());
      query.setString(2, normalDiscount.getDiscountBase());
      if (normalDiscount.getBaseQty() == null) {
        query.setInteger(3, 0);
      } else {
        query.setInteger(3, normalDiscount.getBaseQty());
      }
      query.setDouble(4, normalDiscount.getDiscountRate());
      query.setString(5, normalDiscount.getActivity());
      query.setInteger(6, normalId);
      query.executeUpdate();

    } catch (HibernateException e) {
      e.printStackTrace();
    }
  }
示例#2
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);
   }
 }
示例#3
0
  public void updateFromDrop(
      Long resourceComponentId,
      Long resourceParentId,
      Long resourceComponentParentId,
      Double componentOrder) {

    Session session = SessionFactory.getInstance().openSession();
    Query query = session.getNamedQuery("updateFromDrop");
    query.setLong("resourceComponentId", resourceComponentId);
    if (resourceParentId == null) {
      query.setLong("resourceId", 0l);
    } else {
      query.setLong("resourceId", resourceParentId);
    }
    if (resourceComponentParentId == null) {
      query.setLong("parentResourceComponentId", 0l);
    } else {
      query.setLong("parentResourceComponentId", resourceComponentParentId);
    }
    query.setDouble("resourcesOrder", componentOrder);
    query.list();
    session.close();
  }
  @Override
  @SuppressWarnings("unchecked")
  public List<TypePayeurDto> getListeTypesPayeurs(
      TypePayeurCriteresDto criteres, Long idRoleGarantieAssure) {
    final StringBuffer requete =
        new StringBuffer(
            "select p.id, p.eid, p.libelle, b.bareme1Eid, b.bareme1Zone, b.bareme2Eid, b.bareme2Zone ");
    requete.append("from Contrat cg, Contrat cp, Garantie g, GarantieBareme b, TypePayeur p ");
    requete.append(
        "where substring(cg.identifiantExterieur,1,13) = substring(cp.identifiantExterieur,1,13) ");
    requete.append("and g.contrat.id = cp.id ");
    requete.append("and g.id = b.garantie.id ");
    requete.append("and p.id = b.typePayeur.id ");
    requete.append("and g.role.id = :idRoleGarantieAssure ");
    if (criteres.getGarantieGestion() != null) {
      requete.append("and g.libelleGarantieGestion = :garantieGestion ");
    }
    if (criteres.getProduitGestion() != null) {
      requete.append("and g.libelleProduitGestion = :produitGestion ");
    }
    if (criteres.getContrat() != null) {
      requete.append("and cg.numeroContrat = :numeroContrat ");
    }
    if (criteres.getCodeTarif() != null) {
      requete.append("and g.codeTarif = :codeTarif ");
    }
    if (criteres.getMontantSouscrit() != null) {
      requete.append("and g.montantSouscrit = :montantSouscrit ");
    }
    if (criteres.getLibPopulation() != null) {
      requete.append("and g.libellePopulation = :libPopulation ");
    }
    requete.append(
        "group by p.id, p.eid, p.libelle, b.bareme1Eid, b.bareme1Zone, b.bareme2Eid, b.bareme2Zone ");

    final Query query = createQuery(requete.toString());
    query.setLong("idRoleGarantieAssure", idRoleGarantieAssure);
    if (criteres.getGarantieGestion() != null) {
      query.setString("garantieGestion", criteres.getGarantieGestion());
    }
    if (criteres.getProduitGestion() != null) {
      query.setString("produitGestion", criteres.getProduitGestion());
    }
    if (criteres.getContrat() != null) {
      query.setString("numeroContrat", criteres.getContrat());
    }
    if (criteres.getCodeTarif() != null) {
      query.setString("codeTarif", criteres.getCodeTarif());
    }
    if (criteres.getMontantSouscrit() != null) {
      query.setDouble("montantSouscrit", criteres.getMontantSouscrit());
    }
    if (criteres.getLibPopulation() != null) {
      query.setString("libPopulation", criteres.getLibPopulation());
    }

    final List<Object[]> rows = query.list();
    final List<TypePayeurDto> liste = new ArrayList<TypePayeurDto>();
    for (Object[] row : rows) {
      liste.add(
          new TypePayeurDto(
              (Long) row[0],
              (String) row[1],
              (String) row[2],
              (String) row[3],
              (Integer) row[4],
              (String) row[5],
              (Integer) row[6]));
    }
    return liste;
  }