@Override
  public int importIdentifiers(
      @NotNull IdentifiersMapping idMapping, @NotNull IdentifierGenerator pIdentifier) {
    IdentifierGenerator localParticipantIdentifier =
        pIdentifier == null ? participantIdentifier : pIdentifier;

    ValueTable identifiersTable =
        identifiersTableService.ensureIdentifiersTable(idMapping.getEntityType());
    Variable variable = identifiersTableService.ensureIdentifiersMapping(idMapping);
    PrivateVariableEntityMap entityMap =
        new OpalPrivateVariableEntityMap(identifiersTable, variable, localParticipantIdentifier);

    List<VariableEntity> systemEntities =
        StreamSupport.stream(
                new IdentifiersMaps(identifiersTable, idMapping.getName()).spliterator(), true) //
            .filter(unitId -> !unitId.hasPrivateIdentifier()) //
            .map(IdentifiersMaps.IdentifiersMap::getSystemEntity) //
            .collect(Collectors.toList());

    entityMap.createPrivateEntities(systemEntities);

    return systemEntities.size();
  }
  private void importIdentifiers(
      @NotNull IdentifiersMapping idMapping, ValueTable sourceTable, @Nullable String select) {

    Variable variable = identifiersTableService.ensureIdentifiersMapping(idMapping);
    String selectScript =
        select == null //
            ? variable.hasAttribute("select")
                ? variable.getAttributeStringValue("select")
                : null //
            : select;

    ValueTable sourceIdentifiersTable =
        identifierService.createPrivateView(sourceTable.getName(), sourceTable, selectScript);
    Variable identifierVariable =
        identifierService.createIdentifierVariable(sourceIdentifiersTable, idMapping);

    PrivateVariableEntityMap entityMap =
        new OpalPrivateVariableEntityMap(
            identifiersTableService.getIdentifiersTable(idMapping.getEntityType()),
            identifierVariable,
            participantIdentifier);

    try (ValueTableWriter identifiersTableWriter =
        identifiersTableService.createIdentifiersTableWriter(idMapping.getEntityType())) {
      for (VariableEntity privateEntity : sourceIdentifiersTable.getVariableEntities()) {
        if (entityMap.publicEntity(privateEntity) == null) {
          entityMap.createPublicEntity(privateEntity);
        }
        identifierService.copyParticipantIdentifiers(
            entityMap.publicEntity(privateEntity),
            sourceIdentifiersTable,
            entityMap,
            identifiersTableWriter);
      }
    }
  }
 @Override
 public void importIdentifiers(
     @NotNull IdentifiersMapping idMapping, Datasource sourceDatasource, @Nullable String select)
     throws IOException {
   try {
     for (ValueTable vt : sourceDatasource.getValueTables()) {
       if (idMapping.isForTable(vt)) {
         importIdentifiers(idMapping, vt, select);
       }
     }
   } finally {
     if (MagmaEngine.get().hasTransientDatasource(sourceDatasource.getName()))
       MagmaEngine.get().removeTransientDatasource(sourceDatasource.getName());
   }
 }