/[volute]/trunk/projects/theory/snapdm/res/intermediate2ddl.xsl
ViewVC logotype

Diff of /trunk/projects/theory/snapdm/res/intermediate2ddl.xsl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 342 by gerard.lemson, Sun Apr 27 20:13:17 2008 UTC revision 343 by gerard.lemson, Wed Apr 30 16:30:47 2008 UTC
# Line 4  Line 4 
4  intermediate representation to a relational database  intermediate representation to a relational database
5  Data Definition Language script.  Data Definition Language script.
6    
7  It depends on our assumed object-relational mapping  By default we use the "joined" object-relational mapping strategy.
8  prescription and should be compatible with the persistence  That is, each objectType has a table of its own, in which only those features defined on
9  framework used for example in the Java/JPA generation.  the objectType are mapped to columns, the  inherited are mapped by base classes.
10    
11  We also generate view definitions representing each objectType.  We also generate view definitions representing each objectType.
12    
# Line 38  Line 38 
38        
39    <xsl:param name="schema"/> <!--  select="'SNAP.'" -->    <xsl:param name="schema"/> <!--  select="'SNAP.'" -->
40        
   <!-- define the OR mapping strategy -->  
   <xsl:variable name="ORMapping_hierarchical" select="'hierarchical'"/>    
   <xsl:variable name="ORMapping_joined" select="'joined'"/>    
   <xsl:variable name="ORMapping_class" select="'class'"/>    
   <xsl:param name="ORMapping" select="$ORMapping_joined"/>  
41        
42  <!-- Define parameters/variables that can be reused in this script an in others using it (JPA) -->  <!-- Define parameters/variables that can be reused in this script an in others using it (JPA) -->
43    <!-- next two might also be parameters, or obtained from a config file -->    <!-- next two might also be parameters, or obtained from a config file -->
# Line 51  Line 46 
46    
47    <xsl:variable name="discriminatorColumnName" select="'DTYPE'"/>    <xsl:variable name="discriminatorColumnName" select="'DTYPE'"/>
48    <xsl:variable name="discriminatorColumnLength" select="'128'"/>    <xsl:variable name="discriminatorColumnLength" select="'128'"/>
49    <xsl:variable name="discriminatorColumnType">    <xsl:variable name="discriminatorColumnType"> varchar(<xsl:value-of select="$discriminatorColumnLength"/>) </xsl:variable>  
     varchar(<xsl:value-of select="$discriminatorColumnLength"/>)  
   </xsl:variable>    
50        
51    <xsl:variable name="primaryKeyColumnName" select="'ID'"/>    <xsl:variable name="primaryKeyColumnName" select="'ID'"/>
52        
# Line 61  Line 54 
54        
55    <!-- start -->    <!-- start -->
56    <xsl:template match="/">    <xsl:template match="/">
57      <xsl:apply-templates select="model"/>      <xsl:apply-templates select="model" mode="tables"/>
58    </xsl:template>    </xsl:template>
59        
60        
61        
62        
63    <xsl:template match="model">    <xsl:template match="model" mode="dropTables">
64        <xsl:apply-templates select=".//objectType" mode="droptable"/>
65      </xsl:template>  
66      
67      
68    
69    
70      <xsl:template match="model" mode="tables">
71      <xsl:message>Model = <xsl:value-of select="name"></xsl:value-of></xsl:message>      <xsl:message>Model = <xsl:value-of select="name"></xsl:value-of></xsl:message>
72            
73      -- last modification date of the UML model <xsl:value-of select="$lastModified"/>&cr;      -- last modification date of the UML model <xsl:value-of select="$lastModified"/>&cr;
74              <xsl:apply-templates select=".//objectType" mode="joined"/>
     <xsl:choose>  
       <xsl:when test="$ORMapping = $ORMapping_joined">  
         <xsl:apply-templates select=".//objectType" mode="joined"/>  
       </xsl:when>  
       <xsl:otherwise>  
         <xsl:apply-templates select=".//objectType[not(extends)]" mode="hierarchical"/>  
       </xsl:otherwise>  
     </xsl:choose>  
75            
76    </xsl:template>      </xsl:template>  
77    
78    
79    
80        
81        <xsl:template match="objectType">
     
     
   <xsl:template match="objectType" mode="hierarchical">  
     <!-- generate a single table for the whole object hierarchy below the matched objectType -->  
     <xsl:variable name="tableName">  
       <xsl:apply-templates select="." mode="tableName"/>  
     </xsl:variable>  
     <xsl:variable name="containers">  
     </xsl:variable>  
     CREATE TABLE <xsl:value-of select="$tableName"/> (  
     id bigint not null  
     <xsl:apply-templates select="." mode="discriminatorColumnDeclaration"/>  
     <xsl:apply-templates select="." mode="containers"/>  
     <xsl:apply-templates select="." mode="hierarchy"/>  
     );&cr;&cr;  
   </xsl:template>  
     
     
     
     
   <xsl:template match="objectType" mode="containers">  
     <xsl:variable name="xmiid" select="@xmiid"/>  
     <xsl:if test="/model//objectType[collection/datatype/@xmiidref = $xmiid]">  
       , containerId bigint not null -- <xsl:value-of select="/model//objectType[collection/datatype/@xmiidref = $xmiid]/name"/>  
     </xsl:if>  
     <xsl:apply-templates select="/model//objectType[extends/datatype/@xmiidref = $xmiid]" mode="containers"/>  
   </xsl:template>    
     
     
     
     
   <xsl:template match="objectType" mode="hierarchy">  
     <xsl:variable name="xmiid" select="@xmiid"/>  
     -- fields from <xsl:value-of select="name"/>  
     <xsl:apply-templates select="attribute" />  
     <xsl:apply-templates select="reference" />  
     <xsl:apply-templates select="/model//objectType[extends/datatype/@xmiidref = $xmiid]" mode="hierarchy"/>  
   </xsl:template>  
     
     
     
     
   <xsl:template match="objectType" mode="joined">  
82      <!-- generate a single table for the whole object hierarchy below the matched objectType -->      <!-- generate a single table for the whole object hierarchy below the matched objectType -->
83      <xsl:variable name="tableName">      <xsl:variable name="tableName">
84        <xsl:apply-templates select="." mode="tableName"/>        <xsl:apply-templates select="." mode="tableName"/>
85      </xsl:variable>      </xsl:variable>
86      <xsl:variable name="containers">  CREATE TABLE <xsl:value-of select="$tableName"/> (
87      </xsl:variable>    id bigint not null
88      CREATE TABLE <xsl:value-of select="$tableName"/> (  <xsl:if test="not(extends)"><xsl:apply-templates select="." mode="discriminatorColumnDeclaration"/></xsl:if>
89      id bigint not null  <xsl:apply-templates select="." mode="container"/>
90      <xsl:if test="not(extends)">  <xsl:apply-templates select="attribute" />
91      <xsl:apply-templates select="." mode="discriminatorColumnDeclaration"/>  <xsl:apply-templates select="reference" />);&cr;&cr;
     </xsl:if>  
     <xsl:apply-templates select="." mode="container"/>  
     <xsl:apply-templates select="attribute" />  
     <xsl:apply-templates select="reference" />);&cr;&cr;  
92    </xsl:template>    </xsl:template>
93        
94        
95        
96        <!-- determine whether there is a class that contains this class.
97      If so generate a containerID column.
98      NOTE we should ensure that there is only 1  -->
99    <xsl:template match="objectType" mode="container">    <xsl:template match="objectType" mode="container">
100      <xsl:variable name="xmiid" select="@xmiid"/>      <xsl:variable name="xmiid" select="@xmiid"/>
101      <xsl:if test="/model//objectType[collection/datatype/@xmiidref = $xmiid]">, containerId bigint not null -- <xsl:value-of select="/model//objectType[collection/datatype/@xmiidref = $xmiid]/name"/>&cr;      <xsl:if test="/model//objectType[collection/datatype/@xmiidref = $xmiid]">, containerId bigint not null -- <xsl:value-of select="/model//objectType[collection/datatype/@xmiidref = $xmiid]/name"/>&cr;
# Line 171  Line 121 
121            
122      <xsl:choose>      <xsl:choose>
123        <xsl:when test="datatype/@class"><xsl:apply-templates select="key('element',datatype/@xmiidref)" mode="columns"><xsl:with-param name="prefix" select="$columnname"/></xsl:apply-templates></xsl:when>        <xsl:when test="datatype/@class"><xsl:apply-templates select="key('element',datatype/@xmiidref)" mode="columns"><xsl:with-param name="prefix" select="$columnname"/></xsl:apply-templates></xsl:when>
         
124        <xsl:otherwise>        <xsl:otherwise>
125          <xsl:variable name="sqltype">          <xsl:variable name="sqltype">
126            <xsl:call-template name="sqltype">            <xsl:call-template name="sqltype">
# Line 257  Line 206 
206        
207    <!-- We need lengths for (var)char datatypes -->    <!-- We need lengths for (var)char datatypes -->
208    <xsl:template match="*/enumeration" mode="columns">    <xsl:template match="*/enumeration" mode="columns">
209      <xsl:param name="prefix"/>      <xsl:param name="prefix"/>, <xsl:value-of select="$prefix"/> varchar(256) -- <xsl:value-of select="name"/>&cr;
     , <xsl:value-of select="$prefix"/> varchar(256) -- <xsl:value-of select="name"/>&cr;  
210    </xsl:template>    </xsl:template>
211        
212        
# Line 283  Line 231 
231        
232        
233        
   <xsl:template name="combineNullity">  
     <xsl:param name="first"/>  
     <xsl:param name="second"/>  
     <xsl:choose>  
       <xsl:when test="$first = 'not null' and $second = 'not null'"><xsl:value-of select="'not null'"/></xsl:when>  
       <xsl:otherwise><xsl:value-of select="'null'"/></xsl:otherwise>  
     </xsl:choose>  
   </xsl:template>  
     
     
     
234        
235    <!-- TODO    <!-- TODO
236    Add templates retrieving for a given objectType the table it is in    Add templates retrieving for a given objectType the table it is in
# Line 317  Line 254 
254    
255    
256  <!-- Discriminator column templates -->  <!-- Discriminator column templates -->
257    <xsl:template match="objectType" mode="discriminatorColumnDeclaration">    <xsl:template match="objectType" mode="discriminatorColumnDeclaration">, <xsl:value-of select="$discriminatorColumnName"/> <xsl:value-of select="$discriminatorColumnType"/>&cr;
 ,   <xsl:value-of select="$discriminatorColumnName"/> <xsl:value-of select="$discriminatorColumnType"/>)  
258    </xsl:template>    </xsl:template>
259        
260    

Legend:
Removed from v.342  
changed lines
  Added in v.343

msdemlei@ari.uni-heidelberg.de
ViewVC Help
Powered by ViewVC 1.1.26