|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.alfresco.ibatis.RollupResultHandler
public class RollupResultHandler
A ResultHandler
that collapses multiple rows based on a set of properties.
The set of properties given act as a unique key. When the unique key changes, the collection
values from the nested ResultMap are coalesced and the given ResultHandler
is called. It is
possible to embed several instances of this handler for deeply-nested ResultMap declarations.
Use this instance as a regular ResultHandler
, but with one big exception: call RollupResultHandler.processLastResults()
after executing the SQL statement. Remove the groupBy attribute from the iBatis ResultMap
declaration.
Example iBatis 2.x (TODO migrate example to MyBatis 3.x):
Example usage:
<resultMap id="result_AuditQueryAllValues"
extends="alfresco.audit.result_AuditQueryNoValues"
class="AuditQueryResult">
<result property="auditValues" resultMap="alfresco.propval.result_PropertyIdSearchRow"/>
</resultMap>
RowHandler rowHandler = new RowHandler()
{
public void handleRow(Object valueObject)
{
// DO SOMETHING
}
};
RollupRowHandler rollupRowHandler = new RollupRowHandler(
new String[] {"auditEntryId"},
"auditValues",
rowHandler,
maxResults);
if (maxResults > 0)
{
// Calculate the maximum results required
int sqlMaxResults = (maxResults > 0 ? ((maxResults+1) * 20) : Integer.MAX_VALUE);
List
This class is not thread-safe; use a new instance for each use.
Constructor Summary | |
---|---|
RollupResultHandler(java.lang.String[] keyProperties,
java.lang.String collectionProperty,
org.apache.ibatis.session.ResultHandler resultHandler)
|
|
RollupResultHandler(java.lang.String[] keyProperties,
java.lang.String collectionProperty,
org.apache.ibatis.session.ResultHandler resultHandler,
int maxResults)
|
Method Summary | |
---|---|
void |
handleResult(org.apache.ibatis.session.ResultContext context)
|
void |
processLastResults()
Client code must call this method once the query returns so that the final results can be passed to the inner RowHandler . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RollupResultHandler(java.lang.String[] keyProperties, java.lang.String collectionProperty, org.apache.ibatis.session.ResultHandler resultHandler)
keyProperties
- the properties that make up the unique keycollectionProperty
- the property mapped using a nested ResultMapresultHandler
- the result handler that will receive the rolled-up resultspublic RollupResultHandler(java.lang.String[] keyProperties, java.lang.String collectionProperty, org.apache.ibatis.session.ResultHandler resultHandler, int maxResults)
keyProperties
- the properties that make up the unique keycollectionProperty
- the property mapped using a nested ResultMapresultHandler
- the result handler that will receive the rolled-up resultsmaxResults
- the maximum number of results to retrieve (-1 for no limit).
Make sure that the query result limit is large enough to produce this
at least this number of resultsMethod Detail |
---|
public void handleResult(org.apache.ibatis.session.ResultContext context)
handleResult
in interface org.apache.ibatis.session.ResultHandler
public void processLastResults()
RowHandler
. If a query is limited by size, then it is
possible that the unprocessed results represent an incomplete final object; in this case
it would be best to ignore the last results. If the query is complete (i.e. all results
are returned) then this method should be called.
If you want X results and each result is made up of N rows (on average), then set the query
limit to:
L = X * (N+1)
and don't call this method.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |