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.tapas.evidence.repository.TeacherRepositoryImpl.java

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

From source file:com.thingtrack.konekti.dao.impl.internal.ProductDaoImpl.java

@Override
@SuppressWarnings("unchecked")
public List<Product> getAll(User user) throws Exception {
    StringBuffer queryString = new StringBuffer("SELECT p FROM " + getEntityName() + " p");

    if (user.getActiveArea() != null)
        queryString.append(" WHERE :area MEMBER OF p.areas");

    Query query = (Query) getEntityManager().createQuery(queryString.toString());

    if (user.getActiveArea() != null)
        query.setParameter("area", user.getActiveArea());

    return query.getResultList();

}

From source file:cz.muni.fi.pa165.deliveryservice.dao.jpa.JPACourierDAO.java

@Override
public User getUser(Courier courier) {
    Query query;
    query = em.createQuery("SELECT u FROM User u WHERE u.id = :id ");
    query.setParameter("id", courier.getUser().getId());

    User user = (User) query.getSingleResult();
    return user;// w w  w .  jav  a  2 s  . c o  m
}

From source file:info.toegepaste.www.service.PdfServiceImpl.java

@Override
@TransactionAttribute(REQUIRES_NEW)/*from  ww w  .  j a  v  a  2  s . c o m*/
public Student getStudentById(int id) {
    Student student = null;
    Query q = em.createNamedQuery("Student.findByStudentid");
    q.setParameter("studentid", id);
    student = (Student) q.getSingleResult();
    return student;
}

From source file:com.dhenton9000.birt.persistence.dao.impl.EmployeesDaoImpl.java

@Override
public List<Orders> getOrdersForEmployee(Integer employeeId) {

    String qString = "select o " + " from Orders o " + " join  o.customer   cust " + " join  cust.employee   e "
            + " where e.employeeNumber = :id ";

    Query q = this.getEntityManager().createQuery(qString);
    q.setParameter("id", employeeId);
    List orders = q.getResultList();

    //   http://www.objectdb.com/java/jpa/query/jpql/select

    return orders;
}

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

public Page<DeploymentEntity> getDeploymentListByDataId(String keyword, Pagination pagination) {
    // Query/*  w w w. j  a v a 2s . c o  m*/
    String queryString = String.format(KEYWORD_DATA_ID_QUERY, Direction.fromString(pagination.getOrder()));
    Query query = entityManager.createNativeQuery(queryString, DeploymentEntity.class);
    query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword));
    query.setParameter(2, pagination.getSortBy());
    query.setParameter(3, pagination.getPerPage());
    query.setParameter(4, pagination.getPage() * pagination.getPerPage());
    List<DeploymentEntity> results = query.getResultList();
    // Count
    query = entityManager.createNativeQuery(KEYWORD_DATA_ID_QUERY_COUNT);
    query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword));
    long count = ((BigInteger) query.getSingleResult()).longValue();
    return new PageImpl<DeploymentEntity>(results, null, count);
}

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

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

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

public Page<DeploymentEntity> getDeploymentListByDeploymentId(String keyword, Pagination pagination) {
    // Query/*from   w  ww  .ja  v a2 s.c  om*/
    String queryString = String.format(KEYWORD_DEPLOYMENT_ID_QUERY,
            Direction.fromString(pagination.getOrder()));
    Query query = entityManager.createNativeQuery(queryString, DeploymentEntity.class);
    query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword));
    query.setParameter(2, pagination.getSortBy());
    query.setParameter(3, pagination.getPerPage());
    query.setParameter(4, pagination.getPage() * pagination.getPerPage());
    List<DeploymentEntity> results = query.getResultList();
    // Count
    query = entityManager.createNativeQuery(KEYWORD_DEPLOYMENT_ID_QUERY_COUNT);
    query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword));
    long count = ((BigInteger) query.getSingleResult()).longValue();
    return new PageImpl<DeploymentEntity>(results, null, count);
}

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

public Page<DeploymentEntity> getDeploymentListByCapabilitiesUrl(String keyword, Pagination pagination) {
    // Query/*  www. ja va 2  s .c  o  m*/
    String queryString = String.format(KEYWORD_CAPABILITIES_URL_QUERY,
            Direction.fromString(pagination.getOrder()));
    Query query = entityManager.createNativeQuery(queryString, DeploymentEntity.class);
    query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword));
    query.setParameter(2, pagination.getSortBy());
    query.setParameter(3, pagination.getPerPage());
    query.setParameter(4, pagination.getPage() * pagination.getPerPage());
    List<DeploymentEntity> results = query.getResultList();
    // Count
    query = entityManager.createNativeQuery(KEYWORD_CAPABILITIES_URL_QUERY_COUNT);
    query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword));
    long count = ((BigInteger) query.getSingleResult()).longValue();
    return new PageImpl<DeploymentEntity>(results, null, count);
}

From source file:com.dhenton9000.birt.persistence.dao.impl.EmployeesDaoImpl.java

@Override
public List<Employees> getEmployeesForOffice(String officeCode) {

    String qString = "select employees from " + "Offices o join o.employees employees "
            + "where o.officeCode = :id ";

    Query q = this.getEntityManager().createQuery(qString);
    q.setParameter("id", officeCode);
    log.debug("office code is " + officeCode);
    List<Employees> officeEmployees = q.getResultList();

    //   http://www.objectdb.com/java/jpa/query/jpql/select

    return officeEmployees;

}