Ejemplo n.º 1
0
 @Override
 public boolean getPendingChanges() {
   for (EntityObjectVO eo : mmp.getAllValues()) {
     if (eo.isFlagNew() || eo.isFlagRemoved() || eo.isFlagUpdated()) return true;
     if (eo.getDependants().getPendingChanges()) return true;
   }
   return false;
 }
Ejemplo n.º 2
0
  /**
   * sets the parent id of masterdata records.
   *
   * @param iGenericObjectId
   */
  @Override
  public void setParent(
      String moduleEntityName,
      Integer iGenericObjectId,
      Map<EntityAndFieldName, String> collSubEntities) {
    if (iGenericObjectId == null) {
      throw new NullArgumentException("iGenericObjectId");
    }

    Long longId = IdUtils.toLongId(iGenericObjectId);
    /** @todo eliminate this workaround: */
    final MasterDataMetaProvider cache =
        SpringApplicationContextHolder.getBean(MasterDataMetaProvider.class);
    for (String sEntityName : this.getEntityNames()) {
      if (cache != null) {
        final MasterDataMetaVO mdmetavo = cache.getMetaData(sEntityName);
        if (mdmetavo.isEditable()) {
          for (EntityObjectVO mdvo : this.getData(sEntityName)) {
            String foreignKeyIdField = null;
            for (EntityAndFieldName entityAndFieldName : collSubEntities.keySet()) {
              if (entityAndFieldName.getEntityName().equals(sEntityName)) {
                foreignKeyIdField = entityAndFieldName.getFieldName();
                break;
              }
            }
            if (foreignKeyIdField == null)
              foreignKeyIdField = getForeignKeyField(mdmetavo, moduleEntityName, false);
            final Long iOldGenericObjectId = mdvo.getFieldId(foreignKeyIdField);
            if (iOldGenericObjectId != null && !longId.equals(iOldGenericObjectId)) {
              log.warn(
                  "Bad parent id in dependant masterdata record; old id: "
                      + iOldGenericObjectId
                      + ", new id: "
                      + longId
                      + ".");
            }
            if (iOldGenericObjectId == null
                || (!longId.equals(iOldGenericObjectId) && mdvo.isFlagUpdated())) {
              mdvo.getFieldIds().put(foreignKeyIdField, longId);
            }
          }
        }
      }
    }
  }
Ejemplo n.º 3
0
  @Override
  protected DalCallResult batchInsertOrUpdate(
      List<IColumnToVOMapping<? extends Object>> columns,
      Collection<EntityObjectVO> colDalVO,
      boolean failAfterBatch) {
    DalCallResult dcr = new DalCallResult();
    for (EntityObjectVO dalVO : colDalVO) {
      Map<String, Object> columnValueMap = getColumnValuesMap(valueColumnsUpdate, dalVO, false);
      Map<String, Object> columnConditionMap = getColumnValuesMap(conditionColumns, dalVO, false);

      DbTableStatement stmt = null;
      try {
        boolean updated = false;
        if (importStructure.isUpdate()) {
          columnValueMap.put("INTVERSION", DbIncrement.INCREMENT);
          stmt = new DbUpdateStatement(getDbSourceForDML(), columnValueMap, columnConditionMap);
          updated = dataBaseHelper.getDbAccess().execute(stmt) > 0;
          if (updated) this.updated++;
        }

        dalVO.setId(DalUtils.getNextId());
        columnValueMap = getColumnValuesMap(valueColumnsInsert, dalVO, false);
        if (importStructure.isInsert() && !updated) {
          stmt = new DbInsertStatement(getDbSourceForDML(), columnValueMap);
          dataBaseHelper.getDbAccess().execute(stmt);
          inserted++;
        }

        if (eMeta.isStateModel() && !updated) {
          EOGenericObjectVO eogo = new EOGenericObjectVO();
          eogo.setId(dalVO.getId());
          eogo.setCreatedBy(dalVO.getCreatedBy());
          eogo.setCreatedAt(dalVO.getCreatedAt());
          eogo.setChangedBy(dalVO.getChangedBy());
          eogo.setChangedAt(dalVO.getChangedAt());
          eogo.setModuleId(eMeta.getId());
          eogo.setVersion(1);
          eogo.flagNew();
          NucletDalProvider.getInstance().getEOGenericObjectProcessor().insertOrUpdate(eogo);
        }
      } catch (DbException ex) {
        if (!failAfterBatch) {
          throw ex;
        }
        ex.setIdIfNull(dalVO.getId());
        dcr.addBusinessException(ex);
      }
    }
    return dcr;
  }