public abstract class AbstractSearcher extends java.lang.Object implements ResultHandler
The entire search module is implemented in a pipe and filter chain. Each concrete searcher in the chain is a concrete class of this AbstractSearcher class, and they are configured to search on different set of search criteria that input by the user.
The actual combination of searchers chain is configured in SearchManager.
Modifier and Type | Field and Description |
---|---|
protected java.util.ArrayList<XMLDBModel> |
_currentResults
Contains the currently found results in this searcher.
|
protected DBConnection |
_dbConnection
Connection to the xml database.
|
protected java.util.List<XMLDBModel> |
_errorModels
The models contains error or cannot be parsed.
|
protected boolean |
_isIndependent
Indicate whether the searcher existing depends on the existing of other
searchers.
|
protected ResultHandler |
_nextResultHandler
The next result handler to be called to pass the search results
from this result handler.
|
protected java.util.ArrayList<XMLDBModel> |
_previousResults
Results found and passed by the previous searchers.
|
Constructor and Description |
---|
AbstractSearcher() |
Modifier and Type | Method and Description |
---|---|
protected void |
_addErrorModel(XMLDBModel errorModel)
In case of getting model result with error or cannot be parsed, use this
method to add the error model to the stored error models list.
|
protected boolean |
_isFirstSearcher()
Check whether this searcher is the first searcher in the chain.
|
protected boolean |
_isIndependent()
Check whether this searcher is independent to exist without other
searchers.
|
protected boolean |
_isIntersectNeeded()
Check with this searcher needs to intersect the results that it finds
with the passed results from the other searchers.
|
protected boolean |
_isLastSeacher()
Check whether this searcher is the last searcher in the chain.
|
protected abstract boolean |
_isSearchCriteriaSet()
Checks whether the search criteria has been set in this
particular searcher.
|
protected void |
_pass()
Mark the search is done in this searcher.
|
protected abstract void |
_search()
Perform the actual search.
|
void |
handleIntermediateResults(java.util.List<XMLDBModel> intermediateResults,
ResultHandler resultHandler)
Handle the intermediate results that found and passed by the other
searcher.
|
void |
handleResults(java.util.ArrayList<XMLDBModel> modelResults)
Handle the model results passed to this class, and handle the results
according to the certain search criteria.
|
boolean |
isPassed()
Check with this searcher has been passed the searching.
|
boolean |
isSearchCancelled()
Check whether the search process has been canceled by the user.
|
void |
noIntersect()
Mark this searcher as it does not need to intersect the results it find
with the results passed by other searchers.
|
void |
passErrorModels(java.util.List<XMLDBModel> errorModels)
In the case of getting some models that cannot be parsed or contains
some error, use this method to pass these error models to store for
error handling.
|
void |
setConnection(DBConnection connection)
Set the DB connection for this searcher.
|
void |
setFirstSearcher()
Mark this searcher as the first searcher in the chain.
|
void |
setLastSearcher()
Mark this searcher as the last searcher in the chain.
|
void |
setNextResultHandler(ResultHandler nextResultHandler)
Set the next result handler object to this searcher.
|
void |
setPreviousSeacher(AbstractSearcher previousSearcher)
Set the previous searcher that does the searching before this searcher.
|
void |
wholeSearchDone()
Notify the search result buffer that the searching is done.
|
protected java.util.ArrayList<XMLDBModel> _currentResults
protected DBConnection _dbConnection
protected java.util.List<XMLDBModel> _errorModels
protected boolean _isIndependent
protected ResultHandler _nextResultHandler
protected java.util.ArrayList<XMLDBModel> _previousResults
public void handleIntermediateResults(java.util.List<XMLDBModel> intermediateResults, ResultHandler resultHandler)
The searcher normally passes the intermediate results to the next result handler.
handleIntermediateResults
in interface ResultHandler
intermediateResults
- The intermediate results to be handled.resultHandler
- The result handler that found and pass these
results.public void handleResults(java.util.ArrayList<XMLDBModel> modelResults) throws DBConnectionException, DBExecutionException
handleResults
in interface ResultHandler
modelResults
- The results to be handled in this searcher.DBConnectionException
- Thrown by the DBConnectorFactory
if getting the DBConnection from it, which
indicates that the DBConnection cannot be obtained.DBExecutionException
- Happens in the execution
of DB tasks, and is thrown by the concrete searcher if they
are performing the actual searching in the database.public boolean isSearchCancelled()
isSearchCancelled
in interface ResultHandler
public boolean isPassed()
public void noIntersect()
public void passErrorModels(java.util.List<XMLDBModel> errorModels)
passErrorModels
in interface ResultHandler
errorModels
- The error models.public void setConnection(DBConnection connection)
setConnection
in interface ResultHandler
connection
- The DBConnection instance to be set in this searcher.public void setFirstSearcher()
public void setLastSearcher()
public void setNextResultHandler(ResultHandler nextResultHandler)
nextResultHandler
- The next ResultHandler to set to this handler.public void setPreviousSeacher(AbstractSearcher previousSearcher)
previousSearcher
- The previous searcher to set in this searcher.public void wholeSearchDone() throws DBConnectionException
wholeSearchDone
in interface ResultHandler
DBConnectionException
- Thrown from the database layer if the
database connection cannot be obtained.protected void _addErrorModel(XMLDBModel errorModel)
errorModel
- The error model to be added to the list.protected boolean _isFirstSearcher()
protected boolean _isIndependent()
protected boolean _isIntersectNeeded()
protected boolean _isLastSeacher()
protected abstract boolean _isSearchCriteriaSet()
protected void _pass()
isPassed()
protected abstract void _search() throws DBExecutionException, DBConnectionException
DBExecutionException
- Thrown from the database layer if
there is error occurring during the search.DBConnectionException
- Thrown by the DBConnectorFactory
if getting the DBConnection from it, which
indicates that the DBConnection cannot be obtained.