org.springframework.data.gemfire
Class GemfireTemplate

java.lang.Object
  extended by org.springframework.data.gemfire.GemfireAccessor
      extended by org.springframework.data.gemfire.GemfireTemplate
All Implemented Interfaces:
InitializingBean

public class GemfireTemplate
extends GemfireAccessor

Helper class that simplifies GemFire data access code and converts GemFireCheckedException and GemFireException into Spring DataAccessException, following the org.springframework.dao exception hierarchy.

The central method is execute, supporting GemFire access code implementing the GemfireCallback interface. It provides dedicated handling such that neither the GemfireCallback implementation nor the calling code needs to explicitly care about handling Region life-cycle exceptions. Typically used to implement data access or business logic services that use GemFire within their implementation but are GemFire-agnostic in their interface. The latter or code calling the latter only have to deal with business objects, query objects, and org.springframework.dao exceptions.

Author:
Costin Leau

Field Summary
 
Fields inherited from class org.springframework.data.gemfire.GemfireAccessor
log
 
Constructor Summary
GemfireTemplate()
           
GemfireTemplate(Region<K,V> region)
           
 
Method Summary
 void afterPropertiesSet()
           
protected
<K,V> Region<K,V>
createRegionProxy(Region<K,V> region)
          Create a close-suppressing proxy for the given GemFire Region.
<T> T
execute(GemfireCallback<T> action)
           
<T> T
execute(GemfireCallback<T> action, boolean exposeNativeRegion)
          Execute the action specified by the given action object within a Region.
<K,V> V
get(K key)
           
 boolean isExposeNativeRegion()
          Returns whether to expose the native GemFire Region to GemfireCallback code, or rather a Region proxy.
<K,V> V
put(K key, V value)
           
<E> SelectResults<E>
query(String query)
           
<K,V> V
remove(K key)
           
 void setExposeNativeRegion(boolean exposeNativeRegion)
          Sets whether to expose the native Gemfire Region to GemfireCallback code.
 
Methods inherited from class org.springframework.data.gemfire.GemfireAccessor
convertGemFireAccessException, convertGemFireAccessException, convertGemFireQueryException, getRegion, setRegion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GemfireTemplate

public GemfireTemplate()

GemfireTemplate

public GemfireTemplate(Region<K,V> region)
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface InitializingBean
Overrides:
afterPropertiesSet in class GemfireAccessor

setExposeNativeRegion

public void setExposeNativeRegion(boolean exposeNativeRegion)
Sets whether to expose the native Gemfire Region to GemfireCallback code. Default is "false": a Region proxy will be returned, suppressing close calls.

As there is often a need to cast to a interface, the exposed proxy implements all interfaces implemented by the original Region. If this is not sufficient, turn this flag to "true".

See Also:
GemfireCallback

isExposeNativeRegion

public boolean isExposeNativeRegion()
Returns whether to expose the native GemFire Region to GemfireCallback code, or rather a Region proxy.


get

public <K,V> V get(K key)

put

public <K,V> V put(K key,
                   V value)

remove

public <K,V> V remove(K key)

query

public <E> SelectResults<E> query(String query)

execute

public <T> T execute(GemfireCallback<T> action)
          throws DataAccessException
Throws:
DataAccessException

execute

public <T> T execute(GemfireCallback<T> action,
                     boolean exposeNativeRegion)
          throws DataAccessException
Execute the action specified by the given action object within a Region.

Parameters:
action - callback object that specifies the Gemfire action
exposeNativeRegion - whether to expose the native GemFire region to callback code
Returns:
a result object returned by the action, or null
Throws:
DataAccessException - in case of GemFire errors

createRegionProxy

protected <K,V> Region<K,V> createRegionProxy(Region<K,V> region)
Create a close-suppressing proxy for the given GemFire Region. Called by the execute method.

Parameters:
region - the GemFire Region to create a proxy for
Returns:
the Region proxy, implementing all interfaces implemented by the passed-in Region object
See Also:
Region.close(), execute(GemfireCallback, boolean)


Copyright © 2010 SpringSource, a division of VMware. All Rights Reserved.