<p>Insert immutable line into DB.</p>
@param pAddParam additional param
@param pEntity entity
@throws Exception - an exception
779159
public final void updateOwner(final Map<String, Object> pAddParam,
    final AdditionCostLine pEntity) throws Exception {
    String query =
    "select sum(ITSTOTAL) as ITSTOTAL from"
      + " ADDITIONCOSTLINE where ITSOWNER="
        + pEntity.getItsOwner().getItsId();
    Double total = getSrvDatabase().evalDoubleResult(query, "ITSTOTAL");
    pEntity.getItsOwner().setTotalAdditionCost(BigDecimal.valueOf(total)
.setScale(getSrvAccSettings().lazyGetAccSettings(pAddParam).getCostPrecision(),
  getSrvAccSettings().lazyGetAccSettings(pAddParam).getRoundingMode()));
    pEntity.getItsOwner().setItsTotal(pEntity.getItsOwner()
      .getTotalMaterialsCost().add(pEntity.getItsOwner()
        .getTotalAdditionCost()).setScale(getSrvAccSettings()
      .lazyGetAccSettings(pAddParam).getCostPrecision(),
    getSrvAccSettings().lazyGetAccSettings(pAddParam).getRoundingMode()));
    pEntity.getItsOwner().setItsCost(pEntity.getItsOwner().getItsTotal()
      .divide(pEntity.getItsOwner().getItsQuantity(),
        getSrvAccSettings().lazyGetAccSettings(pAddParam).getCostPrecision(),
          getSrvAccSettings().lazyGetAccSettings(pAddParam).getRoundingMode()));
    getSrvOrm().updateEntity(pAddParam, pEntity.getItsOwner());
  }
282633
public final <T> void prepareColumnValuesForUpdate(
    final ColumnsValues pColumnsValues,
      final T pEntity) throws Exception {
    //remove old version and ID columns:
    pColumnsValues.getLongsMap().remove(ISrvOrm.VERSIONOLD_NAME);
    TableSql tableSql = this.tablesMap.get(pEntity.getClass().getSimpleName());
    for (String idFldNm : tableSql.getIdColumnsNames()) {
      pColumnsValues.remove(idFldNm);
    }
  }
389766
public final void useMaterialReverse(final Map<String, Object> pAddParam,
    final Manufacture pEntity)
    throws Exception {
    //reverse draw product in process from manufacturing process
    UseMaterialEntry dies = getSrvOrm()
      .retrieveEntityWithConditions(pAddParam, UseMaterialEntry.class,
        " where DRAWINGTYPE=" + pEntity.constTypeCode()
          + " and DRAWINGID=" + pEntity.getReversedId());
    UseMaterialEntry die = new UseMaterialEntry();
    die.setItsDate(pEntity.getItsDate());
    die.setIdDatabaseBirth(getSrvOrm().getIdDatabase());
    die.setSourceType(dies.getSourceType());
    die.setSourceId(dies.getSourceId());
    die.setDrawingType(pEntity.constTypeCode());
    die.setDrawingId(pEntity.getItsId());
    die.setDrawingOwnerId(null);
    die.setDrawingOwnerType(null);
    die.setSourceOwnerId(dies.getSourceOwnerId());
    die.setSourceOwnerType(dies.getSourceOwnerType());
    die.setItsCost(dies.getItsCost());
    die.setItsTotal(dies.getItsTotal().negate());
    die.setUnitOfMeasure(dies.getUnitOfMeasure());
    die.setInvItem(dies.getInvItem());
    die.setItsQuantity(dies.getItsQuantity().negate());
    die.setReversedId(die.getItsId());
    String langDef = (String) pAddParam.get("langDef");
    DateFormat dateFormat = DateFormat.getDateTimeInstance(
      DateFormat.MEDIUM, DateFormat.SHORT, new Locale(langDef));
    die.setDescription(makeDescription(pEntity, langDef, dateFormat)
      + " " + getSrvI18n().getMsg("reversed_entry_n", langDef)
        + dies.getIdDatabaseBirth() + "-" + dies.getItsId());
    getSrvOrm().insertEntity(pAddParam, die);
    die.setIsNew(false);
    pEntity.getManufacturingProcess().setTheRest(pEntity
      .getManufacturingProcess().getTheRest().add(dies.getItsQuantity()));
    getSrvOrm().updateEntity(pAddParam, pEntity.getManufacturingProcess());
    dies.setReversedId(die.getItsId());
    dies.setDescription(dies.getDescription() + " " + getSrvI18n()
      .getMsg("reversing_entry_n", langDef) + die.getIdDatabaseBirth() + "-"
        + die.getItsId()); //local
    getSrvOrm().updateEntity(pAddParam, dies);
  }
1206406
protected final PrcPaymentToGfr<RS> createPutPrcPaymentToGfr(
    final Map<String, Object> pAddParam) throws Exception {
    PrcPaymentToGfr<RS> proc = new PrcPaymentToGfr<RS>();
    @SuppressWarnings("unchecked")
    IEntityProcessor<PaymentTo, Long> procDlg =
      (IEntityProcessor<PaymentTo, Long>)
        lazyGetPrcAccDocGetForReverse(pAddParam);
    proc.setPrcAccDocGetForReverse(procDlg);
    proc.setSrvTypeCode(getSrvTypeCode());
    //assigning fully initialized object:
    this.processorsMap.put(PrcPaymentToGfr.class.getSimpleName(), proc);
    return proc;
  }
1273277
@Override
  public final ReplicatorXmlHttp<RS> create(
    final Map<String, Object> pAddParam) throws Exception {
    ReplicatorXmlHttp<RS> srvGetDbCopyXml = new ReplicatorXmlHttp<RS>();
    SrvEntityReaderXml srvEntityReaderXml = new SrvEntityReaderXml();
    srvEntityReaderXml.setUtilXml(this.factoryAppBeans.lazyGetUtilXml());
    SrvEntityFieldFillerStd srvEntityFieldFillerStd =
      new SrvEntityFieldFillerStd();
    srvEntityFieldFillerStd.setUtilXml(this.factoryAppBeans.lazyGetUtilXml());
    srvEntityFieldFillerStd.setUtlReflection(this.factoryAppBeans
      .lazyGetUtlReflection());
    SrvEntityFieldPersistableBaseRepl srvEntityFieldPersistableBaseRepl =
      new SrvEntityFieldPersistableBaseRepl();
    srvEntityFieldPersistableBaseRepl
      .setUtlReflection(this.factoryAppBeans.lazyGetUtlReflection());
    SrvEntityFieldHasIdStringRepl srvEntityFieldHasIdStringRepl =
      new SrvEntityFieldHasIdStringRepl();
    srvEntityFieldHasIdStringRepl
      .setUtlReflection(this.factoryAppBeans.lazyGetUtlReflection());
    SrvEntityFieldHasIdLongRepl srvEntityFieldHasIdLongRepl =
      new SrvEntityFieldHasIdLongRepl();
    srvEntityFieldHasIdLongRepl
      .setUtlReflection(this.factoryAppBeans.lazyGetUtlReflection());
    SrvEntityFieldUserTomcatRepl srvEntityFieldUserTomcatRepl =
      new SrvEntityFieldUserTomcatRepl();
    Map<String, ISrvEntityFieldFiller> fieldsFillersMap =
      new HashMap<String, ISrvEntityFieldFiller>();
    fieldsFillersMap.put("SrvEntityFieldFillerStd",
      srvEntityFieldFillerStd);
    fieldsFillersMap.put("SrvEntityFieldPersistableBaseRepl",
      srvEntityFieldPersistableBaseRepl);
    fieldsFillersMap.put("SrvEntityFieldHasIdStringRepl",
      srvEntityFieldHasIdStringRepl);
    fieldsFillersMap.put("SrvEntityFieldHasIdLongRepl",
      srvEntityFieldHasIdLongRepl);
    fieldsFillersMap.put("SrvEntityFieldUserTomcatRepl",
      srvEntityFieldUserTomcatRepl);
    srvEntityReaderXml.setFieldsFillersMap(fieldsFillersMap);
    srvEntityReaderXml.setMngSettings(this.factoryAppBeans
      .lazyGetMngSettingsGetDbCopy());
    DatabaseReaderIdenticalXml<RS> databaseReaderIdenticalXml =
     new DatabaseReaderIdenticalXml<RS>();
    databaseReaderIdenticalXml.setUtilXml(this.factoryAppBeans
      .lazyGetUtilXml());
    databaseReaderIdenticalXml.setSrvEntityReader(srvEntityReaderXml);
    databaseReaderIdenticalXml.setSrvDatabase(this.factoryAppBeans
      .lazyGetSrvDatabase());
    databaseReaderIdenticalXml.setSrvOrm(this.factoryAppBeans.lazyGetSrvOrm());
    databaseReaderIdenticalXml.setLogger(this.factoryAppBeans.lazyGetLogger());
    SrvClearDatabase<RS> srvClearDatabase = new SrvClearDatabase<RS>();
    srvClearDatabase.setMngSettings(this.factoryAppBeans
      .lazyGetMngSettingsGetDbCopy());
    srvClearDatabase.setLogger(this.factoryAppBeans.lazyGetLogger());
    srvClearDatabase.setSrvDatabase(this.factoryAppBeans.lazyGetSrvDatabase());
    srvGetDbCopyXml.setDatabasePrepearerBefore(srvClearDatabase);
    srvGetDbCopyXml.setDatabasePrepearerAfter(this.factoryAppBeans
      .lazyGetPrepareDbAfterFullImport());
    srvGetDbCopyXml.setUtilXml(this.factoryAppBeans.lazyGetUtilXml());
    srvGetDbCopyXml.setSrvEntityReaderXml(srvEntityReaderXml);
    srvGetDbCopyXml.setMngSettings(this.factoryAppBeans
      .lazyGetMngSettingsGetDbCopy());
    srvGetDbCopyXml.setSrvDatabase(this.factoryAppBeans.lazyGetSrvDatabase());
    srvGetDbCopyXml.setDatabaseReader(databaseReaderIdenticalXml);
    srvGetDbCopyXml.setLogger(this.factoryAppBeans.lazyGetLogger());
    return srvGetDbCopyXml;
  }
72076
@Override
  public final void makeFirstPrepareForSave(final Map<String, Object> pAddParam,
    final PaymentTo pEntity, final IRequestData pRequestData) throws Exception {
    //BeigeORM refresh:
    pEntity.setAccCash(getSrvOrm()
      .retrieveEntity(pAddParam, pEntity.getAccCash()));
    if (pEntity.getAccCash().getSubaccType() != null
      && pEntity.getSubaccCashId() == null) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "select_subaccount");
    }
    if (pEntity.getPurchaseInvoice() != null) {
      PurchaseInvoice purchaseInvoice = getSrvOrm()
        .retrieveEntity(pAddParam, pEntity.getPurchaseInvoice());
      if (!purchaseInvoice.getHasMadeAccEntries()
        || purchaseInvoice.getReversedId() != null) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "purchase_invoice_must_be_accounted");
      }
      pEntity.setPurchaseInvoice(purchaseInvoice);
    }
  }
482603
public final <T> T retrieveEntity(final Map<String, Object> pAddParam,
    final Class<T> pEntityClass,
      final IRecordSet<RS> pRecordSet) throws Exception {
    @SuppressWarnings("unchecked")
    IFactorySimple<T> facEn = (IFactorySimple<T>) this.entitiesFactoriesFatory
      .lazyGet(pAddParam, pEntityClass);
    T entity = facEn.create(pAddParam);
    String foreignFieldNmsNm = "foreignFieldNms";
    List<String> foreignFieldNms = new ArrayList<String>();
    pAddParam.put(foreignFieldNmsNm, foreignFieldNms);
    String currentLevelNm = "currentLevel";
    List<Integer> currentLevel = new ArrayList<Integer>();
    currentLevel.add(1);
    pAddParam.put(currentLevelNm, currentLevel);
    String deepLevelNm = "deepLevel";
    List<Integer> deepLevel = new ArrayList<Integer>();
    deepLevel.add(2); //default top level
    pAddParam.put(deepLevelNm, deepLevel);
    this.fillerEntitiesFromRs.fill(pAddParam, entity, pRecordSet);
    //(TODO itself) exit from all recursions:
    pAddParam.remove(currentLevelNm);
    pAddParam.remove(deepLevelNm);
    pAddParam.remove(foreignFieldNmsNm);
    return entity;
  }
839398
protected final PrcEntityFfolDelete<RS, IHasId<Object>, Object>
    createPutPrcEntityFfolDelete(
      final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcEntityFfolDelete<RS, IHasId<Object>, Object> proc =
      (PrcEntityFfolDelete<RS, IHasId<Object>, Object>)
        this.fctBnEntitiesProcessors
          .lazyGet(pAddParam, PrcEntityFfolDelete.class.getSimpleName());
    //assigning fully initialized object:
    this.processorsMap.put(PrcEntityFfolDelete.class.getSimpleName(), proc);
    return proc;
  }
922112
@Override
  public final <T> Integer evalRowCount(
    final Map<String, Object> pAddParam,
      final Class<T> pEntityClass) throws Exception {
    String query = "select count(*) as TOTALROWS from " + pEntityClass
      .getSimpleName().toUpperCase() + ";";
    return evalRowCountByQuery(pAddParam, pEntityClass, query);
  }
168407
@Override
  public final void make(
    final Map<String, Object> pAddParam) throws Exception {
    this.replicationMethod.setLastDateReplication(new Date());
    getSrvOrm().updateEntity(pAddParam, this.replicationMethod);
  }
1215302
@Override
  public final AccountingEntries create(
    final Map<String, Object> pAddParam) throws Exception {
    AccountingEntries object = new AccountingEntries();
    object.setIsNew(false);
    object.setIdDatabaseBirth(this.databaseId);
    object.setItsDate(new Date());
    return object;
  }
579130
@Override
  public final void makeOtherEntries(final Map<String, Object> pAddParam,
    final ManufacturingProcess pEntity, final IRequestData pRequestData,
      final boolean pIsNew) throws Exception {
    String actionAdd = pRequestData.getParameter("actionAdd");
    if ("makeAccEntries".equals(actionAdd)
      && pEntity.getReversedId() != null) {
      pEntity.setTheRest(BigDecimal.ZERO);
      //reverse none-reversed lines:
      ManufacturingProcess reversed = getSrvOrm()
        .retrieveEntityById(pAddParam, ManufacturingProcess.class,
          pEntity.getReversedId());
      reversed.setTheRest(BigDecimal.ZERO);
      getSrvOrm().updateEntity(pAddParam, reversed);
      UsedMaterialLine umlrd = new UsedMaterialLine();
      umlrd.setItsOwner(reversed);
      List<UsedMaterialLine> reversedMaterials = getSrvOrm().
        retrieveListForField(pAddParam, umlrd, "itsOwner");
      String langDef = (String) pAddParam.get("langDef");
      for (UsedMaterialLine reversedLine : reversedMaterials) {
        if (reversedLine.getReversedId() == null) {
          UsedMaterialLine reversingLine = new UsedMaterialLine();
          reversingLine.setIdDatabaseBirth(getSrvOrm().getIdDatabase());
          reversingLine.setReversedId(reversedLine.getItsId());
          reversingLine.setItsCost(reversedLine.getItsCost());
          reversingLine.setInvItem(reversedLine.getInvItem());
          reversingLine.setUnitOfMeasure(reversedLine.getUnitOfMeasure());
          reversingLine.setItsQuantity(reversedLine.getItsQuantity().negate());
          reversingLine.setItsTotal(reversedLine.getItsTotal().negate());
          reversingLine.setIsNew(true);
          reversingLine.setItsOwner(pEntity);
          reversingLine.setDescription(getSrvI18n()
            .getMsg("reversed_n", langDef) + reversedLine.getIdDatabaseBirth()
              + "-" + reversedLine.getItsId()); //local
          getSrvOrm().insertEntity(pAddParam, reversingLine);
          reversingLine.setIsNew(false);
          getSrvWarehouseEntry().reverseDraw(pAddParam, reversingLine);
          getSrvUseMaterialEntry().reverseDraw(pAddParam, reversingLine,
            pEntity.getItsDate(), pEntity.getItsId());
          String descr;
          if (reversedLine.getDescription() == null) {
            descr = "";
          } else {
            descr = reversedLine.getDescription();
          }
          reversedLine.setDescription(descr
            + " " + getSrvI18n().getMsg("reversing_n", langDef) + reversingLine
              .getIdDatabaseBirth() + "-" + reversingLine.getItsId());
          reversedLine.setReversedId(reversingLine.getItsId());
          getSrvOrm().updateEntity(pAddParam, reversedLine);
        }
      }
      AdditionCostLine acl = new AdditionCostLine();
      acl.setItsOwner(reversed);
      List<AdditionCostLine> reversedAcl = getSrvOrm().
        retrieveListForField(pAddParam, acl, "itsOwner");
      for (AdditionCostLine reversedLine : reversedAcl) {
        if (reversedLine.getReversedId() == null) {
          AdditionCostLine reversingLine = new AdditionCostLine();
          reversingLine.setIdDatabaseBirth(getSrvOrm().getIdDatabase());
          reversingLine.setReversedId(reversedLine.getItsId());
          reversingLine.setSubaccExpense(reversedLine.getSubaccExpense());
          reversingLine.setSubaccExpenseId(reversedLine.getSubaccExpenseId());
          reversingLine.setSubaccExpenseType(reversedLine
            .getSubaccExpenseType());
          reversingLine.setAccExpense(reversedLine.getAccExpense());
          reversingLine.setItsTotal(reversedLine.getItsTotal().negate());
          reversingLine.setIsNew(true);
          reversingLine.setItsOwner(pEntity);
          reversingLine.setDescription(getSrvI18n()
            .getMsg("reversed_n", langDef) + reversedLine.getIdDatabaseBirth()
              + "-" + reversedLine.getItsId()); //local
          getSrvOrm().insertEntity(pAddParam, reversingLine);
          reversingLine.setIsNew(false);
          String descr;
          if (reversedLine.getDescription() == null) {
            descr = "";
          } else {
            descr = reversedLine.getDescription();
          }
          reversedLine.setDescription(descr
            + " " + getSrvI18n().getMsg("reversing_n", langDef) + reversingLine
              .getIdDatabaseBirth() + "-" + reversingLine.getItsId());
          reversedLine.setReversedId(reversingLine.getItsId());
          getSrvOrm().updateEntity(pAddParam, reversedLine);
        }
      }
    }
    if (pEntity.getIsComplete()) { //need to make warehouse entries
      if (pEntity.getItsCost().doubleValue() <= 0) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "cost_less_or_eq_zero");
      }
      //load or reverse load:
      getSrvWarehouseEntry().load(pAddParam, pEntity,
        pEntity.getWarehouseSite());
    }
  }
630714
@Override
  public final boolean sync(final Map<String, Object> pAddParam,
    final Object pEntity) throws Exception {
    AccountingEntry entityPb = (AccountingEntry) pEntity;
    int currDbId = getSrvOrm().getIdDatabase();
    if (currDbId == entityPb.getIdDatabaseBirth()) {
      throw new ExceptionWithCode(ExceptionWithCode.SOMETHING_WRONG,
        "Foreign entity born in this database! {ID, ID BIRTH, DB BIRTH}:"
          + " {" + entityPb.getItsId() + ", " + entityPb.getIdBirth()
            + "," + entityPb.getIdDatabaseBirth());
    }
    String tblNm = pEntity.getClass().getSimpleName().toUpperCase();
    String whereStr = " where " + tblNm + ".IDBIRTH=" + entityPb.getItsId()
      + " and " + tblNm + ".IDDATABASEBIRTH=" + entityPb.getIdDatabaseBirth();
    AccountingEntry entityPbDb = getSrvOrm()
      .retrieveEntityWithConditions(pAddParam, entityPb.getClass(), whereStr);
    if (entityPb.getSourceType().equals(this.accountingEntriesCode)) {
      tblNm = AccountingEntries.class.getSimpleName().toUpperCase();
      whereStr = " where " + tblNm + ".IDBIRTH=" + entityPb.getSourceId()
      + " and " + tblNm + ".IDDATABASEBIRTH=" + entityPb.getIdDatabaseBirth();
      AccountingEntries accountingEntries = getSrvOrm()
      .retrieveEntityWithConditions(pAddParam, AccountingEntries.class,
        whereStr);
      if (accountingEntries == null) {
        throw new ExceptionWithCode(ExceptionWithCode.SOMETHING_WRONG,
          "Can't find foreign AccountingEntries {ID BIRTH, DB BIRTH}:"
            + " {" + entityPb.getSourceId()
              + "," + entityPb.getIdDatabaseBirth());
      }
      entityPb.setSourceId(accountingEntries.getItsId());
    }
    entityPb.setIdBirth(entityPb.getItsId());
    entityPb.setItsId(null);
    boolean isNew = true;
    if (entityPbDb != null) {
      entityPb.setItsId(entityPbDb.getItsId());
      isNew = false;
    }
    getSrvBalance().handleNewAccountEntry(pAddParam, null, null,
      entityPb.getItsDate()); //This is for SrvBalanceStd only!!!
    return isNew;
  }
1084007
protected final PrcBankStatementLineSave<RS> lazyGetPrcBankStatementLineSave(
    final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcBankStatementLineSave<RS> proc = (PrcBankStatementLineSave<RS>)
      this.processorsMap.get(PrcBankStatementLineSave.class.getSimpleName());
    if (proc == null) {
      proc = new PrcBankStatementLineSave<RS>();
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvI18n(getSrvI18n());
      proc.setSrvAccEntry(getSrvAccEntry());
      proc.setPrcPurchaseInvoiceSave(lazyGetPrcPurchaseInvoiceSave(pAddParam));
      proc.setPrcSalesInvoiceSave(lazyGetPrcSalesInvoiceSave(pAddParam));
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcBankStatementLineSave.class.getSimpleName(), proc);
    }
    return proc;
  }
958817
@Override
  public final <T> void fill(final Map<String, Object> pAddParam,
    final T pEntity, final IRecordSet<RS> pSource) throws Exception {
    @SuppressWarnings("unchecked")
    IFillerObjectFields<T> filler = (IFillerObjectFields<T>)
      fillersFieldsFactory.lazyGet(pAddParam, pEntity.getClass());
    TableSql tableSql = this.tablesMap.get(pEntity.getClass().getSimpleName());
    @SuppressWarnings("unchecked")
    Collection<String> fieldsNames = (Collection<String>) pAddParam.
      get(pEntity.getClass().getSimpleName() + "neededFields");
    if (fieldsNames == null) {
      fieldsNames = tableSql.getFieldsMap().keySet();
    }
    boolean isDbgSh = this.logger.getDbgSh(this.getClass())
      && this.logger.getDbgFl() < 7031 && this.logger.getDbgCl() > 7033;
    String currentLevelNm = "currentLevel";
    @SuppressWarnings("unchecked")
    List<Integer> currentLevel = (List<Integer>) pAddParam.get(currentLevelNm);
    String deepLevelNm = "deepLevel";
    @SuppressWarnings("unchecked")
    List<Integer> deepLevel = (List<Integer>) pAddParam.get(deepLevelNm);
    @SuppressWarnings("unchecked")
    List<String> foreignFieldNms = (List<String>)
      pAddParam.get("foreignFieldNms");
    for (String fieldName : fieldsNames) {
      if (!tableSql.getFieldsMap().get(fieldName).getTypeField()
            .equals(ETypeField.DERIVED_FROM_COMPOSITE)) {
        String convName = this.fieldConverterNamesHolder.getFor(pEntity
         .getClass(), fieldName);
        IConverterByName<IRecordSet<RS>, ?> conv = this.convertersFieldsFatory
          .lazyGet(pAddParam, convName);
        if (conv != null) { // e.g. transient or composite (non-foreign) itsId
          try {
            Field field = this.fieldsRapiHolder
              .getFor(pEntity.getClass(), fieldName);
            String parName;
            String tableAlias;
            if (currentLevel.get(0) > 1) { // in TOP level
              String currForeignFieldNm = foreignFieldNms
                .get(foreignFieldNms.size() - 1);
              tableAlias = currForeignFieldNm.toUpperCase();
            } else {
              tableAlias = "";
            }
            if (Enum.class.isAssignableFrom(field.getType())) {
              parName = tableAlias + fieldName.toUpperCase();
              pAddParam.put("fieldClass", field.getType());
            } else {
              if (tableSql.getFieldsMap().get(fieldName)
                .getForeignEntity() != null) {
                Integer deepLevelReq = (Integer) pAddParam.get(pEntity
                  .getClass().getSimpleName() + fieldName + deepLevelNm);
                if (deepLevelReq != null) {
                  //sub-entities with overridden deep:
                  currentLevel.add(1);
                  deepLevel.add(deepLevelReq);
                } //nothing for sub-entities
                if (deepLevel.size() != currentLevel.size()) {
                  throw new Exception(
                "Algorithm error: deepLevel.size/currentLevel.size/Entity/Field"
                  + deepLevel.size() + "/" + currentLevel.size() + "/"
                    + pEntity.getClass().getSimpleName() + "/" + fieldName);
                }
                parName = fieldName;
                 //table current alias for name
                foreignFieldNms.add(fieldName);
                // foreign entity class for factory:
                pAddParam.put("fieldClass", field.getType());
                pAddParam.put("entityClass", pEntity.getClass());
                if (isDbgSh) {
                  StringBuffer sb = new StringBuffer();
                  sb.append("deepLevel size/value1/value...: " + deepLevel
                    .size() + "/");
                  for (Integer dl : deepLevel) {
                    sb.append(dl + "/");
                  }
                  sb.append("\ncurrentLevel size/value1/value...: "
                    + currentLevel.size() + "/");
                  for (Integer cl : currentLevel) {
                    sb.append(cl + "/");
                  }
                  sb.append("\nforeignFieldNms size/value1/value...: "
                    + foreignFieldNms.size() + "/");
                  for (String fln : foreignFieldNms) {
                    sb.append(fln + "/");
                  }
                  sb.append("\nForeign class/fieldNm/type: "
                    + pEntity.getClass().getSimpleName() + "/" + fieldName + "/"
                     + field.getType().getSimpleName());
                  this.logger.debug(null, FillerEntitiesFromRs.class,
                    sb.toString());
                }
              } else {
                parName = tableAlias + fieldName.toUpperCase();
              }
            }
            Object fieldVal = conv.convert(pAddParam, pSource, parName);
            if (isDbgSh) {
              this.logger.debug(null, FillerEntitiesFromRs.class,
                "Converted from RS class/field/type/converter/value: "
                  + pEntity.getClass().getSimpleName() + "/" + fieldName + "/"
                    + field.getType().getSimpleName() + "/"
                      + conv.getClass().getSimpleName() + "/" + fieldVal);
            }
            filler.fill(pAddParam, pEntity, fieldVal, fieldName);
          } catch (Exception ex) {
            String msg = "Can't fill field/class: " + fieldName + "/"
              + pEntity.getClass().getCanonicalName();
            throw new ExceptionWithCode(ExceptionWithCode.SOMETHING_WRONG,
              msg, ex);
          }
        }
      }
    }
    pAddParam.remove("fieldClass");
    pAddParam.remove("entityClass");
  }
404597
@Override
  public final DatabaseWriterXml<RS> create(
    final Map<String, Object> pAddParam) throws Exception {
    DatabaseWriterXml<RS> dbWriterXmlFullImport = new DatabaseWriterXml<RS>();
    SrvEntityWriterXml srvEntityWriterXml = new SrvEntityWriterXml();
    SrvFieldWriterXmlStd srvFieldWriterXmlStd = new SrvFieldWriterXmlStd();
    srvFieldWriterXmlStd.setUtilXml(this.factoryAppBeans.lazyGetUtilXml());
    SrvFieldHasIdWriterXml srvFieldHasIdWriterXml =
      new SrvFieldHasIdWriterXml();
    srvFieldHasIdWriterXml.setUtilXml(this.factoryAppBeans.lazyGetUtilXml());
    srvEntityWriterXml.setUtlReflection(this.factoryAppBeans
      .lazyGetUtlReflection());
    Map<String, ISrvFieldWriter> fieldsWritersMap =
      new HashMap<String, ISrvFieldWriter>();
    fieldsWritersMap.put("SrvFieldWriterXmlStd", srvFieldWriterXmlStd);
    fieldsWritersMap.put("SrvFieldHasIdWriterXml", srvFieldHasIdWriterXml);
    srvEntityWriterXml.setFieldsWritersMap(fieldsWritersMap);
    srvEntityWriterXml.setMngSettings(this.factoryAppBeans
      .lazyGetMngSettingsGetDbCopy());
    dbWriterXmlFullImport.setLogger(this.factoryAppBeans.lazyGetLogger());
    dbWriterXmlFullImport.setSrvEntityWriter(srvEntityWriterXml);
    dbWriterXmlFullImport.setSrvDatabase(this.factoryAppBeans
      .lazyGetSrvDatabase());
    dbWriterXmlFullImport.setSrvOrm(this.factoryAppBeans.lazyGetSrvOrm());
    return dbWriterXmlFullImport;
  }
461183
@Override
  public final <T> void fill(final Map<String, Object> pAddParam,
    final T pEntity, final IRequestData pReq) throws Exception {
    boolean isDbgSh = this.logger.getDbgSh(this.getClass())
      && this.logger.getDbgFl() < 7010 && this.logger.getDbgCl() > 7015;
    if (isDbgSh) {
      this.logger.debug(null, FillEntityFromReq.class,
        "Default charset = " + Charset.defaultCharset());
    }
    @SuppressWarnings("unchecked")
    IFillerObjectFields<T> filler = (IFillerObjectFields<T>)
      this.fillersFieldsFactory.lazyGet(pAddParam, pEntity.getClass());
    for (String fieldName : filler.getFieldsNames()) {
      try {
        String valStr = pReq.getParameter(pEntity.getClass().getSimpleName()
          + "." + fieldName); // standard
        if (valStr != null) { // e.g. Boolean checkbox or none-editable
          String convName = this.fieldConverterNamesHolder.getFor(pEntity
           .getClass(), fieldName);
          if (isDbgSh) {
            this.logger.debug(null, FillEntityFromReq.class,
              "Try fill field/inClass/converterName/value: " + fieldName + "/"
                + pEntity.getClass().getCanonicalName() + "/" + convName
                  + "/" + valStr);
          }
          IConverterToFromString conv = this.convertersFieldsFatory
            .lazyGet(pAddParam, convName);
          Object fieldVal = conv.fromString(pAddParam,  valStr);
          if (fieldVal != null && isDbgSh) {
              this.logger.debug(null, FillEntityFromReq.class,
                "Converted fieldClass/toString: " + fieldVal.getClass()
                  .getCanonicalName() + "/" + fieldVal);
          }
          filler.fill(pAddParam, pEntity, fieldVal, fieldName);
        }
      } catch (Exception ex) {
        String msg = "Can't fill field/class: " + fieldName + "/"
          + pEntity.getClass().getCanonicalName();
        throw new ExceptionWithCode(ExceptionWithCode.SOMETHING_WRONG, msg, ex);
      }
    }
  }