3333import javax .inject .Inject ;
3434import javax .naming .ConfigurationException ;
3535
36+ import com .cloud .utils .db .Transaction ;
37+ import com .cloud .utils .db .TransactionCallback ;
38+ import com .cloud .utils .db .TransactionLegacy ;
3639import org .apache .cloudstack .framework .config .dao .ConfigurationDao ;
3740import org .apache .cloudstack .quota .activationrule .presetvariables .Configuration ;
3841import org .apache .cloudstack .quota .activationrule .presetvariables .GenericPresetVariable ;
5053import org .apache .cloudstack .quota .vo .QuotaBalanceVO ;
5154import org .apache .cloudstack .quota .vo .QuotaTariffUsageVO ;
5255import org .apache .cloudstack .quota .vo .QuotaTariffVO ;
56+ import org .apache .cloudstack .quota .vo .QuotaUsageJoinVO ;
5357import org .apache .cloudstack .quota .vo .QuotaUsageVO ;
5458import org .apache .cloudstack .usage .UsageUnitTypes ;
5559import org .apache .cloudstack .utils .bytescale .ByteScaleUtils ;
@@ -353,7 +357,7 @@ protected List<QuotaUsageVO> createQuotaUsagesAccordingToQuotaTariffs(AccountVO
353357 return new ArrayList <>();
354358 }
355359
356- return persistUsagesAndQuotaUsagesAndRetrievePersistedQuotaUsages (mapUsageAndQuotaUsage );
360+ return Transaction . execute ( TransactionLegacy . USAGE_DB , ( TransactionCallback < List < QuotaUsageVO >>) status -> persistUsagesAndQuotaUsagesAndRetrievePersistedQuotaUsages (mapUsageAndQuotaUsage ) );
357361 }
358362
359363 protected boolean shouldCalculateUsageRecord (AccountVO accountVO , UsageVO usageRecord ) {
@@ -366,7 +370,7 @@ protected boolean shouldCalculateUsageRecord(AccountVO accountVO, UsageVO usageR
366370 }
367371
368372 protected List <QuotaUsageVO > persistUsagesAndQuotaUsagesAndRetrievePersistedQuotaUsages (Map <UsageVO , Pair <QuotaUsageVO , List <QuotaTariffUsageVO >>> mapUsageAndQuotaTariffUsage ) {
369- List <QuotaUsageVO > quotaUsages = new ArrayList <>(); // TODO: isso tem que ser em uma transação
373+ List <QuotaUsageVO > quotaUsages = new ArrayList <>();
370374
371375 for (Map .Entry <UsageVO , Pair <QuotaUsageVO , List <QuotaTariffUsageVO >>> usageAndTariffUsage : mapUsageAndQuotaTariffUsage .entrySet ()) {
372376 UsageVO usageVo = usageAndTariffUsage .getKey ();
0 commit comments