Custom Mappings

Custom Mappings allow to map a XWiki class to its own database scheme (as opposite to class that are not mapped, that do use the standard, predefined, XWiki tables scheme). Custom mappings can be usefull for improving performances (when expecting a class to have a large number of instances for example), or for sharing external datas (enterprise datas, or other software datas for example) with XWiki.

To make use of a custom mapping, the first thing to do is to define the actual hibernate mapping, in a .hbm file (see as an example the file mailing.hbm.xml, attached). This file should then be located under the WEB-INF directory of the xwiki webapp (where XWiki standard mappings can be found too : xwiki.hbm.xml, feeds.hbm.xml).

Then, the target XWiki class, for which the mapping has been written, should be set programmatically as been such a custom mapping. The following groovy snippet will do the trick. (Remember for groovy code to be executed, the page that contains the code should be saved by a user having the programming right allowed on that document). This could also be done in a Java plugin too.

<%
import java.util.*;
classDoc = xwiki.getDocument("Mailing.MailingMemberClass")
classDoc2 = classDoc.document
println "Before: "
println classDoc2.xWikiClass.customMapping
classDoc2.xWikiClass.setCustomMapping("internal")
xwiki.xWiki.saveDocument(classDoc2, context.context)
classDoc = xwiki.getDocument("Mailing.MailingMemberClass")
println " After: "
println classDoc2.xWikiClass.customMapping
%>
Version 3.1 last modified by VincentMassol on 10/12/2007 at 16:35

Comments 0

No comments for this document

Attachments 2

BIN
custommapping.xar 1.2
PostedBy: jvdrean on 10/12/2007 (4kb )
XML
mailing.hbm.xml 1.2
PostedBy: slauriere on 10/12/2007 (1kb )

Creator: jvdrean on 2007/10/31 18:25
This wiki is licensed under a Creative Commons license
1.5.2.12758