created Cassandra-specific Spring DataAccessException for each Datastax DriverException
This commit is contained in:
@@ -16,37 +16,83 @@
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.data.cassandra.core.exceptions.*;
|
||||
|
||||
import com.datastax.driver.core.exceptions.InvalidQueryException;
|
||||
import com.datastax.driver.core.exceptions.*;
|
||||
|
||||
/**
|
||||
* Simple {@link PersistenceExceptionTranslator} for Cassandra. Convert the given runtime exception to an appropriate
|
||||
* exception from the {@code org.springframework.dao} hierarchy. Return {@literal null} if no translation is
|
||||
* appropriate: any other exception may have resulted from user code, and should not be translated.
|
||||
* Simple {@link PersistenceExceptionTranslator} for Cassandra. Convert the
|
||||
* given runtime exception to an appropriate exception from the
|
||||
* {@code org.springframework.dao} hierarchy. Return {@literal null} if no
|
||||
* translation is appropriate: any other exception may have resulted from user
|
||||
* code, and should not be translated.
|
||||
*
|
||||
* @author Alex Shvid
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
|
||||
public class CassandraExceptionTranslator implements PersistenceExceptionTranslator {
|
||||
public class CassandraExceptionTranslator implements
|
||||
PersistenceExceptionTranslator {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.dao.support.PersistenceExceptionTranslator#translateExceptionIfPossible(java.lang.RuntimeException)
|
||||
*
|
||||
* @see org.springframework.dao.support.PersistenceExceptionTranslator#
|
||||
* translateExceptionIfPossible(java.lang.RuntimeException)
|
||||
*/
|
||||
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
|
||||
public DataAccessException translateExceptionIfPossible(RuntimeException x) {
|
||||
|
||||
// Check for well-known Cassandra subclasses.
|
||||
|
||||
if (ex instanceof InvalidQueryException) {
|
||||
return new DataAccessResourceFailureException(ex.getMessage(), ex);
|
||||
if (!(x instanceof DriverException)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If we get here, we have an exception that resulted from user code,
|
||||
// rather than the persistence provider, so we return null to indicate
|
||||
// that translation should not occur.
|
||||
return null;
|
||||
|
||||
if (x instanceof AuthenticationException) {
|
||||
return new CassandraAuthenticationException(x.getMessage(), x);
|
||||
}
|
||||
if (x instanceof DriverInternalError) {
|
||||
return new CassandraDriverInternalErrorException(x.getMessage(), x);
|
||||
}
|
||||
if (x instanceof InvalidTypeException) {
|
||||
return new CassandraInvalidTypeException(x.getMessage(), x);
|
||||
}
|
||||
if (x instanceof NoHostAvailableException) {
|
||||
return new CassandraNoHostAvailableException(x.getMessage(), x);
|
||||
}
|
||||
if (x instanceof ReadTimeoutException) {
|
||||
return new CassandraReadTimeoutException(x.getMessage(), x);
|
||||
}
|
||||
if (x instanceof WriteTimeoutException) {
|
||||
return new CassandraWriteTimeoutException(x.getMessage(), x);
|
||||
}
|
||||
if (x instanceof TruncateException) {
|
||||
return new CassandraTruncateException(x.getMessage(), x);
|
||||
}
|
||||
if (x instanceof UnavailableException) {
|
||||
return new CassandraUnavailableException(x.getMessage(), x);
|
||||
}
|
||||
if (x instanceof AlreadyExistsException) {
|
||||
return new CassandraAlreadyExistsException(x.getMessage(), x);
|
||||
}
|
||||
if (x instanceof InvalidConfigurationInQueryException) {
|
||||
return new CassandraInvalidConfigurationInQueryException(
|
||||
x.getMessage(), x);
|
||||
}
|
||||
// this must come after cases for subclasses
|
||||
if (x instanceof InvalidQueryException) {
|
||||
return new CassandraInvalidQueryException(x.getMessage(), x);
|
||||
}
|
||||
if (x instanceof SyntaxError) {
|
||||
return new CassandraSyntaxErrorException(x.getMessage(), x);
|
||||
}
|
||||
if (x instanceof UnauthorizedException) {
|
||||
return new CassandraUnauthorizedException(x.getMessage(), x);
|
||||
}
|
||||
if (x instanceof TraceRetrievalException) {
|
||||
return new CassandraTraceRetrievalException(x.getMessage(), x);
|
||||
}
|
||||
|
||||
// unknown or unhandled exception
|
||||
return new CassandraUncategorizedException(x.getMessage(), x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.core.exceptions.CassandraConnectionFailureException;
|
||||
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
|
||||
import org.springframework.data.cassandra.mapping.CassandraPersistentProperty;
|
||||
import org.springframework.data.cassandra.vo.RingMember;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.NonTransientDataAccessException;
|
||||
|
||||
public class CassandraAlreadyExistsException extends
|
||||
NonTransientDataAccessException {
|
||||
|
||||
private static final long serialVersionUID = 6032967419751410352L;
|
||||
|
||||
public CassandraAlreadyExistsException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CassandraAlreadyExistsException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.PermissionDeniedDataAccessException;
|
||||
|
||||
public class CassandraAuthenticationException extends
|
||||
PermissionDeniedDataAccessException {
|
||||
|
||||
private static final long serialVersionUID = 8556304586797273927L;
|
||||
|
||||
public CassandraAuthenticationException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
|
||||
@@ -24,6 +24,8 @@ import org.springframework.dao.DataAccessResourceFailureException;
|
||||
*/
|
||||
public class CassandraConnectionFailureException extends DataAccessResourceFailureException {
|
||||
|
||||
private static final long serialVersionUID = 4856524591258560460L;
|
||||
|
||||
public CassandraConnectionFailureException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
|
||||
public class CassandraDriverInternalErrorException extends
|
||||
DataAccessResourceFailureException {
|
||||
|
||||
private static final long serialVersionUID = 433061676465346338L;
|
||||
|
||||
public CassandraDriverInternalErrorException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CassandraDriverInternalErrorException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
|
||||
public class CassandraInvalidConfigurationInQueryException extends
|
||||
InvalidDataAccessApiUsageException {
|
||||
|
||||
private static final long serialVersionUID = 4594321191806182918L;
|
||||
|
||||
public CassandraInvalidConfigurationInQueryException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CassandraInvalidConfigurationInQueryException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
|
||||
public class CassandraInvalidQueryException extends
|
||||
InvalidDataAccessApiUsageException {
|
||||
|
||||
private static final long serialVersionUID = 4594321191806182918L;
|
||||
|
||||
public CassandraInvalidQueryException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CassandraInvalidQueryException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.TypeMismatchDataAccessException;
|
||||
|
||||
public class CassandraInvalidTypeException extends
|
||||
TypeMismatchDataAccessException {
|
||||
|
||||
private static final long serialVersionUID = -7420058975444905629L;
|
||||
|
||||
public CassandraInvalidTypeException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CassandraInvalidTypeException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
|
||||
public class CassandraNoHostAvailableException extends
|
||||
DataAccessResourceFailureException {
|
||||
|
||||
private static final long serialVersionUID = 6299912054261646552L;
|
||||
|
||||
public CassandraNoHostAvailableException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CassandraNoHostAvailableException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.QueryTimeoutException;
|
||||
|
||||
public class CassandraReadTimeoutException extends QueryTimeoutException {
|
||||
|
||||
private static final long serialVersionUID = -787022307935203387L;
|
||||
|
||||
public CassandraReadTimeoutException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CassandraReadTimeoutException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
|
||||
public class CassandraSyntaxErrorException extends InvalidDataAccessApiUsageException {
|
||||
|
||||
private static final long serialVersionUID = 4398474399882434154L;
|
||||
|
||||
public CassandraSyntaxErrorException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CassandraSyntaxErrorException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.TransientDataAccessException;
|
||||
|
||||
public class CassandraTraceRetrievalException extends
|
||||
TransientDataAccessException {
|
||||
|
||||
private static final long serialVersionUID = -3163557220324700239L;
|
||||
|
||||
public CassandraTraceRetrievalException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CassandraTraceRetrievalException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.TransientDataAccessException;
|
||||
|
||||
public class CassandraTruncateException extends TransientDataAccessException {
|
||||
|
||||
private static final long serialVersionUID = 5730642491362430311L;
|
||||
|
||||
public CassandraTruncateException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CassandraTruncateException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.PermissionDeniedDataAccessException;
|
||||
|
||||
public class CassandraUnauthorizedException extends
|
||||
PermissionDeniedDataAccessException {
|
||||
|
||||
private static final long serialVersionUID = 4618185356687726647L;
|
||||
|
||||
public CassandraUnauthorizedException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
|
||||
public class CassandraUnavailableException extends ConcurrencyFailureException {
|
||||
|
||||
private static final long serialVersionUID = 6415130674604814905L;
|
||||
|
||||
public CassandraUnavailableException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CassandraUnavailableException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.UncategorizedDataAccessException;
|
||||
|
||||
@@ -23,10 +23,11 @@ import org.springframework.dao.UncategorizedDataAccessException;
|
||||
* @author Alex Shvid
|
||||
*/
|
||||
|
||||
public class CassandraSystemException extends UncategorizedDataAccessException {
|
||||
public class CassandraUncategorizedException extends UncategorizedDataAccessException {
|
||||
|
||||
public CassandraSystemException(String msg, Throwable cause) {
|
||||
private static final long serialVersionUID = 1029525121238025444L;
|
||||
|
||||
public CassandraUncategorizedException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springframework.data.cassandra.core.exceptions;
|
||||
|
||||
import org.springframework.dao.QueryTimeoutException;
|
||||
|
||||
public class CassandraWriteTimeoutException extends QueryTimeoutException {
|
||||
|
||||
private static final long serialVersionUID = -4374826375213670718L;
|
||||
|
||||
public CassandraWriteTimeoutException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CassandraWriteTimeoutException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user