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.tarificateur.noyau.dao.implementations.DevisDaoImpl.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<Integer> getEidsProduitDevis(final Long idDevis) {
    final Query query = createQuery(
            "select distinct ld.eidProduit from Devis devis inner join devis.listeLigneDevis ld where devis.id = :idDevis");
    query.setLong("idDevis", idDevis);
    return query.list();
}

From source file:com.square.tarificateur.noyau.dao.implementations.LigneDevisDaoImpl.java

License:Open Source License

/**
 * {@inheritDoc}/*  w ww .  j a va  2 s .c o m*/
 */
@SuppressWarnings("unchecked")
@Override
public List<LigneDevis> getLigneDevisPrincipalParIdDevis(Long idDevis) {
    final StringBuffer sql = new StringBuffer(
            "select distinct ligneDevis from LigneDevis ligneDevis left join fetch ligneDevis.listeReglesValeurs ")
                    .append("left join fetch ligneDevis.listeValeurCritereLigneDevis ")
                    .append("where ligneDevis.devis.id = :idDevis ")
                    .append(" and ligneDevis.id not in (select ligneDevisLiee.id from LigneDevisLiee where ligneDevisLiee.devis.id = :idDevis)");
    final Query query = createQuery(sql.toString());
    query.setLong("idDevis", idDevis);
    return (ArrayList<LigneDevis>) query.list();
}

From source file:com.square.tarificateur.noyau.dao.implementations.LigneDevisDaoImpl.java

License:Open Source License

/**
 * {@inheritDoc}/*from  ww  w  . jav a 2 s.  co m*/
 */
@SuppressWarnings("unchecked")
@Override
public List<Long> getIdLigneDevisPrincipalParIdDevis(Long idDevis) {
    final StringBuffer sql = new StringBuffer(
            " select ligneDevis.id from LigneDevis ligneDevis where ligneDevis.devis.id = :idDevis").append(
                    " and ligneDevis.id not in (select ligneDevisLiee.id from LigneDevisLiee where ligneDevisLiee.devis.id = :idDevis)");
    final Query query = createQuery(sql.toString());
    query.setLong("idDevis", idDevis);
    return (ArrayList<Long>) query.list();
}

From source file:com.square.tarificateur.noyau.dao.implementations.LigneDevisDaoImpl.java

License:Open Source License

/**
 * {@inheritDoc}// w w  w  .jav a 2s .co  m
 */
@Override
public boolean estUneLigneLiee(Long idLigneDevis) {
    final StringBuffer sql = new StringBuffer(
            "select ligneDevisLiee.id from LigneDevisLiee where ligneDevisLiee.id = :idLigneDevis");
    final Query query = createQuery(sql.toString());
    query.setLong("idLigneDevis", idLigneDevis);
    return query.uniqueResult() != null;
}

From source file:com.square.tarificateur.noyau.dao.implementations.LigneDevisDaoImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*w w  w  .j  av a2s.  c o  m*/
public List<LigneDevis> getLignesLieesLignePrincipale(Long idLignePrincipale) {
    final StringBuffer sql = new StringBuffer(
            "select ldl.ligneDevisLiee from LigneDevisLiee ldl where ldl.ligneDevisSource.id = :idLignePrincipale");
    final Query query = createQuery(sql.toString());
    query.setLong("idLignePrincipale", idLignePrincipale);
    return (ArrayList<LigneDevis>) query.list();
}

From source file:com.square.tarificateur.noyau.dao.implementations.LigneDevisDaoImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from  w w w  .j a v a 2  s  . c o  m
public List<Long> getIdsFinaliteLigneDevis(Long idDevis) {
    final StringBuffer sql = new StringBuffer(
            "select distinct ligneDevis.finalite.id from LigneDevis ligneDevis where ligneDevis.devis.id = :idDevis");
    final Query query = createQuery(sql.toString());
    query.setLong("idDevis", idDevis);
    return (ArrayList<Long>) query.list();
}

From source file:com.thoughtworks.go.server.dao.AccessTokenSqlMapDao.java

License:Apache License

public void updateLastUsedTime(Map<Long, Timestamp> accessTokenIdToLastUsedTimestamp) {
    transactionTemplate.execute(transactionCallback -> {
        final Session currentSession = sessionFactory.getCurrentSession();

        accessTokenIdToLastUsedTimestamp.keySet().forEach(tokenId -> {
            final Query query = currentSession
                    .createQuery("UPDATE AccessToken SET lastUsed = :lastUsed WHERE id = :id");
            query.setLong("id", tokenId);
            query.setTimestamp("lastUsed", accessTokenIdToLastUsedTimestamp.get(tokenId));
            query.executeUpdate();//from w  w  w .jav  a  2 s .c o  m
        });

        return Boolean.TRUE;
    });
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

Modification findLatestModification(final MaterialInstance expandedInstance) {
    Modifications modifications = cachedModifications(expandedInstance);
    if (modifications != null && !modifications.isEmpty()) {
        return modifications.get(0);
    }/*  w  ww  .  j  av  a  2  s.  co m*/
    String cacheKey = latestMaterialModificationsKey(expandedInstance);
    synchronized (cacheKey) {
        Modification modification = (Modification) getHibernateTemplate()
                .execute((HibernateCallback) session -> {
                    Query query = session
                            .createQuery("FROM Modification WHERE materialId = ? ORDER BY id DESC");
                    query.setMaxResults(1);
                    query.setLong(0, expandedInstance.getId());
                    return query.uniqueResult();
                });
        goCache.put(cacheKey, new Modifications(modification));
        return modification;
    }
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

Modification findModificationWithRevision(Session session, long materialId, String revision) {
    Modification modification;/*from   w  w  w  . j  av a  2  s.  c o  m*/
    String key = cacheKeyForModificationWithRevision(materialId, revision);
    modification = (Modification) goCache.get(key);
    if (modification == null) {
        synchronized (key) {
            modification = (Modification) goCache.get(key);
            if (modification == null) {
                Query query = session.createQuery(
                        "FROM Modification WHERE materialId = ? and revision = ? ORDER BY id DESC");
                query.setLong(0, materialId);
                query.setString(1, revision);
                modification = (Modification) query.uniqueResult();
                goCache.put(key, modification);
            }
        }
    }
    return modification;
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

public Long getTotalModificationsFor(final MaterialInstance materialInstance) {
    String key = materialModificationCountKey(materialInstance);
    Long totalCount = (Long) goCache.get(key);
    if (totalCount == null || totalCount == 0) {
        synchronized (key) {
            totalCount = (Long) goCache.get(key);
            if (totalCount == null || totalCount == 0) {
                totalCount = (Long) getHibernateTemplate().execute((HibernateCallback) session -> {
                    Query q = session.createQuery("select count(*) FROM Modification WHERE materialId = ?");
                    q.setLong(0, materialInstance.getId());
                    return q.uniqueResult();
                });// w  w w  .ja  va 2 s.c o m
                goCache.put(key, totalCount);
            }
        }
    }
    return totalCount;
}