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:org.simbasecurity.core.config.store.DatabaseConfigurationStore.java

public String setValue(ConfigurationParameter parameter, String value) {
    String oldValue = getValue(parameter);

    Query query = entityManager.createNativeQuery(SQL_SET);
    query.setParameter(1, value);
    query.setParameter(2, String.valueOf(parameter));
    query.executeUpdate();/* w w w .  j a  v a 2 s  .  co m*/

    return oldValue;
}

From source file:at.irian.demo.jsfatwork.repository.jpa.JpaGroupRepository.java

public List<Group> loadAllFor(User user) {
    Query query = this.entityManager.createNamedQuery(DomainQueryDetails.FIND_SUBSCRIBED_GROUPS);
    query.setParameter(DomainQueryDetails.PARAMETER_USER, user);
    return query.getResultList();
}

From source file:com.branded.holdings.qpc.repository.jpa.JpaVisitRepositoryImpl.java

@Override
@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:com.github.iexel.fontus.services.ProductsService.java

@Override
@Transactional(rollbackFor = Throwable.class)
public void deleteProduct(int productId, int productVersion) throws ServiceException {

    Query query = entityManager.createNamedQuery("Product.delete");
    query.setParameter("id", productId);
    query.setParameter("version", productVersion);
    int numberOfRecords = query.executeUpdate();

    if (numberOfRecords == 0) {
        throw new ServiceException(ServiceException.ErrorCode.EXCEPTION_MODIFIED_BY_ANOTHER_USER);
    }/*from  www .  j a  v  a  2 s. c  om*/
}

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

@Override
public List<Event> findEventsByUserId(int userId) {
    Query query = this.entityManager.createQuery("SELECT e from Event e where e.eventOwner.id =:id");
    query.setParameter("id", userId);
    return query.getResultList();
}

From source file:modelo.dao.GestionProductosImpl.java

@Override
public List<Producto> obtenerProductos(int user, int color) {
    Query q = em.createNamedQuery("Producto.findByUserColor");
    q.setParameter(1, user);
    q.setParameter(2, color);/*  w  w w  . j a  va 2 s  . c  o m*/

    return q.getResultList();
}

From source file:at.irian.demo.jsfatwork.repository.jpa.JpaGroupRepository.java

public List<Group> loadUnSubscribedGroups(User user) {
    Query query = this.entityManager.createNamedQuery(DomainQueryDetails.FIND_UNSUBSCRIBED_GROUPS);
    query.setParameter(DomainQueryDetails.PARAMETER_USER, user);
    return query.getResultList();
}

From source file:bc8.movies.dao.ActorDaoImpl.java

public Actor getActor(String actorName) {
    Query query = em.createQuery("select actor from Actor actor where actor.name= :actorName");
    query.setParameter("actorName", actorName);
    return (Actor) query.getSingleResult();
}

From source file:bc8.movies.dao.MovieDaoImpl.java

public boolean isMovieInDB(String movieName) {
    Query query = em.createQuery("select movie from Movie movie where movie.name= :movieName");

    query.setParameter("movieName", movieName);

    return !query.getResultList().isEmpty();
}

From source file:bc8.movies.dao.MovieDaoImpl.java

public Movie getMovie(String movieName) {
    Query query = em.createQuery("select movie from Movie movie where movie.name= :movieName");

    query.setParameter("movieName", movieName);

    return (Movie) query.getSingleResult();
}