forked from spring-projects/spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request spring-projects#10812 from alexsderkach:issue/8925
* pr/10812: Polish "Add support for reactive Spring Data Couchbase" Add support for reactive Spring Data Couchbase
- Loading branch information
Showing
17 changed files
with
732 additions
and
5 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...ngframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveDataAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2012-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.boot.autoconfigure.data.couchbase; | ||
|
||
import com.couchbase.client.java.Bucket; | ||
import reactor.core.publisher.Flux; | ||
|
||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.couchbase.repository.ReactiveCouchbaseRepository; | ||
|
||
/** | ||
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Reactive Couchbase | ||
* support. | ||
* | ||
* @author Alex Derkach | ||
* @since 2.0.0 | ||
*/ | ||
@Configuration | ||
@ConditionalOnClass({Bucket.class, ReactiveCouchbaseRepository.class, Flux.class}) | ||
@AutoConfigureAfter(CouchbaseDataAutoConfiguration.class) | ||
@Import(SpringBootCouchbaseReactiveDataConfiguration.class) | ||
public class CouchbaseReactiveDataAutoConfiguration { | ||
} |
49 changes: 49 additions & 0 deletions
49
...ork/boot/autoconfigure/data/couchbase/CouchbaseReactiveRepositoriesAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2012-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.boot.autoconfigure.data.couchbase; | ||
|
||
import com.couchbase.client.java.Bucket; | ||
|
||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.couchbase.repository.ReactiveCouchbaseRepository; | ||
import org.springframework.data.couchbase.repository.config.ReactiveRepositoryOperationsMapping; | ||
import org.springframework.data.couchbase.repository.support.ReactiveCouchbaseRepositoryFactoryBean; | ||
|
||
/** | ||
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Couchbase | ||
* Reactive Repositories. | ||
* | ||
* @author Alex Derkach | ||
* @since 2.0.0 | ||
*/ | ||
@Configuration | ||
@ConditionalOnClass({Bucket.class, ReactiveCouchbaseRepository.class}) | ||
@ConditionalOnProperty(prefix = "spring.data.couchbase.reactive-repositories", name = "enabled", havingValue = "true", matchIfMissing = true) | ||
@ConditionalOnBean(ReactiveRepositoryOperationsMapping.class) | ||
@ConditionalOnMissingBean(ReactiveCouchbaseRepositoryFactoryBean.class) | ||
@Import(CouchbaseReactiveRepositoriesAutoConfigureRegistrar.class) | ||
@AutoConfigureAfter(CouchbaseReactiveDataAutoConfiguration.class) | ||
public class CouchbaseReactiveRepositoriesAutoConfiguration { | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
...oot/autoconfigure/data/couchbase/CouchbaseReactiveRepositoriesAutoConfigureRegistrar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2012-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.boot.autoconfigure.data.couchbase; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
import org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport; | ||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; | ||
import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories; | ||
import org.springframework.data.couchbase.repository.config.ReactiveCouchbaseRepositoryConfigurationExtension; | ||
import org.springframework.data.repository.config.RepositoryConfigurationExtension; | ||
|
||
/** | ||
* {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data Couchbase | ||
* Reactive Repositories. | ||
* | ||
* @author Alex Derkach | ||
* @since 2.0.0 | ||
*/ | ||
public class CouchbaseReactiveRepositoriesAutoConfigureRegistrar | ||
extends AbstractRepositoryConfigurationSourceSupport { | ||
|
||
@Override | ||
protected Class<? extends Annotation> getAnnotation() { | ||
return EnableReactiveCouchbaseRepositories.class; | ||
} | ||
|
||
@Override | ||
protected Class<?> getConfiguration() { | ||
return EnableReactiveCouchbaseRepositoriesConfiguration.class; | ||
} | ||
|
||
@Override | ||
protected RepositoryConfigurationExtension getRepositoryConfigurationExtension() { | ||
return new ReactiveCouchbaseRepositoryConfigurationExtension(); | ||
} | ||
|
||
@EnableReactiveCouchbaseRepositories | ||
private static class EnableReactiveCouchbaseRepositoriesConfiguration { | ||
|
||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
...ework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseReactiveDataConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2012-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.boot.autoconfigure.data.couchbase; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.couchbase.config.AbstractReactiveCouchbaseDataConfiguration; | ||
import org.springframework.data.couchbase.config.BeanNames; | ||
import org.springframework.data.couchbase.config.CouchbaseConfigurer; | ||
import org.springframework.data.couchbase.core.RxJavaCouchbaseTemplate; | ||
import org.springframework.data.couchbase.core.query.Consistency; | ||
import org.springframework.data.couchbase.repository.config.ReactiveRepositoryOperationsMapping; | ||
|
||
/** | ||
* Configure Spring Data's reactive couchbase support. | ||
* | ||
* @author Alex Derkach | ||
* @since 2.0.0 | ||
*/ | ||
@Configuration | ||
@ConditionalOnMissingBean(AbstractReactiveCouchbaseDataConfiguration.class) | ||
@ConditionalOnBean(CouchbaseConfigurer.class) | ||
class SpringBootCouchbaseReactiveDataConfiguration | ||
extends AbstractReactiveCouchbaseDataConfiguration { | ||
|
||
private final CouchbaseDataProperties properties; | ||
|
||
private final CouchbaseConfigurer couchbaseConfigurer; | ||
|
||
SpringBootCouchbaseReactiveDataConfiguration(CouchbaseDataProperties properties, | ||
CouchbaseConfigurer couchbaseConfigurer) { | ||
this.properties = properties; | ||
this.couchbaseConfigurer = couchbaseConfigurer; | ||
} | ||
|
||
@Override | ||
protected CouchbaseConfigurer couchbaseConfigurer() { | ||
return this.couchbaseConfigurer; | ||
} | ||
|
||
@Override | ||
protected Consistency getDefaultConsistency() { | ||
return this.properties.getConsistency(); | ||
} | ||
|
||
@Override | ||
@ConditionalOnMissingBean(name = BeanNames.RXJAVA1_COUCHBASE_TEMPLATE) | ||
@Bean(name = BeanNames.RXJAVA1_COUCHBASE_TEMPLATE) | ||
public RxJavaCouchbaseTemplate reactiveCouchbaseTemplate() throws Exception { | ||
return super.reactiveCouchbaseTemplate(); | ||
} | ||
|
||
@Override | ||
@ConditionalOnMissingBean(name = BeanNames.REACTIVE_COUCHBASE_OPERATIONS_MAPPING) | ||
@Bean(name = BeanNames.REACTIVE_COUCHBASE_OPERATIONS_MAPPING) | ||
public ReactiveRepositoryOperationsMapping reactiveRepositoryOperationsMapping(RxJavaCouchbaseTemplate reactiveCouchbaseTemplate) throws Exception { | ||
return super.reactiveRepositoryOperationsMapping(reactiveCouchbaseTemplate); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...pringframework/boot/autoconfigure/data/alt/couchbase/ReactiveCityCouchbaseRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2012-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.boot.autoconfigure.data.alt.couchbase; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
import org.springframework.boot.autoconfigure.data.couchbase.city.City; | ||
import org.springframework.data.repository.Repository; | ||
|
||
public interface ReactiveCityCouchbaseRepository extends Repository<City, Long> { | ||
Mono<City> save(City city); | ||
|
||
Mono<City> findById(Long id); | ||
|
||
} |
101 changes: 101 additions & 0 deletions
101
...figure/data/couchbase/CouchbaseReactiveAndBlockingRepositoriesAutoConfigurationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright 2012-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.boot.autoconfigure.data.couchbase; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.After; | ||
import org.junit.Test; | ||
|
||
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; | ||
import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfigurationTests; | ||
import org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer; | ||
import org.springframework.boot.autoconfigure.data.couchbase.city.CityRepository; | ||
import org.springframework.boot.autoconfigure.data.couchbase.city.ReactiveCityRepository; | ||
import org.springframework.boot.test.util.TestPropertyValues; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.context.annotation.ImportSelector; | ||
import org.springframework.core.type.AnnotationMetadata; | ||
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories; | ||
import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for {@link CouchbaseRepositoriesAutoConfiguration} and | ||
* {@link CouchbaseReactiveRepositoriesAutoConfiguration}. | ||
* | ||
* @author Stephane Nicoll | ||
*/ | ||
public class CouchbaseReactiveAndBlockingRepositoriesAutoConfigurationTests { | ||
|
||
private AnnotationConfigApplicationContext context; | ||
|
||
@After | ||
public void close() { | ||
this.context.close(); | ||
} | ||
|
||
@Test | ||
public void shouldCreateInstancesForReactiveAndBlockingRepositories() | ||
throws Exception { | ||
this.context = new AnnotationConfigApplicationContext(); | ||
TestPropertyValues.of("spring.datasource.initialization-mode:never") | ||
.applyTo(this.context); | ||
this.context.register(BlockingAndReactiveConfiguration.class, | ||
BaseConfiguration.class); | ||
this.context.refresh(); | ||
assertThat(this.context.getBean(CityRepository.class)).isNotNull(); | ||
assertThat(this.context.getBean(ReactiveCityRepository.class)).isNotNull(); | ||
} | ||
|
||
@Configuration | ||
@TestAutoConfigurationPackage(CouchbaseAutoConfigurationTests.class) | ||
@EnableCouchbaseRepositories(basePackageClasses = CityRepository.class) | ||
@EnableReactiveCouchbaseRepositories(basePackageClasses = ReactiveCityRepository.class) | ||
protected static class BlockingAndReactiveConfiguration { | ||
|
||
} | ||
|
||
@Configuration | ||
@Import({ CouchbaseTestConfigurer.class, Registrar.class }) | ||
protected static class BaseConfiguration { | ||
|
||
} | ||
|
||
protected static class Registrar implements ImportSelector { | ||
|
||
@Override | ||
public String[] selectImports(AnnotationMetadata importingClassMetadata) { | ||
List<String> names = new ArrayList<>(); | ||
for (Class<?> type : new Class<?>[] { CouchbaseAutoConfiguration.class, | ||
CouchbaseDataAutoConfiguration.class, | ||
CouchbaseRepositoriesAutoConfiguration.class, | ||
CouchbaseReactiveDataAutoConfiguration.class, | ||
CouchbaseReactiveRepositoriesAutoConfiguration.class }) { | ||
names.add(type.getName()); | ||
} | ||
return names.toArray(new String[0]); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.