Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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:

  • PropertyName
  • PropertyName|FieldName when the resulting temp-table field name should not match the .NET property name
  • PropertyName|FieldName(ABL DataType) when the resulting temp-table field name or data type should not match the .NET property. This allows to map String properties to either CHARACTER or CLOB or Enumerations to either INTEGER or CHARACTER


Code Block
titleSample code that builds an ABL temp-table from a .NET type
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 */) .

Populating an instance of the .NET Value Object with data from 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.

Code Block
titleSample code for populating a .NET value object from a temp-table record
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 */.

Populating a temp-table record with data from a .NET Value Object instance

The method CopyFromObject of the TempTableToObjectMapper class allows developers to assign field values in a record buffer with data from a .NET value object:

Code Block
titleSample to assign temp-table field values 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.

Code Block
titleSample to assign temp-table with before image information from .NET value object
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.