diff --git a/src/main/java/org/springframework/data/gemfire/GemfireAccessor.java b/src/main/java/org/springframework/data/gemfire/GemfireAccessor.java index c86d6b1d..098e6449 100644 --- a/src/main/java/org/springframework/data/gemfire/GemfireAccessor.java +++ b/src/main/java/org/springframework/data/gemfire/GemfireAccessor.java @@ -24,6 +24,9 @@ import org.springframework.dao.DataAccessException; import com.gemstone.gemfire.GemFireCheckedException; import com.gemstone.gemfire.GemFireException; import com.gemstone.gemfire.cache.Region; +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}. @@ -70,15 +73,27 @@ public class GemfireAccessor implements InitializingBean { /** * Converts the given GemFire exception to an appropriate exception from the * org.springframework.dao hierarchy. Note that this particular implementation - * is called only for GemFire exception that extend {@link IllegalArgumentException}. + * is called only for GemFire querying exception that do NOT extend from GemFire exception. * May be overridden in subclasses. * * @see com.gemstone.gemfire.cache.query.CqInvalidException * @param ex GemFireException that occurred * @return the corresponding DataAccessException instance */ - public DataAccessException convertGemFireAccessException(IllegalArgumentException ex) { - return GemfireCacheUtils.convertGemfireAccessException(ex); + public DataAccessException convertGemFireQueryException(RuntimeException ex) { + 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); } /** diff --git a/src/main/java/org/springframework/data/gemfire/GemfireCacheUtils.java b/src/main/java/org/springframework/data/gemfire/GemfireCacheUtils.java index 20da530d..fe62978d 100644 --- a/src/main/java/org/springframework/data/gemfire/GemfireCacheUtils.java +++ b/src/main/java/org/springframework/data/gemfire/GemfireCacheUtils.java @@ -232,10 +232,39 @@ public abstract class GemfireCacheUtils { if (ex instanceof UnmodifiableException) { return new GemfireSystemException(ex); } + + // for exceptions that had their parent changed in 6.5 + DataAccessException dae = convertQueryExceptions(ex); + if (dae != null) + return dae; + // fall back return new GemfireSystemException(ex); } + /** + * Dedicated method for converting exceptions changed in 6.5 that had their + * parent changed. This method exists to 'fool' the compiler type checks + * by loosening the type so the code compiles on both 6.5 (pre and current) branches. + * + * @param ex + * @return + */ + private static DataAccessException convertQueryExceptions(RuntimeException ex) { + if (ex instanceof IndexInvalidException) { + return convertGemfireAccessException((IndexInvalidException) ex); + } + if (ex instanceof QueryInvalidException) { + return convertGemfireAccessException((QueryInvalidException) ex); + } + + if (ex instanceof CqInvalidException) { + return convertGemfireAccessException((CqInvalidException) ex); + } + + return null; + } + /** * Converts the given (checked) Gemfire exception to an appropriate one from the * org.springframework.dao hierarchy. @@ -264,20 +293,39 @@ public abstract class GemfireCacheUtils { return new GemfireSystemException(ex); } - public static DataAccessException convertGemfireAccessException(IllegalArgumentException ex) { - if (ex instanceof IndexInvalidException) { - return new GemfireIndexException((IndexInvalidException) ex); - } + /** + * 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. + * + * @param ex Gemfire unchecked exception + * @return new the corresponding DataAccessException instance + */ + public static DataAccessException convertGemfireAccessException(IndexInvalidException ex) { + return new GemfireIndexException(ex); + } - if (ex instanceof CqInvalidException) { - return new GemfireQueryException((CqInvalidException) ex); - } + /** + * 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. + * + * @param ex Gemfire unchecked exception + * @return new the corresponding DataAccessException instance + */ + public static DataAccessException convertGemfireAccessException(QueryInvalidException ex) { + return new GemfireQueryException(ex); + } - if (ex instanceof QueryInvalidException) { - return new GemfireQueryException((QueryInvalidException) ex); - } - - // fall back - return new GemfireSystemException(ex); + /** + * 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. + * + * @param ex Gemfire unchecked exception + * @return new the corresponding DataAccessException instance + */ + public static DataAccessException convertGemfireAccessException(CqInvalidException ex) { + return new GemfireQueryException(ex); } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/GemfireSystemException.java b/src/main/java/org/springframework/data/gemfire/GemfireSystemException.java index 534387cb..d735cab3 100644 --- a/src/main/java/org/springframework/data/gemfire/GemfireSystemException.java +++ b/src/main/java/org/springframework/data/gemfire/GemfireSystemException.java @@ -36,7 +36,7 @@ public class GemfireSystemException extends UncategorizedDataAccessException { super(ex.getMessage(), ex); } - public GemfireSystemException(IllegalArgumentException ex) { + public GemfireSystemException(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 3744f426..6ca34b27 100644 --- a/src/main/java/org/springframework/data/gemfire/GemfireTemplate.java +++ b/src/main/java/org/springframework/data/gemfire/GemfireTemplate.java @@ -117,16 +117,16 @@ public class GemfireTemplate extends GemfireAccessor { Region regionToExpose = (exposeNativeRegion ? getRegion() : regionProxy); T result = action.doInGemfire(regionToExpose); return result; + } catch (IndexInvalidException ex) { + throw convertGemFireQueryException(ex); + } catch (CqInvalidException ex) { + throw convertGemFireQueryException(ex); + } catch (QueryInvalidException ex) { + throw convertGemFireQueryException(ex); } catch (GemFireCheckedException ex) { throw convertGemFireAccessException(ex); } catch (GemFireException ex) { throw convertGemFireAccessException(ex); - } catch (IndexInvalidException ex) { - throw convertGemFireAccessException(ex); - } catch (CqInvalidException ex) { - throw convertGemFireAccessException(ex); - } catch (QueryInvalidException ex) { - throw convertGemFireAccessException(ex); } catch (RuntimeException ex) { // callback code threw application exception throw ex;