com.bigllc.retsiq.simpleclient.util
Class DivideAndConquerStrategy<T>

java.lang.Object
  extended by com.bigllc.retsiq.simpleclient.util.DivideAndConquerStrategy<T>
All Implemented Interfaces:
SearchStrategy
Direct Known Subclasses:
DateFieldSearchStrategy, DateTimeFieldSearchStrategy, IntegerFieldSearchStrategy

public abstract class DivideAndConquerStrategy<T>
extends java.lang.Object
implements SearchStrategy

Abstract search strategy for dividing and conquering on a particular data type. This checks a record count for a range of the field supplied. If the count falls within the record limit then the query is added to the stack. If it exceed the limit then the range is halved. When search queries have been created to allow a full listing download the queries are all executed sequentially.

Author:
Marc G. Smith

Constructor Summary
DivideAndConquerStrategy(int recordCountLimit, java.lang.String fieldName, T startValue, T endValue)
          Create a strategy that is based around an integer field.
 
Method Summary
protected abstract  T getMidPoint(T start, T end)
          Get the mid point of the two supplied value, rounding down however that applies to the type.
 java.util.List<java.lang.String> getQueryBatches(RETSUserSession session, java.lang.String path, java.lang.String query)
          Get a list of queries that break up the original query so that all records for the original query can be retrieved/
protected abstract  java.lang.String getSearchValue(T value)
          Return the value as a string that is valid for a DMQL2 query for that data type.
protected abstract  T incrementValue(T value)
          Increment the value by one unit whatever that means for the type.
 void search(RETSUserSession session, java.lang.String path, java.lang.String query, java.util.List<java.lang.String> fields, boolean decoded, SearchResponseHandler out)
          Execute a search using the strategy implemented to return all the records using multiple queries.
protected abstract  boolean valuesEqual(T o1, T o2)
          Compare the two values for equality.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DivideAndConquerStrategy

public DivideAndConquerStrategy(int recordCountLimit,
                                java.lang.String fieldName,
                                T startValue,
                                T endValue)
Create a strategy that is based around an integer field.

Parameters:
recordCountLimit - the limit for each search, this should be less than any limit imposed by the server
fieldName - the name of the field to be used for dividing and conquering searches. For example the list price
startValue - The inclusive start value of the range to query for that type.
endValue - The inclusive end value of the range to query. A further query is executed for anything above this value to catch outliers.
Method Detail

search

public void search(RETSUserSession session,
                   java.lang.String path,
                   java.lang.String query,
                   java.util.List<java.lang.String> fields,
                   boolean decoded,
                   SearchResponseHandler out)
            throws RETSClientException
Description copied from interface: SearchStrategy
Execute a search using the strategy implemented to return all the records using multiple queries.

Specified by:
search in interface SearchStrategy
Parameters:
session - the user session to search with
path - the resource and classification to query in the following format - /<Resource>/<Classification>.
query - the DMQL2 query to execute.
fields - the fields to return, an empty list or null will fetch all the fields.
decoded - if true lookup values are decoded otherwise raw values are returned.
out - the handler to process the response.
Throws:
RETSClientException

getQueryBatches

public java.util.List<java.lang.String> getQueryBatches(RETSUserSession session,
                                                        java.lang.String path,
                                                        java.lang.String query)
                                                 throws RETSClientException
Description copied from interface: SearchStrategy
Get a list of queries that break up the original query so that all records for the original query can be retrieved/

Specified by:
getQueryBatches in interface SearchStrategy
Parameters:
session - the user session to search with
path - the resource and classification to query in the following format - /<Resource>/<Classification>.
query - the DMQL2 query to execute.
Returns:
Throws:
RETSClientException

getSearchValue

protected abstract java.lang.String getSearchValue(T value)
Return the value as a string that is valid for a DMQL2 query for that data type.

Parameters:
value - the value
Returns:
the DMQL2 valid string format of the value

getMidPoint

protected abstract T getMidPoint(T start,
                                 T end)
Get the mid point of the two supplied value, rounding down however that applies to the type. So for an integer this would be akin to ((end - start) / 2) + start.

Parameters:
start - the lower bounded value
end - the upper bounded value
Returns:
the midpoint rounded down however that is applicable

incrementValue

protected abstract T incrementValue(T value)
Increment the value by one unit whatever that means for the type.

Parameters:
value - the value to increment
Returns:
the incremented value

valuesEqual

protected abstract boolean valuesEqual(T o1,
                                       T o2)
Compare the two values for equality. This is used for the escape condition if the granularity is to coarse for the record limit.

Parameters:
o1 - the value to compare against
o2 - the value to compare to
Returns:
true if they are equal, false otherwise