You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-30Lines changed: 60 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,7 @@ _(Example assumes that your classname is `SampleApps.Serialize.MapTesting`, that
24
24
From the terminal,in the name space where your class exists :
25
25
26
26
```javascript
27
+
27
28
Set obj = ##class(SampleApps.Serialize.MapTesting).%OpenId(1)
28
29
Set objJSON =obj.Export()
29
30
Do objJSON.%ToJSON()
@@ -62,60 +63,89 @@ Code | Category | Description
62
63
During map generation, by default, the Adaptor sets export and Import conversion methods for dates and streams (which are exported as a stream in base64).
[5]*Template Class that implement export/import logic*
81
+
82
+
[6]*Method Class to dispatch for export/import*
73
83
74
84
---
75
85
76
86
### How could we configure our mapping for serialization?
77
87
78
-
We can have as much mapping definitions for a class as we need. An easy way to start to define our customized maps is exporting the default MAP0 and importing it again with a different name, then we can make changes in the map regarding the properties that should be exported /imported, names, conversor methods to apply (***)
79
-
(***) See OPNLIB.SERIALIZE.ADAPTOR.Serialize.Util library for tools to export/import maps, get / set property mappings,etc…)
88
+
We can have as much mapping definitions for a class as we need. An easy way to start to define our customized maps is exporting the default MAP0 and importing it again with a different name, then we can make changes in the map regarding the properties that should be exported /imported, names, conversor methods to apply. To do this, we can modify directly in the global, or do it programatically (See `OPNLib.Serialize.Util` class for tools to export/import maps, get / set property mappings,etc…)
89
+
90
+
---
91
+
**Example:**
92
+
93
+
```javascript
94
+
set tClassName ="SampleApps.Serialize.MapTesting"
95
+
;Assuming the classhas only 1 map:MAP0, used in^MAPS and ^MAPSREV
96
+
set json = ##class(OPNLib.Serialize.Util).ExportMapsToJSON(tClassName)
97
+
98
+
;change name of map from MAP0 to MAP1
99
+
set json.maps.%Get(0).map="MAP1"//change mapname entry in corresponding to ^MAPS
100
+
set json.maps.%Get(1).map="MAP1"//change mapname entry corresponding to ^MAPSREV
80
101
81
-
We also have the possibility of changing a bit the way in which default map MAP0 is generated :
82
-
• Change the name of default map.
83
-
○ Use parameter EXPTDEFAULTMAP to indicate a name for default map before compiling the class
84
-
• Excluding properties
85
-
○ if we don't want to export some properties, we should include them in the parameter : EXPTEXCLUDEPROP before compiling the class (the properties will be in a comma separated list)
86
-
• include object references
87
-
○ Even when we decide not to drill down through referenced objects, we still have the chance to export the object reference itself if we set the parameter EXPTINCLUDEOREF to 1.
88
-
• Drill down levels
89
-
○ To indicate up to what number of levels we want the export mechanism to drill down through object references. 0 means no drill down. A positive number(n) means to drill down n times through the chain of references.
102
+
;Overwrite map (2) ofSampleApps.Serialize.MapTestingwith map in object:json
103
+
set tSC = ##class(OPNLib.Serialize.Util).ImportMapsFromJSON(json,2,tClassName)
90
104
91
-
Example:
105
+
;Get settings of one of the properties. They are returned in a json object
106
+
set propExprt = ##class(SampleApps.Serialize.MapTesting).GetMappedPropSettings("code","MAP1",tClassName,1)
92
107
93
-
<<<createMAP1fromMAP0 >>>
108
+
;We change the targetPropertyName setting
109
+
set $ListUpdate(propExprt.settings,1) ="codeAccepted"
110
+
do ##class(SampleApps.Serialize.MapTesting).SetMappedPropSettings("code",propExprt,"MAP1",tClassName,1)
94
111
95
-
<<<USINGMAP0andMAP1fromthesameobjectinstance >>>
112
+
;Now we open and object and exportitusingnewmapping
113
+
set obj = ##class(SampleApps.Serialize.MapTesting).%OpenId(1)
114
+
set objJSON =obj.Export(,,,,"MAP1")
115
+
do objJSON.%ToJSON()
96
116
97
-
How did it work the default mechanism?
117
+
```
98
118
99
-
Both methods, export and Import will call the generated methods: exportStd and imoortStd respectively. These two methods will go through the global ^MAPS and ^MAPSREV respectively, looking for the properties to export /import and applying the required conversions.
100
-
Both methods work over an already instantiated method. This is particularly important for import, as we can have an object in memory with some data already and import the rest of the data from a serialized object. The import mechanism will replace with the new content the properties contained in the serialization but will preserve other properties already set in the instance that are not included in the serialization that we import.
119
+
We also have the possibility of changing a bit the way in which default map `MAP0` is generated :
120
+
* Change the name of default map.
121
+
* Use parameter `EXPTDEFAULTMAP` to indicate a name for default map before compiling the class
122
+
* Excluding properties
123
+
* if we don't want to export some properties, we should include them (comma separated list) in the parameter : `EXPTEXCLUDEPROP` before compiling the class
124
+
* include object references
125
+
* Even when we decide not to drill down through referenced objects, we still have the chance to export the object reference itself if we set the parameter `EXPTINCLUDEOREF` to 1.
126
+
* Drill down levels
127
+
* Use `EXPTDRILLDOWN`To indicate up to what number of levels that the export/import logic should follow through object references. 0 means no drill down. A positive number(n) means to drill down n times through the chain of references.
101
128
102
-
Example:
129
+
## How did it work the default mechanism?
103
130
104
-
<< import a JSON with just some properties in an object where we already have some others set >>>
131
+
Both methods, `Export` and `Import` will call the generated methods: `exportStd` and `importStd` respectively. These two methods will go through the global `^MAPS` and `^MAPSREV` respectively, looking for the properties to export /import and applying the required conversions.
132
+
Both methods work over an already instantiated method. This is particularly interesting for import, as we can have an object in memory with some data already and import the rest of the data from a serialized object. The import mechanism will replace with the new content the properties contained in the serialization but will preserve other properties already set in the instance that are not included in the serialization that we import.
105
133
106
-
This way of working give us the flexibility of using different mappings using the same autogenerated code but it can have a penalty in performance if we use it massively in loops or in very high concurrency use cases. Anyway,better test in such scenarios.
134
+
This way of working give us the flexibility of using different mappings using the same autogenerated code but it can have a penalty in performance if we use it massively in loops or in very high concurrency use cases. Anyway,better test in such scenarios.
107
135
108
-
Some considerations about performance
136
+
## Some considerations about performance
109
137
110
-
As we already mentioned, the default mechanism resolve the mapping sets at real time, trasversing a global to set the properties to export/import targets. That means that this mechanism will always be slower than if we already had that settings resolved at compile time. In order to provide that functionality, we can use the Template classes.
138
+
As it was already mentioned, the default mechanism resolve the mapping sets at real time, trasversing a global to set the properties to export/import targets. That means that this mechanism will always be slower than if we already had that settings resolved at compile time. In order to provide that functionality, we can use the Template classes.
111
139
112
-
What are the template classes for?
140
+
##What are the template classes for?
113
141
114
-
The templates classes allow us to generate the logic to export/import at compile time.
142
+
The templates classes allow us to generate the logic to export/import at compile time.
115
143
This have benefits over performance but comes at the price of having to use a different class for each type of serialization format and mapping.
116
144
117
145
Anyway, the primary class is not affected and doesn't have to be changed no matter how many templates define to handle the serialization of its objects.
118
146
147
+
148
+
119
149
Example :
120
150
121
151
<<< define and use different template classes, for different maps in JSON and also for different serialization (CSV)
0 commit comments