#1 2015-06-04 18:11:13

martin.suer
Member
Registered: 2013-12-15
Posts: 76

supported datatypes in ddd podo

Are arrays or lists supported as property types for ddd podos? (the TDomUser example doesn't use them)

Offline

#2 2015-06-04 18:16:54

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: supported datatypes in ddd podo

T*ObjArray are supported.

But not fully tested yet.

Offline

#3 2015-06-22 13:42:42

emaxx
Member
Registered: 2014-07-03
Posts: 18

Re: supported datatypes in ddd podo

TDDDRepositoryRestFactory.ComputeSQLRecord is a very handy function. It does the mapping from pure DDD-Objects to ORM-Objects.

But with T*ObjArray seems to be problem. For example:

  TDetails = class(TPersistent)
  private
    fName: RawUTF8;
  published
    property Name: RawUTF8 read fName write fName;
  end;

  TDetailsObjArray = array of TDetails;

  TMaster = class(TSynAutoCreateFields)
  private
    fName: RawUTF8;
    fDetails: TDetailsObjArray;
  published
    property Name: RawUTF8 read fName write fName;
    property Details: TDetailsObjArray read fDetails write fDetails;
  end;
  
  initialization  
    TJSONSerializer.RegisterObjArrayForJSON(TypeInfo(TDetailsObjArray), TDetails);

The generated ORM-Object would look like

type
  /// ORM class corresponding to TMaster DDD aggregate
  TSQLRecordMaster = class(TSQLRecord)
  protected
    fName: RawUTF8; // RawUTF8
    fDetails: variant; // TDetailsObjArray
  published
    /// maps TMaster.Name
    property Name: RawUTF8 read fName write fName;
    /// maps TMaster.Details
    property Details: variant read fDetails write fDetails;
  end;

The Details variant type becomes a TEXT column in SQLite: CREATE TABLE Master(..., Details TEXT COLLATE NOCASE);   

But when creating a TDDDRepositoryRestFactory class there is an exception raised:

TDDDRepositoryRestFactory types do not match at DB level: TMaster.Details:TDetailsObjArray=42746606 and TSQLRecordMaster.Details:Variant=55746606

Right: aggregate SQLDBFieldType (sftBlobDynArray) isn't equal to record SQLDBFieldType (sftVariant).

By manual patching the generated TSQLRecord class to this, all the stuff is working fine:

type
  /// ORM class corresponding to TMaster DDD aggregate
  TSQLRecordMaster = class(TSQLRecord)
  protected
    fName: RawUTF8; // RawUTF8
    fDetails: TDetailsObjArray; // TDetailsObjArray
  published
    /// maps TMaster.Name
    property Name: RawUTF8 read fName write fName;
    /// maps TMaster.Details
    property Details: TDetailsObjArray read fDetails write fDetails;
  end;

The corresponding TDetailsObjArray type becomes a BLOB column in SQLite: CREATE TABLE Master(..., Details BLOB); 

Is it possible to compute T*ObjArray-Properties to appropriate types, or is there another solution?

Offline

#4 2015-06-22 17:51:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: supported datatypes in ddd podo

Please try http://synopse.info/fossil/info/f40b6aa628

(not fully tested, though)

Offline

#5 2015-06-23 09:48:57

emaxx
Member
Registered: 2014-07-03
Posts: 18

Re: supported datatypes in ddd podo

Thank you for the patch! It works like a charm smile

It should be noted that in SQLite the variant Details becomes a BLOB column (before the patch it was a TEXT column).

Offline

#6 2015-06-23 10:02:38

emaxx
Member
Registered: 2014-07-03
Posts: 18

Re: supported datatypes in ddd podo

sorry, my mistake: The column type is TEXT as before. My DCU-file was not correctly updated wink

Offline

#7 2015-06-23 14:53:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: supported datatypes in ddd podo

DDD now also allows mapping with a RawUTF8 ORM field for T*ObjArray published fields, in addition to default variant type, if the on-the-fly conversion to/from TDocVariant appears to be a bottleneck.
See http://synopse.info/fossil/info/898b225dab

Thanks for the feedback.

Offline

Board footer

Powered by FluxBB