public List<ICFAccTaxObj> readAllTax(boolean forceRead) { final String S_ProcName = "readAllTax"; if ((allTax == null) || forceRead) { Map<CFAccTaxPKey, ICFAccTaxObj> map = new HashMap<CFAccTaxPKey, ICFAccTaxObj>(); allTax = map; CFAccTaxBuff[] buffList = ((ICFAccSchema) schema.getBackingStore()) .getTableTax() .readAllDerived(schema.getAuthorization()); CFAccTaxBuff buff; ICFAccTaxObj obj; for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; obj = newInstance(); obj.setPKey(((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newPKey()); obj.setBuff(buff); ICFAccTaxObj realized = (ICFAccTaxObj) obj.realize(); } } Comparator<ICFAccTaxObj> cmp = new Comparator<ICFAccTaxObj>() { public int compare(ICFAccTaxObj lhs, ICFAccTaxObj rhs) { if (lhs == null) { if (rhs == null) { return (0); } else { return (-1); } } else if (rhs == null) { return (1); } else { CFAccTaxPKey lhsPKey = lhs.getPKey(); CFAccTaxPKey rhsPKey = rhs.getPKey(); int ret = lhsPKey.compareTo(rhsPKey); return (ret); } } }; int len = allTax.size(); ICFAccTaxObj arr[] = new ICFAccTaxObj[len]; Iterator<ICFAccTaxObj> valIter = allTax.values().iterator(); int idx = 0; while ((idx < len) && valIter.hasNext()) { arr[idx++] = valIter.next(); } if (idx < len) { throw CFLib.getDefaultExceptionFactory() .newArgumentUnderflowException(getClass(), S_ProcName, 0, "idx", idx, len); } else if (valIter.hasNext()) { throw CFLib.getDefaultExceptionFactory() .newArgumentOverflowException(getClass(), S_ProcName, 0, "idx", idx, len); } Arrays.sort(arr, cmp); ArrayList<ICFAccTaxObj> arrayList = new ArrayList<ICFAccTaxObj>(len); for (idx = 0; idx < len; idx++) { arrayList.add(arr[idx]); } List<ICFAccTaxObj> sortedList = arrayList; return (sortedList); }
public ChangeVO updateRow( int windowNo, int AD_Tab_ID, int queryResultID, int relRowNo, Map<String, String> context, boolean force) { if (context == null || context.size() == 0) return new ChangeVO(true, Msg.translate(m_context, "NoContext")); ArrayList<String[]> data = m_results.get(queryResultID); if (data == null || data.size() == 0) return new ChangeVO(true, Msg.translate(m_context, "CachedDataNotFound")); UITab tab = getTab(AD_Tab_ID); if (tab == null) { log.config("Not found AD_Tab_ID=" + AD_Tab_ID); return new ChangeVO(true, Msg.translate(m_context, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID)); } CContext ctx = new CContext(m_context.entrySet()); ctx.addWindow(windowNo, context); ChangeVO retValue; if (force) retValue = tab.saveRow(ctx, windowNo, false, null); else retValue = tab.saveRow(ctx, windowNo, false, data.get(relRowNo)); if (retValue.hasError()) return retValue; // Update Results String[] dataRow = retValue.rowData.clone(); data.set(relRowNo, dataRow); postProcessChangeVO(retValue, windowNo, context, dataRow, tab); retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo()); if (retValue.isRefreshAll()) {} return retValue; }
/** * Save (Insert new) Row of Tab * * @param windowNo relative window * @param AD_Tab_ID tab * @param curRow insert after relative row number in results * @param context current (relevant) context of new row * @return error message or null */ public ChangeVO insertRow( int windowNo, int AD_Tab_ID, int queryResultID, int curRow, Map<String, String> context) { if (context == null || context.size() == 0) return new ChangeVO(true, "No Context"); UITab tab = getTab(AD_Tab_ID); if (tab == null) { log.config("Not found AD_Tab_ID=" + AD_Tab_ID); return new ChangeVO(true, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID); } log.info("Line Amt:" + context.get("LineNetAmt")); CContext ctx = new CContext(m_context.entrySet()); ctx.addWindow(windowNo, context); ChangeVO retValue = tab.saveRow(ctx, windowNo, true); if (retValue.hasError()) return retValue; // Update Results ArrayList<String[]> data = m_results.get(queryResultID); if (data == null) retValue.addError("Data Not Found"); else { String[] dataRow = retValue.rowData; if (curRow >= data.size()) data.add(dataRow); else data.add(curRow, dataRow); retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo()); } return retValue; } // insertRow
/** * Refresh current row of Tab * * @param windowNo relative window * @param AD_Tab_ID tab * @param relRowNo relative row number in results * @param context current (relevant) context of new row * @return error message or null */ public ChangeVO refreshRow( int windowNo, int AD_Tab_ID, int queryResultID, int relRowNo, Map<String, String> context) { if (context == null || context.size() == 0) return new ChangeVO(true, "No Context"); UITab tab = getTab(AD_Tab_ID); if (tab == null) { log.config("Not found AD_Tab_ID=" + AD_Tab_ID); return new ChangeVO(true, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID); } CContext ctx = new CContext(m_context.entrySet()); ctx.addWindow(windowNo, context); ChangeVO retValue = tab.refreshRow(ctx, windowNo); if (retValue.hasError()) return retValue; // Update Results ArrayList<String[]> data = m_results.get(queryResultID); if (data == null) retValue.addError("Data Not Found"); else { String[] dataRow = retValue.rowData.clone(); data.set(relRowNo, dataRow); postProcessChangeVO(retValue, windowNo, context, dataRow, tab); retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo()); } return retValue; } // refreshRow
public List<ICFAccTaxObj> readTaxByTenantIdx(long TenantId, boolean forceRead) { final String S_ProcName = "readTaxByTenantIdx"; CFAccTaxByTenantIdxKey key = ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newTenantIdxKey(); key.setRequiredTenantId(TenantId); Map<CFAccTaxPKey, ICFAccTaxObj> dict; if (indexByTenantIdx == null) { indexByTenantIdx = new HashMap<CFAccTaxByTenantIdxKey, Map<CFAccTaxPKey, ICFAccTaxObj>>(); } if ((!forceRead) && indexByTenantIdx.containsKey(key)) { dict = indexByTenantIdx.get(key); } else { dict = new HashMap<CFAccTaxPKey, ICFAccTaxObj>(); // Allow other threads to dirty-read while we're loading indexByTenantIdx.put(key, dict); ICFAccTaxObj obj; CFAccTaxBuff[] buffList = ((ICFAccSchema) schema.getBackingStore()) .getTableTax() .readDerivedByTenantIdx(schema.getAuthorization(), TenantId); CFAccTaxBuff buff; for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; obj = schema.getTaxTableObj().newInstance(); obj.setPKey(((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newPKey()); obj.setBuff(buff); ICFAccTaxObj realized = (ICFAccTaxObj) obj.realize(); } } Comparator<ICFAccTaxObj> cmp = new Comparator<ICFAccTaxObj>() { public int compare(ICFAccTaxObj lhs, ICFAccTaxObj rhs) { if (lhs == null) { if (rhs == null) { return (0); } else { return (-1); } } else if (rhs == null) { return (1); } else { CFAccTaxPKey lhsPKey = lhs.getPKey(); CFAccTaxPKey rhsPKey = rhs.getPKey(); int ret = lhsPKey.compareTo(rhsPKey); return (ret); } } }; int len = dict.size(); ICFAccTaxObj arr[] = new ICFAccTaxObj[len]; Iterator<ICFAccTaxObj> valIter = dict.values().iterator(); int idx = 0; while ((idx < len) && valIter.hasNext()) { arr[idx++] = valIter.next(); } if (idx < len) { throw CFLib.getDefaultExceptionFactory() .newArgumentUnderflowException(getClass(), S_ProcName, 0, "idx", idx, len); } else if (valIter.hasNext()) { throw CFLib.getDefaultExceptionFactory() .newArgumentOverflowException(getClass(), S_ProcName, 0, "idx", idx, len); } Arrays.sort(arr, cmp); ArrayList<ICFAccTaxObj> arrayList = new ArrayList<ICFAccTaxObj>(len); for (idx = 0; idx < len; idx++) { arrayList.add(arr[idx]); } List<ICFAccTaxObj> sortedList = arrayList; return (sortedList); }