diff --git a/src/main/java/org/springframework/data/gemfire/CacheFactoryBean.java b/src/main/java/org/springframework/data/gemfire/CacheFactoryBean.java
index d690ad08..c1ec3ac3 100644
--- a/src/main/java/org/springframework/data/gemfire/CacheFactoryBean.java
+++ b/src/main/java/org/springframework/data/gemfire/CacheFactoryBean.java
@@ -36,9 +36,6 @@ import com.gemstone.gemfire.GemFireException;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.CacheFactory;
-// /* TODO Check 6.0 and 6.5 compatibility import com.gemstone.gemfire.cache.query.CqInvalidException;
-import com.gemstone.gemfire.cache.query.IndexInvalidException;
-import com.gemstone.gemfire.cache.query.QueryInvalidException;
import com.gemstone.gemfire.distributed.DistributedMember;
import com.gemstone.gemfire.distributed.DistributedSystem;
@@ -139,15 +136,10 @@ public class CacheFactoryBean implements BeanNameAware, BeanFactoryAware, BeanCl
return GemfireCacheUtils.convertGemfireAccessException((GemFireException) ex);
}
if (ex instanceof IllegalArgumentException) {
- if (ex instanceof IndexInvalidException) {
- return GemfireCacheUtils.convertGemfireAccessException((IndexInvalidException) ex);
- }
- /* TODO Add back some mapping to be compatible with 6.0 and 6.0
- if (ex instanceof CqInvalidException) {
- return GemfireCacheUtils.convertGemfireAccessException((CqInvalidException) ex);
- }*/
- if (ex instanceof QueryInvalidException) {
- return GemfireCacheUtils.convertGemfireAccessException((QueryInvalidException) ex);
+ DataAccessException wrapped = GemfireCacheUtils.convertQueryExceptions(ex);
+ // ignore conversion if the generic exception is returned
+ if (!(wrapped instanceof GemfireSystemException)) {
+ return wrapped;
}
}
diff --git a/src/main/java/org/springframework/data/gemfire/GemfireAccessor.java b/src/main/java/org/springframework/data/gemfire/GemfireAccessor.java
index e5a7087f..dbccc62c 100644
--- a/src/main/java/org/springframework/data/gemfire/GemfireAccessor.java
+++ b/src/main/java/org/springframework/data/gemfire/GemfireAccessor.java
@@ -24,9 +24,6 @@ import org.springframework.dao.DataAccessException;
import com.gemstone.gemfire.GemFireCheckedException;
import com.gemstone.gemfire.GemFireException;
import com.gemstone.gemfire.cache.Region;
-// TODO Check 6.0 and 6.5 compatibility import com.gemstone.gemfire.cache.query.CqInvalidException;
-import com.gemstone.gemfire.cache.query.IndexInvalidException;
-import com.gemstone.gemfire.cache.query.QueryInvalidException;
/**
* Base class for GemfireTemplate and GemfireInterceptor, defining common properties such as {@link Region}.
@@ -81,20 +78,7 @@ public class GemfireAccessor implements InitializingBean {
* @return the corresponding DataAccessException instance
*/
public DataAccessException convertGemFireQueryException(RuntimeException ex) {
- /* TODO Check 6.0 and 6.5 compatibility
- if (ex instanceof CqInvalidException) {
- return GemfireCacheUtils.convertGemfireAccessException((CqInvalidException) ex);
- }*/
-
- if (ex instanceof IndexInvalidException) {
- return GemfireCacheUtils.convertGemfireAccessException((IndexInvalidException) ex);
- }
-
- if (ex instanceof QueryInvalidException) {
- return GemfireCacheUtils.convertGemfireAccessException((QueryInvalidException) ex);
- }
-
- return new GemfireSystemException(ex);
+ return GemfireCacheUtils.convertQueryExceptions(ex);
}
/**
diff --git a/src/main/java/org/springframework/data/gemfire/GemfireCacheUtils.java b/src/main/java/org/springframework/data/gemfire/GemfireCacheUtils.java
index 3f9a999f..55686fef 100644
--- a/src/main/java/org/springframework/data/gemfire/GemfireCacheUtils.java
+++ b/src/main/java/org/springframework/data/gemfire/GemfireCacheUtils.java
@@ -26,6 +26,7 @@ import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.dao.PermissionDeniedDataAccessException;
import org.springframework.dao.PessimisticLockingFailureException;
import org.springframework.dao.TypeMismatchDataAccessException;
+import org.springframework.util.ClassUtils;
import com.gemstone.gemfire.CancelException;
import com.gemstone.gemfire.CopyException;
@@ -72,7 +73,6 @@ import com.gemstone.gemfire.cache.VersionException;
import com.gemstone.gemfire.cache.client.ServerConnectivityException;
import com.gemstone.gemfire.cache.execute.FunctionException;
import com.gemstone.gemfire.cache.query.CqClosedException;
-// TODO Check 6.0 and 6.5 compatibility import com.gemstone.gemfire.cache.query.CqInvalidException;
import com.gemstone.gemfire.cache.query.IndexInvalidException;
import com.gemstone.gemfire.cache.query.IndexMaintenanceException;
import com.gemstone.gemfire.cache.query.QueryException;
@@ -88,6 +88,23 @@ import com.gemstone.gemfire.security.GemFireSecurityException;
*/
public abstract class GemfireCacheUtils {
+ private static Class> CQ_EXCEPTION_CLASS;
+
+ {
+ Class> clz = null;
+
+ try {
+
+ clz = ClassUtils.resolveClassName("com.gemstone.gemfire.cache.query.CqInvalidException",
+ GemfireCacheUtils.class.getClassLoader());
+
+ } catch (IllegalArgumentException iae) {
+ }
+
+ CQ_EXCEPTION_CLASS = clz;
+ }
+
+
/**
* Converts the given (unchecked) Gemfire exception to an appropriate one from the
* org.springframework.dao hierarchy.
@@ -250,19 +267,20 @@ public abstract class GemfireCacheUtils {
* @param ex
* @return
*/
- private static DataAccessException convertQueryExceptions(RuntimeException ex) {
+ static DataAccessException convertQueryExceptions(RuntimeException ex) {
if (ex instanceof IndexInvalidException) {
return convertGemfireAccessException((IndexInvalidException) ex);
}
if (ex instanceof QueryInvalidException) {
return convertGemfireAccessException((QueryInvalidException) ex);
}
- /* TODO Check 6.0 and 6.5 compatibility
- if (ex instanceof CqInvalidException) {
- return convertGemfireAccessException((CqInvalidException) ex);
+
+ if (isCqInvalidException(ex)) {
+ return convertCqInvalidException(ex);
}
- */
- return null;
+
+ // fall back
+ return new GemfireSystemException(ex);
}
/**
@@ -317,16 +335,25 @@ public abstract class GemfireCacheUtils {
return new GemfireQueryException(ex);
}
+ /**
+ * Package protected method for detecting CqInvalidException which has been removed in GemFire 6.5 GA.
+ *
+ * @param ex
+ * @return
+ */
+ static boolean isCqInvalidException(RuntimeException ex) {
+ return (CQ_EXCEPTION_CLASS != null && CQ_EXCEPTION_CLASS.isAssignableFrom(ex.getClass()));
+ }
+
/**
* Converts the given (unchecked) Gemfire exception to an appropriate one from the
* org.springframework.dao hierarchy. This method exists to handle backwards compatibility
- * for exceptions that had their parents changed in GemFire 6.5.
+ * for exceptions that have been removed in 6.5.
*
* @param ex Gemfire unchecked exception
* @return new the corresponding DataAccessException instance
*/
- /* TODO Check 6.0 and 6.5 compatibility
- public static DataAccessException convertGemfireAccessException(CqInvalidException ex) {
+ static DataAccessException convertCqInvalidException(RuntimeException ex) {
return new GemfireQueryException(ex);
- }*/
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/springframework/data/gemfire/GemfireQueryException.java b/src/main/java/org/springframework/data/gemfire/GemfireQueryException.java
index 0301fb88..9927397a 100644
--- a/src/main/java/org/springframework/data/gemfire/GemfireQueryException.java
+++ b/src/main/java/org/springframework/data/gemfire/GemfireQueryException.java
@@ -18,7 +18,6 @@ package org.springframework.data.gemfire;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
-//TODO Check 6.0 and 6.5 compatibility import com.gemstone.gemfire.cache.query.CqInvalidException;
import com.gemstone.gemfire.cache.query.QueryException;
import com.gemstone.gemfire.cache.query.QueryExecutionTimeoutException;
import com.gemstone.gemfire.cache.query.QueryInvalidException;
@@ -43,8 +42,13 @@ public class GemfireQueryException extends InvalidDataAccessResourceUsageExcepti
super(ex.getMessage(), ex);
}
- /* TODO Check 6.0 and 6.5 compatibility
- public GemfireQueryException(CqInvalidException ex) {
+ /**
+ * Dedicated constructor for CqInvalidException. Since the class has been removed in 6.5,
+ * the constructor is protected to prevent illegal access.
+ *
+ * @param ex
+ */
+ GemfireQueryException(RuntimeException ex) {
super(ex.getMessage(), ex);
- }*/
+ }
}
diff --git a/src/main/java/org/springframework/data/gemfire/GemfireTemplate.java b/src/main/java/org/springframework/data/gemfire/GemfireTemplate.java
index 2343400d..da33d8b2 100644
--- a/src/main/java/org/springframework/data/gemfire/GemfireTemplate.java
+++ b/src/main/java/org/springframework/data/gemfire/GemfireTemplate.java
@@ -28,7 +28,6 @@ import org.springframework.util.ClassUtils;
import com.gemstone.gemfire.GemFireCheckedException;
import com.gemstone.gemfire.GemFireException;
import com.gemstone.gemfire.cache.Region;
-//TODO Check 6.0 and 6.5 compatibility import com.gemstone.gemfire.cache.query.CqInvalidException;
import com.gemstone.gemfire.cache.query.IndexInvalidException;
import com.gemstone.gemfire.cache.query.QueryInvalidException;
import com.gemstone.gemfire.cache.query.SelectResults;
@@ -119,10 +118,6 @@ public class GemfireTemplate extends GemfireAccessor {
return result;
} catch (IndexInvalidException ex) {
throw convertGemFireQueryException(ex);
- /* TODO Check 6.0 and 6.5 compatibility
- } catch (CqInvalidException ex) {
- throw convertGemFireQueryException(ex);
- */
} catch (QueryInvalidException ex) {
throw convertGemFireQueryException(ex);
} catch (GemFireCheckedException ex) {
@@ -130,6 +125,10 @@ public class GemfireTemplate extends GemfireAccessor {
} catch (GemFireException ex) {
throw convertGemFireAccessException(ex);
} catch (RuntimeException ex) {
+ // try first the CqInvalidException (removed in 6.5)
+ if (GemfireCacheUtils.isCqInvalidException(ex)) {
+ throw GemfireCacheUtils.convertCqInvalidException(ex);
+ }
// callback code threw application exception
throw ex;
}