edu.internet2.middleware.grouper.hibernate
Class ByHql

java.lang.Object
  extended by edu.internet2.middleware.grouper.hibernate.ByHql
All Implemented Interfaces:
HqlQuery

public class ByHql
extends Object
implements HqlQuery

for simple HQL, use this instead of inverse of control. this will do proper error handling and descriptive exception handling. This will by default use the transaction modes GrouperTransactionType.READONLY_OR_USE_EXISTING, and GrouperTransactionType.READ_WRITE_OR_USE_EXISTING depending on if a transaction is needed.

Author:
mchyzer

Field Summary
static int queryCountQueries
          query count exec queries, used for testing
 
Constructor Summary
ByHql(HibernateSession theHibernateSession)
           
 
Method Summary
 ByHql createQuery(String theHqlQuery)
          set the query to run
 void executeUpdate()
           call hql executeUpdate, e.g.
 boolean isIgnoreHooks()
          if we should ignore hooks
<T> List<T>
list(Class<T> returnType)
           call hql list result e.g.
<K,V> Map<K,V>
listMap(Class<K> keyClass, Class<V> valueClass, String keyPropertyName)
           call hql list result, and put the results in map with the key as one of the fields
<S> Set<S>
listSet(Class<S> returnType)
           call hql list result, and put the results in an ordered set e.g.
static void main(String[] args)
           
 ByHql options(QueryOptions queryOptions1)
          add a paging/sorting/resultSetSize, etc to the query
 ByHql setCacheable(Boolean cacheable)
          assign if this query is cacheable or not.
 ByHql setCacheRegion(String cacheRegion)
          cache region for cache
 ByHql setCollectionInClause(StringBuilder query, Collection<?> params)
          append a certain number of params, and commas, and attach the data.
 void setConvertHqlColumnsToObject(boolean theConvertHqlColumnsToObject)
          if use resulttransformer to change columns to object
 ByHql setDouble(String bindVarName, Double value)
          assign data to the bind var
 ByHql setGrouperTransactionType(GrouperTransactionType theGrouperTransactionType)
          assign a different grouperTransactionType (e.g.
 edu.internet2.middleware.grouper.hibernate.ByQueryBase setIgnoreHooks(boolean theIgnoreHooks)
          if we should ignore hooks
 ByHql setInteger(String bindVarName, Integer value)
          assign data to the bind var
 ByHql setLong(String bindVarName, Long value)
          assign data to the bind var
 ByHql setScalar(String bindVarName, Object value)
          assign data to the bind var
 ByHql setString(String bindVarName, String value)
          assign data to the bind var
 ByHql setTimestamp(String bindVarName, Date value)
          assign data to the bind var
 String toString()
          string value for error handling
<T> T
uniqueResult(Class<T> returnType)
           call hql unique result (returns one or null) e.g.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

queryCountQueries

public static int queryCountQueries
query count exec queries, used for testing

Constructor Detail

ByHql

public ByHql(HibernateSession theHibernateSession)
Parameters:
theHibernateSession -
Method Detail

setConvertHqlColumnsToObject

public void setConvertHqlColumnsToObject(boolean theConvertHqlColumnsToObject)
if use resulttransformer to change columns to object

Parameters:
theConvertHqlColumnsToObject -

setTimestamp

public ByHql setTimestamp(String bindVarName,
                          Date value)
assign data to the bind var

Parameters:
bindVarName -
value -
Returns:
this object for chaining

setGrouperTransactionType

public ByHql setGrouperTransactionType(GrouperTransactionType theGrouperTransactionType)
assign a different grouperTransactionType (e.g. for autonomous transactions)

Parameters:
theGrouperTransactionType -
Returns:
the same object for chaining

setCacheable

public ByHql setCacheable(Boolean cacheable)
assign if this query is cacheable or not.

Parameters:
cacheable - the cacheable to set
Returns:
this object for chaining

toString

public String toString()
string value for error handling

Overrides:
toString in class Object
Returns:
the string value

createQuery

public ByHql createQuery(String theHqlQuery)
set the query to run

Parameters:
theHqlQuery -
Returns:
this object for chaining

setCacheRegion

public ByHql setCacheRegion(String cacheRegion)
cache region for cache

Parameters:
cacheRegion - the cacheRegion to set
Returns:
this object for chaining

setCollectionInClause

public ByHql setCollectionInClause(StringBuilder query,
                                   Collection<?> params)
append a certain number of params, and commas, and attach the data. Note any params before the in clause need to be already attached, since these will attach now (ordering issue)

Parameters:
query -
params - collection of params, note, this is for an inclause, so it cant be null
Returns:
this for chaining

setString

public ByHql setString(String bindVarName,
                       String value)
assign data to the bind var

Specified by:
setString in interface HqlQuery
Parameters:
bindVarName -
value -
Returns:
this object for chaining

setLong

public ByHql setLong(String bindVarName,
                     Long value)
assign data to the bind var

Parameters:
bindVarName -
value - is long, primitive so not null
Returns:
this object for chaining

setInteger

public ByHql setInteger(String bindVarName,
                        Integer value)
assign data to the bind var

Parameters:
bindVarName -
value - is long, primitive so not null
Returns:
this object for chaining

uniqueResult

public <T> T uniqueResult(Class<T> returnType)
               throws GrouperDAOException
 call hql unique result (returns one or null)
 
 e.g.
 
 Hib3GroupDAO hib3GroupDAO = HibernateSession.byHqlStatic()
 .createQuery("from Hib3GroupDAO as g where g.uuid = :uuid")
  .setCacheable(false)
  .setCacheRegion(KLASS + ".Exists")
  .setString("uuid", uuid).uniqueResult(Hib3GroupDAO.class);
 
 

Type Parameters:
T - is the template
Parameters:
returnType - type of the result (in future can use this for typecasting)
Returns:
the object or null if none found
Throws:
GrouperDAOException

executeUpdate

public void executeUpdate()
                   throws GrouperDAOException
 call hql executeUpdate, e.g. delete or update statement
 
 

Throws:
GrouperDAOException

list

public <T> List<T> list(Class<T> returnType)
 call hql list result
 
 e.g.
 
 List hib3GroupTypeTupleDAOs = 
  HibernateSession.byHqlStatic()
    .createQuery("from Hib3GroupTypeTupleDAO as gtt where gtt.groupUuid = :group")
    .setCacheable(false).setString("group", uuid).list(Hib3GroupTypeTupleDAO.class);
 

Type Parameters:
T - is the template
Parameters:
returnType - type of the result (can typecast)
Returns:
the list or the empty list if not found (only null if not retrieving results)
Throws:
GrouperDAOException

listMap

public <K,V> Map<K,V> listMap(Class<K> keyClass,
                              Class<V> valueClass,
                              String keyPropertyName)
                 throws GrouperDAOException
 call hql list result, and put the results in map with the key as one of the fields
 
 

Type Parameters:
K - is the template of the value of the map
V - is the template of the value of the map
Parameters:
valueClass - type of the result (can typecast)
keyClass - is the type of the key of the map
keyPropertyName - name of the javabeans property for the key in the map
Returns:
the ordered set or the empty set if not found (never null)
Throws:
GrouperDAOException

listSet

public <S> Set<S> listSet(Class<S> returnType)
               throws GrouperDAOException
 call hql list result, and put the results in an ordered set
 
 e.g.
 
 Set groupTypeTupleDTOs = 
  HibernateSession.byHqlStatic()
    .createQuery("from Hib3GroupTypeTupleDAO as gtt where gtt.groupUuid = :group")
    .setCacheable(false).setString("group", uuid).listSet(Hib3GroupTypeTupleDAO.class);
 

Type Parameters:
S - is the template
Parameters:
returnType - type of the result (can typecast)
Returns:
the ordered set or the empty set if not found (never null)
Throws:
GrouperDAOException

setScalar

public ByHql setScalar(String bindVarName,
                       Object value)
assign data to the bind var

Specified by:
setScalar in interface HqlQuery
Parameters:
bindVarName -
value - is long, primitive so not null
Returns:
this object for chaining

options

public ByHql options(QueryOptions queryOptions1)
add a paging/sorting/resultSetSize, etc to the query

Parameters:
queryOptions1 -
Returns:
this for chaining

setDouble

public ByHql setDouble(String bindVarName,
                       Double value)
assign data to the bind var

Parameters:
bindVarName -
value - is double
Returns:
this object for chaining

setIgnoreHooks

public edu.internet2.middleware.grouper.hibernate.ByQueryBase setIgnoreHooks(boolean theIgnoreHooks)
if we should ignore hooks

Parameters:
theIgnoreHooks -
Returns:
if we should ignore hooks

isIgnoreHooks

public boolean isIgnoreHooks()
if we should ignore hooks

Returns:
if we should ignore hooks

main

public static void main(String[] args)
Parameters:
args -