List of usage examples for javax.persistence EntityManager createNamedQuery
public Query createNamedQuery(String name);
Query
for executing a named query (in the Java Persistence query language or in native SQL). From source file:com.impetus.kvapps.runner.ExecutorService.java
private static List<User> findByEmail(final EntityManager em, String query, String parameter) { Query q = em.createNamedQuery(query); q.setParameter(1, parameter);// w w w . j av a2s.c o m List<User> users = q.getResultList(); return users; }
From source file:com.impetus.kvapps.runner.ExecutorService.java
/** * on find by wild search query.//from w ww. j av a 2s . c om * * @param em entity manager instance. * @param query query. */ @SuppressWarnings("unchecked") static void findByQuery(final EntityManager em, final String query) { Query q = em.createNamedQuery(query); logger.info("[On Find All by Query]"); List<User> users = q.getResultList(); if (users == null || users.isEmpty()) { logger.info("0 Users Returned"); return; } System.out.println("#######################START##########################################"); logger.info("\t\t Total number of users:" + users.size()); logger.info("\t\t User's total tweets:" + users.get(0).getTweets().size()); printTweets(users); logger.info("\n"); // logger.info("First tweet:" users.get(0).getTweets().); System.out.println("#######################END############################################"); logger.info("\n"); }
From source file:com.hmsinc.epicenter.model.util.ModelUtils.java
/** * Creates a cacheable named query./*from w ww . java 2 s. co m*/ * * @param entityManager * @param namedQuery * @return */ public static Query namedQuery(final EntityManager entityManager, final String namedQuery) { return entityManager.createNamedQuery(namedQuery).setHint("org.hibernate.cacheable", Boolean.TRUE); }
From source file:org.cesecore.audit.impl.queued.entity.LogManagementData.java
public static LogManagementData getCurrentConfiguration(final EntityManager em) { final Query query = em.createNamedQuery("LogManagementData.CURRENT").setHint("org.hibernate.cacheable", true);//from ww w . jav a2 s . c o m return QueryResultWrapper.getSingleResult(query); }
From source file:com.autentia.common.util.ejb.EntityManagerUtils.java
/** * Devuelve una lista de entidades de tipo <code>T</code>, obtenida como resultado de ejectua una * <code>NamedQuery</code>, y haciendo la susticucin de parmetros (la sustitucin de parmetros ser posicional). * //from w w w . ja va 2s. co m * @param <T> tipo de los objetos devueltos por la bsqueda. * @param em el {@link EntityManager} donde se va a ejecutar la consulta. * @param namedQuery nombre de la <code>NamedQuery</code> que se quiere ejecutar. * @param queryParams parmetros de la consulta, la <code>NamedQuery</code> tendr ?1, ?2, ?3, ... * @return lista de entidades de tipo <code>T</code>. */ public static <T> List<T> find(EntityManager em, String namedQuery, Object... queryParams) { if (log.isDebugEnabled()) { log.debug("Executing named query: " + namedQuery + ", with parameters: " + queryParams); } final Query query = em.createNamedQuery(namedQuery); return find(query, queryParams); }
From source file:au.org.ands.vocabs.toolkit.db.AccessPointUtils.java
/** Delete all access points of a certain type for a version. * @param version The version./*from ww w .j ava2 s . c om*/ * @param type The type of access point to look for. */ public static void deleteAccessPointsForVersionAndType(final Version version, final String type) { EntityManager em = DBContext.getEntityManager(); em.getTransaction().begin(); Query q = em.createNamedQuery(AccessPoint.DELETE_ACCESSPOINTS_FOR_VERSION_AND_TYPE) .setParameter(AccessPoint.DELETE_ACCESSPOINTS_FOR_VERSION_AND_TYPE_VERSIONID, version.getId()) .setParameter(AccessPoint.DELETE_ACCESSPOINTS_FOR_VERSION_AND_TYPE_TYPE, type); q.executeUpdate(); em.getTransaction().commit(); em.close(); }
From source file:org.opencastproject.messages.MailService.java
public static Option<MessageTemplateDto> findMessageTemplateById(long id, String orgId, EntityManager em) { Query q = em.createNamedQuery("MessageTemplate.findById").setParameter("id", id).setParameter("org", orgId); try {/*from ww w. j a va 2s .com*/ return some((MessageTemplateDto) q.getSingleResult()); } catch (NoResultException e) { return none(); } }
From source file:org.opencastproject.messages.MailService.java
public static Option<EmailConfigurationDto> findEmailConfiguration(String organization, EntityManager em) { Query q = em.createNamedQuery("EmailConfiguration.findAll").setParameter("org", organization) .setMaxResults(1);//from w w w.j a v a 2 s .c o m try { return some((EmailConfigurationDto) q.getSingleResult()); } catch (NoResultException e) { return none(); } }
From source file:org.opencastproject.messages.MailService.java
public static Option<MessageSignatureDto> findMessageSignatureById(long id, String orgId, EntityManager em) { Query q = em.createNamedQuery("MessageSignature.findById").setParameter("id", id).setParameter("org", orgId);/*from w ww . jav a2 s . c om*/ try { return some((MessageSignatureDto) q.getSingleResult()); } catch (NoResultException e) { return none(); } }
From source file:org.yestech.lib.jpa.YesJpaTemplate.java
public int bulkUpdateNamedQuery(final String queryName, final Object... values) throws DataAccessException { return (Integer) execute(new JpaCallback() { @Override//from w w w . j a v a2 s . c om public Object doInJpa(EntityManager em) throws PersistenceException { Query queryObject = em.createNamedQuery(queryName); if (values != null) { for (int i = 0; i < values.length; i++) { queryObject.setParameter(i, values[i]); } } return queryObject.executeUpdate(); } }); }