diff --git a/src/main/java/org/springframework/data/gemfire/GemfireAccessor.java b/src/main/java/org/springframework/data/gemfire/GemfireAccessor.java new file mode 100644 index 00000000..537c02b9 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/GemfireAccessor.java @@ -0,0 +1,87 @@ +/* + * Copyright 2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.gemfire; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.dao.DataAccessException; + +import com.gemstone.gemfire.GemFireCheckedException; +import com.gemstone.gemfire.GemFireException; +import com.gemstone.gemfire.cache.Region; + +/** + * Base class for GemfireTemplate and GemfireInterceptor, defining common properties such as {@link Region}. + *
+ * Not intended to be used directly. + * + * @author Costin Leau + */ +public class GemfireAccessor implements InitializingBean { + + /** Logger available to subclasses */ + protected final Log log = LogFactory.getLog(getClass()); + + private Region, ?> region; + + public void afterPropertiesSet() { + if (getRegion() == null) { + throw new IllegalArgumentException("Property 'region' is required"); + } + } + + /** + * Converts the given {@link GemFireCheckedException} to an appropriate exception from the + *org.springframework.dao hierarchy.
+ * May be overridden in subclasses.
+ * @param ex GemFireCheckedException that occurred
+ * @return the corresponding DataAccessException instance
+ */
+ public DataAccessException convertGemFireAccessException(GemFireCheckedException ex) {
+ return GemfireCacheUtils.convertGemfireAccessException(ex);
+ }
+
+ /**
+ * Converts the given {@link GemFireException} to an appropriate exception from the
+ * org.springframework.dao hierarchy.
+ * May be overridden in subclasses.
+ * @param ex GemFireException that occurred
+ * @return the corresponding DataAccessException instance
+ */
+ public DataAccessException convertGemFireAccessException(GemFireException ex) {
+ return GemfireCacheUtils.convertGemfireAccessException(ex);
+ }
+
+ /**
+ * Returns the template region.
+ *
+ * @return the region
+ */
+ public Region, ?> getRegion() {
+ return region;
+ }
+
+ /**
+ * Sets the template region.
+ *
+ * @param region the region to set
+ */
+ public void setRegion(Region, ?> region) {
+ this.region = region;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/springframework/data/gemfire/GemfireCallback.java b/src/main/java/org/springframework/data/gemfire/GemfireCallback.java
new file mode 100644
index 00000000..73f11dfe
--- /dev/null
+++ b/src/main/java/org/springframework/data/gemfire/GemfireCallback.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.data.gemfire;
+
+import com.gemstone.gemfire.GemFireCheckedException;
+import com.gemstone.gemfire.GemFireException;
+import com.gemstone.gemfire.cache.Region;
+
+/**
+ * Callback interface for GemFire code. To be used with {@link GemfireTemplate}'s execution methods, often as anonymous
+ * classes within a method implementation. A typical implementation will call Region.get/put/query to perform some
+ * operations on stored objects.
+ *
+ * @author Costin Leau
+ */
+public interface GemfireCallbackclose calls.
+ * As there is often a need to cast to a interface, the exposed proxy
+ * implements all interfaces implemented by the original {@link Region}.
+ * If this is not sufficient, turn this flag to "true".
+ * @see GemfireCallback
+ */
+ public void setExposeNativeRegion(boolean exposeNativeRegion) {
+ this.exposeNativeRegion = exposeNativeRegion;
+ }
+
+ /**
+ * Returns whether to expose the native GemFire Region to GemfireCallback
+ * code, or rather a Region proxy.
+ */
+ public boolean isExposeNativeRegion() {
+ return this.exposeNativeRegion;
+ }
+
+
+ public null
+ * @throws org.springframework.dao.DataAccessException in case of GemFire errors
+ */
+ public execute method.
+ *
+ * @param pm the GemFire Region to create a proxy for
+ * @return the Region proxy, implementing all interfaces
+ * implemented by the passed-in Region object
+ * @see Region#close()
+ * @see #execute(GemfireCallback, boolean)
+ */
+ @SuppressWarnings("unchecked")
+ protected