List of usage examples for javax.persistence Query setParameter
Query setParameter(int position, Object value);
From source file:com.ewcms.publication.PublishIntegratedTest.java
private void updateArticleStutas() { JpaTemplate template = createJpaTemplate(); template.execute(new JpaCallback<Object>() { @Override//from w w w. j a v a2 s. c om public Object doInJpa(EntityManager em) throws PersistenceException { em.getTransaction().begin(); String hql = "Update Article o Set o.status=?1 Where o.status = ?2"; Query query = em.createQuery(hql); query.setParameter(1, Article.Status.PRERELEASE); query.setParameter(2, Article.Status.RELEASE); query.executeUpdate(); em.getTransaction().commit(); return null; } }); }
From source file:com.expressui.core.dao.security.RoleDao.java
/** * Finds Role by a given name.//from www . java2 s . c o m * * @param name name to query * @return found Role */ public Role findByName(String name) { Query query = getEntityManager().createQuery("SELECT r FROM Role r WHERE r.name = :name"); query.setParameter("name", name); return (Role) query.getSingleResult(); }
From source file:org.opentides.dao.impl.SystemCodesDaoJpaImpl.java
/** * Selects all available categories except for the * specified ones //w w w . j ava 2 s . c o m */ @SuppressWarnings("unchecked") public List<String> getAllCategoriesExcept(String... categories) { String queryString = getJpqlQuery("jpql.systemcodes.findAllCategoriesExcept"); Query queryObject = getEntityManager().createQuery(queryString); queryObject.setParameter("categories", categories); return queryObject.getResultList(); }
From source file:com.gerenciaProyecto.DaoImple.ProductoDaoImpl.java
@Override public List<Producto> listar() { EntityManager em = getEntityManager(); List<Producto> lista = new ArrayList<Producto>(); Query q = em.createQuery("SELECT p FROM Producto p where p.estado= :estado "); q.setParameter("estado", Producto.ESTADOS.ACTIVO.getEstado()); lista = q.getResultList();//from w w w . j a v a2 s. co m return lista; }
From source file:com.gerenciaProyecto.DaoImple.ProductoDaoImpl.java
@Override public List<Producto> listarInactivos() { EntityManager em = getEntityManager(); List<Producto> lista = new ArrayList<Producto>(); Query q = em.createQuery("SELECT p FROM Producto p where p.estado= :estado "); q.setParameter("estado", Producto.ESTADOS.INACTIVO.getEstado()); lista = q.getResultList();//from w w w.j av a 2s.c om return lista; }
From source file:com.healthcit.cacure.dao.ModuleDao.java
public BaseModule getById(Long id) { Query query = em.createQuery("from BaseModule fe where id = :Id"); query.setParameter("Id", id); return (BaseModule) query.getSingleResult(); }
From source file:org.chtijbug.drools.platform.persistence.SessionExecutionRepositoryImpl.java
/** * @param ruleBaseID//from w ww . ja v a2 s. c o m * @param sessionId * @return * @Query("select s from SessionExecution s " + * "where s.platformRuntimeInstance.ruleBaseID= :ruleBaseID and s.sessionId = :sessionId "+ * "and s.platformRuntimeInstance.endDate is null ") */ @Override public SessionExecution findByRuleBaseIDAndSessionIdAndEndDateIsNull(@Param("ruleBaseID") Long ruleBaseID, @Param("sessionId") Long sessionId) { logger.debug(">> findByRuleBaseIDAndSessionIdAndEndDateIsNull"); SessionExecution sessionExecutionFound = null; try { String jpaQuery = "SELECT s.id, s.enddate, s.sessionexecutionstatus, s.sessionid, s.startdate, s.starteventid, \n" + " s.stopeventid, s.platform_runtime_instance_id\n" + " FROM session_execution s, platform_runtime_instance p \n" + " where s.platform_runtime_instance_id = p.id\n" + " and s.sessionid=:sessionid\n" + " and p.rulebaseid = :rulebaseID\n" + " and p.enddate is null"; //___ Append other filters Query query = entityManager.createNativeQuery(jpaQuery, SessionExecution.class); query.setParameter("rulebaseID", ruleBaseID); query.setParameter("sessionid", sessionId); List<SessionExecution> result = query.getResultList(); if (result.size() == 1) { sessionExecutionFound = result.get(0); } return sessionExecutionFound; } finally { logger.debug("<< findByRuleBaseIDAndSessionIdAndEndDateIsNull()"); } }
From source file:things.jpa.MysqlJpaConnector.java
@Override public Observable<? extends Thing<?>> findThingsMatchingTypeAndKey(String type, String key) { final Timer.Context context = find_matching_type_and_key_timer.time(); try {/*from w ww .j ava 2s. co m*/ String sqlQuery = "select * from things thing0_ where thing0_.thing_type regexp :thingType and thing0_.thing_key regexp :thingKey"; Query q = entityManager.createNativeQuery(sqlQuery, Thing.class); q.setParameter("thingType", MatcherUtils.convertGlobToRegex(type)); q.setParameter("thingKey", MatcherUtils.convertGlobToRegex(key)); List<Thing<?>> result = q.getResultList(); return Observable.from(result); } finally { context.stop(); } }
From source file:things.jpa.MysqlJpaConnector.java
@Override public Observable<? extends Thing<?>> findThingsForTypeMatchingKey(String type, String key) { final Timer.Context context = find_matching_type_and_key_timer.time(); try {/*w w w .j a v a 2s . co m*/ String sqlQuery = "select * from things thing0_ where thing0_.thing_type = :thingType and thing0_.thing_key regexp :thingKey"; Query q = entityManager.createNativeQuery(sqlQuery, Thing.class); q.setParameter("thingType", type); q.setParameter("thingKey", MatcherUtils.convertGlobToRegex(key)); List<Thing<?>> result = q.getResultList(); return Observable.from(result); } finally { context.stop(); } }
From source file:com.plan.proyecto.repositorios.DaoContenidoImpl.java
@Override public List<Contenido> findComentariosoByMensaje(Contenido mensaje) { if (mensaje == null) { return null; }//from w ww. j av a 2 s .c o m Query query = em.createNamedQuery("Contenido.findComentariosByMensaje"); query.setParameter("idValor", mensaje.getId()); return query.getResultList(); }