Using Custom Code( Sysoperation controller) approach to create records in target table after DIXF staging import.

// To import larger number of records , we can use custom sysoperaion batch controller runs in Asynchronous mode to improve performance.
use DIXF to bring data to staging , then use custom approach to copy records to target




Steps:


1. create a query on DMF-staging table , Use other system table to join staging table as required as per data requirement to avoid taking junk data for processing


2. Use the query created in step1 in your contract class


3. Create a controller class for service class which has  above contract class as a parameter in sysentrypointAttribute method  , New method which will execute the SysentrypointAttribute method.




4. import place to write our code
// postGetStagingData() method on DMF staging table get executed only once after staging records imported. So we will use this method to execute sysoperation controller methods which actually does copying record from staging to target with set based operation , can be update/insert ( sometime delete based on scenarios)



sample Controller class should have atleast below method to be defined


public static afmPurchPriceFullLoadImportController construct()
{
    return new afmPurchPriceFullLoadImportController();
}
--
protected void new()
{
    super(classStr(afmPurchPriceFullLoadImportService), methodStr(afmPurchPriceFullLoadImportService, importPriceFromStaging), SysOperationExecutionMode::Asynchronous);
}
-- // to filer records in DMF staging table using execution id
public void buildQuery(Args _args)
{
    afmPurchPriceFullLoadImportContract           purchPriceFullLoadImportContract;
    Query                                         purchPriceFullLoad;
    QueryBuildRange                               purchPriceDiscQueryRange;
    DMFDefinitionGroupExecution                   executionHistory;
    purchPriceFullLoadImportContract = this.getDataContractObject('_priceImportContract');
    if(_args && _args.dataset() == tableNum(DMFDefinitionGroupExecution))
    {
        // cast record
        executionHistory = _args.record();
        purchPriceFullLoad = new query(queryStr(afmPurchPriceFullLoad)); // query defined on staging table
        purchPriceDiscQueryRange = purchPriceFullLoad.dataSourceTable(tableNum(DMFafmPurchPriceDiscTableEntity)).addRange(fieldNum(DMFafmPurchPriceDiscTableEntity,executionId));
        purchPriceDiscQueryRange.value(executionHistory.ExecutionId);
        purchPriceDiscQueryRange.status(RangeStatus::Locked);
    }
    // set query on datacontract
    purchPriceFullLoadImportContract.setQuery(purchPriceFullLoad);
}
______________
public void postGetStagingData(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution)
{
    DMFDefinitionGroupExecution                 dMFDefinitionGroupExecution = _dmfDefinitionGroupExecution;
    afmPurchPriceFullLoadImportController       purchPriceFullLoadImportController;
    Args                                        args = new Args();
    args.record(dMFDefinitionGroupExecution);
    purchPriceFullLoadImportController = afmPurchPriceFullLoadImportController::construct();
    purchPriceFullLoadImportController.parmShowDialog(false);
    purchPriceFullLoadImportController.parmShowProgressForm(false);
    purchPriceFullLoadImportController.buildQuery(args);
    purchPriceFullLoadImportController.startOperation();
}
__
[SysEntryPointAttribute (true),
AifCollectionTypeAttribute('afmPurchPriceFullLoadImportContract', Types::Class, classStr(afmPurchPriceFullLoadImportContract))
]
public void importPriceFromStaging(afmPurchPriceFullLoadImportContract _priceImportContract)
{
    Query                           q;
    QueryRun                        qr;
    int64                           counter = 0;
    q = _priceImportContract.getQuery();
    qr = new QueryRun(q);
 // perform set based operation
 //( insert , update , delete) in the query loop. ( use unit of work class, Recordinsetlist ..ete)
    counter = afmPurchPriceFullLoadImportService::iterateAndInsert(qr);
 // post insert and update of target records if you want to perform some operation , write method here (below)
    this.updatePurchasePrice();
    info(strFmt("@SYS54782",counter));
}

Comments