List of usage examples for javax.persistence TypedQuery setParameter
TypedQuery<X> setParameter(int position, Object value);
From source file:com.clustercontrol.platform.collect.QueryExecutor.java
public static <T> List<T> getListWithTimeout(String queryName, Class<T> resultClass, Map<String, Object> parameters) { setStatementTimeout();/* www . j a v a2 s. co m*/ HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); TypedQuery<T> query = em.createNamedQuery(queryName, resultClass); for (String key : parameters.keySet()) { query.setParameter(key, parameters.get(key)); } List<T> list = query.getResultList(); resetStatementTimeout(); return list; }
From source file:org.kew.rmf.matchconf.Dictionary.java
public static TypedQuery<Dictionary> findDictionariesByNameEquals(String name) { if (name == null || name.length() == 0) throw new IllegalArgumentException("The name argument is required"); EntityManager em = Dictionary.entityManager(); TypedQuery<Dictionary> q = em.createQuery("SELECT o FROM Dictionary AS o WHERE o.name = :name", Dictionary.class); q.setParameter("name", name); return q;/*from w w w.j ava 2s. c o m*/ }
From source file:ar.edu.unlp.sedici.sedici2003.model.JerarquiasTermino.java
public static List<JerarquiasTermino> findAll(String text, String[] parents, boolean includeChilds, boolean includeSelf, int start, int count) { if (text == null || text.length() == 0) throw new IllegalArgumentException("The text argument is required"); if (parents == null || parents.length == 0) throw new IllegalArgumentException("The parents argument is required"); if (start < 0) start = 0;//from ww w .j a va2 s. c o m if (count <= 0) count = 10; // Armamos el filtro de descendencia String parentFilter = "("; if (includeChilds) { for (String parentID : parents) { if (!parentID.endsWith(".")) parentID += "."; parentFilter += " terminos.id LIKE '" + parentID + "%' OR"; } } else { for (String parentID : parents) { parentFilter += " relaciones.id.idTermino1 = '" + parentID + "' OR"; } } if (includeSelf) { for (String parentID : parents) { if (parentID.endsWith(".")) parentID = parentID.substring(0, parentID.length() - 1); parentFilter += " terminos.id LIKE '" + parentID + "' OR"; } } //Sacamos el ultimo OR parentFilter = parentFilter.substring(0, parentFilter.length() - 2) + ")"; String sql = "SELECT terminos " + "FROM JerarquiasTermino AS terminos, JerarquiasRelaciones AS relaciones " + "WHERE terminos.id = relaciones.id.idTermino2 AND relaciones.tipoRelacion = 1 " + "AND LOWER(terminos.nombreEs) LIKE LOWER(:filtro) AND " + parentFilter; //Agrego el orden sql = sql + " ORDER BY terminos.nombreEs ASC"; // System.out.println(sql); EntityManager em = JerarquiasTermino.entityManager(); TypedQuery<JerarquiasTermino> q = em.createQuery(sql, JerarquiasTermino.class); q.setParameter("filtro", "%" + text + "%"); q.setFirstResult(start); q.setMaxResults(count); return q.getResultList(); }
From source file:com.enioka.jqm.tools.ResourceParser.java
private static JndiResourceDescriptor fromDatabase(String alias) throws NamingException { JndiObjectResource resource = null;/* w w w. ja v a 2 s. co m*/ EntityManager em = null; try { // Using the horrible CriteriaBuilder API instead of a string query. This avoids classloading issues - Hibernate binds // the entities at run time with the thread current classloader... em = Helpers.getNewEm(); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<JndiObjectResource> q = cb.createQuery(JndiObjectResource.class); Root<JndiObjectResource> c = q.from(JndiObjectResource.class); ParameterExpression<String> p = cb.parameter(String.class); q.select(c).where(cb.equal(c.get("name"), p)); TypedQuery<JndiObjectResource> query = em.createQuery(q); query.setParameter(p, alias); resource = query.getSingleResult(); } catch (Exception e) { NamingException ex = new NamingException("Could not find a JNDI object resource of name " + alias); ex.setRootCause(e); throw ex; } finally { if (em != null) { em.close(); } } // Create the ResourceDescriptor from the JPA object JndiResourceDescriptor d = new JndiResourceDescriptor(resource.getType(), resource.getDescription(), null, resource.getAuth(), resource.getFactory(), resource.getSingleton()); for (JndiObjectResourceParameter prm : resource.getParameters()) { d.add(new StringRefAddr(prm.getKey(), prm.getValue())); } return d; }
From source file:ar.edu.unlp.sedici.sedici2003.model.TesaurosTermino.java
public static List<TesaurosTermino> findAll(String text, String[] parents, boolean includeChilds, int start, int count) { //if (text == null || text.length() == 0) throw new IllegalArgumentException("The text argument is required"); if (parents == null || parents.length == 0) throw new IllegalArgumentException("The parents argument is required"); if (start < 0) start = 0;/*from w w w .j a v a2 s. co m*/ if (count <= 0) count = 60; // Armamos el filtro de descendencia String parentFilter = "("; if (includeChilds) { for (String parentID : parents) { if (!parentID.endsWith(".")) parentID += "."; parentFilter += " terminos.id LIKE '" + parentID + "%' OR"; } } else { for (String parentID : parents) { parentFilter += " relaciones.id.idTermino1 = '" + parentID + "' OR"; } } //Sacamos el ultimo OR parentFilter = parentFilter.substring(0, parentFilter.length() - 2) + ")"; String sql = "SELECT terminos " + "FROM TesaurosTermino AS terminos, TesaurosRelaciones AS relaciones " + "WHERE terminos.id = relaciones.id.idTermino2 AND relaciones.id.tipoRelacion = 1 " + "AND LOWER(terminos.nombreEs) LIKE LOWER(:filtro) AND " + parentFilter; //Agrego el orden sql = sql + " ORDER BY terminos.nombreEs ASC"; EntityManager em = TesaurosTermino.entityManager(); TypedQuery<TesaurosTermino> q = em.createQuery(sql, TesaurosTermino.class); if (text != null || text.length() != 0) { q.setParameter("filtro", "%" + text.trim() + "%"); } q.setFirstResult(start); q.setMaxResults(count); return q.getResultList(); }
From source file:fr.univrouen.poste.domain.PosteAPourvoir.java
public static List<PosteAPourvoir> findPosteAPourvoirsByNumEmplois(List<String> numEmplois) { if (numEmplois == null) throw new IllegalArgumentException("The numEmplois argument is required"); TypedQuery<PosteAPourvoir> q = entityManager().createQuery( "SELECT o FROM PosteAPourvoir o WHERE o.numEmploi IN :numEmplois ORDER BY o.numEmploi asc", PosteAPourvoir.class); q.setParameter("numEmplois", numEmplois); return q.getResultList(); }
From source file:fr.univrouen.poste.domain.PosteAPourvoir.java
public static List<PosteAPourvoir> findPosteAPourvoirsByMembre(User membre) { if (membre == null) throw new IllegalArgumentException("The membre argument is required"); TypedQuery<PosteAPourvoir> q = entityManager().createQuery( "SELECT o FROM PosteAPourvoir o WHERE :membre MEMBER OF o.membres ORDER BY o.numEmploi asc", PosteAPourvoir.class); q.setParameter("membre", membre); return q.getResultList(); }
From source file:ar.edu.unlp.sedici.sedici2003.model.Personas.java
public static List<Personas> findPersonasesByApellidoYNombre(String apellido, String nombre, int start, int count) { if (apellido == null || apellido.length() == 0) apellido = ""; if (nombre == null) nombre = ""; if (start < 0) start = 0;/*from w ww .j a v a2 s .c om*/ if (count <= 0) count = 20; apellido = Personas.convertirParaQuery(apellido); nombre = Personas.convertirParaQuery(nombre); String where = Personas.generateCondition(apellido, nombre); EntityManager em = Personas.entityManager(); TypedQuery<Personas> q = em.createQuery( "SELECT o FROM Personas AS o " + where + " ORDER BY o.apellido, o.nombre ASC", Personas.class); if (apellido.length() != 0) q.setParameter("apellido", apellido); if (nombre.length() != 0) q.setParameter("nombre", nombre); q.setFirstResult(start); q.setMaxResults(count); return q.getResultList(); }
From source file:com.clustercontrol.infra.util.QueryUtil.java
public static List<InfraCheckResult> getInfraCheckResultFindByModuleId(String managementId, String moduleId) { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); TypedQuery<InfraCheckResult> query = em.createNamedQuery("InfraCheckResultEntity.findByModuleId", InfraCheckResult.class); query.setParameter("managementId", managementId); query.setParameter("moduleId", moduleId); List<InfraCheckResult> list = query.getResultList(); return list;/*from ww w.j a va 2 s. com*/ }
From source file:com.clustercontrol.infra.util.QueryUtil.java
public static List<InfraCheckResult> getInfraCheckResultFindByManagementId(String managementId) { HinemosEntityManager em = new JpaTransactionManager().getEntityManager(); TypedQuery<InfraCheckResult> query = em.createNamedQuery("InfraCheckResultEntity.findByManagementId", InfraCheckResult.class); query.setParameter("managementId", managementId); List<InfraCheckResult> list = query.getResultList(); return list;//from w ww. j a v a 2 s .c om }