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:de.alpharogroup.message.system.service.MessageRecipientsBusinessService.java

@Override
@SuppressWarnings("unchecked")
public boolean deleteMessageRecipient(final Users recipient, final Messages message) {
    final String hqlSelectString = "select distinct mr from " + MessageRecipients.class.getSimpleName() + " mr "
            + "where mr.recipient=:recipient " + "and mr.message=:message";

    final Query query = getQuery(hqlSelectString);
    query.setParameter("recipient", recipient);
    query.setParameter("message", message);
    final List<MessageRecipients> toDel = query.getResultList();
    if (toDel != null && !toDel.isEmpty()) {
        for (final Iterator<MessageRecipients> iterator = toDel.iterator(); iterator.hasNext();) {
            MessageRecipients messageRecipient = iterator.next();
            messageRecipient.setMessage(null);
            messageRecipient.setRecipient(null);
            messageRecipient = merge(messageRecipient);
            delete(messageRecipient);//  w ww  . j  av  a  2  s  .  c o  m
        }
        return true;
    }
    return false;
}

From source file:de.inetsource.jsfforum.db.ThreadFacade.java

public int countThreadsByForum(Forum forumId) {
    String SQL = "SELECT count(thread) FROM Thread thread WHERE thread.forumId = :forumId";
    javax.persistence.Query q = getEntityManager().createQuery(SQL);
    q.setParameter("forumId", forumId);
    return ((Long) q.getSingleResult()).intValue();
}

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

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

From source file:modelo.dao.GestionProductosImpl.java

@Override
public List<Producto> obtenerProductos(int user) {
    Query q = em.createNamedQuery("Producto.findByUser");
    q.setParameter(1, user);

    return q.getResultList();
}

From source file:modelo.DaoTiposActividadesImpl.java

@Override
public void eliminarActividad(int idtipoActividad) {
    /* EntityManager em=this.obtenerEntityManager();
     Actividad act=em.find(Actividad.class,idactividades);
     EntityTransaction tx=em.getTransaction();
     tx.begin();//from   www.j a  va  2  s  .c  o m
     em.remove(act);
     tx.commit();
     em.close();*/

    String jpql = "delete from Actividad act where act.idactividades=?1";

    Query q = em.createQuery(jpql);
    q.setParameter(1, idtipoActividad);
    EntityTransaction tx = em.getTransaction();
    tx.begin();
    q.executeUpdate();
    tx.commit();
    em.close();

}

From source file:org.osiam.auth.oauth_client.ClientDao.java

private ClientEntity getClientById(final String id) {
    final Query query = em.createNamedQuery("getClientById");
    query.setParameter("id", id);
    final List<?> result = query.getResultList();
    if (result.isEmpty()) {
        throw new ResourceNotFoundException("Resource " + id + " not found.");
    }/*from   www.j  ava  2s  .c  o m*/
    return (ClientEntity) result.get(0);
}

From source file:org.simbasecurity.core.config.store.DatabaseConfigurationStore.java

@SuppressWarnings("unchecked")
public List<String> getValueList(ConfigurationParameter parameter) {
    Query query = entityManager.createNativeQuery(SQL_GET);
    query.setParameter(1, String.valueOf(parameter));
    return query.getResultList();
}

From source file:com.pet.demo.repository.jpa.JpaVisitRepositoryImpl.java

@SuppressWarnings("unchecked")
public List<Visit> findByPetId(Integer petId) {
    Query query = this.em.createQuery("SELECT visit FROM Visit v where v.pets.id= :id");
    query.setParameter("id", petId);
    return query.getResultList();
}

From source file:de.inetsource.jsfforum.db.PostFacade.java

public int count(Thread thread) {
    Query q = em.createQuery("Select count(p.id) from Post p where p.threadId = :thread");
    q.setParameter("thread", thread);
    return ((Long) q.getSingleResult()).intValue();
}

From source file:org.simbasecurity.core.config.store.DatabaseConfigurationStore.java

public String getValue(ConfigurationParameter parameter) {
    Query query = entityManager.createNativeQuery(SQL_GET);
    query.setParameter(1, String.valueOf(parameter));
    try {/*  w  ww .j  ava2s. c o m*/
        return (String) query.getSingleResult();
    } catch (Exception ignore) {
        return "";
    }
}