It's all about the answers!

Ask a question

What parameters are needed to instantiate an ItemQueryIterator object

Andrew Soloninka (5511924) | asked May 22 '13, 5:10 p.m.
 As part of an Asynchronous Task, I need to get a list of Project Areas so I use the code snippet below:

private List<IProjectAreaHandle> findProjectAreas(IProgressMonitor monitor) throws TeamRepositoryException {
IItemType itemType= IProjectArea.ITEM_TYPE;
IDynamicQueryModel model= itemType.getQueryModel();
IItemQuery query= IItemQuery.FACTORY.newInstance((IItemQueryModel) model);
IQueryService queryService = getService(IQueryService.class);
ItemQueryIterator<IProjectAreaHandle> iterator= new ItemQueryIterator<IProjectAreaHandle>(queryService, query, parameters );
return iterator.getAllItems();

When instantiating ItemQueryIterator, one of the parameters is an Object array called parameters. What values do I use for this array? Can you point me to documentation that would answer this question?

2 answers

permanent link
Jorge Diaz (8664234) | answered May 23 '13, 6:11 a.m.
Hi Andrew,

if your query is parameterized, you will pass an array with the expected parameters. In the snippet you provide however, you wouldn't need to pass parameters so you can use the constructor that doesn't expect parameters:

ItemQueryIterator(IServerQueryService queryService, IItemQuery query)

Note that for querying for the project areas you can find a snippet of code here:



Andrew Soloninka commented May 23 '13, 11:59 a.m.
I think the constructor above has been removed because I checked the source code and only found 2 constructors for  ItemQueryIterator:

public ItemQueryIterator(IQueryService queryService, IItemQuery itemQuery, Object[] parameters) throws TeamRepositoryException 

public ItemQueryIterator(IQueryService queryService, IItemQuery itemQuery, Object[] parameters, int pageSize) throws TeamRepositoryException 

Both of them require the parameters parameter.

Jorge Diaz commented May 24 '13, 10:27 a.m. | edited May 24 '13, 10:27 a.m.

Note there are more than one "ItemQueryIterator" classes. The one from the wiki page I mentioned is from work items.

Anyway, your solution of "IQueryService.EMPTY_PARAMETERS" sounds good to me as well.

permanent link
Andrew Soloninka (5511924) | answered May 23 '13, 11:21 a.m.
edited May 23 '13, 11:46 a.m.
Found the constant  IQueryService.EMPTY_PARAMETERS 

I used it for the parameters parameter and it worked.

Your answer

Register or to post your answer.