org.broadleafcommerce.common.util.dao
Class TypedQueryBuilder<T>

java.lang.Object
  extended by org.broadleafcommerce.common.util.dao.TypedQueryBuilder<T>
Type Parameters:
T - the class that is being queried for

public class TypedQueryBuilder<T>
extends Object

Utility class to construct typed query-language queries. This has an advantage over CriteriaQuery in that it will be automatically responsive to polymorphism thanks to Hibernate's handling of query-language strings.

Author:
Andre Azzolini (apazzolini)

Field Summary
protected  Map<String,Object> paramMap
           
protected  List<TQRestriction> restrictions
           
protected  String rootAlias
           
protected  Class<T> rootClass
           
 
Constructor Summary
TypedQueryBuilder(Class<T> rootClass, String rootAlias)
          Creates a new TypedQueryBuilder that will utilize the rootAlias as the named object of the class
 
Method Summary
 TypedQueryBuilder<T> addRestriction(String expression, String operation, Object parameter)
          Adds a simple restriction to the query.
 TypedQueryBuilder<T> addRestriction(TQRestriction restriction)
          Adds an explicit TQRestriction object.
 Map<String,Object> getParamMap()
           
 javax.persistence.TypedQuery<T> toQuery(javax.persistence.EntityManager em)
          Returns a TypedQuery that represents this builder object.
 String toQueryString()
          Generates the query string based on the current contents of this builder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rootClass

protected Class<T> rootClass

rootAlias

protected String rootAlias

restrictions

protected List<TQRestriction> restrictions

paramMap

protected Map<String,Object> paramMap
Constructor Detail

TypedQueryBuilder

public TypedQueryBuilder(Class<T> rootClass,
                         String rootAlias)
Creates a new TypedQueryBuilder that will utilize the rootAlias as the named object of the class

Parameters:
rootClass -
rootAlias -
Method Detail

addRestriction

public TypedQueryBuilder<T> addRestriction(String expression,
                                           String operation,
                                           Object parameter)
Adds a simple restriction to the query. Note that all restrictions present on the TypedQueryBuilder will be joined with an AND clause.

Parameters:
expression -
operation -
parameter -

addRestriction

public TypedQueryBuilder<T> addRestriction(TQRestriction restriction)
Adds an explicit TQRestriction object. Note that all restrictions present on the TypedQueryBuilder will be joined with an AND clause.

Parameters:
restriction -
Returns:

toQueryString

public String toQueryString()
Generates the query string based on the current contents of this builder. As the string is generated, this method will also populate the paramMap, which binds actual restriction values. Note that this method should typically not be invoked through DAOs. Instead, utilize toQuery(EntityManager), which will automatically generate the TypedQuery and populate the required parameters.

Returns:
the QL string

toQuery

public javax.persistence.TypedQuery<T> toQuery(javax.persistence.EntityManager em)
Returns a TypedQuery that represents this builder object. It will already have all of the appropriate parameter values set and is able to be immediately queried against.

Parameters:
em -
Returns:
the TypedQuery

getParamMap

public Map<String,Object> getParamMap()
Returns:
the paramMap


Copyright © 2013. All Rights Reserved.