Example usage for org.hibernate SQLQuery addSynchronizedEntityClass

List of usage examples for org.hibernate SQLQuery addSynchronizedEntityClass

Introduction

In this page you can find the example usage for org.hibernate SQLQuery addSynchronizedEntityClass.

Prototype

@Override
    SQLQuery<T> addSynchronizedEntityClass(Class entityClass) throws MappingException;

Source Link

Usage

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

License:Open Source License

/**
 * Crer la requte HQL et ajoute les critres.
 * @param select clause select de la requte
 * @param criteresPagines les critres de recherche
 * @param orderBy true pour ajouter la clause order by  la requte.
 * @return requte HQL/*from  w  w  w . j  av a 2s  .  c o  m*/
 */
private Query creerQuery(String select,
        RemotePagingCriteriasDto<PrestationCriteresRechercheDto> criteresPagines, boolean orderBy,
        boolean groupBy) {
    final SQLQuery query;
    Map<String, Object> params = null;
    final StringBuffer requete = new StringBuffer(select);
    requete.append(" from data_decompte d");
    requete.append(" left join dim_decompte_acte acte on (acte.decompte_acte_uid = d.decompte_lig_acte_uid) ");
    requete.append(
            " left join dim_decompte_origine origine on (origine.decompte_origine_uid = d.decompte_origine_uid) ");
    requete.append(" left join data_banque banque on (banque.banque_uid = d.decompte_reglement_banque_uid) ");
    if (groupBy) {
        requete.append(
                " left join data_personne_physique bs on (bs.personne_uid = d.decompte_lig_patient_uid) ");
    }
    requete.append(" where 1 = 1");

    final PrestationCriteresRechercheDto criteres = criteresPagines.getCriterias();
    if (criteres != null) {
        params = new HashMap<String, Object>();
        if (criteres.getIdAssure() != null) {
            final String param = "uidAssure";
            requete.append(" and d.decompte_assure_uid = :" + param);
            params.put(param, criteres.getIdAssure());
        }
        if (criteres.getIdBeneficiaire() != null) {
            final String param = "uidLigPatient";
            requete.append(" and d.decompte_lig_patient_uid = :" + param);
            params.put(param, criteres.getIdBeneficiaire());
        }
        if (criteres.getNumero() != null) {
            final String param = "numero";
            requete.append(" and d.decompte_numero like :" + param);
            params.put(param, criteres.getNumero() + "%");
        }
        if (criteres.getNumeroDecompteExact() != null) {
            final String param = "numero";
            requete.append(" and d.decompte_numero = :" + param);
            params.put(param, criteres.getNumeroDecompteExact());
        }
        if (criteres.getDateDebutSoins() != null) {
            final String param = "dateDebut";
            requete.append(" and d.decompte_lig_date_debut_soin >= :" + param);
            params.put(param, criteres.getDateDebutSoins());
        }
        if (criteres.getDateFinSoins() != null) {
            final String param = "dateFin";
            requete.append(" and d.decompte_lig_date_debut_soin <= :" + param);
            params.put(param, criteres.getDateFinSoins());
        }
        if (criteres.getIdOrigine() != null) {
            final String param = "uidOrigine";
            requete.append(" and origine.decompte_origine_uid = :" + param);
            params.put(param, criteres.getIdOrigine());
        }
        if (criteres.getIdActes() != null && criteres.getIdActes().size() > 0) {
            final String param = "listeUidActe";
            requete.append(" and acte.decompte_acte_uid in (:" + param + ")");
            params.put(param, criteres.getIdActes());
        }
        if (criteres.getIdActesAExclure() != null && criteres.getIdActesAExclure().size() > 0) {
            final String param = "listeUidActe";
            requete.append(" and acte.decompte_acte_uid not in (:" + param + ")");
            params.put(param, criteres.getIdActesAExclure());
        }
    }
    if (groupBy) {
        requete.append(
                " group by d.decompte_numero, d.decompte_date_reglement, origine.decompte_origine_uid, origine.decompte_origine_lib, ");
        requete.append(
                " banque.banque_compte, banque.banque_domiciliation, d.decompte_destinataire_nom, d.decompte_benef_reglement_nom, ");
        requete.append(
                " d.decompte_reglement_professionnel_sante, d.decompte_reglement_numero_cheque, d.decompte_statut_paiement,");
        requete.append(" bs.personne_uid, bs.personne_nom, bs.personne_prenom");
    }
    if (orderBy) {
        query = createSqlQuery(requete.toString(), criteresPagines);
    } else {
        query = createSqlQuery(requete.toString());
    }
    if (criteres != null) {
        query.setProperties(params);
    }
    query.addSynchronizedEntityClass(Decompte.class);
    logger.debug(query.toString());
    return query;
}

From source file:org.jtalks.jcommune.model.dao.hibernate.LastReadPostHibernateDaoTest.java

License:Open Source License

@Test
public void testDeleteMarksTopicsToUser() {
    List<Topic> topics = PersistedObjectsFactory.createAndSaveTopicListWithPosts(10);
    JCUser user = PersistedObjectsFactory.getDefaultUser();
    SQLQuery deletedEntities = (SQLQuery) session.getNamedQuery("deleteAllMarksReadToUser");
    deletedEntities.addSynchronizedEntityClass(LastReadPost.class).setParameter("user", user.getId())
            .setParameter("branch", topics.get(0).getBranch().getId()).setCacheable(false).executeUpdate();

    List<LastReadPost> lastReadPostList = lastReadPostDao.getLastReadPosts(user, topics);

    //check delete record about read posts for user
    assertTrue(lastReadPostList.isEmpty());
}