Example usage for javax.persistence TypedQuery setParameter

List of usage examples for javax.persistence TypedQuery setParameter

Introduction

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

Prototype

TypedQuery<X> setParameter(int position, Object value);

Source Link

Document

Bind an argument value to a positional parameter.

Usage

From source file:com.jcs.goboax.aulavirtual.dao.impl.RegistroAccesoDaoImpl.java

@Override
public RegistroAcceso readBySessionId(String aSessionId) {
    TypedQuery<RegistroAcceso> myTypedQuery = entityManager
            .createNamedQuery(RegistroAcceso.REGISTRO_ACCESO_BY_SESSION, RegistroAcceso.class);
    myTypedQuery.setParameter(RegistroAcceso.REGISTRO_ACCESO_SESSION_PARAMETER, aSessionId);

    return getSingleResult(myTypedQuery);
}

From source file:com.siriusit.spezg.multilib.storage.jpa.JpaMessageRepository.java

@Override
public long countMessagesByViewedState(Person receiver, boolean viewedState) {
    TypedQuery<Long> query = entityManager.createNamedQuery("findMessageByViewedState", Long.class);
    query.setParameter("receiver", receiver);
    query.setParameter("viewed", viewedState);
    return query.getSingleResult();
}

From source file:com.expressui.sample.view.user.UserQuery.java

@Override
public void setParameters(TypedQuery typedQuery) {
    if (!isEmpty(loginName)) {
        typedQuery.setParameter("loginName", "%" + loginName.toUpperCase() + "%");
    }//from  w  w  w. ja va  2s. c  o m
    if (!isEmpty(doesNotBelongToRole)) {
        typedQuery.setParameter("doesNotBelongToRole", doesNotBelongToRole);
    }
}

From source file:com.plan.proyecto.repositorios.DaoContenidoImpl.java

@Override
public List<Contenido> findContenidosByCuenta(Long id) {
    TypedQuery<Contenido> query = em.createNamedQuery("Contenido.findByCuenta", Contenido.class);
    query.setParameter("valor", id);
    return query.getResultList();
}

From source file:org.cleverbus.core.common.dao.RequestResponseDaoJpaImpl.java

@Nullable
@Override//from  w w  w  . j  a  va  2s.  co m
public Request findLastRequest(String uri, String responseJoinId) {
    Assert.hasText(uri, "the uri must not be empty");
    Assert.hasText(responseJoinId, "the responseJoinId must not be empty");

    String jSql = "SELECT r " + "FROM " + Request.class.getName() + " r "
            + "WHERE r.responseJoinId = :responseJoinId AND r.uri = :uri " + "ORDER BY r.reqTimestamp";

    TypedQuery<Request> q = em.createQuery(jSql, Request.class);
    q.setParameter("responseJoinId", responseJoinId);
    q.setParameter("uri", uri);

    // we search by unique key - it's not possible to have more records
    List<Request> requests = q.getResultList();
    if (requests.isEmpty()) {
        return null;
    } else {
        return requests.get(0); // if find more items then return first one only
    }
}

From source file:com.tpg.tmjug.springdata.demo.jpa.repository.JpaCustomerDAOImpl.java

@Override
public List<Customer> findByAddress(Address address) {

    TypedQuery<Customer> query = em.createQuery("select c from Customer c where c.address = :address",
            Customer.class);
    query.setParameter("address", address);

    return query.getResultList();
}

From source file:io.github.todolist.core.repository.impl.UserRepositoryImpl.java

/**
 * {@inheritDoc}/*w  w w .  ja v  a 2s. co  m*/
 */
public boolean login(final String email, final String password) {
    TypedQuery<User> query = entityManager.createNamedQuery("findUserByEmailAndPassword", User.class);
    query.setParameter("p_email", email);
    query.setParameter("p_password", password);
    List<User> users = query.getResultList();
    return (users != null && !users.isEmpty());
}

From source file:com.deltastar.task7.core.repository.api.impl.EmployeeRepositoryImpl.java

/**
 * {@inheritDoc}/* w ww.  j a v  a  2s. com*/
 */
public Employee getEmployeeByUserName(final String userName) {
    TypedQuery<Employee> query = entityManager.createNamedQuery("findEmployeeByUserName", Employee.class);
    query.setParameter("p_userName", userName);
    List<Employee> employees = query.getResultList();
    return (employees != null && !employees.isEmpty()) ? employees.get(0) : null;
}

From source file:com.deltastar.task7.core.repository.api.impl.FundRepositoryImpl.java

@Override
public Fund getFundBySymbol(String symbol) {
    TypedQuery<Fund> query = entityManager.createNamedQuery("findFundBySymbol", Fund.class);
    query.setParameter("p_symbol", symbol);
    List<Fund> fundList = query.getResultList();
    return (fundList != null && !fundList.isEmpty()) ? fundList.get(0) : null;
}

From source file:net.triptech.metahive.model.Record.java

/**
 * Find the record going by the supplied record id.
 *
 * @param recordId the recordId//from   w  w w  . jav a2 s  .co m
 * @return the record
 */
public static Record findRecordByRecordIdEquals(String recordId) {

    Record record = null;

    if (StringUtils.isBlank(recordId)) {
        throw new IllegalArgumentException("The recordId argument is required");
    }

    TypedQuery<Record> q = entityManager()
            .createQuery("SELECT r FROM Record AS r WHERE LOWER(r.recordId) = LOWER(:recordId)", Record.class);
    q.setParameter("recordId", recordId);

    List<Record> records = q.getResultList();

    if (records != null && records.size() > 0) {
        record = records.get(0);
    }
    return record;
}