[xwiki-devs] Hashmap vs. Objects (theoretical question about a data model)
Hi All, This question "might" be related to the thread that has been active in the past couple of days about the data model. We have a similar situation with the only difference being that we want to create lists or collections (like Groups) of certain pre- created Objects. The Object as a whole may/will belong to more than one such collection - which means that if we were to use a Document to link a Collection and its contents, then every document will have a COPY of the same object and this is definitely not desirable for good performance - Right? So, in that case, we have 2 alternatives: 1) Use the techiniques used in XWiki to create Groups: each group has objects of class XWikiGroup with just one field that refers to the Member name. OR 2) Use XWiki.getHashmap() and add the Collection and its members to the hashmap (as the Key and Value resp.) The XWiki API indicates that the option #2 must be used in xwiki when Objects can not be created. My Question is: -> Even though I could use option #1 and create objects and add them to the document that would represent the Collection, can I still use option #2 because I think that it will provide better performance. Am I right in my assumption? What should I do? Thanks a lot for all help!
Kamna Jain wrote:
Hi All,
This question "might" be related to the thread that has been active in the past couple of days about the data model. We have a similar situation with the only difference being that we want to create lists or collections (like Groups) of certain pre- created Objects. The Object as a whole may/will belong to more than one such collection - which means that if we were to use a Document to link a Collection and its contents, then every document will have a COPY of the same object and this is definitely not desirable for good performance - Right?
Right. Any duplication (except for backup purposes) is bad.
So, in that case, we have 2 alternatives: 1) Use the techiniques used in XWiki to create Groups: each group has objects of class XWikiGroup with just one field that refers to the Member name. OR
Yes, this is somehow similar to the Foreign Key concept in databases, so it should be a good way to approach your problem.
2) Use XWiki.getHashmap() and add the Collection and its members to the hashmap (as the Key and Value resp.)
The XWiki API indicates that the option #2 must be used in xwiki when Objects can not be created. My Question is: -> Even though I could use option #1 and create objects and add them to the document that would represent the Collection, can I still use option #2 because I think that it will provide better performance. Am I right in my assumption? What should I do?
#2 is a bit faster, but it does not provide persistence. When the current request is over, that hashmap is gone. Given the fact that you probably have to store your data in a database, in the end you get almost the same performance as #1, but you have to reimplement what the XWiki platform already offers. When using a platform (any platform), you have to get used to the best practices of that platform; this is true for XWiki also: although some might be used to low level improvements of storage and SQL queries, and feel that they know better how queries should be written, XWiki offers a simple, high-level data model that should be used. The Google BigTable model was also received by some with dismay, since it doesn't follow the classical SQL principles. -- Sergiu Dumitriu http://purl.org/net/sergiu/
Sergiu Dumitriu wrote:
So, in that case, we have 2 alternatives: 1) Use the techiniques used in XWiki to create Groups: each group has objects of class XWikiGroup with just one field that refers to the Member name. OR
Yes, this is somehow similar to the Foreign Key concept in databases, so it should be a good way to approach your problem.
This explanation easies things for me at least. Please, could you provide an example? Some thing like how could we retrieve the email address for all members of a given group? Thanks! Regards, Ricardo -- Ricardo RodrÃguez Your EPEC Network ICT Team
Hi! Sergiu Dumitriu wrote:
Kamna Jain wrote:
So, in that case, we have 2 alternatives: 1) Use the techiniques used in XWiki to create Groups: each group has objects of class XWikiGroup with just one field that refers to the Member name. OR
Yes, this is somehow similar to the Foreign Key concept in databases, so it should be a good way to approach your problem.
I feel myself a bit more comfortable with classical SQL concepts so far! :-) Please, does XWiki provide Referential Integrity? Cascading delete and cascading update are my concerns at the current point. I've tried by renaming a document used to "link" a given group-like class with a number of "group-members". It seems that after I rename the document, the content of the "link" record remains unchanged. Working with groups and group members the situation is a bit different: if I rename an user, she/he is removed from the group/groups it belongs to. But, in any case, a rename action doesn't respect groups membership for a given user. I am working with XE 1.3.8295. Any insight will be welcome! Thanks! Cheers, Ricardo -- Ricardo RodrÃguez Your EPEC Network ICT Team
Thanks Sergiu. Your response was very helpful! On 5/5/08, Kamna Jain <[email protected]> wrote:
Hi All,
This question "might" be related to the thread that has been active in the past couple of days about the data model. We have a similar situation with the only difference being that we want to create lists or collections (like Groups) of certain pre- created Objects. The Object as a whole may/will belong to more than one such collection - which means that if we were to use a Document to link a Collection and its contents, then every document will have a COPY of the same object and this is definitely not desirable for good performance - Right?
So, in that case, we have 2 alternatives: 1) Use the techiniques used in XWiki to create Groups: each group has objects of class XWikiGroup with just one field that refers to the Member name. OR 2) Use XWiki.getHashmap() and add the Collection and its members to the hashmap (as the Key and Value resp.)
The XWiki API indicates that the option #2 must be used in xwiki when Objects can not be created. My Question is: -> Even though I could use option #1 and create objects and add them to the document that would represent the Collection, can I still use option #2 because I think that it will provide better performance. Am I right in my assumption? What should I do?
Thanks a lot for all help!
Ok. So I am using Option #1 and now I need to add objects to the document at the click of a button. I am able to successfully add the objects to the document but NOT able to display them on the page (because the template of teh class is not getting copied) Thats becuase, I am nto sure how to set the template for that page. I tried: 1) $doc.setDefaultTemplate..but this did not work 2) I also tried $response.sendRedirect($projDoc.getURL("view","template=${etemplate}")) (where etemplate is the encoded template name) but this gives the error that the document already exists ! 3) The only thing that works is when I manually copy #includeForm("Classsheet") in the wiki editor of my page. Q: How can I set the template once, so it is used for all objects of that class. Thanks On 5/5/08, Kamna Jain <[email protected]> wrote:
Thanks Sergiu. Your response was very helpful!
On 5/5/08, Kamna Jain <[email protected]> wrote:
Hi All,
This question "might" be related to the thread that has been active in the past couple of days about the data model. We have a similar situation with the only difference being that we want to create lists or collections (like Groups) of certain pre- created Objects. The Object as a whole may/will belong to more than one such collection - which means that if we were to use a Document to link a Collection and its contents, then every document will have a COPY of the same object and this is definitely not desirable for good performance - Right?
So, in that case, we have 2 alternatives: 1) Use the techiniques used in XWiki to create Groups: each group has objects of class XWikiGroup with just one field that refers to the Member name. OR 2) Use XWiki.getHashmap() and add the Collection and its members to the hashmap (as the Key and Value resp.)
The XWiki API indicates that the option #2 must be used in xwiki when Objects can not be created. My Question is: -> Even though I could use option #1 and create objects and add them to the document that would represent the Collection, can I still use option #2 because I think that it will provide better performance. Am I right in my assumption? What should I do?
Thanks a lot for all help!
participants (3)
-
[Ricardo Rodriguez] Your EPEC Network ICT Team -
Kamna Jain -
Sergiu Dumitriu