W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
DatastoreOperations
通過(guò)performTransaction
方法提供讀寫事務(wù):
@Autowired DatastoreOperations myDatastoreOperations; public String doWorkInsideTransaction() { return myDatastoreOperations.performTransaction( transactionDatastoreOperations -> { // Work with transactionDatastoreOperations here. // It is also a DatastoreOperations object. return "transaction completed"; } ); }
performTransaction
方法接受Function
,該Function
是DatastoreOperations
對(duì)象的實(shí)例。函數(shù)的最終返回值和類型由用戶確定。
您可以像常規(guī)DatastoreOperations
一樣使用此對(duì)象,但有一個(gè)例外:
由于Cloud Datastore的一致性保證,因此在事務(wù)內(nèi)部使用的實(shí)體之間的操作和關(guān)系存在 限制 。
此功能要求使用spring-cloud-gcp-starter-data-datastore
時(shí)提供的bean為DatastoreTransactionManager
。
DatastoreTemplate
和DatastoreRepository
支持將@Transactional
注釋作為事務(wù)運(yùn)行的方法。如果用@Transactional
注釋的方法調(diào)用了另一個(gè)也注釋的方法,則這兩種方法將在同一事務(wù)中工作。performTransaction
無(wú)法在帶有注釋的@Transactional
方法中使用,因?yàn)镃loud Datastore不支持事務(wù)內(nèi)的事務(wù)。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: