org.rhq.core.domain.util
Class PersistenceUtility

java.lang.Object
  extended by org.rhq.core.domain.util.PersistenceUtility

public class PersistenceUtility
extends Object

Various persistence utility methods - mostly Hibernate-specific.


Field Summary
static String HIBERNATE_STATISTICS_MBEAN_OBJECTNAME
           
 
Constructor Summary
PersistenceUtility()
           
 
Method Summary
static javax.persistence.Query createCountQuery(javax.persistence.EntityManager em, String queryName)
          Builds a count(*) version of the named query so we don't have duplicate all our queries to use two query pagination model.
static javax.persistence.Query createCountQuery(javax.persistence.EntityManager entityManager, String queryName, String countItem)
          Builds a count(*) version of the named query so we don't have duplicate all our queries to use two query pagination model.
static PageList createPaginationFilter(javax.persistence.EntityManager entityManager, Collection collection, PageControl pageControl)
          Creates and executes a filter query for a collection relationship.
static javax.persistence.Query createQueryWithOrderBy(javax.persistence.EntityManager entityManager, String queryName, OrderingField... orderByFields)
          Create a query from a named query with a transformed order by clause with multiple new ordery by clauses.
static javax.persistence.Query createQueryWithOrderBy(javax.persistence.EntityManager entityManager, String queryName, PageControl pageControl)
          Used to create queries to use with the PageControl objects.
static void enableHibernateStatistics(javax.persistence.EntityManager entityManager, MBeanServer server)
          Enables the hibernate statistics mbean to provide access to information on the ejb3 persistence tier.
static
<T> List<T>
findByCriteria(javax.persistence.EntityManager entityManager, Class<T> type, org.hibernate.criterion.Criterion... criterion)
          Use this inside subclasses as a convenience method.
static String formatSearchParameter(String value)
           
static org.hibernate.Session getHibernateSession(javax.persistence.EntityManager entityManager)
           
static void setDataPage(javax.persistence.Query query, PageControl pageControl)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HIBERNATE_STATISTICS_MBEAN_OBJECTNAME

public static final String HIBERNATE_STATISTICS_MBEAN_OBJECTNAME
See Also:
Constant Field Values
Constructor Detail

PersistenceUtility

public PersistenceUtility()
Method Detail

createQueryWithOrderBy

public static javax.persistence.Query createQueryWithOrderBy(javax.persistence.EntityManager entityManager,
                                                             String queryName,
                                                             PageControl pageControl)
Used to create queries to use with the PageControl objects. The query will already have its sort column and order appended as well as having its first result and max results set according to the page control data.

Parameters:
entityManager - your entity manager
queryName - name of the query
pageControl - the controls on the paging and sorting
Returns:
a preconfigured query for ordered pagination

createQueryWithOrderBy

public static javax.persistence.Query createQueryWithOrderBy(javax.persistence.EntityManager entityManager,
                                                             String queryName,
                                                             OrderingField... orderByFields)
Create a query from a named query with a transformed order by clause with multiple new ordery by clauses.

Parameters:
entityManager - the entity manager to build the query against
queryName - the name of the query to transform
orderByFields - an array of clauses to contribute to the order by
Returns:
the transformed query

createCountQuery

public static javax.persistence.Query createCountQuery(javax.persistence.EntityManager em,
                                                       String queryName)
Builds a count(*) version of the named query so we don't have duplicate all our queries to use two query pagination model.

Parameters:
em - the entity manager to build the query for
queryName - the NamedQuery to transform
Returns:
a query that can be bound and executed to get the total count of results

createCountQuery

public static javax.persistence.Query createCountQuery(javax.persistence.EntityManager entityManager,
                                                       String queryName,
                                                       String countItem)
Builds a count(*) version of the named query so we don't have duplicate all our queries to use two query pagination model.

Parameters:
entityManager - the entity manager to build the query for
queryName - the NamedQuery to transform
countItem - the object or attribute that needs to be counted, when it's ambiguous
Returns:
a query that can be bound and executed to get the total count of results

setDataPage

public static void setDataPage(javax.persistence.Query query,
                               PageControl pageControl)

formatSearchParameter

public static String formatSearchParameter(String value)

createPaginationFilter

public static PageList createPaginationFilter(javax.persistence.EntityManager entityManager,
                                              Collection collection,
                                              PageControl pageControl)
Creates and executes a filter query for a collection relationship. This executes without passing back the query object because the most common case is to simply paginate for a relationship. Use the createFilter method to create more generic filters and get access to the hibernate query object for setting parameters etc.

Parameters:
entityManager -
collection -
pageControl -
Returns:
the result list of the entities from the filtered relationship

findByCriteria

public static <T> List<T> findByCriteria(javax.persistence.EntityManager entityManager,
                                         Class<T> type,
                                         org.hibernate.criterion.Criterion... criterion)
Use this inside subclasses as a convenience method.


getHibernateSession

public static org.hibernate.Session getHibernateSession(javax.persistence.EntityManager entityManager)

enableHibernateStatistics

public static void enableHibernateStatistics(javax.persistence.EntityManager entityManager,
                                             MBeanServer server)
Enables the hibernate statistics mbean to provide access to information on the ejb3 persistence tier.

Parameters:
entityManager - an inject entity manager whose session factory will be tracked with these statistics
server - the MBeanServer where the statistics MBean should be registered; if null, the first one in the list returned by MBeanServerFactory.findMBeanServer(null) is used


Copyright © 2008 RHQ Project Advisory Board (Red Hat, Inc. and Hyperic, Inc.). All Rights Reserved.