Attribute or Data Type Conversion
(Created page with "Evolving from one data type to another is not automatically due to the side effects of conversions. Mdriven provides different options for converting data types, # Using FormerNames property setting. # Using a method. # Using derived attributes (Recommended). # Using SafeCast. === Important to know before performing a conversion === * Data conversions have to be done meticulously that as they can result in data loss. Backup your database before performing any conver...")
 
No edit summary
 
(20 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Evolving from one data type to another is not automatically due to the side effects of conversions.  
Evolving from one data type to another is not automatically available in MDriven due to the side effects of conversions.  


Mdriven provides different options for converting data types,
MDriven provides different options for converting data types:


# Using FormerNames property setting.
# Using the FormerNames property setting.
# Using a method.
# Using a method.
# Using derived attributes (Recommended).
# Using derived attributes.
# Using SafeCast.
# Using [[Documentation:OCLOperators safeCast|SafeCast]].


=== Important to know before performing a conversion ===
=== Important to know before performing a conversion ===


* Data conversions have to be done meticulously that as they can result in data loss. Backup your database before performing any conversions.
* Data conversions have to be done meticulously as they can result in data loss. <u>Backup your database</u> before performing any conversions.


=== Using FormerNames property setting ===
=== Using the FormerNames Property Setting ===
- Set New Type on Attribute
This solution involves renaming the attribute.


- The easiest way to use this is using the rename option
# Set new type on attribute.
# Rename the attribute to a new name and make sure to check Set Former Name checkbox.
#* When you rename an attribute, the previous attribute will be dropped or destroyed when the attribute with a new name is created. Checking the Set Former Name checkbox will add the previous attribute name in the Database property setting FormerNames.
# Upload model. The MDriven evolver will try to transform and transfer the transformed data from the old attribute to the new attribute.
# After checking and making sure the data has been successfully transformed, repeat step 2 and step 3, renaming the attribute to its previous name.


- Rename the attribute to a new name and make sure to check Set Former Name checkbox
<br />Example showing conversion of a '''Price''' attribute from '''Integer''' to '''Decimal'''.    [[File:Using-former-names-property.png|alt=Using FormerNames Property|none|thumb|785x785px]]
[[File:rename-attribute-window.png|alt=Rename Attribute Window Settings|none|thumb|789x789px]]


   When you rename an attribute, the previous attribute will be dropped or destroyed and attribute with new name is created.
=== Using a Method ===
Using a method can be more useful in scenarios where you want to be more explicit about your conversion or want to combine the data of two attributes into one.  


   Checking the Set Former Name checkbox will add the previous attribute name in the Database property setting FormerNames.
# Create new attribute and set new type on attribute
# Add a method to the class, go to method body and use [[Documentation:EAL – ExtendedActionLanguage.|EAL expressions]] for your transformation for the new attribute.
# While the Turnkey and Server applications are running, open the [[Documentation:Ocl debugger|debugger]].
# Run method in Action mode for the instances you would like to perform transformations on.
# Don't forget to save after executing the expression.
# The new attribute with the new type can now be used within the ViewModels. Or, the current attribute can be renamed to something else using method 1 of the FormerNames property setting and the new attribute with preferred type can use the name available in the ViewModels. This eliminates the need to make changes to ViewModels.


- Upload model
For example - below, after preforming the transformations, set the '''Price''' attribute to maybe '''OldPrice''' and set new attribute '''xPrice''' to '''Price'''.


   MDriven evolver will try to transform to transfered and transform data from the old attribute to the new attribute.
<br />Example showing how to convert a '''Price''' attribute from '''Integer''' to '''Decimal''' type and increment price by 1000


   After checking and making sure the data has been successfully transformed. rename the attribute to its previous name and
[[File:using-a-method-for-data-conversion.png|alt=Using a Method for Data Conversion|none|thumb|700x700px]]
[[File:using-ocl-debugger-to-run-method-transformation.png|alt=Using OCL debugger to run method transformations|none|thumb|734x734px]]


   make sure to check Set Former Name checkbox. and upload the model
=== Using Derived Attributes ===
Using [[Training:Derived attributes & associations|derived attributes]] ensures there are no side effects on your data. With this option, current data is retained and you can try other data conversions and transformations without affecting the data. Derived attributes provide a simpler way to test and use new data types and transformations. They are easy to create and remove.


Conversions are not automatically available in mdriven
You can use the new data attributes with the old data type attributes, incase you change your mind. Just delete the new derived attribute and continue using your old data type attribute. 


=== Using Method ===
* Deleting a derived attribute will not have any effect on your data in the database.
- Using a method can be more useful in scenarios where you want to be more explicit about your conversion or want to combine data of  
* Derived attributes ensure that current data is retained in  its state of truthfulness and the new type is also available.
* Derived attributes can also be used for complex transformations.


   two attributes into one
<br />Example showing how to convert '''Price''' attribute from '''Integer''' to '''Decimal''' type and increment price by 1000[[File:using-derived-attributes.png|alt=Using Derived Attributes|none|thumb|744x744px]]


- Start by adding a method to a class
=== Summary ===


- Goto method body and use EAL expressions for your transformation.
* Use derived attributes to test new data types or new attributes and tranformations.
* Use methods for more explicit conversions like combining the data of two attributes or other computations.
* Use the FormerNames property setting after testing to make the new attributes and types changes permanent.


- Open debugger
==== See also: ====


- Run method in Action mode for the instances you would like to peform transformations on
* [[Training:Derived attributes & associations|Derived attributes & associations]]
 
* [[Documentation:EAL – ExtendedActionLanguage.|EAL – ExtendedActionLanguage.]]
- Dont forget to save after executing the expression
* [[Documentation:Learn OCL|Learn OCL]]
 
* [[Documentation:Ocl debugger|Ocl debugger]]
=== Using Derived Attributes (Recommended) ===
- Using derived attributes ensures there are no side effects on your data. With this option current data is retained and your to
 
   try other data conversions and transformations without affecting the data.
 
- You can use the new data attributes with the old data types incase you change your mind, just delete the new derived attribute
 
   and continue using your old data type. Deleting a derived attribute will not have any effect on your data in the database.
 
- Use derived attributes to also test out other transformations with out side effects.
 
- Use derived attributes to test new types or other types - ensures that data is retained and new type is also available
 
- Derived attributes can also be used for complex transformations

Latest revision as of 05:37, 26 July 2024

Evolving from one data type to another is not automatically available in MDriven due to the side effects of conversions.

MDriven provides different options for converting data types:

  1. Using the FormerNames property setting.
  2. Using a method.
  3. Using derived attributes.
  4. Using SafeCast.

Important to know before performing a conversion

  • Data conversions have to be done meticulously as they can result in data loss. Backup your database before performing any conversions.

Using the FormerNames Property Setting

This solution involves renaming the attribute.

  1. Set new type on attribute.
  2. Rename the attribute to a new name and make sure to check Set Former Name checkbox.
    • When you rename an attribute, the previous attribute will be dropped or destroyed when the attribute with a new name is created. Checking the Set Former Name checkbox will add the previous attribute name in the Database property setting FormerNames.
  3. Upload model. The MDriven evolver will try to transform and transfer the transformed data from the old attribute to the new attribute.
  4. After checking and making sure the data has been successfully transformed, repeat step 2 and step 3, renaming the attribute to its previous name.


Example showing conversion of a Price attribute from Integer to Decimal.

Using FormerNames Property
Rename Attribute Window Settings

Using a Method

Using a method can be more useful in scenarios where you want to be more explicit about your conversion or want to combine the data of two attributes into one.

  1. Create new attribute and set new type on attribute
  2. Add a method to the class, go to method body and use EAL expressions for your transformation for the new attribute.
  3. While the Turnkey and Server applications are running, open the debugger.
  4. Run method in Action mode for the instances you would like to perform transformations on.
  5. Don't forget to save after executing the expression.
  6. The new attribute with the new type can now be used within the ViewModels. Or, the current attribute can be renamed to something else using method 1 of the FormerNames property setting and the new attribute with preferred type can use the name available in the ViewModels. This eliminates the need to make changes to ViewModels.

For example - below, after preforming the transformations, set the Price attribute to maybe OldPrice and set new attribute xPrice to Price.


Example showing how to convert a Price attribute from Integer to Decimal type and increment price by 1000

Using a Method for Data Conversion
Using OCL debugger to run method transformations

Using Derived Attributes

Using derived attributes ensures there are no side effects on your data. With this option, current data is retained and you can try other data conversions and transformations without affecting the data. Derived attributes provide a simpler way to test and use new data types and transformations. They are easy to create and remove.

You can use the new data attributes with the old data type attributes, incase you change your mind. Just delete the new derived attribute and continue using your old data type attribute.

  • Deleting a derived attribute will not have any effect on your data in the database.
  • Derived attributes ensure that current data is retained in its state of truthfulness and the new type is also available.
  • Derived attributes can also be used for complex transformations.


Example showing how to convert Price attribute from Integer to Decimal type and increment price by 1000

Using Derived Attributes

Summary

  • Use derived attributes to test new data types or new attributes and tranformations.
  • Use methods for more explicit conversions like combining the data of two attributes or other computations.
  • Use the FormerNames property setting after testing to make the new attributes and types changes permanent.

See also:

This page was edited 52 days ago on 07/26/2024. What links here