mLuceneChunk = mLuceneOp.getNextIndexedIdChunk(HITS_PER_CHUNK); c.indexIds = mLuceneChunk.getIndexIds();
    private void getNextChunk() throws ServiceException    {        if (mCurHitsOffset == -1 || mEndOfHits) {            return;        }        int mailboxId = this.getMailbox().getId();        int searchOrder = this.getResultsSet().getSearchOrder();                if (mIncludedItemIds != null && mIncludedItemIds.size() == 0) {            mNoResultsQuery = true;        }                if (!mNoResultsQuery) {            Connection conn = null;            try {                conn = DbPool.getConnection();                byte sort = MailboxIndex.getDbMailItemSortByte(searchOrder);                Folder[] folders = null;                Folder[] excludeFolders = null;                if (mFolder != null) {                    folders = new Folder[1];                    folders[0] = mFolder;                }                                 if (mExcludeFolder.size() > 0) {                    excludeFolders = (Folder[])(mExcludeFolder.toArray(new Folder[mExcludeFolder.size()]));                }                                byte[] types = getDbQueryTypes();                Tag[] includeTags = null;                Tag[] excludeTags = null;                if (mIncludeTags.size() > 0) {                    includeTags = (Tag[]) mIncludeTags.toArray(new Tag[mIncludeTags.size()]);                }                if (mExcludeTags.size() > 0) {                    excludeTags = (Tag[]) mExcludeTags.toArray(new Tag[mExcludeTags.size()]);                }                                int[] prohibitedConvIds = null;                if (mProhibitedConvIds.size() > 0) {                    prohibitedConvIds = new int[mProhibitedConvIds.size()];                    int i = 0;                    for (Iterator probIter = mProhibitedConvIds.iterator(); probIter.hasNext();) {                        Integer cid = (Integer)probIter.next();                        prohibitedConvIds[i++] = cid.intValue();                    }                }                                DbMailItem.SearchConstraints c = new DbMailItem.SearchConstraints();                c.mailboxId = mailboxId;                c.tags = includeTags;                c.excludeTags = excludeTags;                c.folders = folders;                c.excludeFolders = excludeFolders;                c.convId = mConvId;                c.prohibitedConvIds = prohibitedConvIds;                c.types = types;                c.sort = sort;                                if (mExcludeTypes.length > 0) {                    c.excludeTypes = mExcludeTypes;                }                if (mIncludedItemIds != null) {                    c.itemIds = new int[mIncludedItemIds.size()];                    int offset = 0;                    for (Iterator iter = mIncludedItemIds.iterator(); iter.hasNext(); offset++) {                        c.itemIds[offset] = ((Integer)iter.next()).intValue();                    }                }                if (mExcludedItemIds != null && mExcludedItemIds.size() > 0) {                    c.prohibitedItemIds = new int[mExcludedItemIds.size()];                    int offset = 0;                    for (Iterator iter = mExcludedItemIds.iterator(); iter.hasNext(); offset++) {                        c.prohibitedItemIds[offset] = ((Integer)iter.next()).intValue();                    }                }                                if (mDates.size() > 0) {                    c.dates = (SearchConstraints.Range[])mDates.toArray(new SearchConstraints.Range[mDates.size()]);                }                                if (mSizes.size() > 0) {                    c.sizes = (SearchConstraints.Range[])mSizes.toArray(new SearchConstraints.Range[mSizes.size()]);                }                                                if (mLuceneOp == null) {                    c.offset = mCurHitsOffset;                    c.limit = HITS_PER_CHUNK;                    mDBHits = DbMailItem.search(conn, c);                                    } else {                    // DON'T set an sql LIMIT if we're asking for lucene hits!!!  If we did, then we wouldn't be                    // sure that we'd "consumed" all the Lucene-ID's, and therefore we could miss hits!                    mLuceneChunk = mLuceneOp.getNextIndexedIdChunk(HITS_PER_CHUNK);                    c.indexIds = mLuceneChunk.getIndexIds();                                        if (c.indexIds.length < HITS_PER_CHUNK) {                        // we know we got all the index-id's from lucene.  since we don't have a                        // LIMIT clause, we can be assured that this query will get all the remaining results.                        mEndOfHits = true;                    }                                        if (c.indexIds.length == 0) {                        mDBHits = new ArrayList();                     } else {                        mDBHits = DbMailItem.search(conn, c);                    }                                    }                            } catch (ServiceException e) {                e.printStackTrace();                throw e;            } finally {                DbPool.quietClose(conn);            }                        if (mLog.isDebugEnabled()) {                mLog.debug(this.toString()+" Returned "+mDBHits.size()+" results ("+mCurHitsOffset+")");            }        } else {            if (mLog.isDebugEnabled()) {                mLog.debug(" Returned **NO DB RESULTS (no-results-query-optimization)**");            }            mDBHitsIter = null;            mCurHitsOffset = -1;            return;        }        if (mDBHits.size() == 0) {            mCurHitsOffset = -1;            mDBHitsIter = null;            mDBHits = null;        } else {            if (mLuceneOp == null && mDBHits.size() < HITS_PER_CHUNK) {                mEndOfHits = true;            }            mCurHitsOffset += mDBHits.size();            mDBHitsIter = mDBHits.iterator();        }    }