Copy Model declaration


SYNTAX:
copy_model = COPY_MODEL [ exclusive_clause | inclusive_clause ]  rename_entity_clause END_COPY_MODEL ';' .
exclusive_clause = EXCLUDE '(' [ SUBTYPE ] extended_entity_id  { ',' [ SUBTYPE ] extended_entity_id } ')' ';' .
inclusive_clause = INCLUDE '(' [ SUBTYPE ] extended_entity_id  { ',' [ SUBTYPE ] extended_entity_id } ')' ';' .
rename_entity_clause = RENAME_ENTITY entity_id [ AS new_entity_id ] ';'  rename_attribute_clause END_RENAME_ENTITY ';' .
rename_attribute_clause = [ { attribute_id AS new_attribute_id ';' } ] .
new_entity_id = entity_id .
new_attribute_id = attribute_id .
 
The COPY MODEL declaration is specially designed for mapping data between different versions of the same schema or between schemata that have parts that are very similar.
The COPY MODEL declaration begins with the keyword COPY_MODEL optionally followed by either an exclusive clause or an inclusive clause, i.e. the inclusive clause and the exclusive clause are mutually exclusive.
An exclusive clause begins with the keyword EXCLUDE followed by a list of one or more extended entity references within parentheses. Each extended entity reference is separated by a comma, and the exclusive clause ends with a semicolon. Each extended entity reference can optionally be preceded by the keyword SUBTYPE to exclude all subtype instances of the types in the exclude list.
The inclusive clause is exactly like the exclusive clause except that it starts with the INCLUDE keyword.
The optional exclusive/inclusive clauses can optionally be followed by one or more rename entity clauses. A rename entity clause begins with the keyword RENAME_ENTITY followed by the name of an entity in the source schema, followed by the keyword AS and the new name of the actual entity in the target schema. The rename entity clause can optionally contain one or more rename attribute clauses. A rename attribute clause begins with the name of the attribute in the source schema followed by the keyword AS and the new name of the attribute in the target schema. The keyword END_RENAME_ENTITY terminates a rename entity clause.
In addition to entities that are renamed in the entity clause, the COPY MODEL construct will copy all instances of entities that have the same entity name in the source schema as in the target schema from the source model to the target model. Values of attributes that have the same name in the target schema as in the source schema as well as values of attributes that are specified in the rename attribute clause, will be copied from the source model to the target model. Note that the target attribute data type has to be assignment compatible with the source attribute data type, otherwise the attribute value will not be copied. Other attributes of the target model will not be initialized by the copy model declaration. Uninitialized attributes have the value indeterminate, i.e. unset.
The optional exclusive clause is used to specify which instances that should not be copied from the source model to the target model. That is, all instances of types that have the same name in the target model as in the source model as well as entities specified in a rename entity clause, will be copied, as long as they are not specified in an exclusive clause.
When an optional inclusive clause is specified, only the instances of types listed in the inclusive clause will be copied from the source model to the target model.
The COPY MODEL declaration can be followed by any MAP, COMPOSE, and other declarations for completing the data mapping.
Example:
SCHEMA_MAP anExample;
 
GLOBAL
 DECLARE source INSTANCE OF SOURCE_SCHEMA APXX_V1;
 DECLARE target INSTANCE OF TARGET_SCHEMA APXX_V2;
END_GLOBAL;
 
COPY_MODEL
 (* Specify instance types to be copied *)
 INCLUDE (Part, SUBTYPE Assembly, SUBTYPE Thing);
 RENAME_ENTITY Part AS NewPart;
  AttributeA AS NewAttributeA;
  AttributeB AS NewAttributeB;
 END_RENAME_ENTITY;
 RENAME_ENTITY Thing; -- Only attributes in Thing is renamed
  ThingAttrA AS ThingAttr1;
  ThingAttrB AS ThingAttr2;
 END_RENAME_ENTITY;
END_COPY_MODEL;
. . .
(* Any number of MAP and/or COMPOSE declarations
 can follow a COPY MODEL declaration *)
. . .
END_SCHEMA_MAP;