private function MapPersistenceDataToTransaction(Object\UnitOfWork $UnitOfWork, Relational\Transaction $Transaction, array $PersistenceDataArray)
{
if (count($PersistenceDataArray) === 0) {
return;
}
$EntityRelationalMap = $this->EntityRelationMaps[reset($PersistenceDataArray)->GetEntityType()];
$PrimaryKeyTable = $EntityRelationalMap->GetPrimaryKeyTable();
$ResultRows = $this->MapEntityDataToTransaction($UnitOfWork, $Transaction, $EntityRelationalMap, $PersistenceDataArray);
$RowsWithoutPrimaryKeys = [];
$PersistenceDataToSupply = [];
foreach ($ResultRows as $Key => $ResultRow) {
$Transaction->PersistAll($ResultRow->GetRows());
$PrimaryKeyRow = $ResultRow->GetRow($PrimaryKeyTable);
if (!$PrimaryKeyRow->HasPrimaryKey()) {
$PersistenceDataToSupply[$Key] = $PersistenceDataArray[$Key];
$RowsWithoutPrimaryKeys[$Key] = $PrimaryKeyRow;
}
}
//Adds a callback to supply the unit of work the generated identity after persistence.
$Transaction->SubscribeToPostPersistEvent($PrimaryKeyTable, function () use(&$UnitOfWork, &$EntityRelationalMap, &$RowsWithoutPrimaryKeys, &$PersistenceDataToSupply) {
$Identities = $EntityRelationalMap->MapPrimaryKeysToIdentities($RowsWithoutPrimaryKeys);
foreach ($Identities as $Key => $Identity) {
$UnitOfWork->SupplyIdentity($PersistenceDataToSupply[$Key], $Identity);
}
});
return $ResultRows;
}