Service Desk Practitioners Forum
cancel

How to find all child of root organization and all childs of this funded childs…

Highlighted
Siekierko Przem
Respected Contributor.

How to find all child of root organization and all childs of this funded childs…

I’ve got root Organization with have many child Organizations and those child Organizations have own child organizations. What I’m trying to do is to get all of sub organizations of root organization. I doing it like that (but it’s to slow):

public class Main {
private ApiSDSession session45;
/** Creates a new instance of Main */
public Main() {
session45 = ApiSDSession.openSession("172.30.2.70", "system", "xxx");
Long rootOrgoID = new Long("281478356926666");
IOrganization rootOrg = session45.getOrganizationHome().openOrganization(rootOrgoID);
Date start = new Date();
ArrayList orgsList = ConvertOrgTreeToList(rootOrg);
Date end = new Date();
System.out.println("I found: " + orgsList.size() + " orgs in " + ((end.getTime() - start.getTime())/1000) + "seconds");
session45.closeConnection();
}
public ArrayList ConvertOrgTreeToList(IOrganization root) {
ArrayList orgList = new ArrayList();
FKH(root, orgList);
return orgList;
}

private void FKH(IOrganization org, ArrayList orgList) {
if(org!=null) {
orgList.add(org);

IOrganization[] orgChildrens = org.getChildOrganizations();

if(orgChildrens!=null) {
for(int i=0; i FKH(orgChildrens[i], orgList);
}
}
}
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here

new Main();
}
}

And result of this application is:

I found: 8122 orgs in 259seconds

If someone could tell me how to find this organizations in faster way I would very thankful.
2 REPLIES
Vasily Kamenev
Acclaimed Contributor.

Re: How to find all child of root organization and all childs of this funded childs…

Hi
try use SQL statements with UNION.

Vasily
Siekierko Przem
Respected Contributor.

Re: How to find all child of root organization and all childs of this funded childs…

Could you show me some example query with UNION to get all tree elements with root ID ?? (I can find it on internet and I don't know how to create it)

I found solution on this page:
http://dgoyani.blogspot.com/2005/09/effective-way-to-expand-data-tree-in.html

And itâ s works correctly, but maybe your query would be faster. So if you could, please send me some example.