wherehows-dao/src/main/java/wherehows/dao/table/DatasetOwnerDao.java
public List<List<DsOwner>> diffOwnerList(List<DsOwner> originalList, List<OwnerInfo> owners, int datasetId,
      String datasetUrn, int sourceTime) {

    List<DsOwner> updatedOwners = new ArrayList<>();

    int ownerCount = 0;
    for (OwnerInfo ownerInfo : owners) {
      ownerCount++;

      String owner = ownerInfo.owner.toString();
      // find and update existing owners
      for (DsOwner dsOwner : originalList) {
        if (owner.equalsIgnoreCase(dsOwner.getOwnerId())) {
          dsOwner.setDatasetUrn(datasetUrn);
          fillDsOwnerByOwnerInfo(ownerInfo, dsOwner, sourceTime);

          updatedOwners.add(dsOwner);
          break;
        }
      }

      // if field not exist, add a new field
      if (updatedOwners.size() < ownerCount) {
        DsOwner dsOwner = new DsOwner();
        dsOwner.setDatasetId(datasetId);
        dsOwner.setDatasetUrn(datasetUrn);
        fillDsOwnerByOwnerInfo(ownerInfo, dsOwner, sourceTime);

        updatedOwners.add(dsOwner);
      }
    }

    // remove non-exist owners, the merge updated owners
    List<DsOwner> removedOwners = new ArrayList<>(originalList);
    removedOwners.removeAll(updatedOwners);

    return Arrays.asList(updatedOwners, removedOwners);
  }
/**
   * Find the updated list of owners, and the list of owners that don't exist anymore.
   * @param originalList List<DsOwner>
   * @param owners List<OwnerInfo>
   * @param datasetId int
   * @param datasetUrn String
   * @param sourceTime int epoch second
   * @return [ updated list , removed list of owners]
   */
Find the updated list of owners, and the list of owners that don't exist anymore.
Find the updated list of owners and the list of owners that don ' t exist anymore .
public List<List<DsOwner>> diffOwnerList(List<DsOwner> originalList, List<OwnerInfo> owners, int datasetId,
      String datasetUrn, int sourceTime) {
    List<DsOwner> updatedOwners = new ArrayList<>();
    int ownerCount = 0;
    for (OwnerInfo ownerInfo : owners) {
      ownerCount++;
      String owner = ownerInfo.owner.toString();
      for (DsOwner dsOwner : originalList) {
        if (owner.equalsIgnoreCase(dsOwner.getOwnerId())) {
          dsOwner.setDatasetUrn(datasetUrn);
          fillDsOwnerByOwnerInfo(ownerInfo, dsOwner, sourceTime);
          updatedOwners.add(dsOwner);
          break;
        }
      }
      if (updatedOwners.size() < ownerCount) {
        DsOwner dsOwner = new DsOwner();
        dsOwner.setDatasetId(datasetId);
        dsOwner.setDatasetUrn(datasetUrn);
        fillDsOwnerByOwnerInfo(ownerInfo, dsOwner, sourceTime);
        updatedOwners.add(dsOwner);
      }
    }
    List<DsOwner> removedOwners = new ArrayList<>(originalList);
    removedOwners.removeAll(updatedOwners);
    return Arrays.asList(updatedOwners, removedOwners);
  }
public List < List < DsOwner > > diffOwnerList ( List < DsOwner > originalList , List < OwnerInfo > owners , int datasetId , String datasetUrn , int sourceTime ) { List < DsOwner > updatedOwners = new ArrayList < > ( ) ; int ownerCount = 0 ; for ( OwnerInfo ownerInfo : owners ) { ownerCount ++ ; String owner = ownerInfo . owner . toString ( ) ; for ( DsOwner dsOwner : originalList ) { if ( owner . equalsIgnoreCase ( dsOwner . getOwnerId ( ) ) ) { dsOwner . setDatasetUrn ( datasetUrn ) ; fillDsOwnerByOwnerInfo ( ownerInfo , dsOwner , sourceTime ) ; updatedOwners . add ( dsOwner ) ; break ; } } if ( updatedOwners . size ( ) < ownerCount ) { DsOwner dsOwner = new DsOwner ( ) ; dsOwner . setDatasetId ( datasetId ) ; dsOwner . setDatasetUrn ( datasetUrn ) ; fillDsOwnerByOwnerInfo ( ownerInfo , dsOwner , sourceTime ) ; updatedOwners . add ( dsOwner ) ; } } List < DsOwner > removedOwners = new ArrayList < > ( originalList ) ; removedOwners . removeAll ( updatedOwners ) ; return Arrays . asList ( updatedOwners , removedOwners ) ; }
Find the updated list of owners, and the list of owners that don't exist anymore.
Find the updated list of owners and the list of owners that don ' t exist anymore .
// find and update existing owners // if field not exist, add a new field // remove non-exist owners, the merge updated owners