* @throws TerminatedException DOCUMENT ME!
*/
private NodeSet findAll(XQueryWatchDog watchDog, int relation, DocumentSet docs, NodeSet contextSet, int axis, List<QName> qnames, Indexable value, NodeSet result, Collator collator ) throws TerminatedException
{
final SearchCallback cb = new SearchCallback( docs, contextSet, result, axis == NodeSet.ANCESTOR );
final Lock lock = dbValues.getLock();
for( final Iterator<Collection> iter = docs.getCollectionIterator(); iter.hasNext(); ) {
final int collectionId = iter.next().getId();
final int idxOp = checkRelationOp( relation );
Value searchKey;
Value prefixKey;
watchDog.proceed(null);
if( qnames == null ) {
try {
lock.acquire( Lock.READ_LOCK );
searchKey = new SimpleValue( collectionId, value );
prefixKey = new SimplePrefixValue( collectionId, value.getType() );
final IndexQuery query = new IndexQuery( idxOp, searchKey );
if( idxOp == IndexQuery.EQ ) {
dbValues.query( query, cb );
} else {
dbValues.query( query, prefixKey, cb );
}
}
catch( final EXistException e ) {
LOG.error( e.getMessage(), e );
}
catch( final LockException e ) {
LOG.warn( "Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e );
}
catch( final IOException e ) {
LOG.error( e.getMessage(), e );
}
catch( final BTreeException e ) {
LOG.error( e.getMessage(), e );
}
finally {
lock.release( Lock.READ_LOCK );
}
} else {
for( int i = 0; i < qnames.size(); i++ ) {
final QName qname = ( QName )qnames.get( i );
try {
lock.acquire( Lock.READ_LOCK );
//Compute a key for the value in the collection
searchKey = new QNameValue( collectionId, qname, value, broker.getBrokerPool().getSymbols() );
prefixKey = new QNamePrefixValue( collectionId, qname, value.getType(), broker.getBrokerPool().getSymbols() );
final IndexQuery query = new IndexQuery( idxOp, searchKey );
if( idxOp == IndexQuery.EQ ) {
dbValues.query( query, cb );
} else {
dbValues.query( query, prefixKey, cb );
}
}
catch( final EXistException e ) {
LOG.error( e.getMessage(), e );
}
catch( final LockException e ) {
LOG.warn( "Failed to acquire lock for '" + dbValues.getFile().getName() + "'", e );
}
catch( final IOException e ) {
LOG.error( e.getMessage(), e );
}
catch( final BTreeException e ) {
LOG.error( e.getMessage(), e );
}
finally {
lock.release( Lock.READ_LOCK );
}
}
}
}
return( result );