details: https://code.openbravo.com/erp/devel/pi/rev/8a7979c5a247
changeset: 20495:8a7979c5a247
user: Augusto Mauch <augusto.mauch <at> openbravo.com>
date: Thu May 30 11:45:18 2013 +0200
summary: Fixes issue 23841: Fixed duplicated close, close are done in finally
blocks
diffstat:
modules/org.openbravo.client.application/src/org/openbravo/client/application/event/AcctSchemaEventHandler.java
| 33 +-
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
| 41 +-
modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
| 13 +-
src/org/openbravo/costing/CostingMigrationProcess.java
| 241 +++++----
src/org/openbravo/costing/CostingRuleProcess.java
| 116 ++--
src/org/openbravo/erpCommon/ad_actionButton/MRPManufacturingPlanProcess.java
| 19 +-
src/org/openbravo/erpCommon/ad_process/MRPPurchaseCreateReservations.java
| 107 ++--
src/org/openbravo/erpCommon/utility/WindowTree.java
| 21 +-
8 files changed, 315 insertions(+), 276 deletions(-)
diffs (truncated from 749 to 300 lines):
diff -r c7f57f178baf -r 8a7979c5a247
modules/org.openbravo.client.application/src/org/openbravo/client/application/event/AcctSchemaEventHandler.java
---
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/AcctSchemaEventHandler.java
Thu May 30 10:08:15 2013 +0530
+++
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/AcctSchemaEventHandler.java
Thu May 30 11:45:18 2013 +0200
@@ -153,23 +153,26 @@
elementValueQry.setFetchSize(1000);
ScrollableResults elementvalues =
elementValueQry.scroll(ScrollMode.FORWARD_ONLY);
- // TODO: Review with Martin to see if flush is permitted in handlers
- // int i = 0;
- while (elementvalues.next()) {
- ElementValue elementValue = (ElementValue) elementvalues.get(0);
- boolean isCredit = getAccountSign(elementValue.getAccountType(),
assetPositive,
- liabilityPositive, ownersEquityPositive, expensePositive,
revenuePositive);
- if (!ACCOUNTTYPE_MEMO.equals(elementValue.getAccountType())) {
- elementValue.setAccountSign(isCredit ? ACCOUNTSIGN_CREDIT :
ACCOUNTSIGN_DEBIT);
+ try {
+ // TODO: Review with Martin to see if flush is permitted in handlers
+ // int i = 0;
+ while (elementvalues.next()) {
+ ElementValue elementValue = (ElementValue) elementvalues.get(0);
+ boolean isCredit = getAccountSign(elementValue.getAccountType(),
assetPositive,
+ liabilityPositive, ownersEquityPositive, expensePositive,
revenuePositive);
+ if (!ACCOUNTTYPE_MEMO.equals(elementValue.getAccountType())) {
+ elementValue.setAccountSign(isCredit ? ACCOUNTSIGN_CREDIT :
ACCOUNTSIGN_DEBIT);
+ }
+ // if ((i % 100) == 0) {
+ // OBDal.getInstance().flush();
+ // OBDal.getInstance().getSession().clear();
+ // element = OBDal.getInstance().get(Element.class, element.getId());
+ // }
+ // i++;
}
- // if ((i % 100) == 0) {
- // OBDal.getInstance().flush();
- // OBDal.getInstance().getSession().clear();
- // element = OBDal.getInstance().get(Element.class, element.getId());
- // }
- // i++;
+ } finally {
+ elementvalues.close();
}
- elementvalues.close();
}
private boolean getAccountSign(String accountType, boolean assetPositive,
diff -r c7f57f178baf -r 8a7979c5a247
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
---
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
Thu May 30 10:08:15 2013 +0530
+++
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
Thu May 30 11:45:18 2013 +0200
@@ -313,28 +313,31 @@
toJsonConverter.setAdditionalProperties(JsonUtils.getAdditionalProperties(parameters));
final ScrollableResults scrollableResults = queryService.scroll();
- int i = 0;
- while (scrollableResults.next()) {
- final Object result = scrollableResults.get()[0];
- final JSONObject json = toJsonConverter.toJsonObject((BaseOBObject)
result,
- DataResolvingMode.FULL);
+ try {
+ int i = 0;
+ while (scrollableResults.next()) {
+ final Object result = scrollableResults.get()[0];
+ final JSONObject json = toJsonConverter.toJsonObject((BaseOBObject)
result,
+ DataResolvingMode.FULL);
- try {
- doPostFetch(parameters, json);
- } catch (JSONException e) {
- throw new OBException(e);
+ try {
+ doPostFetch(parameters, json);
+ } catch (JSONException e) {
+ throw new OBException(e);
+ }
+
+ writer.write(json);
+
+ i++;
+ // Clear session every 1000 records to prevent huge memory consumption
in case of big loops
+ if (i % 1000 == 0) {
+ OBDal.getInstance().getSession().clear();
+ log.debug("clearing in record " + i + " elapsed time " +
(System.currentTimeMillis() - t));
+ }
}
-
- writer.write(json);
-
- i++;
- // Clear session every 1000 records to prevent huge memory consumption
in case of big loops
- if (i % 1000 == 0) {
- OBDal.getInstance().getSession().clear();
- log.debug("clearing in record " + i + " elapsed time " +
(System.currentTimeMillis() - t));
- }
+ } finally {
+ scrollableResults.close();
}
- scrollableResults.close();
log.debug("Fetch took " + (System.currentTimeMillis() - t) + " ms");
}
diff -r c7f57f178baf -r 8a7979c5a247
modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
---
a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
Thu May 30 10:08:15 2013 +0530
+++
b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
Thu May 30 11:45:18 2013 +0200
@@ -103,13 +103,16 @@
// Defaulted to endRow + 2 to check for more records while scrolling.
totalRows = endRow + 2;
ScrollableResults queryResults =
selQuery.scroll(ScrollMode.FORWARD_ONLY);
- while (queryResults.next()) {
- queryListSize++;
- if (queryListSize % clearEachLoop == 0) {
- OBDal.getInstance().getSession().clear();
+ try {
+ while (queryResults.next()) {
+ queryListSize++;
+ if (queryListSize % clearEachLoop == 0) {
+ OBDal.getInstance().getSession().clear();
+ }
}
+ } finally {
+ queryResults.close();
}
- queryResults.close();
if (startRow < endRow) {
if (queryListSize < endRow) {
totalRows = queryListSize;
diff -r c7f57f178baf -r 8a7979c5a247
src/org/openbravo/costing/CostingMigrationProcess.java
--- a/src/org/openbravo/costing/CostingMigrationProcess.java Thu May 30
10:08:15 2013 +0530
+++ b/src/org/openbravo/costing/CostingMigrationProcess.java Thu May 30
11:45:18 2013 +0200
@@ -278,17 +278,20 @@
Set<String> naturalTree = osp.getNaturalTree(legalEntity.getId());
ScrollableResults legacyCosts = getLegacyCostScroll(clientId,
naturalTree);
int i = 0;
- while (legacyCosts.next()) {
- Costing cost = (Costing) legacyCosts.get(0);
+ try {
+ while (legacyCosts.next()) {
+ Costing cost = (Costing) legacyCosts.get(0);
- updateTrxLegacyCosts(cost, stdPrecission, naturalTree);
+ updateTrxLegacyCosts(cost, stdPrecission, naturalTree);
- if ((i % 100) == 0) {
- OBDal.getInstance().flush();
- OBDal.getInstance().getSession().clear();
+ if ((i % 100) == 0) {
+ OBDal.getInstance().flush();
+ OBDal.getInstance().getSession().clear();
+ }
}
+ } finally {
+ legacyCosts.close();
}
- legacyCosts.close();
SessionHandler.getInstance().commitAndStart();
}
}
@@ -313,17 +316,20 @@
final ScrollableResults costs = costQry.scroll(ScrollMode.FORWARD_ONLY);
int i = 0;
- while (costs.next()) {
- Costing cost = (Costing) costs.get(0);
- cost.setCurrency(cost.getClient().getCurrency());
- OBDal.getInstance().save(cost);
- if ((i % 100) == 0) {
- OBDal.getInstance().flush();
- OBDal.getInstance().getSession().clear();
+ try {
+ while (costs.next()) {
+ Costing cost = (Costing) costs.get(0);
+ cost.setCurrency(cost.getClient().getCurrency());
+ OBDal.getInstance().save(cost);
+ if ((i % 100) == 0) {
+ OBDal.getInstance().flush();
+ OBDal.getInstance().getSession().clear();
+ }
+ i++;
}
- i++;
+ } finally {
+ costs.close();
}
- costs.close();
}
private void createRules() throws Exception {
@@ -378,57 +384,60 @@
BigDecimal totalCost = BigDecimal.ZERO;
BigDecimal totalStock = BigDecimal.ZERO;
int i = 0;
- while (icls.next()) {
- InventoryCountLine icl = (InventoryCountLine) icls.get(0);
- if (!productId.equals(icl.getProduct().getId())) {
- productId = icl.getProduct().getId();
- HashMap<String, BigDecimal> stock = getCurrentValuedStock(productId,
curId, orgs, orgId);
- totalCost = stock.get("cost");
- totalStock = stock.get("stock");
+ try {
+ while (icls.next()) {
+ InventoryCountLine icl = (InventoryCountLine) icls.get(0);
+ if (!productId.equals(icl.getProduct().getId())) {
+ productId = icl.getProduct().getId();
+ HashMap<String, BigDecimal> stock = getCurrentValuedStock(productId,
curId, orgs, orgId);
+ totalCost = stock.get("cost");
+ totalStock = stock.get("stock");
+ }
+
+ MaterialTransaction trx = crp.getInventoryLineTransaction(icl);
+
trx.setTransactionProcessDate(DateUtils.addSeconds(trx.getTransactionProcessDate(),
-1));
+ trx.setCurrency(OBDal.getInstance().get(Currency.class, curId));
+
+ BigDecimal trxCost = BigDecimal.ZERO;
+ if (totalStock.compareTo(BigDecimal.ZERO) != 0) {
+ trxCost =
totalCost.multiply(trx.getMovementQuantity().abs()).divide(totalStock,
+ stdPrecision, BigDecimal.ROUND_HALF_UP);
+ }
+ if (trx.getMovementQuantity().compareTo(totalStock) == 0) {
+ // Last transaction adjusts remaining cost amount.
+ trxCost = totalCost;
+ }
+ trx.setTransactionCost(trxCost);
+ trx.setCostCalculated(true);
+ trx.setCostingStatus("CC");
+ OBDal.getInstance().save(trx);
+ Currency legalEntityCur =
FinancialUtils.getLegalEntityCurrency(trx.getOrganization());
+ BigDecimal cost = trxCost.divide(trx.getMovementQuantity().abs(),
costPrecision,
+ BigDecimal.ROUND_HALF_UP);
+ if (!legalEntityCur.equals(cur)) {
+ cost = FinancialUtils.getConvertedAmount(cost, cur, legalEntityCur,
new Date(),
+ icl.getOrganization(), FinancialUtils.PRECISION_COSTING);
+ }
+ OBDal.getInstance().refresh(icl.getPhysInventory());
+ CostingRuleInit cri =
icl.getPhysInventory().getCostingRuleInitCloseInventoryList().get(0);
+ InventoryCountLine initICL = crp.getInitIcl(cri.getInitInventory(),
icl);
+ initICL.setCost(cost);
+ OBDal.getInstance().save(initICL);
+
+ totalCost = totalCost.subtract(trxCost);
+ // MovementQty is already negative so add to totalStock to decrease it.
+ totalStock = totalStock.add(trx.getMovementQuantity());
+
+ if ((i % 100) == 0) {
+ OBDal.getInstance().flush();
+ OBDal.getInstance().getSession().clear();
+ cur = OBDal.getInstance().get(Currency.class, curId);
+ }
+ i++;
}
-
- MaterialTransaction trx = crp.getInventoryLineTransaction(icl);
-
trx.setTransactionProcessDate(DateUtils.addSeconds(trx.getTransactionProcessDate(),
-1));
- trx.setCurrency(OBDal.getInstance().get(Currency.class, curId));
-
- BigDecimal trxCost = BigDecimal.ZERO;
- if (totalStock.compareTo(BigDecimal.ZERO) != 0) {
- trxCost =
totalCost.multiply(trx.getMovementQuantity().abs()).divide(totalStock,
- stdPrecision, BigDecimal.ROUND_HALF_UP);
- }
- if (trx.getMovementQuantity().compareTo(totalStock) == 0) {
- // Last transaction adjusts remaining cost amount.
- trxCost = totalCost;
- }
- trx.setTransactionCost(trxCost);
- trx.setCostCalculated(true);
- trx.setCostingStatus("CC");
- OBDal.getInstance().save(trx);
- Currency legalEntityCur =
FinancialUtils.getLegalEntityCurrency(trx.getOrganization());
- BigDecimal cost = trxCost.divide(trx.getMovementQuantity().abs(),
costPrecision,
- BigDecimal.ROUND_HALF_UP);
- if (!legalEntityCur.equals(cur)) {
- cost = FinancialUtils.getConvertedAmount(cost, cur, legalEntityCur,
new Date(),
- icl.getOrganization(), FinancialUtils.PRECISION_COSTING);
- }
- OBDal.getInstance().refresh(icl.getPhysInventory());
- CostingRuleInit cri =
icl.getPhysInventory().getCostingRuleInitCloseInventoryList().get(0);
- InventoryCountLine initICL = crp.getInitIcl(cri.getInitInventory(), icl);
- initICL.setCost(cost);
- OBDal.getInstance().save(initICL);
-
- totalCost = totalCost.subtract(trxCost);
- // MovementQty is already negative so add to totalStock to decrease it.
- totalStock = totalStock.add(trx.getMovementQuantity());
-
- if ((i % 100) == 0) {
- OBDal.getInstance().flush();
- OBDal.getInstance().getSession().clear();
- cur = OBDal.getInstance().get(Currency.class, curId);
- }
- i++;
+ } finally {
+ icls.close();
}
- icls.close();
OBDal.getInstance().flush();
insertTrxCosts();
@@ -579,40 +588,43 @@
ScrollableResults trxs = trxQry.scroll(ScrollMode.FORWARD_ONLY);
int i = 0;
- while (trxs.next()) {
------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits