+ added more exception translation

This commit is contained in:
costin
2010-07-16 00:24:09 +03:00
parent 1331a16915
commit f340b2d174
7 changed files with 63 additions and 0 deletions

View File

@@ -67,6 +67,20 @@ public class GemfireAccessor implements InitializingBean {
return GemfireCacheUtils.convertGemfireAccessException(ex);
}
/**
* 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}.
* 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);
}
/**
* Returns the template region.
*

View File

@@ -72,9 +72,12 @@ 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;
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;
import com.gemstone.gemfire.cache.query.QueryExecutionTimeoutException;
import com.gemstone.gemfire.cache.query.QueryInvalidException;
import com.gemstone.gemfire.distributed.LeaseExpiredException;
import com.gemstone.gemfire.security.GemFireSecurityException;
@@ -260,4 +263,21 @@ public abstract class GemfireCacheUtils {
// fall back
return new GemfireSystemException(ex);
}
public static DataAccessException convertGemfireAccessException(IllegalArgumentException ex) {
if (ex instanceof IndexInvalidException) {
return new GemfireIndexException((IndexInvalidException) ex);
}
if (ex instanceof CqInvalidException) {
return new GemfireQueryException((CqInvalidException) ex);
}
if (ex instanceof QueryInvalidException) {
return new GemfireQueryException((QueryInvalidException) ex);
}
// fall back
return new GemfireSystemException(ex);
}
}

View File

@@ -20,6 +20,7 @@ import org.springframework.dao.DataIntegrityViolationException;
import com.gemstone.gemfire.cache.query.IndexCreationException;
import com.gemstone.gemfire.cache.query.IndexExistsException;
import com.gemstone.gemfire.cache.query.IndexInvalidException;
import com.gemstone.gemfire.cache.query.IndexMaintenanceException;
import com.gemstone.gemfire.cache.query.IndexNameConflictException;
@@ -45,4 +46,8 @@ public class GemfireIndexException extends DataIntegrityViolationException {
public GemfireIndexException(IndexMaintenanceException ex) {
super(ex.getMessage(), ex);
}
public GemfireIndexException(IndexInvalidException ex) {
super(ex.getMessage(), ex);
}
}

View File

@@ -18,8 +18,10 @@ package org.springframework.data.gemfire;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
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;
/**
* GemFire-specific subclass of {@link InvalidDataAccessResourceUsageException} thrown on invalid
@@ -36,4 +38,12 @@ public class GemfireQueryException extends InvalidDataAccessResourceUsageExcepti
public GemfireQueryException(QueryExecutionTimeoutException ex) {
super(ex.getMessage(), ex);
}
public GemfireQueryException(QueryInvalidException ex) {
super(ex.getMessage(), ex);
}
public GemfireQueryException(CqInvalidException ex) {
super(ex.getMessage(), ex);
}
}

View File

@@ -35,4 +35,8 @@ public class GemfireSystemException extends UncategorizedDataAccessException {
public GemfireSystemException(GemFireException ex) {
super(ex.getMessage(), ex);
}
public GemfireSystemException(IllegalArgumentException ex) {
super(ex.getMessage(), ex);
}
}

View File

@@ -28,6 +28,9 @@ import org.springframework.util.ClassUtils;
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;
import com.gemstone.gemfire.cache.query.SelectResults;
/**
@@ -118,6 +121,12 @@ public class GemfireTemplate extends GemfireAccessor {
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;