Browse Source

Merge pull request #19789 from grudir

* pr/19789:
  Polish "Add support for Spring Data Couchbase custom type key"
  Add support for Spring Data Couchbase custom type key

Closes gh-19789
pull/19944/head
Stephane Nicoll 6 years ago
parent
commit
ebcb2ac9ae
  1. 17
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataProperties.java
  2. 7
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseDataConfiguration.java
  3. 16
      spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java
  4. 37
      spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataPropertiesTests.java

17
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataProperties.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.boot.autoconfigure.data.couchbase;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.couchbase.core.convert.DefaultCouchbaseTypeMapper;
import org.springframework.data.couchbase.core.query.Consistency;
/**
@ -39,6 +40,12 @@ public class CouchbaseDataProperties { @@ -39,6 +40,12 @@ public class CouchbaseDataProperties {
*/
private Consistency consistency = Consistency.READ_YOUR_OWN_WRITES;
/**
* Name of the field that stores the type information for complex types when using
* "MappingCouchbaseConverter".
*/
private String typeKey = DefaultCouchbaseTypeMapper.DEFAULT_TYPE_KEY;
public boolean isAutoIndex() {
return this.autoIndex;
}
@ -55,4 +62,12 @@ public class CouchbaseDataProperties { @@ -55,4 +62,12 @@ public class CouchbaseDataProperties {
this.consistency = consistency;
}
public String getTypeKey() {
return this.typeKey;
}
public void setTypeKey(String typeKey) {
this.typeKey = typeKey;
}
}

7
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseDataConfiguration.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -73,6 +73,11 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur @@ -73,6 +73,11 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur
return new EntityScanner(this.applicationContext).scan(Document.class, Persistent.class);
}
@Override
public String typeKey() {
return this.properties.getTypeKey();
}
@Override
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_TEMPLATE)
@Bean(name = BeanNames.COUCHBASE_TEMPLATE)

16
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -40,6 +40,7 @@ import org.springframework.data.couchbase.config.BeanNames; @@ -40,6 +40,7 @@ import org.springframework.data.couchbase.config.BeanNames;
import org.springframework.data.couchbase.config.CouchbaseConfigurer;
import org.springframework.data.couchbase.core.CouchbaseTemplate;
import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversions;
import org.springframework.data.couchbase.core.convert.DefaultCouchbaseTypeMapper;
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
import org.springframework.data.couchbase.core.mapping.event.ValidatingCouchbaseEventListener;
import org.springframework.data.couchbase.core.query.Consistency;
@ -119,6 +120,19 @@ class CouchbaseDataAutoConfigurationTests { @@ -119,6 +120,19 @@ class CouchbaseDataAutoConfigurationTests {
assertThat(initialEntitySet).containsOnly(City.class);
}
@Test
void typeKeyDefault() {
load(CouchbaseTestConfigurer.class);
assertThat(this.context.getBean(AbstractCouchbaseDataConfiguration.class).typeKey())
.isEqualTo(DefaultCouchbaseTypeMapper.DEFAULT_TYPE_KEY);
}
@Test
void typeKeyCanBeCustomized() {
load(CouchbaseTestConfigurer.class, "spring.data.couchbase.type-key=_custom");
assertThat(this.context.getBean(AbstractCouchbaseDataConfiguration.class).typeKey()).isEqualTo("_custom");
}
@Test
void customConversions() {
load(CustomConversionsConfig.class);

37
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataPropertiesTests.java

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
/*
* Copyright 2012-2020 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
*
* https://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.boot.autoconfigure.data.couchbase;
import org.junit.jupiter.api.Test;
import org.springframework.data.couchbase.config.CouchbaseConfigurationSupport;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link CouchbaseDataProperties}.
*
* @author Stephane Nicoll
*/
class CouchbaseDataPropertiesTests {
@Test
void typeKeyHasConsistentDefault() {
assertThat(new CouchbaseDataProperties().getTypeKey()).isEqualTo(new CouchbaseConfigurationSupport().typeKey());
}
}
Loading…
Cancel
Save