Output Entity’s Sample Data using Doc. Composer

There is one special feature in Visual Paradigm’s Entity Relationship Diagram which is allow user defining sample data along with the entity model. This allow Visual Paradigm’s engine not just generate database schema from model, but also insert sample data into database so that user can immediately trying on the database. With both schema and sample data store together user do not need to have different storage to maintain testing data for his database. The sample data can be output to document using Doc. Composer. To output the sample data:

  1. Go to Tools > Doc. Composer.

    Open Doc. Composer

    Open Doc. Composer

  2. Select Build Doc. From Scratch.

    Select Build Doc. from Scratch

    Select Build Doc. from Scratch

  3. Select entity in Model Explorer tree.

    Select Entity in Model Explorer

    Select Entity in Model Explorer

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

    Duplicate a template

    Duplicate a template

  5. Name the template as Sample Records.

    Name the template as Sample Records

    Name the template as Sample Records

  6. Replace the content of the template as follow.
    <?xml version="1.0" encoding="UTF-8"?>
    <ElementBaseInitiationBlock>
      
      <Icon/>
      <Property property="name" style="Title"/>
      <ParagraphBreak/>
      <Text style="Intense Quote">Sample Records</Text>
      <TableBlock tableStyle="Summaries">
        <TableRow>
          <IterationBlock modelType="DBColumn">
            <TableCell>
              <Property property="name"/>
            </TableCell>
          </IterationBlock>
        </TableRow>
    
        <ModelElementProperty property="records">
          <IterationBlock modelType="EntityRecord">
            <Sortings noSort="true"/>
            <TableRow>
              <IterationBlock modelType="EntityRecordCell">
                <TableCell>
                  <ModelElementPropertyConditionChecker property="value">
                    <Conditions>
                      <ValueChecker property="modelType" value="EntityRecordCell"/>
                    </Conditions>
                    <ModelElementProperty property="value">
                      <Property property="value"/>
                    </ModelElementProperty>
                  </ModelElementPropertyConditionChecker>
                  <ValueChecker property="value" value="unnamed" operator="not equals">
                   <Property property="value"/>
                  </ValueChecker>
                </TableCell>
              </IterationBlock>
            </TableRow>
          </IterationBlock>
        </ModelElementProperty>
      </TableBlock>
      
    </ElementBaseInitiationBlock>
  7. Press Save button and close the Edit Template dialog.
  8. Drag the Sample Records template into document editor.

    Drag the template into document editor

    Drag the template into document editor

Now the sample record of the entity are being listed in Doc. Composer.

Sample data outputted to document editor

Sample data outputted to document editor

Explanation of the Template

This template is created under entity model which means its scope is already on entity (DBTable). We first output the icon & name of the entity.

<?xml version="1.0" encoding="UTF-8"?>
<ElementBaseInitiationBlock>
  
  <Icon/>
  <Property property="name" style="Title"/>
  <ParagraphBreak/>
  <Text style="Intense Quote">Sample Records</Text>

After that we create a table and list out its columns as the header.

<TableBlock tableStyle="Summaries">
  <TableRow>
    <IterationBlock modelType="DBColumn">
      <TableCell>
        <Property property="name"/>
      </TableCell>
    </IterationBlock>
  </TableRow>

Next we load the sample data. They are stored under the following structure.

DBTable > records (EntityRecordContainer) > children (EntityRecord) > children (EntityRecordCell)

We will use the ModelElementProperty node to retrieve the record property from DBTable, then using nested IterationBlock to load the EntityRecord and EntityRecordCell and finally reaching the value. The value is an object and we then need to determine it is associated to the foreign key column or it’s already the actual value. If it is associated with a foreign key then the value property of EntityRecordCell will return “unnamed”. We therefore use the ValueChecker to check on this. If it not return “unnamed” we then print out the value, otherwise we retrieve the value object using ModelElementProperty tag and print out its actual value.

<ModelElementProperty property="records">
  <IterationBlock modelType="EntityRecord">
    <Sortings noSort="true"/>
    <TableRow>
      <IterationBlock modelType="EntityRecordCell">
        <TableCell>
          <ModelElementPropertyConditionChecker property="value">
            <Conditions>
              <ValueChecker property="modelType" value="EntityRecordCell"/>
            </Conditions>
            <ModelElementProperty property="value">
              <Property property="value"/>
            </ModelElementProperty>
          </ModelElementPropertyConditionChecker>
          <ValueChecker property="value" value="unnamed" operator="not equals">
            <Property property="value"/>
          </ValueChecker>          
        </TableCell>
      </IterationBlock>
    </TableRow>
  </IterationBlock>
</ModelElementProperty>

 

Related Know-how

Related Link

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply