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

@Override
@SuppressWarnings("unchecked")
public List<ResponsiblePerson> findByKindergartenId(final Long kindergarteId) {
    final Long tenantId = ((EvidenceUserDetails) SecurityContextHolder.getContext().getAuthentication()
            .getPrincipal()).getTenantId();
    Query query = this.entityManager
            .createNamedQuery(ResponsiblePerson.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.exp.tracker.services.impl.JpaPaymentService.java

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)/*from www .  j a v a  2 s.  co m*/
public List<PaymentBean> getPaymnentsForUser(String userName) {
    List<PaymentBean> paymentList = new ArrayList<PaymentBean>();
    Query queryGetPaymentsForUser = null;
    queryGetPaymentsForUser = em.createNamedQuery("paymentsForUser");
    queryGetPaymentsForUser.setParameter("userName", userName);
    // get a list of results
    Collection<Object[]> results = queryGetPaymentsForUser.getResultList();
    for (Object[] oa : results) {
        PaymentBean pb = new PaymentBean();
        // Each object is a list
        pb.setAmount(((Float) oa[0]).floatValue());
        pb.setSettledFlag(((Integer) oa[1]).intValue());
        pb.setStartDate(((Date) oa[2]));
        pb.setEndDate(((Date) oa[3]));
        pb.setSettlementId(((Long) oa[4]).longValue());
        pb.setUserName(((String) oa[5]));
        paymentList.add(pb);
    }
    return paymentList;

}

From source file:com.vizaco.onlinecontrol.dao.jpa.JpaStudentDaoImpl.java

public Collection<Student> findByLastName(String lastName) {
    Query query = this.em.createQuery(
            "SELECT DISTINCT student FROM Student student left join fetch student.users WHERE student.lastName LIKE :lastName");
    query.setParameter("lastName", lastName + "%");
    List resultList = query.getResultList();
    return query.getResultList();
}

From source file:org.syncope.core.persistence.dao.impl.SchemaDAOImpl.java

@Override
public <T extends AbstractAttr> List<T> getAttributes(final AbstractSchema schema, final Class<T> reference) {

    Query query = entityManager
            .createQuery("SELECT e FROM " + reference.getSimpleName() + " e" + " WHERE e.schema=:schema");
    query.setParameter("schema", schema);

    return query.getResultList();
}

From source file:com.music.dao.UserDao.java

public void deleteSocialAuthentication(Long userId, String providerId) {
    Query query = getEntityManager()
            .createQuery("DELETE FROM SocialAuthentication WHERE user.id=:userId AND providerId=:providerId");
    query.setParameter("userId", userId);
    query.setParameter("providerId", providerId);
    query.executeUpdate();//from  www . java 2 s  .  c  o  m
}

From source file:org.venice.piazza.common.hibernate.dao.dataresource.DataResourceDaoImpl.java

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

From source file:com.mothsoft.alexis.dao.SocialConnectionDaoImpl.java

@Override
public SocialConnection findByRemoteUsername(String username, SocialNetworkType socialNetworkType) {
    final Query query = this.em.createQuery("FROM SocialConnection sc WHERE sc.remoteUsername = :username "
            + "AND socialNetworkType = :socialNetworkType");
    query.setParameter("username", username);
    query.setParameter("socialNetworkType", socialNetworkType);

    @SuppressWarnings("unchecked")
    final List<SocialConnection> socialConnections = query.getResultList();

    if (!socialConnections.isEmpty()) {
        return socialConnections.get(0);
    }/*from   w w  w .j a v  a2s.  co m*/

    return null;
}

From source file:org.syncope.core.persistence.dao.impl.TaskDAOImpl.java

@Override
public List<PropagationTask> findAll(final SyncopeUser user) {
    StringBuilder queryString = buildfindAllQuery(PropagationTask.class);
    queryString.append("WHERE e.syncopeUser=:user");
    final Query query = entityManager.createQuery(queryString.toString());
    query.setParameter("user", user);

    return query.getResultList();
}

From source file:com.tsystems.javaschool.logiweb.dao.jpa.TruckDaoJpa.java

/**
 * {@inheritDoc}/*from   ww w .j  a va 2 s  . co  m*/
 */
@Override
public Truck findByLicensePlate(String licensePlate) throws DaoException {
    try {
        EntityManager em = getEntityManager();
        Class<Truck> truckEntityClass = getEntityClass();
        String classSimpleName = truckEntityClass.getSimpleName();

        Query query = em.createQuery("SELECT t FROM " + classSimpleName + " t WHERE licencePlate = :plate",
                truckEntityClass);
        query.setParameter("plate", licensePlate);

        List<Truck> resultList = query.getResultList();
        if (resultList.isEmpty()) {
            return null;
        } else {
            return resultList.get(0);
        }
    } catch (Exception e) {
        LOG.warn(e);
        throw new DaoException(e);
    }
}

From source file:org.syncope.core.persistence.dao.impl.TaskDAOImpl.java

@Override
public List<PropagationTask> findAll(final ExternalResource resource, final SyncopeUser user) {

    StringBuilder queryString = buildfindAllQuery(PropagationTask.class);
    queryString.append("WHERE e.syncopeUser=:user ").append("AND e.resource=:resource");
    final Query query = entityManager.createQuery(queryString.toString());
    query.setParameter("user", user);
    query.setParameter("resource", resource);

    return query.getResultList();
}