Page 1 of 1

Is it a package

PostPosted: Tue Sep 12, 2017 8:19 am
by jvernonjpmc
I reverse-engineered an Oracle database schema. The result was the creation of an element that visually looks like a package. It looks like a folder, but it's blue instead of yellow. In it is stored the definition of the tables in the schema.

Which meta-data type is it? I need to report the contents of this, e.g. #foreach($package in $Package) ...

Thank you

Re: Is it a package

PostPosted: Wed Sep 13, 2017 1:18 am
by gedkvi
Hello,

You probably refer to the Schema model element, then its meta-data type is Package.
It is blue in the containment tree because it has a stereotype <<Schema>> applied to it, that modifies the icon to visually represent that it is a schema rather than a simple Package.

This is the description of the Schema stereotype.
schema.png


Sincerely,
No Magic Customer Support

Re: Is it a package

PostPosted: Tue Nov 14, 2017 1:17 pm
by jvernonjpmc
I agree with you that when I look at the specification of stereotype Schema in the SQL Profile, the metaclass is Package.

I have the code below. When I run this against the contents of a UML package instance that contains an instance of View, I get results; when I run it against an instance of Schema that contains an instance of View, I get no results.

#foreach($package in $Package)

#*#Iterate across elements in each package*#
#foreach($element in $package.ownedElement)

#*#Check if the element is a View or Table*#
#if($element.humanType == 'View' || $element.humanType == 'Persistent Table' || $element.humanType == 'Entity')

#*#Iterate across each element in the View / Table*#
#foreach($innerElement in $element.ownedElement)

#*#Check if the element huamtype is a Property*#
#if($innerElement.humanType == 'Column' || $innerElement.humanType == 'Property')

$package.getName()
$element.getName()
$innerElement.getName()
$innerElement.getType()
#end
#end
#end
#end
#end

When I tried to print the human type of the Schema element, the script printed nothing for it.

#foreach($package in $Package)

#*#Iterate across elements in each package*#
#foreach($element in $package.ownedElement)

$package.getName()
$element.getName()
$element.humanName
#end
#end

Re: Is it a package

PostPosted: Wed Nov 15, 2017 8:08 am
by gedkvi
Hello,

Sorry for the confusion, the call that you used was $Package(in your first cycle), thus it returned only package(excluding Schemas). If you change your script to the one provided, everything should work correctly.
Note: if specification window shows "Package" then using $Package, will return these packages. If the windows shows "Schema" then using $Schema will return these schema elements. This is due to the fact that the element is customized in the profile. If an element only has a stereotype(not in your case), then you need to check for stereotype using $report.containsStereotype(element, stereotypeName, includeDerived).

I have modified the script a little.
Code: Select all
#foreach($schema in $Schema)
$schema.getName()
#*#Iterate across elements in each schema*#
#foreach($table in $schema.ownedElement)
#*#Check if the element is a View or Table*#
#if($table.humanType == 'View' || $table.humanType == 'Persistent Table' || $table.humanType == 'Entity')
  $table.getName()
#*#Iterate across each element in the View / Table*#
#foreach($innerElement in $table.ownedElement)
#*#Check if the element huamtype is a Property*#
#if($innerElement.humanType == 'Column' || $innerElement.humanType == 'Property')
    $innerElement.getName() - $innerElement.getType().getName()
#end
#end
#end
#end
#end


The result on sample project are:
Code: Select all
TypeDemoSchema
  Person
    name - varchar
    surname - varchar_of_20
    accountBalance - numeric
TableDemoSchema
  Salesman
    name - varchar
    quota - numeric


You can find more information about Report wizard in the user manual at <program.install.dir>\manual\MagicDraw ReportWizard UserGuide.pdf

Sincerely,
No Magic Customer Support