Add support for Spring Data Couchbase custom type key
See gh-19789
This commit is contained in:
parent
3290313eb7
commit
d1a44dfacd
|
|
@ -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 {
|
|||
*/
|
||||
private Consistency consistency = Consistency.READ_YOUR_OWN_WRITES;
|
||||
|
||||
/**
|
||||
* Name of the field that will store 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 {
|
|||
this.consistency = consistency;
|
||||
}
|
||||
|
||||
public String getTypeKey() {
|
||||
return this.typeKey;
|
||||
}
|
||||
|
||||
public void setTypeKey(String typeKey) {
|
||||
this.typeKey = typeKey;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,4 +97,9 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur
|
|||
return new IndexManager(false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeKey() {
|
||||
return this.properties.getTypeKey();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -127,6 +128,22 @@ class CouchbaseDataAutoConfigurationTests {
|
|||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void typeKeyIsClassByDefault() {
|
||||
load(CouchbaseTestConfigurer.class);
|
||||
AbstractCouchbaseDataConfiguration couchbaseDataConfiguration = this.context
|
||||
.getBean(AbstractCouchbaseDataConfiguration.class);
|
||||
assertThat(couchbaseDataConfiguration.typeKey()).isEqualTo(DefaultCouchbaseTypeMapper.DEFAULT_TYPE_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customTypeKey() {
|
||||
load(CouchbaseTestConfigurer.class, "spring.data.couchbase.type-key=custom");
|
||||
AbstractCouchbaseDataConfiguration couchbaseDataConfiguration = this.context
|
||||
.getBean(AbstractCouchbaseDataConfiguration.class);
|
||||
assertThat(couchbaseDataConfiguration.typeKey()).isEqualTo("custom");
|
||||
}
|
||||
|
||||
private void load(Class<?> config, String... environment) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues.of(environment).applyTo(context);
|
||||
|
|
|
|||
Loading…
Reference in New Issue