javascript
java sql变更跟踪_如何使用Spring动态跟踪数据库更改?
我使用spring,spring-data,spring-cronjobs和java-mail。我需要立即掃描my-
sql數據庫中存在的表中的更改,并將有關更改的郵件發送給管理員。
我要做的所有工作都是運行cronjob來掃描表中的所有更改,但這是一個繁重的過程,因為表與貨幣交易有關,并且消耗大量資源,因此應用程序變得太慢。
因此,是否有更好的過程可用來跟蹤數據庫中的當前更改。例如,如果有任何方法可以在spring設置觀察者以觸發數據庫更改過程,則將很有幫助。
以下是我正在掃描的表的實體的示例。
/** Import statements **/
@Entity
public class UserWalletTransaction {
@Id
@GeneratedValue
private Long Id;
private String toAccount;
@ManyToOne(fetch = FetchType.LAZY)
User user;
@ManyToOne(fetch = FetchType.LAZY)
Wallet wallet;
private String senderOrMobile;
private String benificiaryName;
private String beniMobile;
private Double transferAmount;
private Double sTax;
private Double charge;
private Double netAmount;
private String apiTId;
private String apiComment;
private String agentId;
private Double apiSTax;
private Double apiCharge;
private Double apiNetAmount;
private Double apiBalanceAmount;
private String transactionMode;
private String bankName;
private String userTrackId;
private String referenceNumber;
private String operatorDescription;
private String mobileNumber;
private String rechargeDateTime;
private String operatorTransactionId;
private String hermesPnr;
private String utId;
private String status;
private Double previousAmount;
private Double balanceAmount;
private Double amountTransacted;
private String transactionType;
private boolean isRaised;
private boolean isRefunded;
@Column(name = "created_by")
private String createdBy;
@Column(name = "created_date")
private Date createdDate;
@Column(name = "updated_by")
private String updatedBy;
@Column(name = "updated_date")
private Date updatedDate;
private String operationPerformed;
@OneToOne
private UserWalletTransaction relationalTransaction;
private String errorComments;
@OneToOne
private User debitUser;
@OneToOne
private User creditUser;
@OneToOne
private ServiceProvider serviceProvider;
@OneToOne
private RefundRequest refundRequests;
..... Getters and setters......
}
以下是我用來掃描數據庫后啟動郵件的示例cron作業。
/** Import statements **/
@Component
@EnableScheduling
public class ValidateCron {
@Autowired
RechargeService rechargeService;
@Scheduled(fixedDelay = 2)
public void demoServiceMethod() {
// Perform tasks related to scan and track the number of records added //after the previous scan. Fire a mail if any change in the database is found.
}
}
請分享我可以改善此功能性能的任何方法。提前致謝。
總結
以上是生活随笔為你收集整理的java sql变更跟踪_如何使用Spring动态跟踪数据库更改?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我的世界最富有的村庄是哪个
- 下一篇: 我的世界手机版怎么驯服海豚(汉典我字的基