org.squashtest.csp.tm.domain.report.query.hibernate
Class HibernateReportQuery

java.lang.Object
  extended by org.squashtest.csp.tm.domain.report.query.hibernate.HibernateReportQuery
All Implemented Interfaces:
ReportQuery
Direct Known Subclasses:
HibernateExecutionProgressQuery, HibernateRequirementCoverageByTestsQuery

public abstract class HibernateReportQuery
extends Object
implements ReportQuery

This class is an implementation of ReportQuery meant for a Hibernate repository. The goal of that Hibernate-oriented ReportQuery is to provide the Dao executing it with a DetachedCriteria query. Note that an HibernateReportQuery will return a HibernateQueryFlavor by design. That abstract class is a superclass for other queries. Note that this abstract class extends the ReportQuery interface by far, including a post processing method convertToDto(java.util.List). The corresponding ReportQueryDao, namely HibernateReportQueryDao is aware of that method and will invoke it. That method is useful for any post processing like the use of a DataFilteringService DataFilteringService, ReportQuery or complex computations that would have been difficult to get directly from the repository. For convenience this implementation uses a class to explicitly design the criteria for that query, the ReportCriterion. A ReportCriterion is meant to hold informations and possibly generate a Hibernate Criterion that will be used in the main DetachedCriteria query, but it's up to the implementor to use it or rebuild the Criterion from scratch. Subclassing a HibernateReportQuery : ======================================== - The constructor must create the needed ReportCriterion and add then to the list of ReportCriterions. - createHibernateQuery() may generate a DetachedCriteria, or return null. - doInSession(Session session) will be executed if createHibernateQuery() returned null. - convertToDto() accepting a list of Hibernate entities and returning a list of different objects that fits the definition of the view (probably a .jasper). Trick : if you couldn't translate your criterion into Hibernate Criterion when implementing the createHibernateQuery() interface, you can postprocess the results with the remaining criteria in this step.

Author:
bsiri

Field Summary
protected  Map<String,ReportCriterion> criterions
           
 
Constructor Summary
HibernateReportQuery()
           
 
Method Summary
protected  org.hibernate.criterion.DetachedCriteria addCriterion(org.hibernate.criterion.DetachedCriteria criteria, String criterionName)
          Short hand for including a Hibernate Criterion in a DetachedCriteria.
abstract  List<?> convertToDto(List<?> rawData)
          This method will convert the raw results from Hibernate into a suitable list of Dto object that the view will process in turn.
abstract  org.hibernate.criterion.DetachedCriteria createHibernateQuery()
           
abstract  List<?> doInSession(org.hibernate.Session session)
          if you really need it.
 Collection<String> getCriterionNames()
           
protected  Map<String,ReportCriterion> getCriterions()
          For internal use of the subclasses, this will return the concrete implementation of the criterions holder.
protected  DataFilteringService getDataFilteringService()
           
 ReportQueryFlavor getFlavor()
           
 Object[] getValue(String key)
           
 boolean isCriterionExists(String name)
          Checks if the given name matches one of the criterion used by this query.
 void setCriterion(String name, Object... values)
          This method will set a criterion.
 void SetDataFilteringService(DataFilteringService service)
          setter for a DataFilteringService.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

criterions

protected Map<String,ReportCriterion> criterions
Constructor Detail

HibernateReportQuery

public HibernateReportQuery()
Method Detail

getFlavor

public ReportQueryFlavor getFlavor()
Specified by:
getFlavor in interface ReportQuery
Returns:
an instance of a subclass of ReportQueryFlavor, that will identify which kind of Dao that Query should be processed through.

setCriterion

public void setCriterion(String name,
                         Object... values)
Description copied from interface: ReportQuery
This method will set a criterion. Using a null value will nullify the use of that criterion.

Specified by:
setCriterion in interface ReportQuery
Parameters:
name - the name of the criterion you will feed with one or several values.
values - an array (which can contains 0, 1 or more elements) containing the actual parameters.

SetDataFilteringService

public void SetDataFilteringService(DataFilteringService service)
Description copied from interface: ReportQuery
setter for a DataFilteringService. Will be invoked by the system. See above, Data Filtering.

Specified by:
SetDataFilteringService in interface ReportQuery

getDataFilteringService

protected DataFilteringService getDataFilteringService()

getCriterions

protected Map<String,ReportCriterion> getCriterions()
For internal use of the subclasses, this will return the concrete implementation of the criterions holder.

Returns:
the map of ReportCriterion, identified by their names (the name does exists both in the Map and in the ReportCriterion).

getCriterionNames

public Collection<String> getCriterionNames()
Specified by:
getCriterionNames in interface ReportQuery
Returns:
the list of the criterion filtering that report.

isCriterionExists

public boolean isCriterionExists(String name)
Description copied from interface: ReportQuery
Checks if the given name matches one of the criterion used by this query.

Specified by:
isCriterionExists in interface ReportQuery
Parameters:
name - the name one wants to check.
Returns:
true if the ReportQuery instance declares a criterion bearing that name, false otherwise.

getValue

public Object[] getValue(String key)
Specified by:
getValue in interface ReportQuery
Parameters:
key - the name of the criterion one want to check or retrieve the actual paramters
Returns:
the parameters for that criterion, or null if the criterion was deactivated or if the criterion doesn't exists (use isCriterionExists() if you need to know what does null means in that later case).

addCriterion

protected org.hibernate.criterion.DetachedCriteria addCriterion(org.hibernate.criterion.DetachedCriteria criteria,
                                                                String criterionName)
Short hand for including a Hibernate Criterion in a DetachedCriteria.

Parameters:
criteria - the DetachedCriteria query to which we add a Criterion.
criterionName - the name of the corresponding ReportCriterion.
Returns:

createHibernateQuery

public abstract org.hibernate.criterion.DetachedCriteria createHibernateQuery()
Returns:
a DetachedCriteria to run in a Hibernate Dao, or null.

doInSession

public abstract List<?> doInSession(org.hibernate.Session session)
if you really need it. Will be executed if createHibernateQuery() returned null;

Parameters:
session -
Returns:

convertToDto

public abstract List<?> convertToDto(List<?> rawData)
This method will convert the raw results from Hibernate into a suitable list of Dto object that the view will process in turn. Should also use the DataFilteringService if need be.

Parameters:
rawData - a List of Hibernate entities.
Returns:
a List of Dtos.


Copyright © 2010-2012 Squashtest TM, Squashtest.org. All Rights Reserved.