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 -> {
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);
});
}
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 -> {
Query query = entityManager.createNamedQuery("get_person_by_name");
TypedQuery<Person> typedQuery = entityManager.createNamedQuery("get_person_by_name", Person.class);
});
}
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);
}
Aggregations