It's all about the answers!

Ask a question

Is it possible to fetch ChangeSets greater than IWorkspaceManager.MAX_QUERY_SIZE using IChangeSetSearchCriteria


0
1
Reji GL (1136) | asked Sep 26 '13, 5:34 p.m.
I am trying to fetch the Changesets within a date interval. There is MAX_QUERY_SIZE = 512. I am not able to fetch changesets above that limit. 

My search criteria will be returning more than 512 changesets. Is there any possible ways to fetch the remaining changesets using client java api.?

Accepted answer


permanent link
Chris Ball (9613) | answered Oct 01 '13, 4:50 a.m.
edited Oct 01 '13, 4:53 a.m.
I don't think there is any way to override the MAX_QUERY_SIZE.

However, as the results are fetched in date order it is possible to run a batch of separate queries and combine the results. This appears to be how the Eclipse UI control works. (in com.ibm.team.internal.filesystem.ui.views.search.changeset.ChangeSetQuery)

This code worked for me (RTC 4.0.4), and was able to return 80000 results.

public static List<IChangeSetHandle> getAllChangeSets(
    final ITeamRepository repository,
    final IChangeSetSearchCriteria searchCriteria,
    final IProgressMonitor monitor, final int maxResults)
    throws TeamRepositoryException {
  int toFetch = maxResults;
  final List<IChangeSetHandle> result = new ArrayList<>(
      toFetch);

  final IWorkspaceManager mgr = SCMPlatform
      .getWorkspaceManager(repository);

  final IChangeSetSearchCriteria pagingCriteria = (IChangeSetSearchCriteria) EcoreUtil
      .copy((EObject) searchCriteria);

  List<IChangeSetHandle> findResult = mgr.findChangeSets(pagingCriteria,
      toFetch, monitor);
  result.addAll(findResult);

  while (toFetch > IWorkspaceManager.MAX_QUERY_SIZE
      && findResult.size() == IWorkspaceManager.MAX_QUERY_SIZE) {
    toFetch = toFetch - findResult.size();
    final IChangeSet lastChangeSet = (IChangeSet) repository
        .itemManager().fetchCompleteItem(
            result.get(result.size() - 1),
            IItemManager.DEFAULT, monitor);
    // update the modified before/after to get the remaining change sets
    if (pagingCriteria.isOldestFirst()) {
      pagingCriteria.setModifiedAfter(new Timestamp(lastChangeSet
          .getLastChangeDate().getTime()));
    } else {
      pagingCriteria.setModifiedBefore(new Timestamp(lastChangeSet
          .getLastChangeDate().getTime()));
    }

    findResult = mgr.findChangeSets(pagingCriteria, toFetch, monitor);
    result.addAll(findResult);
  }
  return result;
}
	
	

Reji GL selected this answer as the correct answer

Comments
Reji GL commented Oct 01 '13, 11:43 a.m.

This solution works perfectly... thanks.. 

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.