Example usage for javax.persistence Query setParameter

List of usage examples for javax.persistence Query setParameter

Introduction

In this page you can find the example usage for javax.persistence Query setParameter.

Prototype

Query setParameter(int position, Object value);

Source Link

Document

Bind an argument value to a positional parameter.

Usage

From source file:com.brienwheeler.lib.db.dao.PersistentAttributeDaoBase.java

@SuppressWarnings("unchecked")
@Override// w  w w .ja  va  2s . co  m
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public List<AttrClass> findByOwner(long ownerId) {
    Query query = entityManager
            .createQuery("from " + getEntityClass().getSimpleName() + " where owner_id = :ownerId");
    query.setParameter("ownerId", ownerId);
    return (List<AttrClass>) query.getResultList();
}

From source file:org.messic.server.datamodel.jpaimpl.DAOJPAAlbumResource.java

@Override
@Transactional//from   w  w  w .j a  va 2s. co m
public MDOAlbumResource get(String username, long sid) {
    Query query = entityManager
            .createQuery("from MDOAlbumResource as a where (a.owner.login = :userName AND a.sid = :sid)");
    query.setParameter("userName", username);
    query.setParameter("sid", sid);

    @SuppressWarnings("unchecked")
    List<MDOAlbumResource> results = query.getResultList();
    if (results != null && results.size() > 0) {
        return results.get(0);
    }
    return null;
}

From source file:org.venice.piazza.common.hibernate.dao.job.JobDaoImpl.java

public Page<JobEntity> getJobList(Pagination pagination) {
    // Query/*from   www.j  a va 2  s.  co  m*/
    String queryString = String.format(JOB_QUERY, Direction.fromString(pagination.getOrder()));
    Query query = entityManager.createNativeQuery(queryString, JobEntity.class);
    query.setParameter(1, pagination.getSortBy());
    query.setParameter(2, pagination.getPerPage());
    query.setParameter(3, pagination.getPage() * pagination.getPerPage());
    List<JobEntity> results = query.getResultList();
    // Count
    query = entityManager.createNativeQuery(JOB_QUERY_COUNT);
    long count = ((BigInteger) query.getSingleResult()).longValue();
    return new PageImpl<JobEntity>(results, null, count);
}

From source file:com.epam.ipodromproject.repository.jpa.JPABetRepository.java

@Transactional
@Override//from w  ww .  ja va 2s . co  m
public void cancelBetsByCompetition(Long competitionID) {
    Query query = entityManager.createNamedQuery("Bet.cancelBetsByCompetitionID");
    query.setParameter("competitionID", competitionID);
    query.setParameter("betResult", BetResult.NOT_CONSIDERED);
    query.setParameter("betResultToSet", BetResult.MONEY_RETURNED);
    query.executeUpdate();
}

From source file:org.venice.piazza.common.hibernate.dao.job.JobDaoImpl.java

public Page<JobEntity> getJobListByUser(String userName, Pagination pagination) {
    // Query/*from   w w w .  ja v a 2  s . c  om*/
    String queryString = String.format(USERNAME_JOB_QUERY, Direction.fromString(pagination.getOrder()));
    Query query = entityManager.createNativeQuery(queryString, JobEntity.class);
    query.setParameter(1, userName);
    query.setParameter(2, pagination.getSortBy());
    query.setParameter(3, pagination.getPerPage());
    query.setParameter(4, pagination.getPage() * pagination.getPerPage());
    List<JobEntity> results = query.getResultList();
    // Count
    query = entityManager.createNativeQuery(USERNAME_JOB_QUERY_COUNT);
    query.setParameter(1, userName);
    long count = ((BigInteger) query.getSingleResult()).longValue();
    return new PageImpl<JobEntity>(results, null, count);
}

From source file:org.venice.piazza.common.hibernate.dao.job.JobDaoImpl.java

public Page<JobEntity> getJobListByStatus(String status, Pagination pagination) {
    // Query/* www  . j  a v a 2  s  .com*/
    String queryString = String.format(STATUS_JOB_QUERY, Direction.fromString(pagination.getOrder()));
    Query query = entityManager.createNativeQuery(queryString, JobEntity.class);
    query.setParameter(1, status);
    query.setParameter(2, pagination.getSortBy());
    query.setParameter(3, pagination.getPerPage());
    query.setParameter(4, pagination.getPage() * pagination.getPerPage());
    List<JobEntity> results = query.getResultList();
    // Count
    query = entityManager.createNativeQuery(STATUS_JOB_QUERY_COUNT);
    query.setParameter(1, status);
    long count = ((BigInteger) query.getSingleResult()).longValue();
    return new PageImpl<JobEntity>(results, null, count);
}

From source file:com.june.app.user.repository.jpa.UserRepositoryImpl.java

@Override
public Long selectUserId(String userId) {
    Query query = this.em
            .createQuery("SELECT count(userInfo) FROM UserInfo userInfo WHERE userInfo.userId =:userId");
    query.setParameter("userId", userId);
    return (Long) query.getSingleResult();
}

From source file:org.venice.piazza.common.hibernate.dao.deployment.DeploymentDaoImpl.java

public Page<DeploymentEntity> getDeploymentList(Pagination pagination) {
    // Query//from w  w  w .  ja v a 2  s . co m
    String queryString = String.format(DEPLOYMENT_QUERY, Direction.fromString(pagination.getOrder()));
    Query query = entityManager.createNativeQuery(queryString, DeploymentEntity.class);
    query.setParameter(1, pagination.getSortBy());
    query.setParameter(2, pagination.getPerPage());
    query.setParameter(3, pagination.getPage() * pagination.getPerPage());
    List<DeploymentEntity> results = query.getResultList();
    // Count
    query = entityManager.createNativeQuery(DEPLOYMENT_QUERY_COUNT);
    long count = ((BigInteger) query.getSingleResult()).longValue();
    return new PageImpl<DeploymentEntity>(results, null, count);
}

From source file:com.sct.descubriendoturuta.service.InsigniaServiceImpl.java

@Override
@Transactional//from  w w w. j  a  v a 2s. c  o  m
public List<Insignia> obtenerInsigniasPor(int usuarioId, int tipo) {

    Query query = em.createQuery("select i from Insignia i Where i.usuario.id = :p and i.tipo = :t");
    query.setParameter("p", usuarioId);
    query.setParameter("t", tipo);

    return query.getResultList();
}

From source file:com.tapas.evidence.repository.ChildRepositoryImpl.java

@Override
@SuppressWarnings("unchecked")
public List<Teacher> findByKindergartenId(final Long kindergartenId) {
    final Long tenantId = ((EvidenceUserDetails) SecurityContextHolder.getContext().getAuthentication()
            .getPrincipal()).getTenantId();
    Query query = this.entityManager
            .createNamedQuery(Child.QUERY_NAME_FIND_BY_KINDERGARTEN_ID_AND_DELETED_FLAG);
    query.setParameter("kindergartenId", kindergartenId);
    query.setParameter("deleted", Boolean.FALSE);
    query.setParameter("tenantId", tenantId);
    return query.getResultList();
}