One alternative approach, since you are using Spring Boot would be to do the following:
- First annotation your
@SpringBootApplication
class with @EnableGemfireCacheTransactions
...
Example:
@SpringBootApplication
@EnableGemfireCacheTransactions
@EnableGemfireRepositories
class YourSpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(YourSpringBootApplication.class, args);
}
...
}
The @EnableGemfireCacheTransactions
annotation enables Spring Data GemFire's GemfireTransactionManager
, which integrates GemFire's CacheTransactionManager
with Spring Transaction Management infrastructure which then allows you to do this...
Now, just annotate your @Service
application component transactional service methods with core Spring's @Transactional
annotation, like so...
@Service
class YourBoxReceiverTransferService {
@Transactional
public <return-type> update(ReceiveContext receiveContext,
TransferContext transferContext {
...
receiveContextRepository.save(receiveContext);
transferContextRepository.save(transferContext);
...
}
}
As you can see here, I also used Spring Data (GemFire's) Repository infrastructure to manage the persistence operations (e.g. CRUD), which will be used appropriately in the transactional scoped-context setup by Spring.
2 advantages with the Spring approach, over using GemFire's public API, which unnecessarily couples you to GemFire (a definite code smell, particularly in a Spring context), is...
You don't have to place a bunch of boilerplate, crap code in to your application components, which does not belong there!
Using Spring's Transaction Management infrastructure, it is extremely easy to change your Transaction Management Strategy, such as by switching from GemFire's local-only cache transactions, to say, Global, JTA-based Transactions if the need every arises (such as, oh, well, now I need to send a message over a JMS message queue after the GemFire Region's and Cassandra BOX Table are updated to notify some downstream process that the Receiver/Transfer context has been updated). With Spring's Transaction Management infrastructure, you do not need to change a single line of application code to change transaction management strategies (such as local to global, or global to local, etc).
Hope this helps!
-John