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.opentides.dao.impl.UserDaoJpaImpl.java

public final boolean isRegisteredByEmail(String emailAddress) {
    if (StringUtil.isEmpty(emailAddress))
        return false;
    String queryString = getJpqlQuery("jpql.user.countByEmailAddress");
    Query queryObject = getEntityManager().createQuery(queryString);
    queryObject.setParameter("emailAddress", emailAddress);
    long count = (Long) queryObject.getSingleResult();
    return count != 0;
}

From source file:boutiqueEnLigne.service.ArticleService2.java

public List<Article> findByGenreOrderByPrixAsc(Genre genre) {
    if (genre == Genre.ENFANT) {
        Query query = em.createQuery("SELECT a FROM Article a WHERE a.genre =:mon_genre");
        query.setParameter("mon_genre", Genre.ENFANT);
        return query.getResultList();
    }// w ww  .  jav  a2s  .c  o m
    if (genre == Genre.FEMME) {
        Query query = em.createQuery("SELECT a FROM Article a WHERE a.genre =:mon_genre");
        query.setParameter("mon_genre", Genre.FEMME);
        Query query2 = em.createQuery("SELECT a FROM Article a WHERE a.genre =:mon_genre2");
        query2.setParameter("mon_genre2", Genre.MIXTE);
        List<Article> articles = new ArrayList<>();
        articles = query.getResultList();
        List<Article> articles2 = new ArrayList<>();
        articles2 = query2.getResultList();
        articles2.addAll(articles);
        return articles2;
    }
    if (genre == Genre.HOMME) {
        Query query = em.createQuery("SELECT a FROM Article a WHERE a.genre =:mon_genre");
        query.setParameter("mon_genre", Genre.HOMME);
        Query query2 = em.createQuery("SELECT a FROM Article a WHERE a.genre =:mon_genre2");
        query2.setParameter("mon_genre2", Genre.MIXTE);
        List<Article> articles = new ArrayList<>();
        articles = query.getResultList();
        List<Article> articles2 = new ArrayList<>();
        articles2 = query2.getResultList();
        articles2.addAll(articles);
        return articles2;
    }
    if (genre == Genre.MIXTE) {
        Query query = em.createQuery("SELECT a FROM Article a WHERE a.genre =:mon_genre");
        query.setParameter("mon_genre", Genre.MIXTE);
        return query.getResultList();
    } else {
        return em.createQuery("SELECT * FROM Article a").getResultList();
    }
}

From source file:com.acmeair.jpa.service.BookingServiceImpl.java

@Override
public List<Booking> getBookingsByUser(String user) {
    Query q = em.createQuery("SELECT obj FROM Booking obj where obj.customer.id=?1");
    q.setParameter(1, user);

    List<Booking> results = (List<Booking>) q.getResultList();

    return results;
}

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

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

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

    return query.getResultList();
}

From source file:pdsanchez.mywebtools.model.dao.jpa.SubcategoryDAOJPAImpl.java

@Override
public Subcategory find(String name) {
    Subcategory sc = null;/*from   w  ww. j  a va2  s  . c  o m*/

    Query q = getEntityManager()
            .createQuery("select o from Subcategory o where lower(o.subcategoryName) = :name");
    q.setParameter("name", name.toLowerCase());
    List<Subcategory> list = q.getResultList();
    if (!list.isEmpty()) {
        sc = list.get(0);
    }

    return sc;
}

From source file:eu.planets_project.tb.impl.persistency.CommentPersistencyImpl.java

public List<Comment> getAllComments(long experimentID) {
    Query query = manager.createQuery("from CommentImpl where experimentID=:expid");
    query.setParameter("expid", experimentID);
    return (List<Comment>) query.getResultList();
}

From source file:eu.planets_project.tb.impl.persistency.CommentPersistencyImpl.java

public List<Comment> getCommentsByParent(long commentID) {
    // TODO Move Entity declaration us so that we access Comments not CommenImpls?
    Query query = manager.createQuery("from CommentImpl where parentID=:parentid");
    query.setParameter("parentid", commentID);
    return (List<Comment>) query.getResultList();
}

From source file:com.iselect.kernal.pageflow.dao.PageRequestDaoImpl.java

@Override
public PageRequestModel getPageRequest(String actionPath, String actionMethod) throws ISelectDaoException {
    Query query = em.createNamedQuery(PageRequestModel.QUERY_BY_PATH_METHOD);
    query.setParameter(PageRequestModel.PARAM_ACTION_METHOD, actionPath);
    query.setParameter(PageRequestModel.PARAM_ACTION_METHOD, actionMethod);
    return (PageRequestModel) query.getSingleResult();
}

From source file:com.thingtrack.konekti.dao.impl.internal.AreaDaoImpl.java

@SuppressWarnings("unchecked")
@Override//from www  .  j a  va2  s .c  o m
public List<Area> getAll(User user) throws Exception {
    String queryString = "SELECT p FROM " + getEntityName() + " p";

    if (user.getActiveLocation() != null)
        queryString += " WHERE p.location = :location";

    Query query = (Query) getEntityManager().createQuery(queryString);

    if (user.getActiveLocation() != null)
        query.setParameter("location", user.getActiveLocation());

    return query.getResultList();
}

From source file:DAO.CommentairesDAOImpl.java

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