This chapter shows you how to run a local MDrivenServer, upload your model, move prototype data from XML persistence to the server database, and verify that model changes update the database schema. It is for Bootcamp learners who completed Training:Bootcamp:Chapter 13 and want to run their application against a relational database.
What you will do
MDrivenServer understands the model you upload and maintains a compatible database schema. In this chapter, you will:
- Start two local server pairs for comparison.
- Select an active MDrivenServer and upload the current model.
- Inspect the uploaded model and data in the MDrivenServer web UI.
- Export data from XML persistence and import it into MDrivenServer persistence.
- Resolve a possible duplicate
SysSingletonafter migration. - Verify that adding, changing, and removing model elements changes the database schema.
A server pair consists of an MDrivenServer and a TurnkeyServer. Turnkey runs the web application; MDrivenServer hosts the uploaded model and its data.
Inspect the current XML prototype data
Before moving data to the server database, locate the XML file used by the local prototype.
- In MDriven Designer, press Play and start the Local Turnkey Prototyper. The web application starts.
- In the prototyper settings, find the file shown beside Use XML file for data. Locate that file on your computer.
- Open the XML file in Notepad or another text editor.
- Confirm that you recognize the objects you created earlier, such as Cars and Brands of Cars.
This file is the source data that you will export and import later in this chapter.
Install and start local server pairs
Use the Cloud-connection dialog to download and operate local server installations.
- Open the Cloud-connection dialog from the MDriven Designer toolbar.
- Download the latest version for Local servers.
- Add a server pair named Server1.
- Refresh the installation for Server1.
- Open the installation folder from its displayed file path and confirm that the installed files are present.
- Add a second server pair named Server2.
- Refresh the installation for Server2.
- Select Server1 and click Start Servers.
- Confirm that two command windows open: one for MDrivenServer and one for TurnkeyServer.
- Click Start Servers again to verify that the Server1 pair restarts.
- Start Server2 and confirm that two additional command windows open.
Choose and test the active MDrivenServer
The active MDrivenServer is the server that MDriven Designer uses when you upload the model and work with server persistence.
- Switch to the Active MDriven Server tab.
- Enter the Server1 MDrivenServer address:
http://localhost:5000. - Enter user name
aand password123456. - Click Check Server status.
- Verify the initial status says Never started, No current version.
- Return to the Local Servers tab, select Server1, and click Use Above MDrivenServer.
Test that the selection follows the server you choose:
- Start or select the Server2 pair.
- Make Server2 active and check its server status.
- Close the two Server2 command windows. These use ports 5002 and 5003.
- Click Check Server status again.
- Verify that the check times out because the selected server address is no longer running.
- Return to Local Servers, select Server1, and click Use Above MDrivenServer.
- Confirm that the green indicator shows
http://localhost:5000.
Upload the model and inspect the server
Upload the current model to create its initial server-side representation and database schema.
- In the Cloud-connection dialog, click Upload model.
- Click Check Server Status. If the response is incomplete, wait briefly and click it again.
- Verify that the status reports that the database was created.
- Click Update ServerSide jobs. No jobs are expected at this point because this Bootcamp has not yet defined server-side jobs.
- Open
http://localhost:5000in a browser. - Sign in with user name
aand password123456. - Open Running, then choose Model. Confirm that the uploaded model is shown.
- Open Running, then select Data in A0.
- Select the
Carclass and click Search. At this stage, verify that no Car data is present in the server database.
The credentials in this exercise are used for a localhost server. Do not treat them as credentials for a server that users can access over a network.
Migrate XML data to MDrivenServer persistence
Export the objects in your XML prototype, then import them into the database managed by MDrivenServer.
Export the XML prototype data
- Return to MDriven Designer and press Play.
- In the System Prototyper, select XML persistence and click Start system.
- Click Migrate.
- In the Migrate window, click the green button.
- Save the exported data as
migrateToDB.xml. - Close the Migrate dialog.
Import the data into MDrivenServer
- Switch the System Prototyper to MDrivenServer persistence.
- Click Start system.
- Click Migrate.
- Click the pink button, select
migrateToDB.xml, and click Open. - Review the reported number of objects created and relations set.
- Click the yellow button to save the imported data.
- Return to the MDrivenServer web UI at
http://localhost:5000. - Open Running, then Data in A0. Select
Carand click Search. - Verify that Cars are now present.
- Double-click a Car in the result list and verify that an AutoForm displays its data.
- For the
BrandOfCarsingle link, click Open. Verify that the Brand AutoForm shows the related data, including the brand image.
Run Turnkey against MDrivenServer
Switch the local Turnkey prototype from XML persistence to the selected MDrivenServer.
- In MDriven Designer, select the LocalTurnkeyPrototyper tab and click Play.
- In the System Prototyper, change Data from Use XML file for data to Use MDriven Server.
- Click Restart to apply the setting to the Turnkey Prototyper.
- Test the spawned web application.
Fix a duplicate SysSingleton error
After migration, the web application can display this error:
The Singleton class SysSingleton has multiple instances
A singleton is a class intended to have one object. In this model, SysSingleton uses the OCL operation oclSingleton; if no instance exists, that operation can recreate one when it is first requested. The migration may have imported one SysSingleton while another instance already existed.
If you see the error, delete one instance. If you do not see the error, you can inspect the data but do not delete an instance unnecessarily.
- In MDriven Designer, open Play and choose MDrivenServer persistence.
- Click Start system, then open the debugger.
- In the class picker, select
SysSingleton. - Click Select 50, then click Execute (F5). Confirm whether two objects are listed.
- Click Seeker, then Search.
- Select one
SysSingletonobject and click Delete Selected. Leave one instance, or leave none if you intendoclSingletonto recreate it. - Return to the main debugger form and click Save.
- Refresh the failed web page with F5 and verify that the application works.
Verify database schema updates from model changes
When MDrivenServer persistence is active, changing the model requires a corresponding database schema change. Uploading the model lets MDrivenServer apply that change.
- Add a new class named
Class1to the model. - Open the Cloud-connection dialog and click Upload Model.
- Click Check Server Status. If there is no new feedback, wait one second and check again.
- Verify that the status reports a new table for objects of
Class1. - Add several attributes to
Class1, upload the model, and verify that the status reports schema changes for the new attributes. - Delete some of those attributes, upload again, and verify that the status reports removed columns.
- Add an association between
Class1andBrandOfCar. - Upload the model and verify that the status reports added columns for the foreign key. At the database level, this foreign key stores the primary key of the associated object.
- Delete the experimental
Class1class. - Upload the model and verify that the status reports that the
Class1table and the association foreign-key column were dropped.
Next steps
For deployment beyond your development machine, run MDrivenServer and MDrivenTurnkey on a server that your intended users can reach, such as an internal company network or an internet-accessible server. Continue with Training:Bootcamp:Chapter 15.
