With SCL-591 we have added to utility classes that support developers in mapping .NET Value objects and ABL Temp-Tables, sort of a foundation for ABL to .NET ORM (object-relational mapping).
The class Consultingwerk.Windows.TempTableObjectMapping.TempTableFromTypeFactory allows developers to create a dynamic temp-table that matches the properties of a .NET type.
The class supports primitive types that are mappable between ABL and .NET and Enumeration (either exposed as Integer or Character). The field mapping definition is provided as a comma delimited list with entries in the form of:
DEFINE VARIABLE cMapping AS CHARACTER NO-UNDO INIT "CustNum|CustomerNumber,Name,City|City(CLOB),Image,ModificationDate|ModDate(DATE),Balance,Weekday,Weekday|Wochentag(CHARACTER)" . /* Get a reference to the .NET Type to map */ oType = Progress.Util.TypeHelper:GetType ("Consultingwerk.DotNetClassLibrary.SampleViewModel", TRUE) . oFactory = NEW TempTableFromTypeFactory () . hTable = oFactory:CreateTempTable (oType, /* Reference to the .NET Type */ cMapping, /* Property/Field Mapping definition */ "CustNum" /* Primary unique key fields for the temp-table */) . |
The class Consultingwerk.Windows.TempTableObjectMapping.TempTableToObjectMapper allows developers to copy data from a temp-table buffer to an object instance and vice-versa.
The class methods CopyFromBuffer and CopyFromObject assume that both the object instance and a record in the provided temp-table buffer are already available (no factory functionality). The code expects the same property/field mapping to be provided as the TempTableFromTypeFactory class method CreateTempTable.
oMapper = NEW TempTableToObjectMapper () . oObject = NEW Consultingwerk.DotNetClassLibrary.SampleViewModel () . hBuffer = hTable:DEFAULT-BUFFER-HANDLE . oMapper:CopyFromBuffer (hBuffer, /* Source ABL buffer */ oObject /* Target .NET object reference */, cMapping) /* Property/Field mapping definition */. |
The method CopyFromObject of the TempTableToObjectMapper class allows developers to assign field values in a record buffer with data from a .NET value object:
oMapper:CopyFromObject (oObject, /* Source .NET object reference */ hBuffer, /* Target ABL buffer */ cMapping, /* Property/Field mapping definition */ ?, ?) . |
The method supports turning Enumeration values either in their integer value of Character label.
The method CopyFromObject map also manipulate the before image information of a ProDataset member buffer. In this case it is expected that the .NET object provides a ReadOnlyDictionary of the original (unchanged) values, with the Property Name as the key and the original value as the value.
oMapper:CopyFromObject (oObject, /* Source .NET object reference */ hBuffer, /* Target ABL buffer */ cMapping, /* Property/Field mapping definition */ oObject:Changes /* Reference to the Dictionary of before values */, FALSE) /* FALSE: Modified row, TRUE: New row */ . |
The method will manipulate the temp-table after buffer and before-buffer accordingly.