public class GemfireTemplate extends GemfireAccessor implements GemfireOperations
GemfireTemplate class simplifies Apache Geode data access operations, converting Apache Geode
GemFireCheckedExceptions and GemFireExceptions into
Spring DataAccessExceptions, following the org.springframework.dao
Exception hierarchy.
The central method is execute, supporting Apache Geode data 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.
This template class is typically used to implement data access operations or business logic services using Apache
Geode within their implementation but are Geode-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.Map,
GemFireCheckedException,
GemFireException,
Region,
ClientCache,
Query,
QueryService,
SelectResults,
GemfireAccessor,
GemfireOperationslogger| Constructor and Description |
|---|
GemfireTemplate()
Constructs a new, uninitialized instance of
GemfireTemplate. |
GemfireTemplate(org.apache.geode.cache.Region<K,V> region)
Constructs a new instance of the
GemfireTemplate initialized with the given Region on which
(cache) data access operations will be performed. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
boolean |
containsKey(Object key) |
boolean |
containsKeyOnServer(Object key) |
boolean |
containsValue(Object value) |
boolean |
containsValueForKey(Object key) |
<K,V> void |
create(K key,
V value) |
protected <K,V> org.apache.geode.cache.Region<K,V> |
createRegionProxy(org.apache.geode.cache.Region<K,V> region)
Create a close-suppressing proxy for the given Apache Geode cache
Region. |
<T> T |
execute(GemfireCallback<T> action)
Executes the given data access operation defined by the
GemfireCallback in the context of Apache Geode. |
<T> T |
execute(GemfireCallback<T> action,
boolean exposeNativeRegion)
Executes the given data access operation defined by the
GemfireCallback in the context of Apache Geode. |
<E> org.apache.geode.cache.query.SelectResults<E> |
find(String query,
Object... arguments)
Executes a GemFire query with the given (optional) parameters and returns the result.
|
<T> T |
findUnique(String query,
Object... arguments)
Executes a GemFire query with the given (optional) parameters and returns the result.
|
<K,V> V |
get(K key) |
<K,V> Map<K,V> |
getAll(Collection<?> keys) |
boolean |
isExposeNativeRegion()
|
<K,V> V |
put(K key,
V value) |
<K,V> void |
putAll(Map<? extends K,? extends V> map) |
<K,V> V |
putIfAbsent(K key,
V value) |
<E> org.apache.geode.cache.query.SelectResults<E> |
query(String query)
Shortcut for
Region.query(String) method. |
<K,V> V |
remove(K key) |
void |
removeAll(Collection<?> keys) |
<K,V> V |
replace(K key,
V value) |
<K,V> boolean |
replace(K key,
V oldValue,
V newValue) |
protected org.apache.geode.cache.query.QueryService |
resolveQueryService(org.apache.geode.cache.Region<?,?> region)
Returns the
QueryService used by this template in its query/finder methods. |
void |
setExposeNativeRegion(boolean exposeNativeRegion)
Configure whether to expose the native
Region to GemfireCallback code. |
convertGemFireAccessException, convertGemFireAccessException, convertGemFireQueryException, getRegion, setRegionpublic GemfireTemplate()
GemfireTemplate.GemfireTemplate(Region)public GemfireTemplate(org.apache.geode.cache.Region<K,V> region)
GemfireTemplate initialized with the given Region on which
(cache) data access operations will be performed.K - type of the Region key.V - type of the Region value.region - Region on which data access operations will be performed by this template;
must not be null.IllegalArgumentException - if Region is null.GemfireAccessor.setRegion(Region),
afterPropertiesSet()public void afterPropertiesSet()
afterPropertiesSet in interface InitializingBeanafterPropertiesSet in class GemfireAccessorpublic void setExposeNativeRegion(boolean exposeNativeRegion)
Region to GemfireCallback code.
Default is false, therefore a Region proxy will be returned,
suppressing close calls.
As there is often a need to cast to an interface, the exposed proxy implements all interfaces implemented by
the original Region. If this is not sufficient, turn this flag to true.
exposeNativeRegion - a boolean value indicating whether the native Region should be exposed to
the GemfireCallback.GemfireCallbackpublic boolean isExposeNativeRegion()
Region or the Region proxy
is exposed to GemfireCallback code.setExposeNativeRegion(boolean)public boolean containsKey(Object key)
containsKey in interface GemfireOperationspublic boolean containsKeyOnServer(Object key)
containsKeyOnServer in interface GemfireOperationspublic boolean containsValue(Object value)
containsValue in interface GemfireOperationspublic boolean containsValueForKey(Object key)
containsValueForKey in interface GemfireOperationspublic <K,V> void create(K key,
V value)
create in interface GemfireOperationspublic <K,V> V get(K key)
get in interface GemfireOperationspublic <K,V> Map<K,V> getAll(Collection<?> keys)
getAll in interface GemfireOperationspublic <K,V> V put(K key,
V value)
put in interface GemfireOperationspublic <K,V> void putAll(Map<? extends K,? extends V> map)
putAll in interface GemfireOperationspublic <K,V> V putIfAbsent(K key,
V value)
putIfAbsent in interface GemfireOperationspublic <K,V> V remove(K key)
remove in interface GemfireOperationspublic void removeAll(Collection<?> keys)
removeAll in interface GemfireOperationspublic <K,V> V replace(K key,
V value)
replace in interface GemfireOperationspublic <K,V> boolean replace(K key,
V oldValue,
V newValue)
replace in interface GemfireOperationspublic <E> org.apache.geode.cache.query.SelectResults<E> query(String query)
GemfireOperationsRegion.query(String) method. Filters the values of this region using the predicate given as a string with the syntax of the WHERE clause of the query language.
The predefined variable this may be used inside the predicate to denote the current element being filtered.
This method evaluates the passed in where clause and returns results. It is supported on servers as well as clients.
When executed on a client, this method always runs on the server and returns results.
When invoking this method from the client, applications can pass in a where clause or a complete query.query in interface GemfireOperationsE - type parameter specifying the type of the select results.query - an OQL Query language boolean query predicate.Region.query(String)public <E> org.apache.geode.cache.query.SelectResults<E> find(String query, Object... arguments) throws InvalidDataAccessApiUsageException
GemfireOperationsGemfireOperations.findUnique(String, Object...).
As oppose, to the GemfireOperations.query(String) method, this method allows for more generic queries (against multiple regions even) to be executed.
Note that the local query service is used if the region is configured as a client without any pool configuration or server connectivity - otherwise the query service on the default pool
is being used.find in interface GemfireOperationsE - type parameter specifying the type of the select results.query - the OQL query statement to execute.arguments - an array of Object values used as arguments to bind to the OQL query parameters (such as $1).SelectResults instance holding the objects matching the queryInvalidDataAccessApiUsageException - in case the query returns a single result (not a SelectResults).QueryService.newQuery(String),
Query.execute(Object[]),
SelectResultspublic <T> T findUnique(String query, Object... arguments) throws InvalidDataAccessApiUsageException
GemfireOperationsGemfireOperations.find(String, Object...).
As oppose, to the GemfireOperations.query(String) method, this method allows for more generic queries (against multiple regions even) to be executed.
Note that the local query service is used if the region is configured as a client without any pool configuration or server connectivity - otherwise the query service on the default pool
is being used.findUnique in interface GemfireOperationsT - type parameter specifying the returned result type.query - the OQL query statement to execute.arguments - an array of Object values used as arguments to bind to the OQL query parameters (such as $1).InvalidDataAccessApiUsageException - in case the query returns multiple objects (through SelectResults).QueryService.newQuery(String),
Query.execute(Object[])protected org.apache.geode.cache.query.QueryService resolveQueryService(org.apache.geode.cache.Region<?,?> region)
QueryService used by this template in its query/finder methods.region - Region used to acquire the QueryService.QueryService that will perform the Query.Region,
Region.getRegionService(),
RegionService.getQueryService(),
ClientCache.getLocalQueryService()public <T> T execute(@NonNull GemfireCallback<T> action) throws DataAccessException
GemfireCallback in the context of Apache Geode.execute in interface GemfireOperationsT - type returned by the GemfireCallback.action - GemfireCallback object defining the Apache Geode action to execute;
must not be null.GemfireCallback.DataAccessException - if an Apache Geode error is thrown by a data access operation.IllegalArgumentException - if GemfireCallback is null.GemfireCallback,
execute(GemfireCallback, boolean)public <T> T execute(@NonNull GemfireCallback<T> action, boolean exposeNativeRegion) throws DataAccessException
GemfireCallback in the context of Apache Geode.execute in interface GemfireOperationsT - type returned by the GemfireCallback.action - GemfireCallback object defining the Apache Geode action to execute;
must not be null.exposeNativeRegion - boolean value indicating whether to pass the native Region
or the Region proxy to the GemfireCallback.GemfireCallback.DataAccessException - if an Apache Geode error is thrown by a data access operation.IllegalArgumentException - if GemfireCallback is null.GemfireCallback@NonNull protected <K,V> org.apache.geode.cache.Region<K,V> createRegionProxy(@NonNull org.apache.geode.cache.Region<K,V> region)
Region.
Called by the execute method.K - type of the Region key.V - type of the Region value.region - Region for which a proxy will be created.Region.close(),
execute(GemfireCallback, boolean)Copyright © 2011–2023 Pivotal Software, Inc.. All rights reserved.