diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/CassandraUncategorizedDataAccessException.java b/spring-cql/src/main/java/org/springframework/cassandra/core/CassandraUncategorizedDataAccessException.java
index 6656db25e..44226c02b 100644
--- a/spring-cql/src/main/java/org/springframework/cassandra/core/CassandraUncategorizedDataAccessException.java
+++ b/spring-cql/src/main/java/org/springframework/cassandra/core/CassandraUncategorizedDataAccessException.java
@@ -1,12 +1,12 @@
/*
* Copyright 2013-2014 the original author or authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,7 +19,7 @@ import org.springframework.dao.UncategorizedDataAccessException;
/**
* Wrapper for all non RuntimeExceptions throws by the Cassandra Driver
- *
+ *
* @author David Webb
*/
public class CassandraUncategorizedDataAccessException extends UncategorizedDataAccessException {
@@ -28,12 +28,12 @@ public class CassandraUncategorizedDataAccessException extends UncategorizedData
/**
* Create the Exception
- *
- * @param msg
+ *
+ * @param message
* @param cause
*/
- public CassandraUncategorizedDataAccessException(String msg, Throwable cause) {
- super(msg, cause);
+ public CassandraUncategorizedDataAccessException(String message, Throwable cause) {
+ super(message, cause);
}
}
diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/CqlTemplate.java b/spring-cql/src/main/java/org/springframework/cassandra/core/CqlTemplate.java
index a7f794136..f36fc38a5 100644
--- a/spring-cql/src/main/java/org/springframework/cassandra/core/CqlTemplate.java
+++ b/spring-cql/src/main/java/org/springframework/cassandra/core/CqlTemplate.java
@@ -251,8 +251,8 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
try {
return callback.doInSession(getSession());
- } catch (Exception e) {
- throw translateExceptionIfPossible(e);
+ } catch (Throwable t) {
+ throw translateExceptionIfPossible(t);
}
}
@@ -335,7 +335,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
} catch (ExecutionException e) {
if (e.getCause() instanceof Exception) {
- throw translateExceptionIfPossible((Exception) e.getCause());
+ throw translateExceptionIfPossible(e.getCause());
}
throw new CassandraUncategorizedDataAccessException("Unknown Throwable", e.getCause());
}
@@ -886,8 +886,8 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
* @see Consistent exception hierarchy
*/
@SuppressWarnings("all")
- protected RuntimeException translateExceptionIfPossible(Exception e) {
- return translateExceptionIfPossible(e, getExceptionTranslator());
+ protected RuntimeException translateExceptionIfPossible(Throwable t) {
+ return translateExceptionIfPossible(t, getExceptionTranslator());
}
/**
@@ -899,14 +899,14 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
* @return
*/
@SuppressWarnings("all")
- protected static RuntimeException translateExceptionIfPossible(Exception e,
+ protected static RuntimeException translateExceptionIfPossible(Throwable t,
PersistenceExceptionTranslator exceptionTranslator) {
- Assert.notNull(e, "Exception must not be null");
+ Assert.notNull(t, "Throwble must not be null");
Assert.notNull(exceptionTranslator, "PersistenceExceptionTranslator must not be null");
- return (e instanceof RuntimeException) ? potentiallyConvertRuntimeException((RuntimeException) e, exceptionTranslator)
- : new CassandraUncategorizedDataAccessException("Caught Uncategorized Exception", e);
+ return (t instanceof RuntimeException) ? potentiallyConvertRuntimeException((RuntimeException) t, exceptionTranslator)
+ : new CassandraUncategorizedDataAccessException("Caught Uncategorized Exception", t);
}
/**
diff --git a/spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java
index c58b045ab..e315f4932 100644
--- a/spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java
+++ b/spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java
@@ -30,6 +30,7 @@ import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.cassandra.support.CassandraExceptionTranslator;
import org.springframework.cassandra.support.exception.CassandraReadTimeoutException;
+import org.springframework.cassandra.support.exception.CassandraUncategorizedException;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
@@ -38,6 +39,7 @@ import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
+import com.datastax.driver.core.exceptions.DriverException;
import com.datastax.driver.core.exceptions.ReadTimeoutException;
import com.datastax.driver.core.querybuilder.Select;
@@ -80,8 +82,11 @@ public class CqlTemplateUnitTests {
verify(mockSession, times(1)).execute(eq("test"));
}
+ /**
+ * @see DATACASS-304
+ */
@Test
- public void doExecuteInSessionCallbackTranslatesException() {
+ public void doExecuteInSessionCallbackTranslatesToCassandraException() {
exception.expect(CassandraReadTimeoutException.class);
exception.expectCause(org.hamcrest.Matchers.isA(ReadTimeoutException.class));
@@ -92,6 +97,38 @@ public class CqlTemplateUnitTests {
});
}
+ /**
+ * @see DATACASS-304
+ */
+ @Test
+ public void doExecuteInSessionCallbackTranslatesToCassandraUncategorizedException() {
+ exception.expect(CassandraUncategorizedException.class);
+ exception.expectCause(org.hamcrest.Matchers.isA(DriverException.class));
+ exception.expectMessage(containsString("test"));
+
+ template.doExecute(new SessionCallback() {
+ @Override public String doInSession(Session session) throws DataAccessException {
+ throw new DriverException("test");
+ }
+ });
+ }
+
+ /**
+ * @see DATACASS-304
+ */
+ @Test
+ public void doExecuteInSessionCallbackTranslatesToCassandraUncategorizedDataAccessException() {
+ exception.expect(CassandraUncategorizedDataAccessException.class);
+ exception.expectCause(org.hamcrest.Matchers.isA(Error.class));
+ exception.expectMessage(containsString("test"));
+
+ template.doExecute(new SessionCallback() {
+ @Override public String doInSession(Session session) throws DataAccessException {
+ throw new Error("test");
+ }
+ });
+ }
+
@Test
public void doExecuteWithNullSessionCallbackThrowsIllegalArgumentException() {
exception.expect(IllegalArgumentException.class);
diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/isolated/RepositoryQueryMethodParameterTypesIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/isolated/RepositoryQueryMethodParameterTypesIntegrationTests.java
index 2ed2314fd..6da9098c4 100644
--- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/isolated/RepositoryQueryMethodParameterTypesIntegrationTests.java
+++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/isolated/RepositoryQueryMethodParameterTypesIntegrationTests.java
@@ -32,6 +32,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cassandra.support.exception.CassandraInvalidQueryException;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.cassandra.config.SchemaAction;
@@ -144,13 +145,11 @@ public class RepositoryQueryMethodParameterTypesIntegrationTests
}
/**
- * @see DATACASS-296
+ * @see DATACASS-296
+ * @see DATACASS-304
*/
- @Test(expected = InvalidQueryException.class)
+ @Test(expected = CassandraInvalidQueryException.class)
public void shouldThrowExceptionUsingWrongMethodParameter() {
-
- // NOTE: InvalidQueryException is a driver exception. This should get fixed with DATACASS-304
-
session.execute("CREATE INDEX IF NOT EXISTS allpossibletypes_date ON allpossibletypes ( date )");
allPossibleTypesRepository.findWithDateParameter(Date.from(Instant.ofEpochSecond(44234123421L)));
}