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:dao.ExperienceDAOImpl.java

@Override
public List<ExperienceEntity> findExperiencesForProfil(Long profileId, int limit) {
    Query q;
    q = this.em.createQuery("SELECT e FROM ExperienceEntity e WHERE e.profile.id = ?");
    q.setParameter(1, profileId);
    q.setMaxResults(limit);/*from ww w .java  2  s  . c  o m*/
    return q.getResultList();
}

From source file:eu.domibus.common.dao.MessagingDao.java

public void delete(String messageId) {
    Query payloadsQuery = em.createNamedQuery("Messaging.findPartInfosForMessage");
    payloadsQuery.setParameter("MESSAGE_ID", messageId);

    Query emptyQuery = em.createNamedQuery("Messaging.emptyPayloads");
    emptyQuery.setParameter("PARTINFOS", payloadsQuery.getResultList());
    emptyQuery.executeUpdate();//from  w  w w  .ja va  2 s.c o m

    final Query messageStatusQuery = this.em.createNamedQuery("MessageLogEntry.setMessageStatus");
    messageStatusQuery.setParameter("MESSAGE_ID", messageId);
    messageStatusQuery.setParameter("TIMESTAMP", new Date());
    messageStatusQuery.setParameter("MESSAGE_STATUS", MessageStatus.DELETED);
    messageStatusQuery.executeUpdate();
}

From source file:DAO.FichiersDAOImpl.java

@Transactional(readOnly = true)
@Override/*  w w  w . java  2  s . c o m*/
public FichiersEntity find(int id) {
    Query q = em.createQuery("SELECT f FROM FichiersEntity f where f.id = ?");
    q.setParameter(1, id);
    try {
        return (FichiersEntity) q.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:de.crowdcode.bitemporal.example.AddressRepository.java

public Address findById(Long id) {
    Query query = em.createQuery("select c from AddressImpl c where c.id = :id");
    query.setParameter("id", id);
    return (Address) query.getSingleResult();
}

From source file:edu.mum.dao.impl.EventDaoRegisterImpl.java

@Override
public List<EventRegister> getNotSelectedEventRegisterByEventId(int eventId) {
    Query query = this.entityManager
            .createQuery("SELECT er from EventRegister er where er.event.id=:id and er.user=null");
    query.setParameter("id", eventId);
    return query.getResultList();
}

From source file:org.kuali.mobility.user.dao.UserDaoImpl.java

public User findUserByDeviceId(String deviceId) {
    Query query = entityManager.createQuery("select u from User u where u.deviceId = :deviceId");
    query.setParameter("deviceId", deviceId);
    try {//from   ww  w.j  av a  2  s  .c  om
        return (User) query.getSingleResult();
    } catch (Exception e) {
        return null;
    }
}

From source file:org.opentides.dao.impl.UserWidgetsDaoJpaImpl.java

@Override
public long countUserWidgetsColumn(Integer column, long userId) {
    Query query = getEntityManager().createQuery(getJpqlQuery("jpql.userwidgets.countUserWidgetsColumn"));
    query.setParameter("userId", userId);
    query.setParameter("column", column);
    return ((Long) query.getSingleResult()).intValue();
}

From source file:org.simbasecurity.core.domain.repository.RuleDatabaseRepository.java

@SuppressWarnings("unchecked")
Collection<ResourceRule> getResourceRulesDirectly(String username, String resource) {
    Query query = entityManager.createQuery(QUERY_RESOURCE_RULES_FOR_USER);

    query.setParameter(USERNAME, username).setParameter(RESOURCE, resource.toLowerCase());

    return query.getResultList();
}

From source file:com.telefonica.euro_iaas.commons.properties.impl.PropertiesDAOJPAImpl.java

/**
 * @see PropertiesDAO#load(String)// ww  w.j a v  a2 s .  c o m
 */
public Properties load(String namespace) {
    Properties prop = new Properties();
    Query query = entityManager.createQuery(FIND_BY_NAMESPACE);
    query.setParameter(NAMESPACE, namespace);
    for (Iterator i = query.getResultList().iterator(); i.hasNext();) {
        PersistentProperty p = (PersistentProperty) i.next();
        prop.setProperty(p.getKey(), p.getValue());
    }
    return prop;
}

From source file:org.jrecruiter.dao.jpa.RoleDaoJpa.java

public Role getRole(final String roleName) {

    final Role role;

    javax.persistence.Query query = entityManager.createQuery("select r from Role r " + "where r.name = :role");
    query.setParameter("role", roleName);

    try {/*from ww w.jav  a2  s  . com*/
        role = (Role) query.getSingleResult();
    } catch (NoResultException e) {
        throw new IllegalStateException(String.format(
                "Role '%s' does not exist. Roles should always " + "be there. Is the seed data populated?",
                roleName));
    }

    return role;
}