Hello!

  I need some expert advice on an architectural pattern.

  Should I be worried if my code looks like this?

: load-scan ( scan-id/f -- resource-scan/f )
    [ scan-info new swap >>id select-tuple ] [ f ] if* ;

: load-scans ( resource-data -- resource-data' )
    [ load-scan ] change-last-path-scan
    [ load-scan ] change-last-short-scan
    [ load-scan ] change-last-full-scan ;

: load-meta ( resource-data -- resource-data' )
    [
        dup guid>> resource-meta new swap >>guid select-tuple
        {
            [ name>> >>name ] [ root>> >>root ]
            [ desc>> >>desc ] [ guid>> >>guid ]
            [ last-path-scan>> >>last-path-scan ]
            [ last-short-scan>> >>last-short-scan ]
            [ last-full-scan>> >>last-full-scan ]
        } cleave
        load-scans
    ] with-resource-db ;

  The reason for such code organization is that resource-data tuple contains 
*-scan slots, which are pointers to scan-info tuples at run-time. But when data 
are stored into a DB, resource-data is stored in one table, and scan-info is in 
another table, linked by ID field ("foreign key", I believe it's called). (The 
reason for that is there are some other things pointing to the scans by ID.)

  Existing persistence mechanism (define-persistent, select-tuple) in Factor 
does not handle foreign keys (does it?), so I have to introduce the 
intermediate tuple called resource-meta, which has the *-scan slots saved as 
INTEGERs:

resource-meta "RESOURCE_META"
{
    { "guid" "GUID" VARCHAR +user-assigned-id+ }
    { "name" "NAME" VARCHAR }
    { "root" "ROOT" VARCHAR }
    { "desc" "DESC" VARCHAR }
    { "last-path-scan" "LAST_PATH_SCAN" INTEGER }
    { "last-short-scan" "LAST_SHORT_SCAN" INTEGER }
    { "last-full-scan" "LAST_FULL_SCAN" INTEGER }
} define-persistent

  When I load the data, I read resource-meta, convert INTEGERs into scan-info 
instances with separate calls to select-tuple (see load-meta above).

  I'm worried about all the slot copying I have to perform while saving and 
loading data:
            [ name>> >>name ] [ root>> >>root ]
            [ desc>> >>desc ] [ guid>> >>guid ]
  ... etc.

  Is there a better way?

---=====---
 Александр

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to