<p>Refresh entity from DB by its ID.</p>
@param <T> entity type
@param pAddParam additional param
@param pEntityClass entity class
@param pItsId entity ID
@return entity or null
@throws Exception - an exception
13879
@Override
  public final <T> T retrieveEntityById(final Map<String, Object> pAddParam,
    final Class<T> pEntityClass, final Object pItsId) throws Exception {
    String query = evalSqlSelect(pAddParam, pEntityClass);
    @SuppressWarnings("unchecked")
    IFactorySimple<T> facEn = (IFactorySimple<T>) this.entitiesFactoriesFatory
      .lazyGet(pAddParam, pEntityClass);
    T entity = facEn.create(pAddParam);
    @SuppressWarnings("unchecked")
    IFillerObjectFields<T> filler = (IFillerObjectFields<T>)
      this.fctFillersObjectFields.lazyGet(pAddParam, pEntityClass);
    String idFldName = this.tablesMap
      .get(pEntityClass.getSimpleName()).getIdFieldName();
    filler.fill(pAddParam, entity, pItsId, idFldName);
    pAddParam.put("isOnlyId", Boolean.TRUE);
    ColumnsValues columnsValues = evalColumnsValues(pAddParam, entity);
    pAddParam.remove("isOnlyId");
    String whereId = evalWhereId(entity, columnsValues);
    return retrieveEntity(pAddParam, pEntityClass,
      query + " where " + whereId + ";\n");
  }
813989
@Override
  public final synchronized EPeriod evalBalanceStorePeriod(
    final Map<String, Object> pAddParam) throws Exception {
    if (!lazyGetBalanceAtAllDirtyCheck(pAddParam).getBalanceStorePeriod()
      .equals(getSrvAccSettings().lazyGetAccSettings(pAddParam)
        .getBalanceStorePeriod())) {
      getLogger().info(null, SrvBalanceStd.class,
        "changing period from " + this.balanceAtAllDirtyCheck
          .getBalanceStorePeriod() + " to " + getSrvAccSettings()
            .lazyGetAccSettings(pAddParam).getBalanceStorePeriod());
      this.balanceAtAllDirtyCheck
        .setBalanceStorePeriod(getSrvAccSettings().lazyGetAccSettings(pAddParam)
          .getBalanceStorePeriod());
      this.balanceAtAllDirtyCheck.setIsPeriodChanged(true);
      this.balanceAtAllDirtyCheck
        .setCurrentBalanceDate(initDate);
      getSrvOrm()
        .updateEntity(pAddParam, this.balanceAtAllDirtyCheck);
    }
    return this.balanceAtAllDirtyCheck.getBalanceStorePeriod();
  }
591552
protected final PrcGoodsAdviseCategoriesSave<RS> lazyGetPrcGoodsAdviseCategoriesSave(final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrcGoodsAdviseCategoriesSave.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrcGoodsAdviseCategoriesSave<RS> proc = (PrcGoodsAdviseCategoriesSave<RS>) this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrcGoodsAdviseCategoriesSave<RS>();
      proc.setSrvOrm(getSrvOrm());
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnTradeEntitiesProcessors.class, beanName + " has been created.");
    }
    return proc;
  }
687446
public final void updateInvItemTaxCategory(
    final Map<String, Object> pAddParam,
      final InvItemTaxCategory pOwner) throws Exception {
    InvItemTaxCategoryLine iitcl = new InvItemTaxCategoryLine();
    iitcl.setItsOwner(pOwner);
    List<InvItemTaxCategoryLine> ptl = getSrvOrm()
      .retrieveListForField(pAddParam, iitcl,  "itsOwner");
    StringBuffer sb = new StringBuffer("");
    int i = 0;
    BigDecimal aggrPercent = BigDecimal.ZERO;
    for (InvItemTaxCategoryLine pt : ptl) {
      aggrPercent = aggrPercent.add(pt.getItsPercentage());
      if (i++ > 0) {
        sb.append(", ");
      }
      sb.append(pt.getTax().getItsName());
    }
    pOwner.setAggrOnlyPercent(aggrPercent);
    pOwner.setTaxesDescription(sb.toString());
    getSrvOrm().updateEntity(pAddParam, pOwner);
  }
798653
@Override
  public final <T> void updateEntity(
    final Map<String, Object> pAddParam,
      final T pEntity) throws Exception {
    ColumnsValues columnsValues = evalColumnsValues(pAddParam, pEntity);
    String whereStr = evalWhereForUpdate(pEntity, columnsValues);
    prepareColumnValuesForUpdate(columnsValues, pEntity);
    int result = getSrvDatabase().executeUpdate(pEntity.getClass()
      .getSimpleName().toUpperCase(), columnsValues, whereStr);
    if (result != 1) {
      if (result == 0 && columnsValues.ifContains(VERSION_NAME)) {
        throw new ExceptionWithCode(ISrvDatabase.DIRTY_READ, "dirty_read");
      } else {
        String query = hlpInsertUpdate.evalSqlUpdate(pEntity.getClass()
          .getSimpleName().toUpperCase(), columnsValues,
            whereStr);
        throw new ExceptionWithCode(ISrvDatabase.ERROR_INSERT_UPDATE,
          "It should be 1 row updated but it was "
            + result + ", query:\n" + query);
      }
    }
  }
207448
@Override
  public final void makeWarehouseRest(final Map<String, Object> pAddParam,
    final IMakingWarehouseEntry pEntity,
      final WarehouseSite pWhSite,
        final BigDecimal pQuantity) throws Exception {
    if (!pEntity.getIdDatabaseBirth()
      .equals(getSrvOrm().getIdDatabase())) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "can_not_make_ws_entry_for_foreign_src");
    }
    WarehouseRest wr = getSrvOrm().retrieveEntityWithConditions(pAddParam,
      WarehouseRest.class, "where WAREHOUSESITE="
        + pWhSite.getItsId() + " and INVITEM="
          + pEntity.getInvItem().getItsId() + " and UNITOFMEASURE="
            + pEntity.getUnitOfMeasure().getItsId());
    if (wr == null) {
      if (pQuantity.doubleValue() < 0) {
        throw new ExceptionWithCode(ExceptionWithCode.FORBIDDEN,
          "attempt_reverse_non_existent_good_in_warehouse");
      }
      wr = new WarehouseRest();
      wr.setIsNew(true);
      wr.setWarehouseSite(pWhSite);
      wr.setUnitOfMeasure(pEntity.getUnitOfMeasure());
      wr.setInvItem(pEntity.getInvItem());
    }
    wr.setTheRest(wr.getTheRest().add(pQuantity));
    if (wr.getTheRest().doubleValue() < 0) {
      throw new ExceptionWithCode(PurchaseInvoice.THERE_IS_NO_GOODS,
        "there_is_no_goods_in_stock");
    }
    if (wr.getIsNew()) {
      getSrvOrm().insertEntity(pAddParam, wr);
      wr.setIsNew(false);
    } else {
      if (this.fastLoc) {
        ColumnsValues cvs = new ColumnsValues();
        cvs.getFormula().add("itsVersion");
        cvs.getFormula().add("theRest");
        cvs.put("itsVersion", "ITSVERSION+1");
        if (pQuantity.compareTo(BigDecimal.ZERO) == -1) {
          cvs.put("theRest", "THEREST" + pQuantity);
        } else {
          cvs.put("theRest", "THEREST+" + pQuantity);
        }
        this.srvDb.executeUpdate("WAREHOUSEREST", cvs, "WAREHOUSESITE="
      + wr.getWarehouseSite().getItsId() + " and INVITEM=" + wr.getInvItem()
    .getItsId() + " and UNITOFMEASURE=" + wr.getUnitOfMeasure().getItsId());
      } else {
        getSrvOrm().updateEntity(pAddParam, wr);
      }
    }
  }
1196461
protected final PrcRevealTaxCat<RS>
    createPutPrcRevealTaxCat(
      final Map<String, Object> pAddParam) throws Exception {
    PrcRevealTaxCat<RS> proc = new PrcRevealTaxCat<RS>();
    proc.setLogger(getLogger());
    proc.setSrvDatabase(getSrvDatabase());
    //assigning fully initialized object:
    this.processorsMap
      .put(PrcRevealTaxCat.class.getSimpleName(), proc);
    return proc;
  }
450565
protected final PrPur<RS> lazyGetPrPur(
    final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrPur.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrPur<RS> proc = (PrPur<RS>)
      this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrPur<RS>();
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvDb(getSrvDatabase());
      proc.setSrvCart(getSrvShoppingCart());
      proc.setLog(getLogger());
      proc.setSecLog(getSecLog());
      proc.setAcpOrd(getAcpOrd());
      proc.setProcFac(this);
      proc.setBuySr(getBuySr());
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnPublicTradeProcessors.class,
        beanName + " has been created.");
    }
    return proc;
  }
1231167
@Override
  public final <T> void deleteEntityWhere(final Map<String, Object> pAddParam,
    final Class<T> pEntityClass, final String pWhere) throws Exception {
    if (pWhere == null) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "param_null_not_accepted");
    }
    getSrvDatabase().executeDelete(pEntityClass.getSimpleName()
      .toUpperCase(), pWhere);
  }
240715
protected final PrcRefreshCatalog
    lazyGetPrcRefreshCatalog(
      final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrcRefreshCatalog.class.getSimpleName();
    PrcRefreshCatalog proc = (PrcRefreshCatalog) this.processorsMap
      .get(beanName);
    if (proc == null) {
      proc = new PrcRefreshCatalog();
      proc.getListeners().add(this.fctBnPublicTradeProcessors
        .lazyGetPrcWebstorePage(pAddParam));
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnTradeProcessors.class,
        beanName + " has been created.");
    }
    return proc;
  }
254403
protected final PrcAdditionCostLineDelete<RS>
    lazyGetPrcAdditionCostLineDelete(
      final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcAdditionCostLineDelete<RS> proc = (PrcAdditionCostLineDelete<RS>)
      this.processorsMap.get(PrcAdditionCostLineDelete.class.getSimpleName());
    if (proc == null) {
      proc = new PrcAdditionCostLineDelete<RS>();
      proc.setSrvAccSettings(getSrvAccSettings());
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvDatabase(getSrvDatabase());
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcAdditionCostLineDelete.class.getSimpleName(), proc);
    }
    return proc;
  }
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());
  }
247391
@Override
  public final void retrievePage(final Map<String, Object> pAddParam,
    final IRequestData pRequestData) throws Exception {
    this.isDbgSh = this.logger.getDbgSh(this.getClass())
        && this.logger.getDbgFl() < 7001 && this.logger.getDbgCl() > 7003;
    this.hlpEntitiesPage.retrievePage(pAddParam, pRequestData, this.entitiesMap,
      this.isDbgSh, this.filterFiMaker);
  }
1109644
protected final PrcEntityFDelete<RS, IHasId<Object>, Object>
    createPutPrcEntityFDelete(
      final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcEntityFDelete<RS, IHasId<Object>, Object> proc =
      (PrcEntityFDelete<RS, IHasId<Object>, Object>)
        this.fctBnEntitiesProcessors
          .lazyGet(pAddParam, PrcEntityFDelete.class.getSimpleName());
    //assigning fully initialized object:
    this.processorsMap.put(PrcEntityFDelete.class.getSimpleName(), proc);
    return proc;
  }
108198
@Override
  public final void makeOtherEntries(final Map<String, Object> pAddParam,
    final PaymentTo pEntity, final IRequestData pRequestData,
      final boolean pIsNew) throws Exception {
    String actionAdd = pRequestData.getParameter("actionAdd");
    if ("makeAccEntries".equals(actionAdd)) {
      this.prcPurchaseInvoiceSave.calculateTotalPayment(pAddParam,
        pEntity.getPurchaseInvoice());
      getSrvOrm().updateEntity(pAddParam, pEntity.getPurchaseInvoice());
    }
  }
507132
protected final PrcDelItemFromCart<RS> lazyGetPrcDelItemFromCart(
    final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrcDelItemFromCart.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrcDelItemFromCart<RS> proc = (PrcDelItemFromCart<RS>)
      this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrcDelItemFromCart<RS>();
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvShoppingCart(getSrvShoppingCart());
      proc.setProcessorsFactory(this);
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnPublicTradeProcessors.class,
        beanName + " has been created.");
    }
    return proc;
  }
1081368
protected final PrCuOrSv<RS> lazyGetPrCuOrSv(final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrCuOrSv.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrCuOrSv<RS> proc = (PrCuOrSv<RS>) this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrCuOrSv<RS>();
      proc.setSrvOrm(getSrvOrm());
      proc.setCncOrd(getCncOrd());
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnTradeEntitiesProcessors.class, beanName + " has been created.");
    }
    return proc;
  }