DATACASS-468 - Polishing.
Increase CassandraRepositoryConfigurationExtension visibility as this class is required by configuration infrastructure that configures Cassandra repository support such as Spring Boot. Initialize MappingCassandraConverter with generic custom conversions and resolve package cycle between mapping and convert by initializing MappingCassandraConverter with generic custom conversions. Cassandra-specific custom conversions require external wiring via configuration. Move IdInterfaceValidator to mapping package to resolve the final cycle between mapping and repository.support.
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.convert;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -24,7 +23,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -96,7 +94,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
* Create a new {@link MappingCassandraConverter} with a {@link CassandraMappingContext}.
|
||||
*/
|
||||
public MappingCassandraConverter() {
|
||||
this(new CassandraMappingContext());
|
||||
this(createMappingContext());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,6 +112,14 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
this.spELContext = new SpELContext(RowReaderPropertyAccessor.INSTANCE);
|
||||
}
|
||||
|
||||
private static CassandraMappingContext createMappingContext() {
|
||||
|
||||
CassandraMappingContext mappingContext = new CassandraMappingContext();
|
||||
mappingContext.setCustomConversions(new CassandraCustomConversions(Collections.emptyList()));
|
||||
|
||||
return mappingContext;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
@@ -494,7 +500,8 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
|
||||
// FIXME: Generics
|
||||
CassandraPersistentEntity<?> whereEntity = compositeIdProperty != null
|
||||
? mappingContext.getRequiredPersistentEntity(compositeIdProperty) : entity;
|
||||
? mappingContext.getRequiredPersistentEntity(compositeIdProperty)
|
||||
: entity;
|
||||
|
||||
return getWhereClauses((MapId) id, whereEntity);
|
||||
}
|
||||
@@ -630,7 +637,8 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
private ConvertingPropertyAccessor getConvertingAccessor(Object source, CassandraPersistentEntity<?> entity) {
|
||||
|
||||
PersistentPropertyAccessor propertyAccessor = (source instanceof PersistentPropertyAccessor
|
||||
? (PersistentPropertyAccessor) source : entity.getPropertyAccessor(source));
|
||||
? (PersistentPropertyAccessor) source
|
||||
: entity.getPropertyAccessor(source));
|
||||
|
||||
return new ConvertingPropertyAccessor(propertyAccessor, getConversionService());
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.data.cassandra.core.convert.CassandraCustomConversions;
|
||||
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification;
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification;
|
||||
import org.springframework.data.cassandra.core.mapping.UserTypeUtil.FrozenLiteralDataType;
|
||||
import org.springframework.data.convert.CustomConversions;
|
||||
import org.springframework.data.convert.CustomConversions.StoreConversions;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.PropertyHandler;
|
||||
import org.springframework.data.mapping.context.AbstractMappingContext;
|
||||
@@ -71,7 +71,8 @@ public class CassandraMappingContext
|
||||
|
||||
private CassandraPersistentEntityMetadataVerifier verifier = new CompositeCassandraPersistentEntityMetadataVerifier();
|
||||
|
||||
private CustomConversions customConversions;
|
||||
private CustomConversions customConversions = new CustomConversions(
|
||||
StoreConversions.of(CassandraSimpleTypeHolder.HOLDER), Collections.emptyList());
|
||||
|
||||
private Mapping mapping = new Mapping();
|
||||
|
||||
@@ -91,7 +92,8 @@ public class CassandraMappingContext
|
||||
*/
|
||||
public CassandraMappingContext() {
|
||||
|
||||
setCustomConversions(new CassandraCustomConversions(Collections.EMPTY_LIST));
|
||||
setCustomConversions(
|
||||
new CustomConversions(StoreConversions.of(CassandraSimpleTypeHolder.HOLDER), Collections.EMPTY_LIST));
|
||||
setSimpleTypeHolder(CassandraSimpleTypeHolder.HOLDER);
|
||||
}
|
||||
|
||||
@@ -244,7 +246,8 @@ public class CassandraMappingContext
|
||||
|
||||
// Prevent conversion types created as CassandraPersistentEntity
|
||||
Optional<BasicCassandraPersistentEntity<?>> optional = shouldCreatePersistentEntityFor(typeInformation)
|
||||
? super.addPersistentEntity(typeInformation) : Optional.empty();
|
||||
? super.addPersistentEntity(typeInformation)
|
||||
: Optional.empty();
|
||||
|
||||
optional.ifPresent(entity -> {
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.support;
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2013-2017 the original author or authors
|
||||
* Copyright 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
|
||||
* 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,
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.support;
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -13,20 +13,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.support;
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.cassandra.core.mapping.MapId;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
|
||||
/**
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class IdInterfaceValidator {
|
||||
class IdInterfaceValidator {
|
||||
|
||||
/**
|
||||
* Validates the form of the given id interface candidate type. If the interface violates the following restrictions,
|
||||
@@ -62,7 +61,7 @@ public class IdInterfaceValidator {
|
||||
* @see IdInterfaceExceptions#getExceptions()
|
||||
* @see {@link IdInterfaceException}
|
||||
*/
|
||||
public static void validate(Class<?> id) {
|
||||
static void validate(Class<?> id) {
|
||||
|
||||
List<MappingException> exceptions = new ArrayList<>();
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.cassandra.repository.support.IdInterfaceValidator;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.w3c.dom.Element;
|
||||
* @author Christoph Strobl
|
||||
* @author Mateusz Szymczak
|
||||
*/
|
||||
class CassandraRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport {
|
||||
public class CassandraRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport {
|
||||
|
||||
private static final String CASSANDRA_TEMPLATE_REF = "cassandra-template-ref";
|
||||
|
||||
|
||||
@@ -17,14 +17,13 @@
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.cassandra.core.mapping.IdInterfaceValidator.*;
|
||||
import static org.springframework.data.cassandra.core.mapping.MapIdFactory.*;
|
||||
import static org.springframework.data.cassandra.repository.support.IdInterfaceValidator.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.cassandra.repository.support.IdInterfaceExceptions;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MapIdFactory}.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* `Update` and `Query` objects.
|
||||
* CRUD repository interface renaming: `CassandraRepository` using `MapId` is now renamed to `MapIdCassandraRepository`. `TypedIdCassandraRepository` is renamed to `CassandraRepository`.
|
||||
* Lightweight transactions via `InsertOptions` and `UpdateOptions` using the Template API.
|
||||
* Merge of Spring CQL into Spring Data Cassandra.
|
||||
|
||||
[[new-features.1-5-0]]
|
||||
== What's new in Spring Data for Apache Cassandra 1.5
|
||||
|
||||
Reference in New Issue
Block a user