From 84e19d24bbd39db7d404b617500bb821a755423d Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 13 Jul 2011 13:05:28 +0300 Subject: [PATCH] SGF-54 --- .../data/gemfire/GemfireTemplate.java | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/src/main/java/org/springframework/data/gemfire/GemfireTemplate.java b/src/main/java/org/springframework/data/gemfire/GemfireTemplate.java index 716814fd..11ca780d 100644 --- a/src/main/java/org/springframework/data/gemfire/GemfireTemplate.java +++ b/src/main/java/org/springframework/data/gemfire/GemfireTemplate.java @@ -20,6 +20,8 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.util.Collection; +import java.util.Map; import org.springframework.dao.DataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; @@ -91,6 +93,52 @@ public class GemfireTemplate extends GemfireAccessor { return this.exposeNativeRegion; } + public boolean containsKey(final Object key) { + return execute(new GemfireCallback() { + @SuppressWarnings("unchecked") + public Boolean doInGemfire(Region region) throws GemFireCheckedException, GemFireException { + return region.containsKey(key); + } + }); + } + + public boolean containsKeyOnServer(final Object key) { + return execute(new GemfireCallback() { + @SuppressWarnings("unchecked") + public Boolean doInGemfire(Region region) throws GemFireCheckedException, GemFireException { + return region.containsKeyOnServer(key); + } + }); + } + + public boolean containsValue(final Object value) { + return execute(new GemfireCallback() { + @SuppressWarnings("unchecked") + public Boolean doInGemfire(Region region) throws GemFireCheckedException, GemFireException { + return region.containsValue(value); + } + }); + } + + public boolean containsValueForKey(final Object key) { + return execute(new GemfireCallback() { + @SuppressWarnings("unchecked") + public Boolean doInGemfire(Region region) throws GemFireCheckedException, GemFireException { + return region.containsValueForKey(key); + } + }); + } + + public void create(final K key, final V value) { + execute(new GemfireCallback() { + @SuppressWarnings("unchecked") + public Object doInGemfire(Region region) throws GemFireCheckedException, GemFireException { + region.create(key, value); + return null; + } + }); + } + public V get(final K key) { return execute(new GemfireCallback() { @SuppressWarnings("unchecked") @@ -109,6 +157,15 @@ public class GemfireTemplate extends GemfireAccessor { }); } + public V putIfAbsent(final K key, final V value) { + return execute(new GemfireCallback() { + @SuppressWarnings("unchecked") + public V doInGemfire(Region region) throws GemFireCheckedException, GemFireException { + return (V) region.putIfAbsent(key, value); + } + }); + } + public V remove(final K key) { return execute(new GemfireCallback() { @SuppressWarnings("unchecked") @@ -118,6 +175,43 @@ public class GemfireTemplate extends GemfireAccessor { }); } + public V replace(final K key, final V value) { + return execute(new GemfireCallback() { + @SuppressWarnings("unchecked") + public V doInGemfire(Region region) throws GemFireCheckedException, GemFireException { + return (V) region.replace(key, value); + } + }); + } + + public boolean replace(final K key, final V oldValue, final V newValue) { + return execute(new GemfireCallback() { + @SuppressWarnings("unchecked") + public Boolean doInGemfire(Region region) throws GemFireCheckedException, GemFireException { + return region.replace(key, oldValue, newValue); + } + }); + } + + public Map getAll(final Collection keys) { + return execute(new GemfireCallback>() { + @SuppressWarnings("unchecked") + public Map doInGemfire(Region region) throws GemFireCheckedException, GemFireException { + return (Map) region.getAll(keys); + } + }); + } + + public void putAll(final Map map) { + execute(new GemfireCallback() { + @SuppressWarnings("unchecked") + public Object doInGemfire(Region region) throws GemFireCheckedException, GemFireException { + region.putAll(map); + return null; + } + }); + } + /** * Shortcut for {@link Region#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.