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.GarantieDaoImpl.java

License:Open Source License

@Override
public boolean hasGarantieAssureBeneficiaire(Long idAssure, Long idBeneficiaire) {
    final StringBuffer requete = new StringBuffer("select count(garantie_uid) from data_garantie ");
    requete.append("where garantie_assure_uid = :idAssure ");
    requete.append("and garantie_beneficiaire_uid = :idBeneficiaire ");
    requete.append("and (garantie_statut_uid = :idStatutEnCours ");
    requete.append("or (garantie_statut_uid = :idStatutResilie and garantie_date_resiliation >= now())) ");
    requete.append("and garantie_date_adhesion <= now() ");
    requete.append("and garantie_visible = true");
    final Query crit = createSqlQuery(requete.toString());
    crit.setLong("idAssure", idAssure);
    crit.setLong("idBeneficiaire", idBeneficiaire);
    crit.setLong("idStatutEnCours", adherentMappingService.getIdStatutGarantieEnCours());
    crit.setLong("idStatutResilie", adherentMappingService.getIdStatutGarantieResiliee());
    return Integer.valueOf(crit.uniqueResult().toString()) > 0;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override/* ww  w .ja va 2  s  .c  o  m*/
public List<Long> getListeAdherentsByIdOptionSouscrite(Long idOption) {
    final StringBuffer requete = new StringBuffer("SELECT o.uidPersonne ");
    requete.append("FROM Option o, EspaceClientInternet c ");
    requete.append("WHERE o.uidPersonne = c.uidPersonne ");
    requete.append("AND o.type.id = :idOption ");
    requete.append("AND o.active = true ");
    requete.append("AND c.active = 'O' ");
    requete.append("ORDER BY o.uidPersonne ");
    final Query query = createQuery(requete.toString());
    query.setLong("idOption", idOption);
    return (ArrayList<Long>) query.list();
}

From source file:com.square.adherent.noyau.dao.implementations.personne.PersonneDaoImpl.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<Long> getListeBeneficiairesPersonne(Long idPersonne) {
    final StringBuffer requete = new StringBuffer();
    requete.append("SELECT distinct garantie.uidBeneficiaire FROM Garantie garantie ");
    requete.append("WHERE garantie.uidAssure = :idPersonne ");
    requete.append(//from ww w  . j  a  va  2  s .  c om
            "AND garantie.statut.id = :idStatutGarantieEnCours and garantie.role.id <> :idRoleGarantieAssure ");
    final Query query = createQuery(requete.toString());
    query.setLong("idPersonne", idPersonne);
    query.setLong("idStatutGarantieEnCours", adherentMappingService.getIdStatutGarantieEnCours());
    query.setLong("idRoleGarantieAssure", adherentMappingService.getIdRoleGarantieAssure());
    return (ArrayList<Long>) query.list();
}

From source file:com.square.adherent.noyau.dao.implementations.personne.PersonneDaoImpl.java

License:Open Source License

@Override
public Long getAdherentPrincipalPersonne(Long idPersonne) {
    final StringBuffer requete = new StringBuffer();
    requete.append("SELECT distinct garantie.uidAssure FROM Garantie garantie ");
    requete.append("WHERE garantie.uidBeneficiaire = :idPersonne ");
    requete.append(// w  w w. j  av a  2s. com
            "AND garantie.statut.id = :idStatutGarantieEnCours and garantie.role.id <> :idRoleGarantieAssure ");
    final Query query = createQuery(requete.toString());
    query.setLong("idPersonne", idPersonne);
    query.setLong("idStatutGarantieEnCours", adherentMappingService.getIdStatutGarantieEnCours());
    query.setLong("idRoleGarantieAssure", adherentMappingService.getIdRoleGarantieAssure());
    return (Long) query.uniqueResult();
}

From source file:com.square.adherent.noyau.dao.implementations.personne.PersonneDaoImpl.java

License:Open Source License

/**
 * {@inheritDoc}//from  w w w. ja va  2  s  .c  o  m
 */
public List<Long> getListePersonnesNotificationSmsByCriteres(CriteresPersonnesNotificationSmsDto criteres) {
    // Construction de la requte
    final StringBuffer requete = new StringBuffer("SELECT distinct l.decompte_assure_uid ")
            .append("FROM data_decompte l ")
            .append("INNER JOIN data_option o ON (l.decompte_assure_uid = o.option_personne_uid and o.option_type_uid = :idTypeOptionSms"
                    + " and o.option_top_actif = true) ")
            .append("WHERE ( ")
            .append("SELECT sum(l2.decompte_lig_remb_compl) as montant_total FROM data_decompte l2 ")
            .append("WHERE l2.decompte_origine_uid not in (:listeOriginesDesactivees) ")
            .append("AND l2.decompte_date_reglement = :datePaiement ")
            .append("AND l2.decompte_assure_uid = l.decompte_assure_uid ").append(") >= :montantMinimal ")
            .append("AND decompte_origine_uid not in (:listeOriginesDesactivees) ");

    final Query query = createSqlQuery(requete.toString());
    query.setCalendar("datePaiement", criteres.getDateReglement());
    query.setFloat("montantMinimal", criteres.getMontantMinimal());
    query.setLong("idTypeOptionSms", adherentMappingService.getIdTypeOptionEnvoiSms());
    query.setParameterList("listeOriginesDesactivees",
            adherentMappingService.getListeOriginesDecomptesExcluesEnvoiSms());

    // on mappe les resultats dans des dtos
    final List<Long> liste = new ArrayList<Long>();
    for (Object item : query.list()) {
        if (item instanceof Long) {
            liste.add((Long) item);
        } else if (item instanceof BigInteger) {
            liste.add(((BigInteger) item).longValue());
        }
    }
    return liste;
}

From source file:com.square.adherent.noyau.dao.implementations.prestation.RelevePrestationDaoImpl.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<RelevePrestation> getListeReleveParCriteres(
        CritereSelectionRelevePrestationDto critereSelectionRelevePrestationDto, Boolean triDesc) {
    final StringBuffer requete = new StringBuffer(
            "select distinct(relevePresta) from RelevePrestation relevePresta ");
    boolean existCritere = false;
    if (critereSelectionRelevePrestationDto.getIdPersonne() != null) {
        requete.append("where relevePresta.uidPersonne =:idPersonne ");
        existCritere = true;// w ww . j  a v a2  s  . c  om
    }
    if (critereSelectionRelevePrestationDto.getRelevePrestationId() != null) {
        requete.append(getConditionSeparator(existCritere)).append("relevePresta.id =:idRelevePresta ");
        existCritere = true;
    }
    if (critereSelectionRelevePrestationDto.getEnvoyeMail() != null) {
        requete.append(getConditionSeparator(existCritere))
                .append("relevePresta.envoyeMail =:envoyeMailParam ");
        existCritere = true;
    }
    if (critereSelectionRelevePrestationDto.getAutorisationEnvoiMail() != null) {
        requete.append(getConditionSeparator(existCritere))
                .append("relevePresta.moyenPaiement.autorisationEnvoiMail = :autorisationEnvoiMailParam ");
        existCritere = true;
    }
    if (critereSelectionRelevePrestationDto.getDateMaxImpression() != null) {
        requete.append(getConditionSeparator(existCritere))
                .append("relevePresta.dateImpression <= :dateMaxImpressionParam ");
        existCritere = true;
    }
    if (critereSelectionRelevePrestationDto.getDateMinImpression() != null) {
        requete.append(getConditionSeparator(existCritere))
                .append("relevePresta.dateImpression >= :dateMinImpressionParam ");
        existCritere = true;
    }
    if (triDesc != null && triDesc) {
        requete.append("order by relevePresta.dateImpression desc");
    } else if (triDesc != null && !triDesc) {
        requete.append("order by relevePresta.dateImpression asc");
    }

    final Query query = createQuery(requete.toString());
    query.setFirstResult(0);
    if (critereSelectionRelevePrestationDto.getNombreMax() != null) {
        query.setMaxResults(critereSelectionRelevePrestationDto.getNombreMax().intValue());
    }

    if (critereSelectionRelevePrestationDto.getIdPersonne() != null) {
        query.setLong("idPersonne", critereSelectionRelevePrestationDto.getIdPersonne());
    }
    if (critereSelectionRelevePrestationDto.getRelevePrestationId() != null) {
        query.setLong("idRelevePresta", critereSelectionRelevePrestationDto.getRelevePrestationId());
    }
    if (critereSelectionRelevePrestationDto.getEnvoyeMail() != null) {
        query.setBoolean("envoyeMailParam", critereSelectionRelevePrestationDto.getEnvoyeMail().booleanValue());
    }
    if (critereSelectionRelevePrestationDto.getAutorisationEnvoiMail() != null) {
        query.setBoolean("autorisationEnvoiMailParam",
                critereSelectionRelevePrestationDto.getAutorisationEnvoiMail().booleanValue());
    }
    if (critereSelectionRelevePrestationDto.getDateMaxImpression() != null) {
        query.setCalendar("dateMaxImpressionParam", critereSelectionRelevePrestationDto.getDateMaxImpression());
    }
    if (critereSelectionRelevePrestationDto.getDateMinImpression() != null) {
        query.setCalendar("dateMinImpressionParam", critereSelectionRelevePrestationDto.getDateMinImpression());
    }
    return (List<RelevePrestation>) query.list();
}

From source file:com.square.adherent.noyau.dao.implementations.prestation.RelevePrestationDaoImpl.java

License:Open Source License

/**
 * {@inheritDoc}//from w ww. j a  v  a 2 s . com
 */
public Integer getNombreCandidatsEnvoiRelevesPrestationEmail(int nbJoursDifferesEnvoiMail,
        Long idNatureConnexionEspaceAdherent, Long idOptionRelevePresta) {
    final StringBuffer requete = new StringBuffer("select count (distinct (releve_personne_uid)) ");
    completerRequeteEnvoiRelevesPrestationEmail(requete, nbJoursDifferesEnvoiMail,
            idNatureConnexionEspaceAdherent, idOptionRelevePresta);
    final Query query = createSqlQuery(requete.toString());
    final Calendar today = Calendar.getInstance();
    final int jour = today.get(Calendar.DAY_OF_MONTH) - nbJoursDifferesEnvoiMail;
    today.set(Calendar.DAY_OF_MONTH, jour);
    query.setCalendar("dateMaxImpressionParam", today);
    query.setLong("nature", idNatureConnexionEspaceAdherent);
    query.setLong("option", idOptionRelevePresta);
    return Integer.valueOf(query.uniqueResult().toString());
}

From source file:com.square.adherent.noyau.dao.implementations.prestation.RelevePrestationDaoImpl.java

License:Open Source License

@Override
public List<Long> getCandidatsEnvoiRelevesPrestationEmail(int firstResult, int maxResult,
        List<Long> listeIdsExclus, int nbJoursDifferesEnvoiMail, Long idNatureConnexionEspaceAdherent,
        Long idOptionRelevePresta) {
    final StringBuffer requete = new StringBuffer("select distinct (releve_personne_uid) ");
    completerRequeteEnvoiRelevesPrestationEmail(requete, nbJoursDifferesEnvoiMail,
            idNatureConnexionEspaceAdherent, idOptionRelevePresta);
    if (listeIdsExclus != null && listeIdsExclus.size() > 0) {
        requete.append(" and releve_personne_uid not in (:listeIdsExclus)");
    }//w w w  . j  a  v  a 2s  .  c  om
    final Query query = createSqlQuery(requete.toString());
    query.setFirstResult(firstResult);
    query.setMaxResults(maxResult);
    final Calendar today = Calendar.getInstance();
    final int jour = today.get(Calendar.DAY_OF_MONTH) - nbJoursDifferesEnvoiMail;
    today.set(Calendar.DAY_OF_MONTH, jour);
    query.setCalendar("dateMaxImpressionParam", today);
    query.setLong("nature", idNatureConnexionEspaceAdherent);
    query.setLong("option", idOptionRelevePresta);
    if (listeIdsExclus != null && listeIdsExclus.size() > 0) {
        query.setParameterList("listeIdsExclus", listeIdsExclus);
    }
    final List<Long> liste = new ArrayList<Long>();
    for (Object item : query.list()) {
        if (item instanceof Long) {
            liste.add((Long) item);
        } else if (item instanceof BigInteger) {
            liste.add(((BigInteger) item).longValue());
        }
    }
    return liste;
}

From source file:com.square.adherent.noyau.dao.implementations.prestation.ReserveBancoDaoImpl.java

License:Open Source License

/**
 * {@inheritDoc}/*from w w  w.j  ava2s .co m*/
 */
@SuppressWarnings("unchecked")
public List<ReserveProduitBancoDto> getListeReservesBancoByAdherent(Long idAdherent) {
    final StringBuffer requete = new StringBuffer(
            "select franchise_cotisation_annuelle, franchise_versee_reserve, franchise_debut_periode, ");
    requete.append("franchise_fin_periode, garantie_date_adhesion ");
    requete.append("from data_franchise inner join data_garantie on franchise_garantie_uid = garantie_uid ");
    requete.append("where franchise_personne_uid = :idAdherent ");
    requete.append("and franchise_fin_periode >= :dateAnneePrecedente ");
    requete.append("and franchise_debut_periode <= :dateDuJour ");
    requete.append("order by franchise_debut_periode, franchise_fin_periode");
    final Query crit = createSqlQuery(requete.toString());
    crit.setLong("idAdherent", idAdherent);
    // on recupere les franchises des annees N et N-1
    final Calendar dateAnneePrecedente = Calendar.getInstance();
    final int anneePrecedente = dateAnneePrecedente.get(Calendar.YEAR) - 1;
    dateAnneePrecedente.clear();
    dateAnneePrecedente.set(Calendar.DAY_OF_MONTH, 1);
    dateAnneePrecedente.set(Calendar.MONTH, 0);
    dateAnneePrecedente.set(Calendar.YEAR, anneePrecedente);
    final Calendar dateDuJour = Calendar.getInstance();
    dateDuJour.clear(Calendar.MILLISECOND);
    dateDuJour.clear(Calendar.SECOND);
    dateDuJour.clear(Calendar.MINUTE);
    dateDuJour.clear(Calendar.HOUR_OF_DAY);
    crit.setCalendar("dateAnneePrecedente", dateAnneePrecedente);
    crit.setCalendar("dateDuJour", dateDuJour);
    final List<Object[]> resultSet = crit.list();
    final List<ReserveProduitBancoDto> results = new ArrayList<ReserveProduitBancoDto>();
    if (resultSet == null || resultSet.isEmpty()) {
        return null;
    } else {
        for (Object[] row : resultSet) {
            final ReserveProduitBancoDto reserveDto = new ReserveProduitBancoDto();
            reserveDto.setReserveAnnuelle(Double.parseDouble(row[0].toString()));
            reserveDto.setReserveConsommee(Double.parseDouble(row[1].toString()));
            final Calendar dateDebutReserve = Calendar.getInstance();
            dateDebutReserve.setTime((Timestamp) row[2]);
            reserveDto.setDateDebutReserve(dateDebutReserve);
            final Calendar dateFinReserve = Calendar.getInstance();
            dateFinReserve.setTime((Timestamp) row[3]);
            reserveDto.setDateFinReserve(dateFinReserve);
            final Calendar dateAnniversaire = Calendar.getInstance();
            dateAnniversaire.setTime((Timestamp) row[4]);
            reserveDto.setDateAnniversaire(dateAnniversaire);
            results.add(reserveDto);
        }
        return results;
    }
}

From source file:com.square.core.dao.implementations.CaisseDaoImplementation.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from w  w w . ja va 2  s  . c om
public List<Caisse> rechercherCaisseParCriteres(DimensionCriteresRechercheCaisseDto criteresRecherche) {
    final StringBuffer requete = new StringBuffer("SELECT c FROM Caisse c ");
    if (criteresRecherche.getIdDepartement() != null) {
        // On n'effectue la jointure que si le critre sur le dpartement est spcifi
        // afin de ne pas retourner plusieurs fois la mme caisse associe  plusieurs dpartements
        requete.append(" LEFT JOIN c.departements d ");
    }
    requete.append(" WHERE 1=1 ");

    // Critre sur l'identifiant
    if (criteresRecherche.getDimensionCriteres() != null) {
        if (criteresRecherche.getDimensionCriteres().getId() != null) {
            requete.append("AND c.id = :id ");
        }
        // Critre sur le libelle
        if (!StringUtils.isBlank(criteresRecherche.getDimensionCriteres().getLibelle())) {
            requete.append("AND (lower(c.nom) like lower(:libelle) ");
            requete.append("OR lower(c.code) like lower(:libelle) ");
            requete.append("OR lower(c.code||'.'||c.centre||'.'||c.nom) like lower(:libelle)) ");
        }
        // Critre sur la visibilit
        if (criteresRecherche.getDimensionCriteres().getVisible() != null) {
            requete.append("AND c.visible = :visible ");
        }
    }
    // Critere sur le rgime
    if (criteresRecherche.getIdRegime() != null) {
        requete.append("AND c.regime.id = :idRegime ");
    }
    // Critere sur le departement
    if (criteresRecherche.getIdDepartement() != null) {
        requete.append("AND d.id = :idDepartement ");
    }
    if (criteresRecherche.getCode() != null) {
        requete.append("AND c.code = :code ");
    }
    if (criteresRecherche.getCentre() != null) {
        requete.append("AND c.centre = :centre ");
    }
    requete.append("ORDER BY c.ordre, c.code, c.centre, c.nom ");

    final Query query = createQuery(requete.toString());
    if (criteresRecherche.getDimensionCriteres() != null) {
        if (criteresRecherche.getDimensionCriteres().getId() != null) {
            query.setLong("id", criteresRecherche.getDimensionCriteres().getId());
        }
        // Critre sur le libelle
        if (criteresRecherche.getDimensionCriteres().getLibelle() != null
                && !criteresRecherche.getDimensionCriteres().getLibelle().equals("")) {
            query.setString("libelle", criteresRecherche.getDimensionCriteres().getLibelle() + "%");
        }
        // Critre sur la visibilit
        if (criteresRecherche.getDimensionCriteres().getVisible() != null) {
            query.setBoolean("visible", criteresRecherche.getDimensionCriteres().getVisible());
        }
        // Maxresults
        if (criteresRecherche.getDimensionCriteres().getMaxResults() != null) {
            query.setFirstResult(0);
            query.setMaxResults(criteresRecherche.getDimensionCriteres().getMaxResults());
        }
    }
    // Critere sur le rgime
    if (criteresRecherche.getIdRegime() != null) {
        query.setLong("idRegime", criteresRecherche.getIdRegime());
    }
    // Critere sur le departement
    if (criteresRecherche.getIdDepartement() != null) {
        query.setLong("idDepartement", criteresRecherche.getIdDepartement());
    }
    if (criteresRecherche.getCode() != null) {
        query.setString("code", criteresRecherche.getCode());
    }
    if (criteresRecherche.getCentre() != null) {
        query.setString("centre", criteresRecherche.getCentre());
    }

    return query.list();
}