org.rhq.enterprise.server.util
Class CriteriaQueryGenerator

java.lang.Object
  extended by org.rhq.enterprise.server.util.CriteriaQueryGenerator

public final class CriteriaQueryGenerator
extends Object

A query generator used to generate queries with specific filtering, prefetching, or sorting requirements.

Author:
Joseph Marques

Nested Class Summary
static class CriteriaQueryGenerator.AuthorizationTokenType
           
 
Constructor Summary
CriteriaQueryGenerator(org.rhq.core.domain.criteria.Criteria criteria)
           
CriteriaQueryGenerator(org.rhq.core.domain.auth.Subject subject, org.rhq.core.domain.criteria.Criteria criteria)
           
 
Method Summary
 void alterProjection(String projection)
          If you want to return something other than the list of entities represented by the passed Criteria object, you can alter the projection here to return a customized subset or superset of data.
static String getCleansedFieldName(Field field, int leadingCharsToStrip)
           
 javax.persistence.Query getCountQuery(javax.persistence.EntityManager em)
           
 List<String> getFetchFields(org.rhq.core.domain.criteria.Criteria criteria)
           
 Map<String,Object> getFilterFields(org.rhq.core.domain.criteria.Criteria criteria)
           
 List<Field> getJoinFetchFields()
           
static org.rhq.core.domain.util.PageControl getPageControl(org.rhq.core.domain.criteria.Criteria criteria)
           
 String getParameterReplacedQuery(boolean countQuery)
           
 List<Field> getPersistentBagFields()
          Note: This method should only be called after getQueryString(boolean)} because it is that method where the persistentBagFields property is initialized.
 javax.persistence.Query getQuery(javax.persistence.EntityManager em)
           
 String getQueryString(boolean countQuery)
           
 boolean isProjectionAltered()
           
static void main(String[] args)
           
 void setAuthorizationCustomConditionFragment(String fragment)
           
 void setAuthorizationResourceFragment(CriteriaQueryGenerator.AuthorizationTokenType type, int subjectId)
           
 void setAuthorizationResourceFragment(CriteriaQueryGenerator.AuthorizationTokenType type, String fragment, int subjectId)
           
 void setGroupByClause(String groupByClause)
          The groupBy clause can be set if and only if the projection is altered.
 void setHavingClause(String havingClause)
          The having clause can be set if and only if the groupBy clause is set.
static void testAlertCriteria()
           
static void testInheritanceCriteria()
           
static void testResourceCriteria()
           
static void testResourceGroupCriteria()
           
static void testSubjectCriteria()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CriteriaQueryGenerator

public CriteriaQueryGenerator(org.rhq.core.domain.criteria.Criteria criteria)

CriteriaQueryGenerator

public CriteriaQueryGenerator(org.rhq.core.domain.auth.Subject subject,
                              org.rhq.core.domain.criteria.Criteria criteria)
Method Detail

setAuthorizationCustomConditionFragment

public void setAuthorizationCustomConditionFragment(String fragment)

setAuthorizationResourceFragment

public void setAuthorizationResourceFragment(CriteriaQueryGenerator.AuthorizationTokenType type,
                                             int subjectId)

setAuthorizationResourceFragment

public void setAuthorizationResourceFragment(CriteriaQueryGenerator.AuthorizationTokenType type,
                                             String fragment,
                                             int subjectId)

getParameterReplacedQuery

public String getParameterReplacedQuery(boolean countQuery)

getQueryString

public String getQueryString(boolean countQuery)

getFetchFields

public List<String> getFetchFields(org.rhq.core.domain.criteria.Criteria criteria)

getCleansedFieldName

public static String getCleansedFieldName(Field field,
                                          int leadingCharsToStrip)

getFilterFields

public Map<String,Object> getFilterFields(org.rhq.core.domain.criteria.Criteria criteria)

getPersistentBagFields

public List<Field> getPersistentBagFields()
Note: This method should only be called after getQueryString(boolean)} because it is that method where the persistentBagFields property is initialized.

Returns:
Returns a list of fields from the persistent class to which the criteria class corresponds. The fields in the list are themselves instances of List and have "bag" semantics.

getJoinFetchFields

public List<Field> getJoinFetchFields()

alterProjection

public void alterProjection(String projection)
If you want to return something other than the list of entities represented by the passed Criteria object, you can alter the projection here to return a customized subset or superset of data. The projection will only affect the ResultSet for the data query, not the count query.

If you are projecting a composite object that does not directly extend the entity your Criteria object represents, then you will need to manually initialize the persistent bags using the methods exposed on CriteriaQueryRunner


isProjectionAltered

public boolean isProjectionAltered()

setGroupByClause

public void setGroupByClause(String groupByClause)
The groupBy clause can be set if and only if the projection is altered. The passed argument should not be prefixed with 'group by'; that part of the query will be auto-generated if the argument is non-null. The new projection must follow standard rules as they apply to statements with groupBy clauses.


setHavingClause

public void setHavingClause(String havingClause)
The having clause can be set if and only if the groupBy clause is set. The passed argument should not be prefixed with 'having'; that part of the query will be auto-generated if the argument is non-null. The having clause must follow standard rules as they apply to statements with groupBy clauses.


getQuery

public javax.persistence.Query getQuery(javax.persistence.EntityManager em)

getCountQuery

public javax.persistence.Query getCountQuery(javax.persistence.EntityManager em)

main

public static void main(String[] args)

testSubjectCriteria

public static void testSubjectCriteria()

testAlertCriteria

public static void testAlertCriteria()

testInheritanceCriteria

public static void testInheritanceCriteria()

testResourceGroupCriteria

public static void testResourceGroupCriteria()

testResourceCriteria

public static void testResourceCriteria()

getPageControl

public static org.rhq.core.domain.util.PageControl getPageControl(org.rhq.core.domain.criteria.Criteria criteria)


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.