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.expressui.core.dao.security.query.RelatedRolesQuery.java

@Override
public void setParameters(TypedQuery<Serializable> typedQuery) {
    if (hasValue(user)) {
        typedQuery.setParameter("user", user);
    }//from  ww w.  ja va  2 s . co m
}

From source file:com.expressui.sample.dao.query.ProfileQuery.java

@Override
public void setParameters(TypedQuery<Serializable> typedQuery) {
    if (hasValue(loginName)) {
        typedQuery.setParameter("loginName", "%" + loginName.toUpperCase() + "%");
    }/*www . ja  va2  s.co  m*/
}

From source file:top.knos.user.UserRepositoryImpl.java

@Override
public List<User> findUsersByNameQuery(String value) {
    TypedQuery<User> tq = em.createQuery("select u from User u where u.username = ?1", User.class);
    tq.setParameter(1, value);
    return tq.getResultList();
}

From source file:top.knos.user.UserRepositoryImpl.java

@Override
public User findUserByNameQuery(String value) {
    TypedQuery<User> tq = em.createQuery("select u from User u where u.username = ?1", User.class);
    tq.setParameter(1, value);
    return tq.getSingleResult();
}

From source file:com.expressui.sample.view.role.RoleQuery.java

@Override
public void setParameters(TypedQuery typedQuery) {
    if (!isEmpty(name)) {
        typedQuery.setParameter("name", "%" + name.toUpperCase() + "%");
    }//from  ww  w .  java2  s  . co  m
    if (!isEmpty(doesNotBelongToUser)) {
        typedQuery.setParameter("doesNotBelongToUser", doesNotBelongToUser);
    }
}

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

/**
 * {@inheritDoc}//from  www  .  j a v a  2s  . c  o m
 */
public List<Todo> getTodoListByUserAndTitle(final long userId, final String title) {
    TypedQuery<Todo> query = entityManager.createNamedQuery("findTodosByTitle", Todo.class);
    query.setParameter(1, userId);
    query.setParameter(2, "%" + title.toUpperCase() + "%");
    return query.getResultList();
}

From source file:org.openmeetings.app.data.logs.ConferenceLogTypeDaoImpl.java

public ConferenceLogType getConferenceLogTypeByEventName(String eventType) {
    try {//from   w  ww .  ja  v a2  s.  c o  m

        String hql = "select a from ConferenceLogType a " + "WHERE a.eventType = :eventType ";

        TypedQuery<ConferenceLogType> query = em.createQuery(hql, ConferenceLogType.class);
        query.setParameter("eventType", eventType);

        //Seems like this does throw an error sometimes cause it does not return a unique Result
        //ConferenceLogType confLogType = (ConferenceLogType) query.getSingleResult();
        List<ConferenceLogType> confLogTypes = query.getResultList();
        ConferenceLogType confLogType = null;
        if (confLogTypes != null && confLogTypes.size() > 0) {
            confLogType = confLogTypes.get(0);
        }

        return confLogType;
    } catch (Exception ex2) {
        log.error("[getConferenceLogTypeByEventName]: " + ex2);
    }
    return null;
}

From source file:eu.europa.ec.fisheries.uvms.rules.dao.ValidationMessageDao.java

public List<ValidationMessage> getValidationMessagesByRawMessageGuid(String rawMsgGuid, String type)
        throws ServiceException {
    TypedQuery query = this.getEntityManager().createNamedQuery(RawMessage.BY_GUID, RawMessage.class);
    query.setParameter("rawMsgGuid", rawMsgGuid);
    RawMsgType typeType = null;//from   w  w  w .j a va 2 s  .  com
    try {
        typeType = RawMsgType.fromValue(type);
    } catch (IllegalArgumentException ex) {
        log.error("[ERROR] Type " + type + " is not present in RawMsgType class..");
    }
    query.setParameter("msgType", typeType);
    List<RawMessage> resultList = (List<RawMessage>) query.getResultList();
    List<ValidationMessage> validMessages = new ArrayList<>();
    if (CollectionUtils.isEmpty(resultList)) {
        return validMessages;
    }
    for (RawMessage rawMsg : resultList) {
        validMessages.addAll(rawMsg.getValidationMessages());
    }
    return validMessages;
}

From source file:com.expressui.sample.dao.query.RelatedContactsQuery.java

@Override
public void setParameters(TypedQuery<Serializable> typedQuery) {
    if (hasValue(account)) {
        typedQuery.setParameter("account", account);
    }//  ww w. j ava  2s.  co  m
}

From source file:br.eti.danielcamargo.backend.common.core.business.UsuarioService.java

public Usuario get(String email) {
    TypedQuery<Usuario> query = em.createNamedQuery(Usuario.GET_USUARIO_BY_EMAIL, Usuario.class);
    query.setParameter("email", email);

    List<Usuario> result = query.getResultList();
    return result.isEmpty() ? null : result.get(0);
}