|
29 | 29 | import com.cloud.utils.db.SearchCriteria; |
30 | 30 | import com.cloud.utils.db.Transaction; |
31 | 31 | import com.cloud.utils.db.TransactionCallback; |
| 32 | +import com.cloud.utils.db.TransactionCallbackNoReturn; |
32 | 33 | import com.cloud.utils.db.TransactionLegacy; |
33 | 34 | import com.cloud.utils.db.TransactionStatus; |
34 | 35 | import com.cloud.utils.exception.CloudRuntimeException; |
@@ -540,21 +541,25 @@ public void saveUsageRecords(List<UsageVO> usageRecords) { |
540 | 541 |
|
541 | 542 | @Override |
542 | 543 | public void removeOldUsageRecords(int days) { |
543 | | - String sql = DELETE_ALL_BY_INTERVAL; |
544 | | - TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); |
545 | | - PreparedStatement pstmt = null; |
546 | | - try { |
547 | | - txn.start(); |
548 | | - pstmt = txn.prepareAutoCloseStatement(sql); |
549 | | - pstmt.setLong(1, days); |
550 | | - pstmt.executeUpdate(); |
551 | | - txn.commit(); |
552 | | - } catch (Exception ex) { |
553 | | - txn.rollback(); |
554 | | - s_logger.error("error removing old cloud_usage records for interval: " + days); |
555 | | - } finally { |
556 | | - txn.close(); |
557 | | - } |
| 544 | + Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallbackNoReturn() { |
| 545 | + @Override |
| 546 | + public void doInTransactionWithoutResult(TransactionStatus status) { |
| 547 | + TransactionLegacy txn = TransactionLegacy.currentTxn(); |
| 548 | + PreparedStatement pstmt = null; |
| 549 | + try { |
| 550 | + txn.start(); |
| 551 | + pstmt = txn.prepareAutoCloseStatement(DELETE_ALL_BY_INTERVAL); |
| 552 | + pstmt.setLong(1, days); |
| 553 | + pstmt.executeUpdate(); |
| 554 | + txn.commit(); |
| 555 | + } catch (Exception ex) { |
| 556 | + txn.rollback(); |
| 557 | + s_logger.error("error removing old cloud_usage records for interval: " + days); |
| 558 | + } finally { |
| 559 | + txn.close(); |
| 560 | + } |
| 561 | + } |
| 562 | + }); |
558 | 563 | } |
559 | 564 |
|
560 | 565 | public UsageVO persistUsage(final UsageVO usage) { |
|
0 commit comments