|
28 | 28 | import com.cloud.utils.db.SearchCriteria; |
29 | 29 | import com.cloud.utils.db.Transaction; |
30 | 30 | import com.cloud.utils.db.TransactionCallback; |
| 31 | +import com.cloud.utils.db.TransactionCallbackNoReturn; |
31 | 32 | import com.cloud.utils.db.TransactionLegacy; |
32 | 33 | import com.cloud.utils.db.TransactionStatus; |
33 | 34 | import com.cloud.utils.exception.CloudRuntimeException; |
@@ -469,21 +470,25 @@ public void saveUsageRecords(List<UsageVO> usageRecords) { |
469 | 470 |
|
470 | 471 | @Override |
471 | 472 | public void removeOldUsageRecords(int days) { |
472 | | - String sql = DELETE_ALL_BY_INTERVAL; |
473 | | - TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); |
474 | | - PreparedStatement pstmt = null; |
475 | | - try { |
476 | | - txn.start(); |
477 | | - pstmt = txn.prepareAutoCloseStatement(sql); |
478 | | - pstmt.setLong(1, days); |
479 | | - pstmt.executeUpdate(); |
480 | | - txn.commit(); |
481 | | - } catch (Exception ex) { |
482 | | - txn.rollback(); |
483 | | - s_logger.error("error removing old cloud_usage records for interval: " + days); |
484 | | - } finally { |
485 | | - txn.close(); |
486 | | - } |
| 473 | + Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallbackNoReturn() { |
| 474 | + @Override |
| 475 | + public void doInTransactionWithoutResult(TransactionStatus status) { |
| 476 | + TransactionLegacy txn = TransactionLegacy.currentTxn(); |
| 477 | + PreparedStatement pstmt = null; |
| 478 | + try { |
| 479 | + txn.start(); |
| 480 | + pstmt = txn.prepareAutoCloseStatement(DELETE_ALL_BY_INTERVAL); |
| 481 | + pstmt.setLong(1, days); |
| 482 | + pstmt.executeUpdate(); |
| 483 | + txn.commit(); |
| 484 | + } catch (Exception ex) { |
| 485 | + txn.rollback(); |
| 486 | + s_logger.error("error removing old cloud_usage records for interval: " + days); |
| 487 | + } finally { |
| 488 | + txn.close(); |
| 489 | + } |
| 490 | + } |
| 491 | + }); |
487 | 492 | } |
488 | 493 |
|
489 | 494 | public UsageVO persistUsage(final UsageVO usage) { |
|
0 commit comments