Import data from other SQL servers
(Created page with "MDriven Server – the new name for BorPred – has been extended with functionality to import data from other sqlbased systems. The MDriven Server is designed for taking car...")
 
No edit summary
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
MDriven Server – the new name for BorPred – has been extended with functionality to import data from other sqlbased systems.
MDriven Server – has been extended with functionality to import data from other sqlbased systems.


The MDriven Server is designed for taking care of the repetitive common tasks that always seems to come back and haunt us system developers. MDriven Server takes a strictly model driven approach to help you with the work.
The MDriven Server is designed for taking care of the repetitive common tasks that always seems to come back and haunt us system developers. MDriven Server takes a strictly model driven approach to help you with the work.


Earlier I described how to export files producing-export-files-with-boringpredictable/
Earlier I described how to export files [[Exporting files from MDriven Server|Exporting files from MDriven Server#Producing export files from MDriven Server]]


and this here is a link to explain more about the concept periodic actions /boringpredictable-periodic-server-side-actions/
and this here is a link to explain more about the concept periodic actions [[MDrivenServer periodic server-side actions]]


What is new today is the ability to read from an external SQL server and import that data – strictly by using MDriven techniques and zero need for external programs.
What is new today is the ability to read from an external SQL server and import that data – strictly by using MDriven techniques and zero need for external programs.
MDriven Server has functionality to import data from other sqlbased systems. The ability to read from an external SQL server and import that data – strictly by using MDriven techniques and zero need for external programs.


Let me show you.
Let me show you.


I have this model and I really want class1 to be reference data from an external database:
´Suppose I have this model and I really want class1 to be reference data from an external database:


[[File:Import - 1.png|frameless]]
[[File:ServerSide Actions Importing Data 01.png|frameless|257x257px]]


So I declare a viewModel that looks like this:
So I declare a viewModel that looks like this:


It defines 4 columns with data and 2 actions.
[[File:ServerSide Actions Importing Data 02.png|frameless|469x469px]]
 
It defines 4 columns with data and 2 actions:


1=ViewModel - the name of yet another viewmodel that will act as a importer of the sql result set
1=<u>'''ViewModel / new Nesting'''</u> – the name of yet another viewmodel that will act as a importer of the sql result set , this can in recent version be replaced with '''Nesting''' and then you are expected to a have a connected nesting with that name in the ViewModel that has the Import action. This '''Nesting''' is then defining the columns to import.
[[File:2019-02-05 15h42 14.png|none|thumb|This show how Nesting column ties to Nesting inside same viewmodel ]]


2=Connectionstring- the external database
2='''<u>Connectionstring</u>'''- the external database (''Update 2018-10-18: you can now use 'connectionstringodbc' and the logic will use ODBC connection instead of sqlserver.'')


3=Query – the sql query – remember that you can build it with data from the rest of your model
3=<u>'''Query'''</u> – the sql query – remember that you can build it with data from the rest of your model


4=Key – if we want the import to be able to update Class1 we need to explain what the key is in the class
4=<u>'''Key'''</u> – if we want the import to be able to update Class1 we need to explain what the key is in the class. The value of Key should be a string with value of the name of the attribute we want to use as key in the class. This attribute must also be the result of the first column on the import nesting.


And the actions:
And the actions:


SQLImport – using this name will trigger the import function in MDriven Server
'''SQLImport''' – using this name will trigger the import function in MDriven Server


Finished – this is a generic action – that just execute the expression – in this case setting Class2.Attribute1 to ‘Done’
Finished – this is a generic action – that just execute the expression – in this case setting Class2.Attribute1 to ‘Done’


So the SQL data returned looks like this:
So the SQL data returned looks like this:
[[File:ServerSide Actions Importing Data 03.png|frameless|323x323px]]


And the ViewModel that is going to act as the import template – called “TheImporter” in the example above looks like this:
And the ViewModel that is going to act as the import template – called “TheImporter” in the example above looks like this:
[[File:ServerSide Actions Importing Data 04.png|frameless]]


I now declare the ServerSide job in MDriven server:
I now declare the ServerSide job in MDriven server:


The actual import is executed by the import logic described here: //www.capableobjects.com/2012/12/14/import-data/
[[File:ServerSide Actions Importing Data 05.png|frameless|422x422px]]


Now the MDriven Server will check every 20:seconds if the expression Class2.allinstances->select(attribute1=’todo’) returns any rows. If it does - it fetches at most 2 of these and executes all the actions found in TheServerSideJob.
Now the MDriven Server will check every 20:seconds if the expression  
Class2.allinstances- >select(attribute1=’todo’)
returns any rows. If it does it fetches at most 2 of these and executes all the actions found in TheServerSideJob.


In MDriven Designer (formerly AppComplete) I can create a Class2 with the debugger and save it:
In MDriven Designer I can create a Class2 with the debugger and save it:


And then I check the MDriven Server log:
[[File:ServerSide Actions Importing Data 06.png|frameless|324x324px]]


I then check my Class2:
And then I check the MDriven Server log: [[File:ServerSide Actions Importing Data 07.png|frameless|493x493px]]
 
I then check my Class2:                             [[File:ServerSide Actions Importing Data 08.png|frameless|448x448px]]


Attribute1 is now ‘Done’ – so the serverside job relaxes and will not find anything more to do just now…
Attribute1 is now ‘Done’ – so the serverside job relaxes and will not find anything more to do just now…
=== Rewriting from old style 2 viewmodels to new style 1 ViewModel with Nesting ===
The Old style was to have a ViewModel column pointing out the description of the import row. The new more compact style is to instead refer to a Nesting within the main ViewModel doing the import.
Example of new:
[[File:2019-05-15 10h38 46.png|none|thumb|610x610px]]
Example of old:
[[File:2019-05-15 10h41 20.png|none|thumb|980x980px]]Make sure the columns in the import are not left as read only as they are created that way default. If they are read only they will not receive any values:
[[File:2020-04-21 11h47 05.png|none|thumb|939x939px]]
[[Category:MDriven Server]]
[[Category:Advanced]]

Revision as of 09:54, 21 April 2020

MDriven Server – has been extended with functionality to import data from other sqlbased systems.

The MDriven Server is designed for taking care of the repetitive common tasks that always seems to come back and haunt us system developers. MDriven Server takes a strictly model driven approach to help you with the work.

Earlier I described how to export files Exporting files from MDriven Server#Producing export files from MDriven Server

and this here is a link to explain more about the concept periodic actions MDrivenServer periodic server-side actions

What is new today is the ability to read from an external SQL server and import that data – strictly by using MDriven techniques and zero need for external programs.

MDriven Server has functionality to import data from other sqlbased systems. The ability to read from an external SQL server and import that data – strictly by using MDriven techniques and zero need for external programs.

Let me show you.

´Suppose I have this model and I really want class1 to be reference data from an external database:

ServerSide Actions Importing Data 01.png

So I declare a viewModel that looks like this:

ServerSide Actions Importing Data 02.png

It defines 4 columns with data and 2 actions:

1=ViewModel / new Nesting – the name of yet another viewmodel that will act as a importer of the sql result set , this can in recent version be replaced with Nesting and then you are expected to a have a connected nesting with that name in the ViewModel that has the Import action. This Nesting is then defining the columns to import.

This show how Nesting column ties to Nesting inside same viewmodel

2=Connectionstring- the external database (Update 2018-10-18: you can now use 'connectionstringodbc' and the logic will use ODBC connection instead of sqlserver.)

3=Query – the sql query – remember that you can build it with data from the rest of your model

4=Key – if we want the import to be able to update Class1 we need to explain what the key is in the class. The value of Key should be a string with value of the name of the attribute we want to use as key in the class. This attribute must also be the result of the first column on the import nesting.

And the actions:

SQLImport – using this name will trigger the import function in MDriven Server

Finished – this is a generic action – that just execute the expression – in this case setting Class2.Attribute1 to ‘Done’

So the SQL data returned looks like this:

ServerSide Actions Importing Data 03.png

And the ViewModel that is going to act as the import template – called “TheImporter” in the example above looks like this:

ServerSide Actions Importing Data 04.png

I now declare the ServerSide job in MDriven server:

ServerSide Actions Importing Data 05.png

Now the MDriven Server will check every 20:seconds if the expression

Class2.allinstances- >select(attribute1=’todo’)

returns any rows. If it does – it fetches at most 2 of these and executes all the actions found in TheServerSideJob.

In MDriven Designer I can create a Class2 with the debugger and save it:

ServerSide Actions Importing Data 06.png

And then I check the MDriven Server log: ServerSide Actions Importing Data 07.png

I then check my Class2: ServerSide Actions Importing Data 08.png

Attribute1 is now ‘Done’ – so the serverside job relaxes and will not find anything more to do just now…

Rewriting from old style 2 viewmodels to new style 1 ViewModel with Nesting

The Old style was to have a ViewModel column pointing out the description of the import row. The new more compact style is to instead refer to a Nesting within the main ViewModel doing the import.

Example of new:

2019-05-15 10h38 46.png

Example of old:

2019-05-15 10h41 20.png

Make sure the columns in the import are not left as read only as they are created that way default. If they are read only they will not receive any values:

2020-04-21 11h47 05.png
This page was edited 78 days ago on 01/11/2024. What links here