List of usage examples for javax.persistence TypedQuery setParameter
TypedQuery<X> setParameter(int position, Object value);
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaActivityDao.java
public List<Activity> find(long accountId, Integer count, Long lastId, Boolean newer, Boolean followers) { String qlString = "SELECT ac " + "FROM Activity ac " + "JOIN ac.account a "; qlString += (followers) ? "JOIN a.followers f JOIN f.follower a2 WHERE a2.id = :accountId " : "WHERE a.id = :accountId "; if (newer != null && newer) { if (lastId != null) { qlString += "AND ac.id > :lastId "; }//from ww w . j a va 2s . co m qlString += "ORDER BY ac.id ASC "; } else { if (lastId != null) { qlString += "AND ac.id < :lastId "; } qlString += "ORDER BY ac.id DESC "; } TypedQuery<Activity> query = em.createQuery(qlString, Activity.class); query.setParameter("accountId", accountId); if (lastId != null) { query.setParameter("lastId", lastId).setMaxResults(count); } List<Activity> activities = query.getResultList(); if (activities.size() == 0) return null; return activities; }
From source file:com.ewcms.content.particular.dao.FontArticleMainDAO.java
public List<ArticleMain> findArticleMainListByChannel(Integer channelId) { String hql = "From ArticleMain As p where p.channelId=:channelId Order By p.article.published desc "; TypedQuery<ArticleMain> query = this.getEntityManager().createQuery(hql, ArticleMain.class); query.setParameter("channelId", channelId); return query.getResultList(); }
From source file:com.ewcms.content.particular.dao.FrontProjectBasicDAO.java
public List<ProjectBasic> findProjectBasicBySector(Long organId) { String hql = "From ProjectBasic As p where p.organ.id=:organId and p.release=true Order By p.published desc "; TypedQuery<ProjectBasic> query = this.getEntityManager().createQuery(hql, ProjectBasic.class); query.setParameter("organId", Integer.valueOf(organId.toString())); return query.getResultList(); }
From source file:com.ewcms.content.particular.dao.FrontProjectBasicDAO.java
public List<ProjectBasic> findProjectShenPiBasicLimit(String shape, Integer number) { String hql = "From ProjectBasic As p where p.shape=:shape and p.release=true Order By p.buildTime desc limit " + number;//from w w w. j ava 2s . c om TypedQuery<ProjectBasic> query = this.getEntityManager().createQuery(hql, ProjectBasic.class); query.setParameter("shape", Shape.valueOf(shape)); return query.getResultList(); }
From source file:com.ewcms.content.particular.dao.FrontEnterpriseBasicDAO.java
public EnterpriseBasic findEnterpriseBasicByYyzzzch(final String yyzzzch) { String hql = "From EnterpriseBasic As p Where p.yyzzzch=:yyzzzch and p.release=true "; TypedQuery<EnterpriseBasic> query = this.getEntityManager().createQuery(hql, EnterpriseBasic.class); query.setParameter("yyzzzch", yyzzzch); EnterpriseBasic enterpriseBasic = null; try {//from w w w . jav a 2 s . c o m enterpriseBasic = (EnterpriseBasic) query.getSingleResult(); } catch (NoResultException e) { } return enterpriseBasic; }
From source file:com.web.mavenproject6.service.PersonalServiceImp.java
@Override public Object findByAccessNumber(String accessNumber) { TypedQuery query = em.createQuery("select p from personal p where p.accessNumber = ?1", personal.class); query.setParameter(1, accessNumber); try {// w w w . ja va 2 s . c om return query.getSingleResult(); } catch (Exception ee) { return false; } }
From source file:com.ewcms.content.particular.dao.FrontProjectBasicDAO.java
public ProjectBasic findProjectBasicByCode(final String code) { String hql = "From ProjectBasic As p Where p.code=:code and p.release=true"; TypedQuery<ProjectBasic> query = this.getEntityManager().createQuery(hql, ProjectBasic.class); query.setParameter("code", code); ProjectBasic projectBasic = null;/*from ww w .jav a 2 s. c om*/ try { projectBasic = (ProjectBasic) query.getSingleResult(); } catch (NoResultException e) { } return projectBasic; }
From source file:com.jcertif.abj2014.intro.spring.data.before.SessionsServiceImpl.java
@Override public List<Sessions> findBySpeaker(Speaker speaker) { TypedQuery<Sessions> query = em.createQuery("select s from Sessions s where s.speaker = ?1", Sessions.class); query.setParameter(1, speaker); return query.getResultList(); }
From source file:com.epam.ipodromproject.repository.jpa.JPAHorseRepository.java
@Override public Horse getHorseByName(String name) { TypedQuery query = entityManager.createNamedQuery("Horse.findByName", Horse.class); query.setParameter("name", name); Horse horse = null;/* w w w. ja va 2 s.c o m*/ try { horse = (Horse) query.getSingleResult(); } catch (Exception e) { } return horse; }
From source file:org.broadleafcommerce.menu.dao.MenuDaoImpl.java
@Override public Menu readMenuByName(String menuName) { TypedQuery<Menu> query = em.createNamedQuery("BC_READ_MENU_BY_NAME", Menu.class); query.setParameter("menuName", menuName); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Cms"); List<Menu> results = query.getResultList(); if (!results.isEmpty()) { return results.get(0); } else {// w w w . j av a2 s . c o m return null; } }