Example usage for org.hibernate Query setLong

List of usage examples for org.hibernate Query setLong

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setLong(String name, long val) 

Source Link

Document

Bind a named long-valued parameter.

Usage

From source file:com.square.adherent.noyau.dao.implementations.contrat.ContratDaoImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//  w w  w.  jav  a  2  s . com
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;
}

From source file:com.square.adherent.noyau.dao.implementations.contrat.ContratDaoImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from   w  w w . j  a  v  a 2s .  c o  m
public String getGestionnaireContratCollectif(Long uidPersonne) {
    final StringBuffer requete = new StringBuffer("select a.contrat_gestionnaire from data_contrat a ")
            .append("join dim_contrat_nature b on a.contrat_nature_uid = b.contrat_nature_uid ")
            .append("join data_personne_physique c on c.personne_uid = a.contrat_assure_uid and c.personne_segment_uid = 3 ")
            .append("inner join (").append("select contrat_assure_uid,max(contrat_nature_eid || ")
            .append("cast(contrat_date_adhesion as text)||cast(coalesce(contrat_date_resiliation,'2222/01/01') as text)) ")
            .append("ID from data_contrat, dim_contrat_nature ")
            .append("where data_contrat.contrat_nature_uid = dim_contrat_nature.contrat_nature_uid ")
            .append("and contrat_segment_uid = 3 ")
            .append("group by contrat_assure_uid) contrat_coll_unique_assure ")
            .append("on a.contrat_assure_uid = contrat_coll_unique_assure.contrat_assure_uid ")
            .append("and b.contrat_nature_eid ||cast(a.contrat_date_adhesion as text) ")
            .append(" || cast(coalesce(a.contrat_date_resiliation,'2222/01/01') as text) = contrat_coll_unique_assure.ID ")
            .append("and a.contrat_segment_uid = 3 ").append("and a.contrat_assure_uid= :uidPersonne");
    final Query crit = createSqlQuery(requete.toString());
    crit.setLong("uidPersonne", uidPersonne);
    final List<String> resultats = (ArrayList<String>) crit.list();
    return resultats.size() >= 1 ? resultats.get(0) : null;
}

From source file:com.square.adherent.noyau.dao.implementations.contrat.ContratDaoImpl.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<PopulationDto> getListePopulations(Long uidPersonneMorale) {
    final StringBuffer requete = new StringBuffer("select population, count(distinct uidAssure) from Contrat ")
            .append("where uidSouscripteur = :uidPersonneMorale ").append("and uidAssure is not null ")
            .append("and statut.id = :idStatutEnCours ").append("and nature.id = :idNatureSante ")
            .append("and isVisible = true ").append("group by population");
    final Query query = createQuery(requete.toString());
    query.setLong("uidPersonneMorale", uidPersonneMorale);
    query.setLong("idStatutEnCours", adherentMappingService.getIdStatutContratEnCours());
    query.setLong("idNatureSante", adherentMappingService.getIdNatureContratSante());

    final List<Object[]> listResult = query.list();
    final List<PopulationDto> listePopulations = new ArrayList<PopulationDto>();
    if (listResult != null && listResult.size() > 0) {
        for (Object[] result : listResult) {
            final String libellePopulation = (String) result[0];
            final Integer effectif = Integer.valueOf((String) result[1].toString());
            final PopulationDto population = new PopulationDto();
            population.setLibelle(libellePopulation);
            population.setEffectif(effectif);
            listePopulations.add(population);
        }//  w  w  w  . j ava 2s.  c o  m
    }
    return listePopulations;
}

From source file:com.square.adherent.noyau.dao.implementations.contrat.ContratDaoImpl.java

License:Open Source License

@Override
public Integer getNombreAdherentsContrat(String eidContrat) {
    final StringBuffer requete = new StringBuffer("select count(distinct uidAssure) from Garantie ")
            .append("where contrat.identifiantExterieur like :idContrat ")
            .append("and contrat.uidAssure is not null ")
            .append("and contrat.statut.id = :idStatutContratEnCours ")
            .append("and statut.id = :idStatutGarantieEnCours ").append("and isVisible = true");
    final Query query = createQuery(requete.toString());
    query.setString("idContrat", eidContrat.substring(0, NB_CARACTERE_ID_CONTRAT) + POURCENT);
    query.setLong("idStatutContratEnCours", adherentMappingService.getIdStatutContratEnCours());
    query.setLong("idStatutGarantieEnCours", adherentMappingService.getIdStatutGarantieEnCours());
    final Integer nbAdherents = Integer.valueOf(query.uniqueResult().toString());
    return nbAdherents;
}

From source file:com.square.adherent.noyau.dao.implementations.contrat.ContratDaoImpl.java

License:Open Source License

@Override
public Integer getNombreBeneficiairesContrat(String eidContrat) {
    final StringBuffer requete = new StringBuffer("select count(distinct uidBeneficiaire) from Garantie ")
            .append("where contrat.identifiantExterieur like :idContrat ")
            .append("and contrat.uidAssure is not null ").append("and uidAssure != uidBeneficiaire ")
            .append("and contrat.statut.id = :idStatutContratEnCours ")
            .append("and statut.id = :idStatutGarantieEnCours ").append("and isVisible = true ");
    final Query query = createQuery(requete.toString());
    query.setString("idContrat", eidContrat.substring(0, NB_CARACTERE_ID_CONTRAT) + POURCENT);
    query.setLong("idStatutContratEnCours", adherentMappingService.getIdStatutContratEnCours());
    query.setLong("idStatutGarantieEnCours", adherentMappingService.getIdStatutGarantieEnCours());
    final Integer nbAdherents = Integer.valueOf(query.uniqueResult().toString());
    return nbAdherents;
}

From source file:com.square.adherent.noyau.dao.implementations.contrat.ContratDaoImpl.java

License:Open Source License

@Override
public Boolean hasPersonneContrats(Long idPersonne) {
    final StringBuffer requete = new StringBuffer("select count(id) from Contrat ")
            .append("where uidAssure = :idPersonne ").append("and isVisible = true");
    final Query query = createQuery(requete.toString());
    query.setLong("idPersonne", idPersonne);
    final Integer nbContrats = Integer.valueOf(query.uniqueResult().toString());
    return nbContrats > 0;
}

From source file:com.square.adherent.noyau.dao.implementations.contrat.ContratDaoImpl.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<ProduitCollectifAdherentDto> getListeProduitsCollectifsAdherent(
        ProduitCollectifAdherentCriteresDto criteres, Long idRoleGarantieAssure, Long idStatutGarantieEnCours,
        Long idStatutGarantieFutur) {
    final StringBuffer requete = new StringBuffer(
            "select g.libelleProduitGestion, g.libelleGarantieGestion, g.codeTarif, g.montantSouscrit ");
    requete.append(", CAST(sum(CASE g.statut.id WHEN :idStatutGarantieEnCours THEN 1 ELSE 0 END) as integer) ");
    requete.append("from Contrat cg, Garantie g, Contrat cp ");
    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.role.id = :idRoleGarantieAssure ");
    requete.append("and g.statut.id in (:idStatutGarantieEnCours, :idStatutGarantieFutur) ");
    if (criteres.getPopulation() != null) {
        requete.append("and g.libellePopulation = :population ");
    }//from  w  w  w  .  j  av a2  s . c om
    if (criteres.getContrat() != null) {
        requete.append("and cg.numeroContrat = :numeroContrat ");
    }
    if (criteres.getUidEntreprise() != null) {
        requete.append("and cg.uidSouscripteur = :uidSouscripteur ");
    }
    if (criteres.getDateEffet() != null) {
        requete.append(" and g.dateAdhesion <= :dateEffet");
        requete.append(" and (g.dateResiliation is null or g.dateResiliation >= :dateEffet)");
    }
    requete.append(
            "group by g.libelleProduitGestion, g.libelleGarantieGestion, g.codeTarif, g.montantSouscrit ");

    final Query query = createQuery(requete.toString());
    query.setLong("idRoleGarantieAssure", idRoleGarantieAssure);
    query.setLong("idStatutGarantieEnCours", idStatutGarantieEnCours);
    query.setLong("idStatutGarantieFutur", idStatutGarantieFutur);
    if (criteres.getUidEntreprise() != null) {
        query.setLong("uidSouscripteur", criteres.getUidEntreprise());
    }
    if (criteres.getContrat() != null) {
        query.setString("numeroContrat", criteres.getContrat());
    }
    if (criteres.getPopulation() != null) {
        query.setString("population", criteres.getPopulation());
    }
    if (criteres.getDateEffet() != null) {
        query.setCalendar("dateEffet", criteres.getDateEffet());
    }

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

From source file:com.square.adherent.noyau.dao.implementations.contrat.ContratDaoImpl.java

License:Open Source License

@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 ");
    }/*from w  w  w. j  av a 2 s  .  co  m*/
    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;
}

From source file:com.square.adherent.noyau.dao.implementations.contrat.GarantieBaremeDaoImpl.java

License:Open Source License

private void setParamQuery(Query query, GarantieBaremeCriteresDto criteres) {
    if (criteres.getGarantie() != null) {
        query.setString("garantie", criteres.getGarantie());
    }/* ww w .j a v a  2 s .c  o m*/
    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.getEidTarifType() != null) {
        query.setString("eidTarifType", criteres.getEidTarifType());
    }
    if (criteres.getEidTypePayeur() != null) {
        query.setString("eidTypePayeur", criteres.getEidTypePayeur());
    }
    if (criteres.getUidAssure() != null) {
        query.setLong("uidAssure", criteres.getUidAssure());
    }
    if (criteres.getIdRoleGarantie() != null) {
        query.setLong("idRole", criteres.getIdRoleGarantie());
    }
    //        if (criteres.getDateEffet() != null) {
    //            query.setCalendar("dateEffet", criteres.getDateEffet());
    //        }
    if (criteres.getDateDebut() != null) {
        query.setCalendar("dateDebut", criteres.getDateDebut());
    }
    if (criteres.getDateFin() != null) {
        query.setCalendar("dateFin", criteres.getDateFin());
    }
    if (criteres.getListeIdsBareme() != null && criteres.getListeIdsBareme().size() > 0) {
        query.setParameterList("listeIdsBareme", criteres.getListeIdsBareme());
    }
}

From source file:com.square.adherent.noyau.dao.implementations.contrat.GarantieDaoImpl.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
// TODO manque la table data_provenance
public List<InfosProduitDto> getInfosProduits(CriteresInfosProduitsDto criteres) {
    final StringBuffer requete = new StringBuffer("select garantie_beneficiaire_uid, ").append(
            "data_garantie.garantie_role_uid, garantie_role_lib, garantie_produit_gestion, garantie_libelle_gestion, ")
            .append("contrat_frequence_paiement_lib, contrat_moyen_paiement_lib, ")
            .append("garantie_date_adhesion, garantie_date_resiliation, data_garantie.garantie_famille_uid, data_garantie.garantie_segment_uid, ")
            .append("garantie_famille_ordre ")
            .append("from data_garantie inner join data_contrat on contrat_uid = garantie_contrat_uid ")
            .append("left join dim_garantie_role on data_garantie.garantie_role_uid = dim_garantie_role.garantie_role_uid ")
            .append("left join dim_garantie_famille on data_garantie.garantie_famille_uid = dim_garantie_famille.garantie_famille_uid ")
            .append("left join dim_contrat_moyen_paiement on data_contrat.contrat_moyen_paiement_cotis_uid=")
            .append("dim_contrat_moyen_paiement.contrat_moyen_paiement_uid ")
            .append("left join dim_contrat_frequence_paiement on ")
            .append("data_contrat.contrat_frequence_paiement_cotis_uid=dim_contrat_frequence_paiement.contrat_frequence_paiement_uid ")
            .append("where data_garantie.garantie_statut_uid = :idStatutGarantieEnCours and data_garantie.garantie_visible = true ");

    if (criteres.getIdContrat() != null) {
        requete.append(" and contrat_uid = :paramContratUid");
    }// ww  w  .  ja  va  2  s. c om
    if (criteres.getIdAssure() != null) {
        requete.append(" and contrat_assure_uid = :paramAssureUid");
    }
    if (criteres.getIdPersonne() != null) {
        requete.append(" and garantie_beneficiaire_uid = :paramPersonneUid");
    }
    if (criteres.getIdFamille() != null) {
        requete.append(" and garantie_famille_uid >= :paramFamilleUid");
    }
    if (criteres.getDateDebutDeGarantie() != null) {
        requete.append(" and garantie_date_adhesion >= :paramDateDebut");
    }
    if (criteres.isHorsProduitsBonus()) {
        requete.append(" and data_garantie.garantie_famille_uid <> :idFamilleGarantieBonus");
    }
    if (criteres.isFiltreNullSurDateDeFin()) {
        requete.append(" and (garantie_date_resiliation is null or garantie_date_resiliation >= now())");
        requete.append(" and garantie_date_adhesion <= now()");
    } else if (criteres.getDateDeFinDeGarantie() != null) {
        requete.append(" and garantie_date_adhesion <= :paramDateFin");
    }
    requete.append(" order by garantie_role_lib, garantie_famille_ordre");

    final Query query = createSqlQuery(requete.toString());
    if (criteres.getIdContrat() != null) {
        query.setLong("paramContratUid", criteres.getIdContrat());
    }
    if (criteres.getIdAssure() != null) {
        query.setLong("paramAssureUid", criteres.getIdAssure());
    }
    if (criteres.getIdPersonne() != null) {
        query.setLong("paramPersonneUid", criteres.getIdPersonne());
    }
    if (criteres.getIdFamille() != null) {
        query.setLong("paramFamilleUid", criteres.getIdFamille());
    }
    if (criteres.getDateDebutDeGarantie() != null) {
        query.setCalendar("paramDateDebut", criteres.getDateDebutDeGarantie());
    }
    if (!criteres.isFiltreNullSurDateDeFin() && criteres.getDateDeFinDeGarantie() != null) {
        query.setCalendar("paramDateFin", criteres.getDateDeFinDeGarantie());
    }
    query.setLong("idStatutGarantieEnCours", adherentMappingService.getIdStatutGarantieEnCours());
    if (criteres.isHorsProduitsBonus()) {
        query.setLong("idFamilleGarantieBonus", adherentMappingService.getIdFamilleGarantieBonus());
    }

    final List<Object[]> resultats = (ArrayList<Object[]>) query.list();
    final List<InfosProduitDto> listeInfosProduit = new ArrayList<InfosProduitDto>();
    for (int i = 0; i < resultats.size(); i++) {
        final Object[] res = (Object[]) resultats.get(i);
        // Mapping d'un rsultat dans le dto associ.
        int j = 0;
        final InfosProduitDto infoProduit = new InfosProduitDto();
        final Object idPersonne = res[j++];
        infoProduit.setIdPersonne(idPersonne != null ? Long.valueOf(idPersonne.toString()) : null);
        final Object idRole = res[j++];
        infoProduit.setIdRole(idRole != null ? Long.valueOf(idRole.toString()) : null);
        // On saute le libell de rle
        j++;
        infoProduit.setProduitAia((String) res[j++]);
        infoProduit.setGarantieAia((String) res[j++]);
        infoProduit.setFrequenceReglement((String) res[j++]);
        infoProduit.setModeReglement((String) res[j++]);
        final Calendar dateEffet = Calendar.getInstance();
        dateEffet.setTimeInMillis(((Timestamp) res[j++]).getTime());
        infoProduit.setDateEffet(dateEffet);
        final Calendar dateResiliation = Calendar.getInstance();
        final Object objDateResiliation = res[j++];
        if (objDateResiliation != null) {
            dateResiliation.setTimeInMillis(((Timestamp) objDateResiliation).getTime());
            infoProduit.setDateResiliation(dateResiliation);
        }
        final Object idFamilleGarantie = res[j++];
        infoProduit.setIdFamilleGarantie(
                idFamilleGarantie != null ? Long.valueOf(idFamilleGarantie.toString()) : null);
        final Object idSegmentGarantieObj = res[j++];
        final Long idSegmentGarantie = idSegmentGarantieObj != null
                ? Long.valueOf(idSegmentGarantieObj.toString())
                : null;
        final boolean isFromContratCollectif = adherentMappingService.getIdSegmentCollectif()
                .equals(idSegmentGarantie)
                || adherentMappingService.getIdSegmentCollectifIndividualise().equals(idSegmentGarantie);
        infoProduit.setIsFromContratCollectif(isFromContratCollectif);
        final Object ordre = res[j++];
        infoProduit.setOrdre(ordre != null ? Integer.valueOf(ordre.toString()) : null);
        listeInfosProduit.add(infoProduit);
    }
    return listeInfosProduit;
}