Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-455

Avoid the need to have to run a custom script to have custom mappings

    XMLWordPrintable

Details

    • New Feature
    • Resolution: Unresolved
    • Major
    • None
    • 1.0 B1
    • Other
    • None

    Description

      Here is the start of a custom mapping generator script that could be added to the developer tools.

      1 Custom Mapping
      
      \{code\}
      <?xml version="1.0"?>
      <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
                  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping>
      <%
       import java.util.*;
      
       list = new ArrayList();
       list.add ("TriniClasses.AdresseClass");
       list = xwiki.searchDocuments("where doc.web='TriniClasses' and doc.name like '%Class'", 0, 0)
       for(className in list) {
        bclassdoc = xwiki.getDocument(className)
        bclass = bclassdoc.xWikiClass
        tableName = bclassdoc.name.substring(0, bclassdoc.name.length()-5).toUpperCase()
        shortName = bclassdoc.name.substring(0,3).toUpperCase()
      %>
      <class entity-name="${className}" table="TRINIDAD_${tableName}">
      <id name="id" type="integer" unsaved-value="any">
      <column name="${shortName}_ID" not-null="true" />
      <generator class="assigned" />
      </id>
      <%
        for(prop in bclass.getProperties()) {
         fieldName = prop.name.toUpperCase()
         if (prop.className=="com.xpn.xwiki.objects.classes.DateClass") {
      %>
      <property name="${prop.name}" type="date">
      <% } else if (prop.className=="com.xpn.xwiki.objects.classes.BooleanClass") { %>
      <property name="${prop.name}" type="integer">
      <% } else if (prop.className=="com.xpn.xwiki.objects.classes.NumberClass") { %>
      <property name="${prop.name}" type="integer">
      <% } else { %>
      <property name="${prop.name}" type="text">
      <% } %>
      <column name="${shortName}_${fieldName}" /></property><% } %>
      </class>
      <%
       }
      %>
      </hibernate-mapping>
      \{code\}
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            ludovic Ludovic Dubost
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: