diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java index 09874c6d0f8..0b45e4f5ceb 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java +++ b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java @@ -106,16 +106,22 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { QuotaBalanceResponse resp = new QuotaBalanceResponse(); BigDecimal lastCredits = new BigDecimal(0); + boolean consecutive=true; for (Iterator it = quotaBalance.iterator(); it.hasNext();) { QuotaBalanceVO entry = it.next(); // s_logger.info("Date=" + entry.getUpdatedOn().toGMTString() + // " balance=" + entry.getCreditBalance() + " credit=" + // entry.getCreditsId()); if (entry.getCreditsId() > 0) { - lastCredits = lastCredits.add(entry.getCreditBalance()); + if (consecutive){ + lastCredits = lastCredits.add(entry.getCreditBalance()); + } resp.addCredits(entry); it.remove(); } + else { + consecutive= false; + } } if (quotaBalance.size() > 0) { diff --git a/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java b/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java index 8bbeb4e7b58..dd2b71c9a66 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java +++ b/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java @@ -108,6 +108,7 @@ public class QuotaBalanceDaoImpl extends GenericDaoBase im @SuppressWarnings("deprecation") @Override public List findQuotaBalance(final Long accountId, final Long domainId, final Date startDate, final Date endDate) { + // TODO account for series of credits around boundaries final short opendb = TransactionLegacy.currentTxn().getDatabaseId(); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); diff --git a/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java b/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java index d5f2f927ca2..a151c4d36d7 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java +++ b/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java @@ -70,7 +70,9 @@ public class QuotaTariffDaoImpl extends GenericDaoBase impl // Switch back TransactionLegacy.open(opendb).close(); if (result.size() > 0) { - //s_logger.info(onOrBeforeDate.toGMTString() + "quota type " + quotaType + " , effective Date=" + result.get(0).getEffectiveOn() + " val=" + result.get(0).getCurrencyValue()); + // s_logger.info(onOrBeforeDate.toGMTString() + "quota type " + + // quotaType + " , effective Date=" + result.get(0).getEffectiveOn() + // + " val=" + result.get(0).getCurrencyValue()); return result.get(0); } else { s_logger.info("Missing quota type " + quotaType); @@ -92,8 +94,11 @@ public class QuotaTariffDaoImpl extends GenericDaoBase impl List result = search(sc, filter); if (result.size() > 0) { tariffs.add(result.get(0)); - //s_logger.info(onOrBeforeDate.toGMTString() + "quota type " + resp.getDescription() + " , effective Date=" + result.get(0).getEffectiveOn() + " val=" - //+ result.get(0).getCurrencyValue()); + // s_logger.info(onOrBeforeDate.toGMTString() + + // "quota type " + resp.getDescription() + + // " , effective Date=" + result.get(0).getEffectiveOn() + + // " val=" + // + result.get(0).getCurrencyValue()); } } } finally { @@ -107,9 +112,15 @@ public class QuotaTariffDaoImpl extends GenericDaoBase impl @Override public boolean updateQuotaTariff(QuotaTariffVO plan) { final short opendb = TransactionLegacy.currentTxn().getDatabaseId(); - TransactionLegacy.open(TransactionLegacy.USAGE_DB).close(); // Switch to - // Usage DB - final boolean result = this.update(plan.getId(), plan); + TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); // Switch + // to + boolean result = false; + try { + // Usage DB + result = this.update(plan.getId(), plan); + } finally { + txn.close(); + } TransactionLegacy.open(opendb).close(); // Switch back return result; } @@ -117,10 +128,16 @@ public class QuotaTariffDaoImpl extends GenericDaoBase impl @Override public QuotaTariffVO addQuotaTariff(QuotaTariffVO plan) { final short opendb = TransactionLegacy.currentTxn().getDatabaseId(); - TransactionLegacy.open(TransactionLegacy.USAGE_DB).close(); // Switch to - // Usage DB - plan.setId(null); - final QuotaTariffVO result = this.persist(plan); + TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); // Switch + // to + QuotaTariffVO result = null; + try { + // Usage DB + plan.setId(null); + result = this.persist(plan); + } finally { + txn.close(); + } TransactionLegacy.open(opendb).close(); // Switch back return result; }