Working with the GemFire APIs Once the GemFire cache and regions have been configured, these can injected and used inside application objects. This chapter describes the integration with the Spring transaction management, DaoException hierarchy and wiring of GemFire managed objects.
Exception translation Using a new API requires not just accommodating to the new semantics but also handling its particular exception set. To accommodate this case, Spring Framework provides a generic, consistent exception hierarchy that abstracts one from proprietary (and usually checked) exceptions to a set of focused runtime exceptions. As mentioned in the Spring Framework documentation, by using annotations (@Repository) or AOP, exception translations happens automatically without any code changes. The same holds true for GemFire as long as at least a CacheFactoryBean is declared. The Cache factory acts as an exception translator which is automatically detected by the Spring infrastructure and used accordingly.
Transaction Management One of the most popular features of Spring Framework is transaction management. If you are not familiar with it, we strongly recommend looking into it as it offers a consistent programming model that works transparently across multiple API that can be configured either programmatically or declaratively (the most popular choice). For Gemfire, SGI provides a dedicated, per-cache, transaction manager that once declared, allows actions on the Regions to be grouped and executed atomically through Spring: ]]> Note that currently GemFire supports optimistic transactions with read committed isolation. Further more to guarantee this isolation, developers should avoid making in-place changes, that is manually modifying the values present in the cache. To prevent this from happening, the transaction manager configured the cache to use copy on read semantics, meaning a clone of the actual value is created, each time a read is performed. This behaviour can be disabled if needed through the copyOnRead property. For more information on the semantics of the underlying GemFire transaction manager, see the GemFire documentation.