use of javax.persistence.TypedQuery in project uPortal by Jasig.
the class JpaPortletCookieDaoImpl method purgeExpiredCookies.
@Override
@PortalTransactional
public void purgeExpiredCookies(int maxAge) {
final DateTime now = DateTime.now();
logger.debug("begin portlet cookie expiration");
final EntityManager entityManager = this.getEntityManager();
final Query deletePortletCookieQuery = entityManager.createQuery(this.deletePortletCookieQueryString);
deletePortletCookieQuery.setParameter(this.nowParameter.getName(), now);
final int deletedPortletCookies = deletePortletCookieQuery.executeUpdate();
logger.debug("finished purging {} portlet cookies with expiration before {}", deletedPortletCookies, now);
final TypedQuery<PortletCookieImpl> expiredByParentCookiesQuery = this.createQuery(findExpiredByParentPortletCookiesQuery);
expiredByParentCookiesQuery.setParameter(this.nowParameter.getName(), now);
final List<PortletCookieImpl> indirectlyExpiredCookies = expiredByParentCookiesQuery.getResultList();
for (final PortletCookieImpl portletCookieImpl : indirectlyExpiredCookies) {
entityManager.remove(portletCookieImpl);
}
logger.debug("finished purging {} portlet cookies with parent expiration before {}", indirectlyExpiredCookies.size(), now);
logger.debug("begin portal cookie expiration");
final Query deletePortalCookieQuery = entityManager.createQuery(this.deletePortalCookieQueryString);
deletePortalCookieQuery.setParameter(this.nowParameter.getName(), now);
final int deletedPortalCookies = deletePortalCookieQuery.executeUpdate();
logger.debug("finished purging {} portal cookies with expiration before {}", deletedPortalCookies, now);
final Query deleteEmptyPortalCookieQuery = entityManager.createQuery(this.deleteEmptyPortalCookieQueryString);
// Add the maxAge to now and then subtract the emptyCookieMaxAge
// For example (now + 1 year) - 1 day == the empty-cookie expiration date
final DateTime emptyExpiration = now.plusSeconds(maxAge).minusSeconds(emptyCookieMaxAge);
deleteEmptyPortalCookieQuery.setParameter(this.nowParameter.getName(), emptyExpiration);
final int deletedEmptyPortalCookies = deleteEmptyPortalCookieQuery.executeUpdate();
logger.debug("finished purging {} empty portal cookies with expiration before {}", deletedEmptyPortalCookies, emptyExpiration);
}
use of javax.persistence.TypedQuery in project jgnash by ccavanaugh.
the class AbstractJpaDAO method query.
/**
* Returns a list of objects that are assignable from from the specified Class.
* <p>
* Objects marked for removal are not included
*
* @param clazz the Class to query for
* @param <T> the type of class to query
* @return A list of type T containing objects of type clazz
*/
@NotNull
public <T extends StoredObject> List<T> query(final Class<T> clazz) {
try {
final Future<List<T>> future = executorService.submit(() -> {
emLock.lock();
try {
final CriteriaBuilder cb = em.getCriteriaBuilder();
final CriteriaQuery<T> cq = cb.createQuery(clazz);
cq.from(clazz);
final TypedQuery<T> query = em.createQuery(cq);
// ensures a ConcurrentModificationException is not thrown in rare circumstances by iterating.
return query.getResultStream().filter(t -> !t.isMarkedForRemoval()).collect(Collectors.toList());
} catch (final ConcurrentModificationException | PersistenceException | IllegalStateException e1) {
logSevere(AbstractJpaDAO.class, e1);
return null;
} finally {
emLock.unlock();
}
});
// block and return
return future.get();
} catch (final InterruptedException | ExecutionException e) {
logSevere(AbstractJpaDAO.class, e);
Thread.currentThread().interrupt();
return null;
}
}
use of javax.persistence.TypedQuery in project hibernate-orm by hibernate.
the class HQLTest method test_jpql_api_example.
@Test
public void test_jpql_api_example() {
doInJPA(this::entityManagerFactory, entityManager -> {
// tag::jpql-api-example[]
Query query = entityManager.createQuery("select p " + "from Person p " + "where p.name like :name");
TypedQuery<Person> typedQuery = entityManager.createQuery("select p " + "from Person p " + "where p.name like :name", Person.class);
// end::jpql-api-example[]
});
}
use of javax.persistence.TypedQuery in project hibernate-orm by hibernate.
the class HQLTest method test_jpql_api_named_query_example.
@Test
public void test_jpql_api_named_query_example() {
doInJPA(this::entityManagerFactory, entityManager -> {
// tag::jpql-api-named-query-example[]
Query query = entityManager.createNamedQuery("get_person_by_name");
TypedQuery<Person> typedQuery = entityManager.createNamedQuery("get_person_by_name", Person.class);
// end::jpql-api-named-query-example[]
});
}
use of javax.persistence.TypedQuery in project mycore by MyCoRe-Org.
the class MCRMigrationCommands method fixMCR1717.
@MCRCommand(syntax = "fix MCR-1717", help = "Fixes wrong entries in tile job table (see MCR-1717 comments)")
public static void fixMCR1717() {
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
TypedQuery<MCRTileJob> allTileJobQuery = em.createNamedQuery("MCRTileJob.all", MCRTileJob.class);
List<MCRTileJob> tiles = allTileJobQuery.getResultList();
tiles.stream().filter(tj -> !tj.getPath().startsWith("/")).peek(tj -> LOGGER.info("Fixing TileJob {}:{}", tj.getDerivate(), tj.getPath())).forEach(tj -> {
String newPath = "/" + tj.getPath();
tj.setPath(newPath);
});
}
Aggregations