Changes for page Custom Mapping

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

<
From version < 4.1 >
edited by Caleb James DeLisle
on 2012/02/13
To version < 5.2 >
edited by Vincent Massol
on 2012/02/14
>
Change comment: Fix indentation

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.CalebJamesDeLisle
1 +XWiki.VincentMassol
Content
... ... @@ -32,20 +32,27 @@
32 32  {{/code}}
33 33  )))
34 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 -
35 +(((
36 36  {{code language="java"}}
37 37  {{groovy}}
38 38  classDocumentName = "Mailing.MailingMemberClass";
39 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.");
40 +xml = classDoc.getxWikiClassXML();
41 +if (xml == null || "".equals(xml)) {
42 + println("The document [" + classDocumentName + "] doesn't seem to "
43 + + ((classDoc.isNew()) ? "exist." : "contain a class."));
45 45  } else {
46 - println("Failed to alter the custom mapping field.");
45 + classDoc.getxWikiClass().setCustomMapping("internal");
46 + xcontext.getContext().getWiki().saveDocument(classDoc, xcontext.getContext());
47 + classDoc = xwiki.getDocument(classDocumentName).getDocument();
48 + if ("internal".equals(classDoc.getxWikiClass().getCustomMapping())) {
49 + println("Success.");
50 + } else {
51 + println("Failed to alter the custom mapping field.");
52 + }
47 47  }
48 48  {{/groovy}}
49 49  {{/code}}
56 +)))
50 50  
51 51  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