查看条件不返回行

时间:2015-02-10 11:24:42

标签: criteria oracle-adf

我是ADF BC的新手,我正在尝试在数据库中保存记录。 如果记录已经存在,我将更新字段,否则我将创建一个新行。

我在其他方法中使用相同的View Criteria并且它可以工作,但不适用于此方法。这是我的代码:

public String saveRecord() {
boolean isNewRow = false;
String merchId = generateIds(); //returns the correct Id, I've checked

DCIteratorBinding dc = (DCIteratorBinding)evaluteEL("#{bindings.GaeInitialSetup1Iterator}");
ViewObject vo = dc.getViewObject();

ViewCriteriaManager vcm = vo.getViewCriteriaManager();
vo.setNamedWhereClauseParam("merchId", merchId);
vcm.applyViewCriteria(vo.getViewCriteriaManager().getViewCriteria("GaeInitialSetupVOCriteria"));
vo.executeQuery(); 

Row rowSelected = vo.next(); //it's always null even if the record exists
if (rowSelected == null) { // null == null - leads to error when trying to insert the same Id twice
    isNewRow = true;
    rowSelected = vo.createRow();
    rowSelected.setAttribute("MerchId", merchId);
    rowSelected.setAttribute("MerchLevel", merchLevelCalc(merchId));
    rowSelected.setAttribute("ParentId", parentIdCalc(merchId));
} 


    rowSelected.setAttribute("IpssDefault", validateIPSSDefault());
    rowSelected.setAttribute("IpssBase", validateIPSSBase());
    rowSelected.setAttribute("LimMinMdqPct", validateLIM_MIN_MDQ_PCT());
    rowSelected.setAttribute("LimMinMdqPctNewSku", validateLIM_MIN_MDQ_PCT_NEW_SKU());
    rowSelected.setAttribute("DifMdqPctMin", validateDIF_MDQ_PCT_MIN());
    rowSelected.setAttribute("VarMinMdqChg", validateVAR_MIN_MDQ_CHG());
    rowSelected.setAttribute("LimMinRotDays", validateLIM_MIN_ROT_DAYS());
    rowSelected.setAttribute("LimMaxRotDays", validateLIM_MAX_ROT_DAYS());
    rowSelected.setAttribute("DaysNewSku", validateDAYS_NEW_SKU());
    rowSelected.setAttribute("IncrS1", validateINCR_S1());
    rowSelected.setAttribute("IncrS2", validateINCR_S2());
    rowSelected.setAttribute("IncrS3", validateINCR_S3());
    rowSelected.setAttribute("IncrS4", validateINCR_S4());
    rowSelected.setAttribute("ReplSuspComb", validateREPL_SUSP_COMB());
    rowSelected.setAttribute("VarPctMinStkRot", validateVAR_PCT_MIN_STK_ROT());
    rowSelected.setAttribute("AbcgA", validateABCG_A());
    rowSelected.setAttribute("AbcgB", validateABCG_B());
    rowSelected.setAttribute("AbcgC", validateABCG_C());
    rowSelected.setAttribute("AbcgD", validateABCG_D());
    rowSelected.setAttribute("AbcgE", validateABCG_E());
    rowSelected.setAttribute("AbcgF", validateABCG_F());
    rowSelected.setAttribute("AbcgG", validateABCG_G());

    if (isNewRow) {
        vo.insertRow(rowSelected);
    }


DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding operationBinding = (OperationBinding)bindings.getOperationBinding("Execute");
operationBinding.execute();

OperationBinding operationBinding2 = (OperationBinding)bindings.getOperationBinding("Commit");
operationBinding2.execute();

return null;

}

我错过了什么?

2 个答案:

答案 0 :(得分:0)

您的代码似乎完全正确,您可以尝试进行下面提到的更改吗?

vo.executeQuery();
if (vo.hasNext()) { 
  Row rowSelected = vo.next(); 
//write rest of your logic here

    }

这不会有null == null检查,这是最好的做法。

答案 1 :(得分:0)

我已经解决了这个问题。

我删除了该行:Row rowSelected = vo.next();

我已添加:Row rowSelected = vo.first();

相关问题