There's more...

There are a few special methods that are used when writing a data entity, which are as follows:

Method

Description

updateEntityDataSource

This is called when updating an existing record

deleteEntityDataSource

This is called when deleting a record

insertEntityDataSource

This is called when inserting a new record

initializeEntityDataSource

This is called when a record is initialized.

These methods are used so that we can update related records that are not directly affected by the tables in the entity. A good example is when a table is related to DirPartyTable. We can't simply delete the related party record in this case when the parent is deleted, as it may be used in other roles.

The following are sample methods for a fictitious ConWHSHaulierTableEntity, which has a main data source, ConWHSHaulierTable, and a child data source, DirPartyBaseEntity.

In this method we will check if the entity is the DirPartyBaseEntity data source, and if it is, it executes logic to handle the DirPartyTable and LogisticsPostalAddress tables. These tables are part of complicated structures, and the helper ensures that they are inserted correctly:

public boolean insertEntityDataSource( 
DataEntityRuntimeContext _entityCtx,
DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
boolean ret;

switch (_dataSourceCtx.name())
{
case dataEntityDataSourceStr(ConWHSHaulierTableEntity,
DirPartyBaseEntity):
DirPartyBaseEntityHelper partyHelper;
partyHelper = new DirPartyBaseEntityHelper();
partyHelper.preInsertEntityDataSource(_entityCtx,
_dataSourceCtx,
dataEntityDataSourceStr(
ConWHSHaulierTableEntity,
LogisticsPostalAddressBaseEntity));

ret = super(_entityCtx, _dataSourceCtx);

if (ret)
{
partyHelper.postInsertEntityDataSource(_entityCtx,
_dataSourceCtx,
dataEntityDataSourceStr(
ConWHSHaulierTableEntity,
LogisticsPostalAddressBaseEntity));
}
break;
default:
ret = super(_entityCtx, _dataSourceCtx);
}
return ret;
}

The following code handles the deletion logic and will correctly handle the update to the global address book (DirPartyTable), removing the links correctly for us:

public boolean deleteEntityDataSource( 
DataEntityRuntimeContext _entityCtx,
DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
boolean ret;

switch (_dataSourceCtx.name())
{
case dataEntityDataSourceStr(ConWHSHaulierTableEntity,
DirPartyBaseEntity)):
DirPartyBaseEntityHelper partyHelper;
partyHelper = new DirPartyBaseEntityHelper();
partyHelper.deleteEntityDataSource(_dataSourceCtx);
break;
default:
ret = super(_entityCtx, _dataSourceCtx);
}
return ret;
}

The final method in this set is the code to handle what happens when records are updated, this is identical to the insertEntityDataSource method except that the method is called updateEntityDataSource.

The following method is called when the record is initialized; the code in this method is used correctly to initialize the global address book data structures:

public void initializeEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx) 
{
super(_entityCtx, _dataSourceCtx);

if (_dataSourceCtx.name() ==
dataEntityDataSourceStr(ConWHSHaulierTableEntity,
DirPartyBaseEntity))
{
// Takes care of maintaining the reference to existing
// parties if this record provides a party number. This is
// because, even though we may be inserting the customer
// record, the party may already exist.
DirPartyBaseEntity::
initializeDirPartyBaseEntityDataSource(
_entityCtx,
_dataSourceCtx);
}
}

You can see examples of how these are used in many of the standard entities; a good example is CustCustomerEntity.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.187.106