List of usage examples for javax.persistence EntityManager createQuery
public <T> TypedQuery<T> createQuery(String qlString, Class<T> resultClass);
TypedQuery
for executing a Java Persistence query language statement. From source file:com.enioka.jqm.test.helpers.TestHelpers.java
public static int getOkCount(EntityManager em) { TypedQuery<Long> q = em.createQuery("SELECT COUNT(h) FROM History h WHERE h.status = 'ENDED'", Long.class); return q.getSingleResult().intValue(); }
From source file:com.enioka.jqm.test.helpers.TestHelpers.java
public static int getNonOkCount(EntityManager em) { TypedQuery<Long> q = em.createQuery("SELECT COUNT(h) FROM History h WHERE h.status != 'ENDED'", Long.class); return q.getSingleResult().intValue(); }
From source file:com.enioka.jqm.test.helpers.TestHelpers.java
public static boolean testOkCount(long theoreticalOkCount, EntityManager em) { TypedQuery<Long> q = em.createQuery("SELECT COUNT(h) FROM History h WHERE h.status = 'ENDED'", Long.class); return q.getSingleResult() == theoreticalOkCount; }
From source file:com.enioka.jqm.test.helpers.TestHelpers.java
public static void waitFor(long nbHistories, int timeoutMs, EntityManager em) { TypedQuery<Long> q = em.createQuery("SELECT COUNT(h) FROM History h", Long.class); Calendar start = Calendar.getInstance(); while (q.getSingleResult() < nbHistories && Calendar.getInstance().getTimeInMillis() - start.getTimeInMillis() <= timeoutMs) { try {//from ww w . j av a 2 s . c o m Thread.sleep(100); } catch (InterruptedException e) { } } }
From source file:com.enioka.jqm.test.helpers.TestHelpers.java
public static void waitForRunning(long nbJobInstances, int timeoutMs, EntityManager em) { TypedQuery<Long> q = em.createQuery("SELECT COUNT(ji) FROM JobInstance ji WHERE ji.state = 'RUNNING'", Long.class); Calendar start = Calendar.getInstance(); while (q.getSingleResult() < nbJobInstances && Calendar.getInstance().getTimeInMillis() - start.getTimeInMillis() <= timeoutMs) { try {/*ww w. j ava 2s .c om*/ Thread.sleep(100); } catch (InterruptedException e) { } } }
From source file:com.enioka.jqm.test.helpers.TestHelpers.java
public static void printHistoryTable(EntityManager em) { List<History> res = em.createQuery("SELECT j FROM History j", History.class).getResultList(); SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss.SSS"); jqmlogger.debug(//from w w w. jav a 2s.c om "=========================================================================================="); for (History h : res) { jqmlogger.debug("JobInstance Id: " + h.getId() + " | " + h.getState() + " | JD: " + h.getJd().getId() + " | " + h.getQueue().getName() + " | enqueue: " + format.format(h.getEnqueueDate().getTime()) + " | attr: " + format.format(h.getAttributionDate().getTime()) + " | exec: " + format.format(h.getExecutionDate().getTime()) + " | end: " + format.format(h.getEndDate().getTime())); } jqmlogger.debug( "=========================================================================================="); }
From source file:io.coala.enterprise.persist.FactDao.java
public static FactDao find(final EntityManager em, final ID id) { final UUID uuid = Objects.requireNonNull(id.unwrap()); try {//from w ww .j a va 2 s . co m return em.createQuery("SELECT d FROM " + ENTITY_NAME + " d WHERE d.id=?1", FactDao.class) .setParameter(1, uuid).getSingleResult(); } catch (final NoResultException ignore) { return null; } }
From source file:io.coala.enterprise.persist.FactDao.java
public static boolean exists(final EntityManager em, final ID id) { final UUID uuid = Objects.requireNonNull(id.unwrap()); try {// w ww . j a v a 2 s .c o m // final Integer pk = em.createQuery("SELECT d.pk FROM " + ENTITY_NAME + " d WHERE d.id=?1", Integer.class) .setParameter(1, uuid).getSingleResult(); return true; } catch (final NoResultException ignore) { return false; } }
From source file:org.kew.rmf.matchconf.Configuration.java
public static List<Configuration> findAllDedupConfigs() { EntityManager em = Configuration.entityManager(); TypedQuery<Configuration> q = em.createQuery( "SELECT o FROM Configuration AS o WHERE o.authorityFileName = :authorityFileName", Configuration.class); q.setParameter("authorityFileName", ""); return q.getResultList(); }
From source file:org.kew.rmf.matchconf.Configuration.java
public static List<Configuration> findAllMatchConfigs() { EntityManager em = Configuration.entityManager(); TypedQuery<Configuration> q = em.createQuery( "SELECT o FROM Configuration AS o WHERE o.authorityFileName != :authorityFileName", Configuration.class); q.setParameter("authorityFileName", ""); return q.getResultList(); }