-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Implementing a filtered tree view with Hibernate
PostPosted: Sat Oct 28, 2006 9:38 am 
Newbie

Joined: Thu Mar 09, 2006 11:52 am
Posts: 13
Hello community,

I have a rather tricky task for which I cannot come up with a satisfying solution - I have to create a tree view for a Hibernate-based web application using Struts 1.2.9. The application I'm working on is quite complex so I hope I can explain everything in sufficient clarity. If not, feel free to ask. I'm really stuck with this so help would be appreciated a lot.

1.) The data structure
Basically, the tree is used to diplay a hierarchy of objects of the same type (Element).

Code:
Element
|
+-Element
   |
   +-Element
[...]


This means, I have a reference to a parentElement property in my Element class as well as a list of childElements. Displaying a tree view like that is no problem. What is a problem is the fact that I have to filter the data in the tree:

Element has a property called state, an integer that can assume values between 0 and 9. The user shall be able to select any number of state values that he wants to see in the tree. For example, the user could select only values 0, 1 and 6 to be displayed.

Collection filters don't seem to be sufficient for this task. Although I can apply a filter to the collection of childElements this does not solve problem, as I must consider every single descendant of an Element (not only direct children) when making the decision whether or not to display the Element in the tree.

Example: The user sets the filter to "show only Elements with a state of 3. Now look at the following tree:

Code:
Element_1 [state=0]
|
+-Element_2 [state=2]
   |
   +-Element_3 [state=3]


Basically the filter would now only display Element_3 as it is the only Element that has a state of 3. The problem is that Element_1 and Element_2 must also be displayed because the user must be able to navigate the tree view in order to reach Element_3 in the first place.

One approach would be to simply load the entire tree of Elements and then simply do not display (= generate markup for) those that have a state outside the current filtering bounds. This is not an applicable solution for my problem, though, as the tree view will contain a total of about 2,500 to 5,000 Elements and it is not an option to select the entire data - I store the data model of the tree in the HTTP session, so I have to pay attention to memory usage. With an estimated 30-50 concurrent users each of whom has his own tree model in the HTTP session, this approach is simply not acceptable.

Another idea would be to select the entire data model and then simply remove unused elements which is not really better than the first approach as it causes the same (superfluous) amount of database activity and (which is worse) creates a bunch of unreferenced objects after the tree structure has been cleaned up which will cause the Garbage Collector to steal performance from the application. Hence, not an option neither.

So my question is: Has anyone around these boards ever coped with complex tree structures like that and can give me some advice on how to handle these problems?

Thanks a lot in advance,
a desperate programmer.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 29, 2006 3:04 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
How do you wish to handle elements that do not have the selected state but CONTAIN elements that do?

My suggestion: I would not think of a "persistent tree" as I would of a visual tree, but as a CONNECTED GRAPH of nodes and edges. This way, you can represent a tree using 2 tables:
1. your nodes (id, value, ..)
2. the edges between them (node1_id, node2_id)

Now, if you wish to filter the tree based on some node property, simpy take only the nodes that have that property. Assuming you made the right associations and answer the question above, it may be the right solution for you.

(p.s. please rate if it is helpful :-) )[/img]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.