import com.atlassian.activeobjects.external.ActiveObjects;
How do i use paramterized IN CLAUSE in WERE QUERY.
String releseIds="";
Query query = Query.select();
query = query.where("JIRA_PROJECT_KEY=?", projectKey);
query = query.where("JIRA_RELEASE_ID IN ?", releseIds);
List<InnotasMap> prjList = newArrayList(ao.find(ObjMap.class,query));
Community moderators have prevented the ability to post new answers.
I got the soluton. However for this we need to add the following in POM to use the google collectons guava library.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>
*****************CODE*************************************
String strMappedProjectID = "123,123123,12312321,12312312"
Iterable<String> matchValues=Splitter.on(',').split(strMappedProjectID);
String placeholderCommaList = Joiner.on(", ").join(
Iterables.transform(matchValues, Functions.constant("?")));
Object[] matchValuesArray = Iterables.toArray(matchValues, Object.class);
Query query = Query.select();
if (ProjectIDs != null) query = query.where("PROJECT_ID IN (" + placeholderCommaList + ")", matchValuesArray);
In case anyone comes across this and can't get it working. it DOES work. (thank you Vikas) however you'll need to trim out any spaces in any comma-delimited string list before you perform splitter on your strMappedProjectID
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rafael,
if i use the array it throws an exception. And if i pass as plain string it gives no result.
public Map<String,Object> getInnotasReleaseMapping(String projectKey, String[] releseIds){ Query query = Query.select(); query = query.where("JIRA_PROJECT_KEY=?", projectKey); query = query.where("JIRA_RELEASE_ID IN (?)", releseIds); //System.out.println("list of release id's: "+ releseIds); List<InnotasMap> prjList = newArrayList(ao.find(InnotasMap.class,query)); System.out.println("Size of the mapping data found : "+prjList.size()); Map<String, Object> prjMap = new TreeMap<String, Object>(); for(InnotasMap prj : prjList) { prjMap.put(prj.getJiraReleaseId(), prj); System.out.println("Innotas Project Name: "+prj.getJiraProjectKey()); } return prjMap;
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
Thanks,
Vikas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rafael,
if i use the array it throws an exception. And if i pass as plain string it gives no result.
public Map<String,Object> getInnotasReleaseMapping(String projectKey, String[] releseIds){ Query query = Query.select(); query = query.where("JIRA_PROJECT_KEY=?", projectKey); query = query.where("JIRA_RELEASE_ID IN (?)", releseIds); //System.out.println("list of release id's: "+ releseIds); List<InnotasMap> prjList = newArrayList(ao.find(InnotasMap.class,query)); System.out.println("Size of the mapping data found : "+prjList.size()); Map<String, Object> prjMap = new TreeMap<String, Object>(); for(InnotasMap prj : prjList) { prjMap.put(prj.getJiraReleaseId(), prj); System.out.println("Innotas Project Name: "+prj.getJiraProjectKey()); } return prjMap;
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
Thanks,
Vikas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi rafael,
Do you mean to try this as is? Variable releseIds contains values in comma seperated like 132,123,4123
You mean
query = query.where(
"JIRA_RELEASE_ID IN (?)"
, releseIds);
@paramArray releseIds;
??
Thanks
Vikas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vikas,
Yes, please.
This is what I would suggest you on doing:
Please enable DEBUG to be able to look the running query.
Kind regards,
Rafael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vikas,
You are able to change the log settings to print out the query you are running. Please, visit Getting Startted with Active Objects and search for "Step 14. Adding some logging (Optional)" for further information.
Would you mind try the following, please:
query = query.where("JIRA_RELEASE_ID IN (?)", releseIds); // @param Array releseIds
Kind regards,
Rafael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.