Changes for page Custom Mapping

Last modified by Alex Cotiugă on 2022/10/12

<
From version < 2.2 >
edited by PeterLiverovsky
on 2012/02/13
To version < 4.1 >
edited by Caleb James DeLisle
on 2012/02/13
>
Change comment: fixed script again which was definitely incorrect

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.PeterLiverovsky
1 +XWiki.CalebJamesDeLisle
Content
... ... @@ -31,20 +31,21 @@
31 31  <mapping resource="/some/package/mailinglist.hbm.xml"/>
32 32  {{/code}}
33 33  )))
34 -1. Last, the XClass for which the mapping has been written should be set as containing a custom mapping. Unfortunately there's currently no way to set this using the XWiki Enterprise UI so you'll have to set it programmatically. The following Groovy snippet will do the trick (Remember that 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). Note that this could also be done in a Java component.(((
35 -{{code}}
34 +1. Last, the XClass for which the mapping has been written should be set as containing a custom mapping. Unfortunately there's currently no way to set this using the XWiki Enterprise UI so you'll have to set it programmatically. The following Groovy snippet will do the trick (Remember that 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). Note that this could also be done in a Java component.
35 +
36 +{{code language="java"}}
36 36  {{groovy}}
37 -classDoc = xwiki.getDocument("Mailing.MailingMemberClass")
38 -classDoc2 = classDoc.document
39 -println "Before: "
40 -println classDoc2.xWikiClass.customMapping
41 -classDoc2.xWikiClass.setCustomMapping("internal")
42 -xcontext.getContext().getWiki().saveDocument(classDoc2, xcontext.getContext())
43 -classDoc = xwiki.getDocument("Mailing.MailingMemberClass")
44 -println " After: "
45 -println classDoc2.xWikiClass.customMapping
38 +classDocumentName = "Mailing.MailingMemberClass";
39 +classDoc = xwiki.getDocument(classDocumentName).getDocument();
40 +classDoc.getxWikiClass().setCustomMapping("internal");
41 +xcontext.getContext().getWiki().saveDocument(classDoc, xcontext.getContext());
42 +classDoc = xwiki.getDocument(classDocumentName).getDocument();
43 +if ("internal".equals(classDoc.getxWikiClass().getCustomMapping())) {
44 + println("Success.");
45 +} else {
46 + println("Failed to alter the custom mapping field.");
47 +}
46 46  {{/groovy}}
47 47  {{/code}}
48 -)))
49 49  
50 50  Once these 3 steps have been done, loading and saving of your XClass will go in the table you've defined in your custom Hibernate mapping file.

Get Connected