+ refactored code to accommodate the exception hierarchy changes in 6.5 for 3 of the query exceptions

This commit is contained in:
costin
2010-07-30 13:47:18 +03:00
parent 7a143259aa
commit 5cc671e632
4 changed files with 86 additions and 23 deletions

View File

@@ -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
* <code>org.springframework.dao</code> 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 <b>NOT</b> 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);
}
/**

View File

@@ -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
* <code>org.springframework.dao</code> 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
* <code>org.springframework.dao</code> 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
* <code>org.springframework.dao</code> 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
* <code>org.springframework.dao</code> 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);
}
}

View File

@@ -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);
}
}

View File

@@ -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;