Listing Entity Column’s Details in Table

Visual Paradigm support model database schema with Entity Relationship Diagram (ERD). In this article we will create custom template to output all columns in entity in tabular form. To do this:

  1. Go to Tools > Composer.

    Open Doc. Composer

    Open Doc. Composer

  2. Select Build Doc. From Scratch.

    Select Build Doc. from Scratch

    Select Build Doc. from Scratch

  3. Press the Document Properties button to open the Document Properties dialog.

    Open Document Properties

    Open Document Properties

  4. Switch to Page Setup tab and change the Page Orientation to Landscape. Press OK to close the dialog.

    Change page orientation to landscape

    Change page orientation to landscape

  5. Select entity in Model Explorer tree.

    Select Entity in Model Explorer

    Select Entity in Model Explorer

  6. Right click on any template in Template pane and select Duplicate from popup menu.

    Duplicate a template

    Duplicate a template

  7. Name the template as Columns Table.

    Name the template as Columns Table

    Name the template as Columns Table

  8. Replace the content of the template as follow.
    <?xml version="1.0" encoding="UTF-8"?>
    <ElementBaseInitiationBlock>
      
      <!-- Basic -->
      <Inline template="Basic (with anchor mark)"/>
        
      <!-- Columns (Details) -->
      <HasChildElementChecker modelType="DBColumn">
        <Text style="@heading+">Column Details</Text>
        <ParagraphBreak/>
        
        <TableBlock colWidths="10, 10, 10, 10, 10, 10, 10, 10, 10, 10" repeatTableHeader="false" tableStyle="summaries">
          <TableRow>
            <TableCell><Text>Name</Text></TableCell>
            <TableCell><Text>Type</Text></TableCell>
            <TableCell><Text>UserType</Text></TableCell>
            <TableCell><Text alignment="center">Length</Text></TableCell>
            <TableCell><Text alignment="center">Scale</Text></TableCell>
            <TableCell><Text alignment="center">Primary Key</Text></TableCell>
            <TableCell><Text alignment="center">Foreign Key</Text></TableCell>
            <TableCell><Text alignment="center">Nullable</Text></TableCell>
            <TableCell><Text alignment="center">Unique</Text></TableCell>
            <TableCell><Text alignment="center">Index</Text></TableCell>
          </TableRow>
          <IterationBlock modelType="DBColumn">
            <Sortings noSort="true"/>
            <TableRow>
              <TableCell><Property property="name"/></TableCell>
              <TableCell><Property property="type"/></TableCell>
              <TableCell>
                <HasValueChecker flag="true" property="userTypes">
                  <ForEach property="userTypes">
                    <Property property="type"/>
                  </ForEach>
                </HasValueChecker>
              </TableCell>
              <TableCell><Property  alignment="center" property="length"/></TableCell>
              <TableCell><Property  alignment="center" property="scale"/></TableCell>
              <TableCell>
                <ValueChecker operator="equals" property="primaryKey" value="true">
                  <Text alignment="center">T</Text>
                </ValueChecker>
              </TableCell>
              <TableCell>
                <ValueChecker operator="equals" property="foreignKey" value="true">
                  <Text alignment="center">T</Text>
                </ValueChecker>
              </TableCell>
              <TableCell verticalAlignment="center">
                <ValueChecker operator="equals" property="nullable" value="true">
                  <Text alignment="center">T</Text>
                </ValueChecker>
              </TableCell>
              <TableCell verticalAlignment="center">
                <ValueChecker operator="equals" property="unique" value="true">
                  <Text alignment="center">T</Text>
                </ValueChecker>
              </TableCell>
              <TableCell verticalAlignment="center">
                <ValueChecker operator="equals" property="index" value="true">
                  <Text alignment="center">T</Text>
                </ValueChecker>
              </TableCell>
            </TableRow>
          </IterationBlock>		
        </TableBlock>
        
      </HasChildElementChecker>
      
    </ElementBaseInitiationBlock>
  9. Press Save button and close the Edit Template dialog.
  10. Drag the Columns Table template into document editor.

    Drag template into document

    Drag template into document

Now the columns of the entity are being outputted in tubular form.

Columns show in table

Columns show in table

Explanation of the template

This template is created under entity model which means its scope is already on entity (DBTable). We first output its basic info such as name and description using the default Basic template.

<?xml version="1.0" encoding="UTF-8"?>
<ElementBaseInitiationBlock>
  
  <!-- Basic -->
  <Inline template="Basic (with anchor mark)"/>

After that we check is the entity contains any columns (DBColumn). If it containing column(s) then we create a table to list out its details.

<!-- Columns (Details) -->
<HasChildElementChecker modelType="DBColumn">
  <Text style="@heading+">Column Details</Text>
  <ParagraphBreak/>
  
  <TableBlock colWidths="10, 10, 10, 10, 10, 10, 10, 10, 10, 10" repeatTableHeader="false" tableStyle="summaries">
    <TableRow>
      <TableCell><Text>Name</Text></TableCell>
      <TableCell><Text>Type</Text></TableCell>
      <TableCell><Text>UserType</Text></TableCell>
      <TableCell><Text alignment="center">Length</Text></TableCell>
      <TableCell><Text alignment="center">Scale</Text></TableCell>
      <TableCell><Text alignment="center">Primary Key</Text></TableCell>
      <TableCell><Text alignment="center">Foreign Key</Text></TableCell>
      <TableCell><Text alignment="center">Nullable</Text></TableCell>
      <TableCell><Text alignment="center">Unique</Text></TableCell>
      <TableCell><Text alignment="center">Index</Text></TableCell>
    </TableRow>

In the table we loop through all the columns in the entity and output the properties in the column. We first output the column’s name and data type.

<IterationBlock modelType="DBColumn">
  <Sortings noSort="true"/>
  <TableRow>
    <TableCell><Property property="name"/></TableCell>
    <TableCell><Property property="type"/></TableCell>

Next we check is the column having any User Type (DBColumnUserType) defined. If it’s being defined then we retrieve its value and output to table.

<TableCell>
  <HasValueChecker flag="true" property="userTypes">
    <ForEach property="userTypes">
      <Property property="type"/>
    </ForEach>
  </HasValueChecker>
</TableCell>

After that we output the values for the length and scale of the column.

<TableCell><Property  alignment="center" property="length"/></TableCell>
<TableCell><Property  alignment="center" property="scale"/></TableCell>

Next we check is the column is primary key, foreign key, unique, nullable and index. If criteria match then we mark it as T.

<TableCell>
  <ValueChecker operator="equals" property="primaryKey" value="true">
    <Text alignment="center">T</Text>
  </ValueChecker>
</TableCell>
<TableCell>
  <ValueChecker operator="equals" property="foreignKey" value="true">
    <Text alignment="center">T</Text>
  </ValueChecker>
</TableCell>
<TableCell verticalAlignment="center">
  <ValueChecker operator="equals" property="nullable" value="true">
    <Text alignment="center">T</Text>
  </ValueChecker>
</TableCell>
<TableCell verticalAlignment="center">
  <ValueChecker operator="equals" property="unique" value="true">
    <Text alignment="center">T</Text>
  </ValueChecker>
</TableCell>
<TableCell verticalAlignment="center">
  <ValueChecker operator="equals" property="index" value="true">
    <Text alignment="center">T</Text>
  </ValueChecker>
</TableCell>

 

Related Know-how

Related Link

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply