Synchronization between code and model in Visual Paradigm - uml

I create a class diagram and then generate their code by Visual Paradigm.
I have inserted a lot of code into generated classes and now I need to update the model. but I would like to perform updating through Visual Paradigm for easiness.
if I update my model and then generate classes and replace them on current classes I will lose my codes.
how could I insert my code in the model to keep and maintain them after generating classes code in the model?
I could update classes and then update the model by them, but updating in the model is more simple and I want to update my model first and then update my classes based on new model and keep classes implementation codes as well.
solved :
in roundtrip, changes will be merged(not overwrites) and codes in the class file will be maintained. so I should update the model and start roundtrip on the existing file to merge new model element in the existing model element and codes.

You want to update your model to reflect the changes done in the sources, that means update classes already defined in your model, add new classes in sources not yet defined in your model, delete classes existing in the model but not anymore present in the sources.
All of that is a "roundtrip" (from sources), which must not be confused with the "reverse" (from sources) which does not update elements in the model but creates elements without considering the fact they already exist or not in the model.
It seems you can do that in Visual Paradigm (even the way to do seems strange for me because starting by a reverse) :
for Java (https://www.visual-paradigm.com/support/documents/vpuserguide/276/381/7530_generateorup.html)
for C++ ( https://www.visual-paradigm.com/support/documents/vpuserguide/276/501/28170_generateorup.html)
I encourage you to learn how to do using a new dedicated model / sources just made for that purpose, to not take the risk to destruct your existing model/sources by error

Related

Core data mapping model with new (non-optional) relationship

My original data model has an entity "Game". I have now updated the model to include an entity, "Match", which can refer to multiple games. I wish to add a Match to all of my old Games, and ideally this would be a non-optional relationship.
Currently I am setting Match to be optional, and simply adding a Match to every old Game in application:didFinishLaunching after the model has been updated. This works, but I'm wondering if this is really the best way to do it.
I have tried to follow the tutorial here, but I am getting stuck on the part with "StepOneEntityMigrationPolicy.m". I have created an NSEntityMigrationPolicy subclass and set it in the mapping model. I've tried overriding both createDestinationInstancesForSourceInstance and createRelationshipsForDestinationInstance:, but neither get called.
Is this perhaps because my Source and Destination are both the same (GameToGame)? Also, is there any benefit to doing this via the mapping model rather than as I am doing it now?
I think the simplest and most pragmatic way is what you are doing now, i.e. inserting the necessary new entities "manually" after an update. This is a common way to populate orphaned entities after a model version upgrade and perfectly fine.

How can domain model classes (generated by EF 5 Database First) support custom logic when a database update replaces the code?

Please pardon the long-winded title to this post.
Basically, I have an entity model that was generated by Entity Framework 5 using the Database First method. Now I would like to develop those POCO entity classes by adding validation logic and anything else I might need to go in there. The problem... (and this is so glaring I can't believe I couldn't find any answer to this on the web)... is that any time my database schema should change and I use the "Update Model from Database" command from my model diagram, the POCO classes are re-generated and all custom code is lost.
As far as I understand, the "domain model" layer in an MVVM application is largely comprised of what EF generates (in database first approach), plus validation (perhaps implementing the IDataErrorInfo. But if this was the right way to do it, why would this be wiped away when using database-first model updates?
What am I missing?
Thanks
You should use partial classes. That is why they are there.
If you want to know the basics see this short example:
http://www.dotnetperls.com/partial
Here is more on partial classes from the msdn:
http://msdn.microsoft.com/en-us/library/vstudio/wa80x488.aspx
If you want to use your own namespaces in the genarted code, you can refer to this SO question:
Entity Framework 5 partial classes not working

Core Data does not use my Mapping Model

When I set the option 'NSInferMappingModelAutomaticallyOption' to yes, the new model is setup using the old models data. However, it should be using my custom Mapping Model to update specific values.
For some reason it does not use this mapping model and I really need it to as some important data is not moved from one old entity to a new entity.
Any ideas?

CoreData: Mogenerator vs. Categories

I have recently inherited a CoreData project from an outside developer. Where I expected to find all my auto-generated NSManagedObject sub-classes, I instead have (what some googling reveals to be) classes generated by Mogenerator, a tool that I have no experience with.
I understand that the purpose of using this tool is to make it so that you can add custom code into the classes corresponding to the CoreData entities without worrying about it being lost when the model changes and the classes are regenerated... but I can do this anyways by using categories.
I currently do not see a real advantage to using Mogenerator over categories.
What are the advantages/disadvantages of using Mogenerator vs. categories? Does Mogenerator serve any additional purposes?
An advantage of using classes vs categories, is that you can extend functionality by subclassing and overriding.
For instance, if your model has subentities, it is possible for them to inherit functionality from a common master class. Subclasses could define specific behavior by overriding the desired methods. On the other hand, it is possible to override methods defined in categories, but it is not recommended. This means logic implemented as categories would have to be repeated in every subclass.
A lot of code in managed objects is boilerplate, so it's really nice to have mogenerator do it automatically.
From their 'site' http://rentzsch.github.com/mogenerator/ :
mogenerator generates Objective-C code for your Core Data custom
classes
Unlike Xcode, mogenerator manages two classes per entity: one for
machines, one for humans
The machine class can always be overwritten to match the data model,
with humans’ work effortlessly preserved
So basically it got nothing to do with categories. Mogenerator (Model Object Generator) generates code which you've seen the results from in the project you've gotten handed over.

Creating a meta model using UML convention and creating a data model out of it

Sorry if the question sounds too vague. I will improve based on your feedback.
I have managed to prepare a UML model of a problem domain. This is essentially a class diagram describing class attributes and aggregation relationships amongst classes. Intention now is to fill data.
For example, class-A aggregates N instances of Class-B. I would like to create a data model that has data for one instance Class-A and 5 instances of Class-B.
Basically, data pertaining to this meta model is available in a document (e.g. xls, framemaker) and it should be possible to read the source and populate the data model.
Are there tools that will let me create this data model? Please advise.
You have two options to creates your database model from our UML model.
You can use the UML model and then add a code generator to generate the database then finally reverse it with a database modeling tool such as erwin.
Another approach is to use the database modeling profile inside your UML model. It means that ypu model and add database stereotype related to java ORM.
Both works pretty well.

Resources