Polishing.
Add Javadoc to exceptions. Align lettercasing of CassandraDriverTimeoutException. Closes #1399
This commit is contained in:
@@ -28,8 +28,15 @@ public class CassandraAuthenticationException extends PermissionDeniedDataAccess
|
||||
|
||||
private static final long serialVersionUID = 8556304586797273927L;
|
||||
|
||||
private EndPoint host;
|
||||
private final EndPoint host;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraAuthenticationException}.
|
||||
*
|
||||
* @param host the affected endpoint.
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraAuthenticationException(EndPoint host, String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.host = host;
|
||||
|
||||
@@ -32,11 +32,18 @@ public class CassandraConnectionFailureException extends DataAccessResourceFailu
|
||||
|
||||
private static final long serialVersionUID = 6299912054261646552L;
|
||||
|
||||
private final Map<Node, Throwable> messagesByHost = new HashMap<>();
|
||||
private final Map<Node, Throwable> messagesByHost;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraConnectionFailureException}.
|
||||
*
|
||||
* @param map the detail failures for each node.
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraConnectionFailureException(Map<Node, Throwable> map, String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.messagesByHost.putAll(map);
|
||||
this.messagesByHost = new HashMap<>(map);
|
||||
}
|
||||
|
||||
public Map<Node, Throwable> getMessagesByHost() {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package org.springframework.data.cassandra;
|
||||
|
||||
import org.springframework.dao.QueryTimeoutException;
|
||||
|
||||
/**
|
||||
* This exception is thrown when driver have timed out during any interation with cassandra coordinator node
|
||||
*
|
||||
* @author Mikhail Polivakha
|
||||
*/
|
||||
public class CassandraDriverTimeOutException extends QueryTimeoutException {
|
||||
|
||||
public CassandraDriverTimeOutException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.springframework.data.cassandra;
|
||||
|
||||
import org.springframework.dao.QueryTimeoutException;
|
||||
|
||||
/**
|
||||
* This exception is thrown when driver has timed out during any interaction with the Cassandra coordinator node.
|
||||
*
|
||||
* @author Mikhail Polivakha
|
||||
* @since 4.2
|
||||
*/
|
||||
public class CassandraDriverTimeoutException extends QueryTimeoutException {
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraDriverTimeoutException}.
|
||||
*
|
||||
* @param message the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraDriverTimeoutException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,22 @@ public class CassandraInsufficientReplicasAvailableException extends TransientDa
|
||||
private int numberRequired;
|
||||
private int numberAlive;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraInsufficientReplicasAvailableException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public CassandraInsufficientReplicasAvailableException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraInsufficientReplicasAvailableException}.
|
||||
*
|
||||
* @param numberRequired the required number of replicas.
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraInsufficientReplicasAvailableException(int numberRequired, int numberAlive, String msg,
|
||||
Throwable cause) {
|
||||
super(msg, cause);
|
||||
|
||||
@@ -26,10 +26,21 @@ public class CassandraInternalException extends DataAccessException {
|
||||
|
||||
private static final long serialVersionUID = 433061676465346338L;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraInternalException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public CassandraInternalException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraInternalException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraInternalException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
@@ -27,10 +27,21 @@ public class CassandraInvalidConfigurationInQueryException extends InvalidDataAc
|
||||
|
||||
private static final long serialVersionUID = 4594321191806182918L;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraInvalidConfigurationInQueryException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public CassandraInvalidConfigurationInQueryException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraInvalidConfigurationInQueryException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraInvalidConfigurationInQueryException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,21 @@ public class CassandraInvalidQueryException extends InvalidDataAccessApiUsageExc
|
||||
|
||||
private static final long serialVersionUID = 4594321191806182918L;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraInvalidQueryException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public CassandraInvalidQueryException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraInvalidQueryException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraInvalidQueryException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,13 @@ public class CassandraKeyspaceExistsException extends CassandraSchemaElementExis
|
||||
|
||||
private static final long serialVersionUID = 6032967419751410352L;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraKeyspaceExistsException}.
|
||||
*
|
||||
* @param keyspaceName the keyspace name.
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraKeyspaceExistsException(String keyspaceName, String msg, Throwable cause) {
|
||||
super(keyspaceName, ElementType.KEYSPACE, msg, cause);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,21 @@ public class CassandraQuerySyntaxException extends InvalidDataAccessApiUsageExce
|
||||
|
||||
private static final long serialVersionUID = 4398474399882434154L;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraQuerySyntaxException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public CassandraQuerySyntaxException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraQuerySyntaxException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraQuerySyntaxException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ public class CassandraReadTimeoutException extends QueryTimeoutException {
|
||||
private final boolean wasDataPresent;
|
||||
|
||||
/**
|
||||
* Constructor for QueryTimeoutException.
|
||||
* Constructor for {@link CassandraReadTimeoutException}.
|
||||
*
|
||||
* @param wasDataPresent whether the actual data was amongst the received replica responses.
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the data access API in use.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraReadTimeoutException(boolean wasDataPresent, String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
|
||||
@@ -36,6 +36,14 @@ public class CassandraSchemaElementExistsException extends NonTransientDataAcces
|
||||
private String elementName;
|
||||
private ElementType elementType;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraSchemaElementExistsException}.
|
||||
*
|
||||
* @param elementName the CQL element name.
|
||||
* @param elementType the CQL element type.
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
@Deprecated
|
||||
public CassandraSchemaElementExistsException(String elementName, ElementType elementType, String msg,
|
||||
Throwable cause) {
|
||||
@@ -44,6 +52,12 @@ public class CassandraSchemaElementExistsException extends NonTransientDataAcces
|
||||
this.elementType = elementType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraSchemaElementExistsException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraSchemaElementExistsException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,13 @@ public class CassandraTableExistsException extends CassandraSchemaElementExistsE
|
||||
|
||||
private static final long serialVersionUID = 6032967419751410352L;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraTableExistsException}.
|
||||
*
|
||||
* @param tableName the table name.
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraTableExistsException(String tableName, String msg, Throwable cause) {
|
||||
super(tableName, ElementType.TABLE, msg, cause);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,21 @@ public class CassandraTraceRetrievalException extends TransientDataAccessExcepti
|
||||
|
||||
private static final long serialVersionUID = -3163557220324700239L;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraTraceRetrievalException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public CassandraTraceRetrievalException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraTraceRetrievalException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraTraceRetrievalException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,21 @@ public class CassandraTruncateException extends TransientDataAccessException {
|
||||
|
||||
private static final long serialVersionUID = 5730642491362430311L;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraTruncateException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public CassandraTruncateException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraTruncateException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraTruncateException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,21 @@ public class CassandraTypeMismatchException extends TypeMismatchDataAccessExcept
|
||||
|
||||
private static final long serialVersionUID = -7420058975444905629L;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraTypeMismatchException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public CassandraTypeMismatchException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraTypeMismatchException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraTypeMismatchException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,12 @@ public class CassandraUnauthorizedException extends PermissionDeniedDataAccessEx
|
||||
|
||||
private static final long serialVersionUID = 4618185356687726647L;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraUnauthorizedException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraUnauthorizedException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,12 @@ public class CassandraUncategorizedException extends UncategorizedDataAccessExce
|
||||
|
||||
private static final long serialVersionUID = 1029525121238025444L;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraUncategorizedException}.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
*/
|
||||
public CassandraUncategorizedException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,14 @@ public class CassandraWriteTimeoutException extends QueryTimeoutException {
|
||||
|
||||
private @Nullable String writeType;
|
||||
|
||||
/**
|
||||
* Constructor for {@link CassandraWriteTimeoutException}.
|
||||
*
|
||||
* @param writeType the write type.
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the underlying data access API.
|
||||
* @see com.datastax.oss.driver.api.core.servererrors.WriteType
|
||||
*/
|
||||
public CassandraWriteTimeoutException(@Nullable String writeType, String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.writeType = writeType;
|
||||
|
||||
@@ -23,22 +23,9 @@ import java.util.Set;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.dao.QueryTimeoutException;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.data.cassandra.CassandraAuthenticationException;
|
||||
import org.springframework.data.cassandra.CassandraConnectionFailureException;
|
||||
import org.springframework.data.cassandra.CassandraDriverTimeOutException;
|
||||
import org.springframework.data.cassandra.CassandraInsufficientReplicasAvailableException;
|
||||
import org.springframework.data.cassandra.CassandraInvalidConfigurationInQueryException;
|
||||
import org.springframework.data.cassandra.CassandraInvalidQueryException;
|
||||
import org.springframework.data.cassandra.CassandraQuerySyntaxException;
|
||||
import org.springframework.data.cassandra.CassandraReadTimeoutException;
|
||||
import org.springframework.data.cassandra.CassandraSchemaElementExistsException;
|
||||
import org.springframework.data.cassandra.CassandraTruncateException;
|
||||
import org.springframework.data.cassandra.CassandraUnauthorizedException;
|
||||
import org.springframework.data.cassandra.CassandraUncategorizedException;
|
||||
import org.springframework.data.cassandra.CassandraWriteTimeoutException;
|
||||
import org.springframework.data.cassandra.*;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -48,19 +35,7 @@ import com.datastax.oss.driver.api.core.DriverException;
|
||||
import com.datastax.oss.driver.api.core.DriverTimeoutException;
|
||||
import com.datastax.oss.driver.api.core.auth.AuthenticationException;
|
||||
import com.datastax.oss.driver.api.core.metadata.Node;
|
||||
import com.datastax.oss.driver.api.core.servererrors.AlreadyExistsException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.BootstrappingException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.CoordinatorException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.InvalidConfigurationInQueryException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.OverloadedException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.ReadTimeoutException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.SyntaxError;
|
||||
import com.datastax.oss.driver.api.core.servererrors.TruncateException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.UnauthorizedException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.UnavailableException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.WriteTimeoutException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.WriteType;
|
||||
import com.datastax.oss.driver.api.core.servererrors.*;
|
||||
|
||||
/**
|
||||
* Simple {@link PersistenceExceptionTranslator} for Cassandra.
|
||||
@@ -110,7 +85,7 @@ public class CassandraExceptionTranslator implements CqlExceptionTranslator {
|
||||
}
|
||||
|
||||
if (exception instanceof DriverTimeoutException driverTimeoutException) {
|
||||
return new CassandraDriverTimeOutException(driverTimeoutException.getMessage(), driverTimeoutException);
|
||||
return new CassandraDriverTimeoutException(driverTimeoutException.getMessage(), driverTimeoutException);
|
||||
}
|
||||
|
||||
if (exception instanceof ReadTimeoutException) {
|
||||
|
||||
@@ -26,19 +26,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
import org.springframework.data.cassandra.CassandraAuthenticationException;
|
||||
import org.springframework.data.cassandra.CassandraConnectionFailureException;
|
||||
import org.springframework.data.cassandra.CassandraDriverTimeOutException;
|
||||
import org.springframework.data.cassandra.CassandraInsufficientReplicasAvailableException;
|
||||
import org.springframework.data.cassandra.CassandraInvalidConfigurationInQueryException;
|
||||
import org.springframework.data.cassandra.CassandraInvalidQueryException;
|
||||
import org.springframework.data.cassandra.CassandraQuerySyntaxException;
|
||||
import org.springframework.data.cassandra.CassandraReadTimeoutException;
|
||||
import org.springframework.data.cassandra.CassandraSchemaElementExistsException;
|
||||
import org.springframework.data.cassandra.CassandraTruncateException;
|
||||
import org.springframework.data.cassandra.CassandraUnauthorizedException;
|
||||
import org.springframework.data.cassandra.CassandraUncategorizedException;
|
||||
import org.springframework.data.cassandra.CassandraWriteTimeoutException;
|
||||
import org.springframework.data.cassandra.*;
|
||||
|
||||
import com.datastax.oss.driver.api.core.DefaultConsistencyLevel;
|
||||
import com.datastax.oss.driver.api.core.DriverTimeoutException;
|
||||
@@ -50,20 +38,7 @@ import com.datastax.oss.driver.api.core.connection.BusyConnectionException;
|
||||
import com.datastax.oss.driver.api.core.connection.FrameTooLongException;
|
||||
import com.datastax.oss.driver.api.core.metadata.EndPoint;
|
||||
import com.datastax.oss.driver.api.core.metadata.Node;
|
||||
import com.datastax.oss.driver.api.core.servererrors.AlreadyExistsException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.BootstrappingException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.InvalidConfigurationInQueryException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.OverloadedException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.ReadFailureException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.ReadTimeoutException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.SyntaxError;
|
||||
import com.datastax.oss.driver.api.core.servererrors.TruncateException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.UnauthorizedException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.UnavailableException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.WriteFailureException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.WriteTimeoutException;
|
||||
import com.datastax.oss.driver.api.core.servererrors.WriteType;
|
||||
import com.datastax.oss.driver.api.core.servererrors.*;
|
||||
import com.datastax.oss.driver.api.core.type.DataTypes;
|
||||
import com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException;
|
||||
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
|
||||
@@ -120,11 +95,13 @@ class CassandraExceptionTranslatorUnitTests {
|
||||
.hasMessageStartingWith("message").hasCauseInstanceOf(InvalidConfigurationInQueryException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRecognizeDriverTimeoutException() {
|
||||
@Test // GH-1399
|
||||
void shouldTranslateDriverTimeoutException() {
|
||||
|
||||
DataAccessException dataAccessException = sut.translateExceptionIfPossible(new DriverTimeoutException("message"));
|
||||
|
||||
assertThat(dataAccessException).isInstanceOf(CassandraDriverTimeOutException.class).hasMessageStartingWith("message")
|
||||
assertThat(dataAccessException).isInstanceOf(CassandraDriverTimeoutException.class)
|
||||
.hasMessageStartingWith("message")
|
||||
.hasCauseInstanceOf(DriverTimeoutException.class);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user