Search in sources :

Example 6 with TypedQuery

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);
    });
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) Person(org.hibernate.userguide.model.Person) Test(org.junit.Test)

Example 7 with TypedQuery

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);
    });
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) Person(org.hibernate.userguide.model.Person) Test(org.junit.Test)

Example 8 with TypedQuery

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);
}
Also used : EntityManager(javax.persistence.EntityManager) OpenEntityManager(org.apereo.portal.jpa.OpenEntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) DateTime(org.joda.time.DateTime)

Aggregations

TypedQuery (javax.persistence.TypedQuery)8 EntityManager (javax.persistence.EntityManager)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4 Test (org.junit.Test)4 Query (javax.persistence.Query)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 Predicate (javax.persistence.criteria.Predicate)3 List (java.util.List)2 Map (java.util.Map)2 Person (org.hibernate.userguide.model.Person)2 DataSourceContext (com.robo4j.db.sql.support.DataSourceContext)1 SortType (com.robo4j.db.sql.support.SortType)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Collectors (java.util.stream.Collectors)1 From (javax.persistence.criteria.From)1 Order (javax.persistence.criteria.Order)1 ParameterExpression (javax.persistence.criteria.ParameterExpression)1 Path (javax.persistence.criteria.Path)1 Root (javax.persistence.criteria.Root)1