|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.rhq.core.server.PersistenceUtility
public class PersistenceUtility
Various persistence utility methods - mostly Hibernate-specific.
Field Summary | |
---|---|
static String |
HIBERNATE_STATISTICS_MBEAN_OBJECTNAME
|
Constructor Summary | |
---|---|
PersistenceUtility()
|
Method Summary | ||
---|---|---|
static String |
addH2NativePagingSortingToQuery(String query,
PageControl pageControl)
|
|
static String |
addOracleNativePagingSortingToQuery(String query,
PageControl pageControl)
|
|
static String |
addPostgresNativePagingSortingToQuery(String query,
PageControl pageControl)
|
|
static String |
addSQLServerNativePagingSortingToQuery(String query,
PageControl pageControl)
Note: always put the rownum column at the END of the columns, so that code which relies on index-based access to the result set data doesn't break Method 1: SELECT outerResults.* FROM ( SELECT innerResults.*, ROW_NUMBER() OVER( {orderByClause} ) AS rownum FROM ( {queryWithoutOrderBy} ) AS innerResults ) AS outerResults WHERE rownum <= maxRowNum AND rownum >= minRowNum The above method fails in circumstances where the orderByClause is built up with aliases that aren't in the explicit select list returned from queryWithoutOrderBy Method 2: Fix above shortcomings by pushing the orderByClause into the actual select list SELECT singleResults.* FROM ( {queryWithoutOrderBySelectList} , ROW_NUMBER() OVER( {orderByClause} ) AS rownum {queryWithoutOrderByRestOfQuery} ) AS singleResults WHERE rownum <= maxRowNum AND rownum >= minRowNum Actually, both of the above methods have small flaws. |
|
static String |
addSQLServerNativePagingSortingToQuery(String query,
PageControl pageControl,
boolean alternatePagingStyle)
|
|
static Object |
cast(String value,
org.hibernate.type.Type hibernateType)
|
|
static Query |
createCountQuery(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 Query |
createCountQuery(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(EntityManager entityManager,
Collection collection,
PageControl pageControl)
Creates and executes a filter query for a collection relationship. |
|
static Query |
createQueryWithOrderBy(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 Query |
createQueryWithOrderBy(EntityManager entityManager,
String queryName,
PageControl pageControl)
Used to create queries to use with the PageControl objects. |
|
static void |
enableHibernateStatistics(EntityManager entityManager,
MBeanServer server)
Enables the hibernate statistics mbean to provide access to information on the ejb3 persistence tier. |
|
static
|
findByCriteria(EntityManager entityManager,
Class<T> type,
org.hibernate.criterion.Criterion... criterion)
Use this inside subclasses as a convenience method. |
|
static String |
getDisplayString(org.hibernate.type.Type hibernateType)
|
|
static org.hibernate.Session |
getHibernateSession(EntityManager entityManager)
|
|
static org.hibernate.stat.Statistics |
getStatisticsService(EntityManager entityManager,
MBeanServer server)
|
|
static void |
setDataPage(Query query,
PageControl pageControl)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String HIBERNATE_STATISTICS_MBEAN_OBJECTNAME
Constructor Detail |
---|
public PersistenceUtility()
Method Detail |
---|
public static String getDisplayString(org.hibernate.type.Type hibernateType)
public static Object cast(String value, org.hibernate.type.Type hibernateType)
public static Query createQueryWithOrderBy(EntityManager entityManager, String queryName, PageControl pageControl)
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.
entityManager
- your entity managerqueryName
- name of the querypageControl
- the controls on the paging and sorting
public static Query createQueryWithOrderBy(EntityManager entityManager, String queryName, OrderingField... orderByFields)
entityManager
- the entity manager to build the query againstqueryName
- the name of the query to transformorderByFields
- an array of clauses to contribute to the order by
public static Query createCountQuery(EntityManager em, String queryName)
em
- the entity manager to build the query forqueryName
- the NamedQuery to transform
public static Query createCountQuery(EntityManager entityManager, String queryName, String countItem)
entityManager
- the entity manager to build the query forqueryName
- the NamedQuery to transformcountItem
- the object or attribute that needs to be counted, when it's ambiguous
public static void setDataPage(Query query, PageControl pageControl)
public static PageList createPaginationFilter(EntityManager entityManager, Collection collection, PageControl pageControl)
entityManager
- collection
- pageControl
-
public static <T> List<T> findByCriteria(EntityManager entityManager, Class<T> type, org.hibernate.criterion.Criterion... criterion)
public static org.hibernate.Session getHibernateSession(EntityManager entityManager)
public static void enableHibernateStatistics(EntityManager entityManager, MBeanServer server)
entityManager
- an inject entity manager whose session factory will be tracked with these statisticsserver
- the MBeanServer where the statistics MBean should be registered; if null
, the
first one in the list returned by MBeanServerFactory.findMBeanServer(null) is usedpublic static org.hibernate.stat.Statistics getStatisticsService(EntityManager entityManager, MBeanServer server)
public static String addPostgresNativePagingSortingToQuery(String query, PageControl pageControl)
public static String addOracleNativePagingSortingToQuery(String query, PageControl pageControl)
public static String addSQLServerNativePagingSortingToQuery(String query, PageControl pageControl)
public static String addSQLServerNativePagingSortingToQuery(String query, PageControl pageControl, boolean alternatePagingStyle)
public static String addH2NativePagingSortingToQuery(String query, PageControl pageControl)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |