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.saax.gestorweb.util.DAOAleatorio.java
public static CentroCusto getCentroCustoAleatorio(EntityManager em) { List<CentroCusto> centroCustos = em.createNamedQuery("CentroCusto.findAll").getResultList(); return centroCustos.get(new Random().nextInt(centroCustos.size() - 1)); }
From source file:com.saax.gestorweb.util.DAOAleatorio.java
public static Departamento getDepartamentoAleatorio(EntityManager em, Empresa e) { List<Departamento> departamentos = em.createNamedQuery("Departamento.findByEmpresa") .setParameter("empresa", e).getResultList(); return departamentos.get(new Random().nextInt(departamentos.size() - 1)); }
From source file:com.saax.gestorweb.util.DAOAleatorio.java
public static EmpresaCliente getEmpresaClienteAleatoria(EntityManager em, Empresa e) { List<EmpresaCliente> empresaClientes = em.createNamedQuery("EmpresaCliente.findByEmpresa") .setParameter("empresa", e).getResultList(); return empresaClientes.get(new Random().nextInt(empresaClientes.size() - 1)); }
From source file:ch.entwine.weblounge.bridge.oaipmh.harvester.LastHarvested.java
public static Option<Date> getLastHarvestDate(PersistenceEnv penv, final String url) { return penv.tx(new Function<EntityManager, Option<Date>>() { public Option<Date> apply(EntityManager em) { Query q = em.createNamedQuery("findLastHarvested"); q.setParameter("url", url); try { return some((Date) q.getSingleResult()); } catch (NoResultException e) { return none(); }/*from www . j a v a 2s.c o m*/ } }); }
From source file:org.opencastproject.oaipmh.harvester.LastHarvested.java
public static Option<Date> getLastHarvestDate(PersistenceEnv penv, final String url) { return penv.tx(new Function<EntityManager, Option<Date>>() { @Override/* w w w.j a v a 2 s . c o m*/ public Option<Date> apply(EntityManager em) { Query q = em.createNamedQuery("findLastHarvested"); q.setParameter("url", url); try { return some((Date) q.getSingleResult()); } catch (NoResultException e) { return none(); } } }); }
From source file:be.fedict.eid.idp.entity.AttributeEntity.java
@SuppressWarnings("unchecked") public static List<AttributeEntity> listAttributes(EntityManager entityManager) { Query query = entityManager.createNamedQuery(LIST_ALL); return query.getResultList(); }
From source file:ch.entwine.weblounge.bridge.oaipmh.harvester.LastHarvested.java
/** * Remove all URLs from the table that do not exist in <code>keepUrls</code>. *//*from w w w . j a v a2s . co m*/ public static void cleanup(PersistenceEnv penv, final String[] keepUrls) { penv.tx(new Function<EntityManager, Void>() { public Void apply(EntityManager em) { List<LastHarvested> lhs = em.createNamedQuery("findAll").getResultList(); for (LastHarvested lh : lhs) { if (!ArrayUtils.contains(keepUrls, lh.getUrl())) { em.remove(lh); } } return null; } }); }
From source file:org.opencastproject.oaipmh.harvester.LastHarvested.java
/** * Remove all URLs from the table that do not exist in <code>keepUrls</code>. *//*from w w w .j a v a2s.c o m*/ public static void cleanup(PersistenceEnv penv, final String[] keepUrls) { penv.tx(new Function<EntityManager, Void>() { @Override public Void apply(EntityManager em) { List<LastHarvested> lhs = em.createNamedQuery("findAll").getResultList(); for (LastHarvested lh : lhs) { if (!ArrayUtils.contains(keepUrls, lh.getUrl())) { em.remove(lh); } } return null; } }); }
From source file:be.fedict.eid.idp.entity.AttributeProtocolUriEntity.java
@SuppressWarnings("unchecked") public static List<AttributeProtocolUriEntity> listAll(EntityManager entityManager) { Query query = entityManager.createNamedQuery(LIST_ALL); return query.getResultList(); }
From source file:be.fedict.eid.idp.entity.AttributeProtocolUriEntity.java
public static AttributeProtocolUriEntity findAttribute(EntityManager entityManager, String uri, String protocolId) {/* w ww . ja v a 2s . c o m*/ Query query = entityManager.createNamedQuery(FIND_ATTRIBUTE); query.setParameter("uri", uri); query.setParameter("protocolId", protocolId); try { return (AttributeProtocolUriEntity) query.getSingleResult(); } catch (NoResultException e) { return null; } }