DATACASS-435 - Remove strict mode in BasicCassandraPersistentEntityMetadataVerifier.
Strict mode is no longer used. Switching to a lenient verification can be achieved with a custom verifier. Made VerifierMappingExceptions immutable by removing VerifierMappingExceptions.add(…).
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors
|
||||
* Copyright 2013-2017 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.
|
||||
@@ -35,8 +35,6 @@ import org.springframework.data.mapping.model.MappingException;
|
||||
*/
|
||||
public class BasicCassandraPersistentEntityMetadataVerifier implements CassandraPersistentEntityMetadataVerifier {
|
||||
|
||||
@Deprecated protected boolean strict = false;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.mapping.CassandraPersistentEntityMetadataVerifier#verify(org.springframework.data.cassandra.mapping.CassandraPersistentEntity)
|
||||
@@ -72,9 +70,6 @@ public class BasicCassandraPersistentEntityMetadataVerifier implements Cassandra
|
||||
}
|
||||
});
|
||||
|
||||
// Perform rules verification on Table/Persistent
|
||||
// TODO Verify annotation values with CqlIndentifier
|
||||
|
||||
/*
|
||||
* Perform rules verification on Table/Persistent
|
||||
*/
|
||||
@@ -113,26 +108,6 @@ public class BasicCassandraPersistentEntityMetadataVerifier implements Cassandra
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the setting for strict.
|
||||
* @deprecated Will be removed in future versions.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unused")
|
||||
public boolean isStrict() {
|
||||
return strict;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param strict boolean setting for strict.
|
||||
* @deprecated Will be removed in future versions.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unused")
|
||||
public void setStrict(boolean strict) {
|
||||
this.strict = strict;
|
||||
}
|
||||
|
||||
private static void fail(CassandraPersistentEntity<?> entity, List<MappingException> exceptions) {
|
||||
throw new VerifierMappingExceptions(entity, exceptions);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.util.Assert;
|
||||
@SuppressWarnings("serial")
|
||||
public class VerifierMappingExceptions extends MappingException {
|
||||
|
||||
final Collection<MappingException> exceptions;
|
||||
private final Collection<MappingException> exceptions;
|
||||
|
||||
private final String className;
|
||||
|
||||
@@ -52,6 +52,8 @@ public class VerifierMappingExceptions extends MappingException {
|
||||
|
||||
this.exceptions = Collections.unmodifiableCollection(new LinkedList<>(exceptions));
|
||||
this.className = entity.getType().getName();
|
||||
|
||||
this.exceptions.forEach(this::addSuppressed);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,56 +68,37 @@ public class VerifierMappingExceptions extends MappingException {
|
||||
|
||||
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
|
||||
|
||||
this.exceptions = new LinkedList<>();
|
||||
this.exceptions = Collections.emptyList();
|
||||
this.className = entity.getType().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mappingException must not be {@literal null}.
|
||||
* @deprecated Exceptions should be immutable so this method is subject to be removed in future versions
|
||||
*/
|
||||
@Deprecated
|
||||
public void add(MappingException mappingException) {
|
||||
|
||||
Assert.notNull(mappingException, "MappingException must not be null");
|
||||
|
||||
exceptions.add(mappingException);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the MappingExceptions aggregated within.
|
||||
* Returns a list of the {@link MappingException}s aggregated within.
|
||||
*
|
||||
* @return The Collection of MappingException
|
||||
* @return collection of {@link MappingException}.
|
||||
*/
|
||||
public Collection<MappingException> getMappingExceptions() {
|
||||
return Collections.unmodifiableCollection(exceptions);
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the MappingException messages aggregated within.
|
||||
* Returns a list of the {@link MappingException} messages aggregated within.
|
||||
*
|
||||
* @return The Collection of Messages
|
||||
* @return collection of messages.
|
||||
*/
|
||||
public Collection<String> getMessages() {
|
||||
return exceptions.stream().map(Throwable::getMessage).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of errors that have been added to this Exception Class.
|
||||
*
|
||||
* @return Number of Errors present
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Throwable#getMessage()
|
||||
*/
|
||||
public int getCount() {
|
||||
return exceptions.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
|
||||
StringBuilder builder = new StringBuilder(className).append(":\n");
|
||||
|
||||
for (MappingException e : exceptions) {
|
||||
builder.append(" - ").append(e.getMessage()).append("\n");
|
||||
}
|
||||
exceptions.forEach(e -> builder.append(" - ").append(e.getMessage()).append("\n"));
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2017 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.mapping.model.MappingException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link VerifierMappingExceptions}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class VerifierMappingExceptionsUnitTests {
|
||||
|
||||
@Mock CassandraPersistentEntity<?> entityMock;
|
||||
|
||||
@Before
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() throws Exception {
|
||||
|
||||
when(entityMock.getType()).thenReturn((Class) VerifierMappingExceptionsUnitTests.class);
|
||||
|
||||
}
|
||||
|
||||
@Test // DATACASS-258
|
||||
public void testDeprecatedMutability() {
|
||||
|
||||
VerifierMappingExceptions exceptions = new VerifierMappingExceptions(entityMock, "err");
|
||||
exceptions.add(new MappingException("my error"));
|
||||
|
||||
assertThat(exceptions.toString()).contains("my error");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user