From 9b8fbe31fa49450580e09e6fa89706c1659d1a50 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 14 Jan 2020 10:26:05 +0100 Subject: [PATCH] DATACASS-713 - Rename Session and SessionFactory bean names with cassandra prefix. We now register the Session under cassandraSession and SessionFactory with cassandraSessionFactory as bean name. ReactiveSession and ReactiveSessionFactory beans are named reactiveCassandraSession respective reactiveCassandraSessionFactory. Beans are consistently named using Java and XML-based configuration avoiding potential clashes with other data integrations that use Session or SessionFactory beans. --- .../AbstractCassandraConfiguration.java | 2 +- ...bstractReactiveCassandraConfiguration.java | 14 ++--- .../config/AbstractSessionConfiguration.java | 2 +- .../config/JavaConfigAuditingTests.java | 2 +- ...assandraConfigurationIntegrationTests.java | 60 +++++++++++++++++++ .../support/IntegrationTestConfig.java | 6 +- src/main/asciidoc/reference/cassandra.adoc | 8 +-- .../reference/migration-guide-2.2-to-3.0.adoc | 4 +- 8 files changed, 80 insertions(+), 18 deletions(-) create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/config/ReactiveCassandraConfigurationIntegrationTests.java diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractCassandraConfiguration.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractCassandraConfiguration.java index d3b7cfa64..e43d6816d 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractCassandraConfiguration.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractCassandraConfiguration.java @@ -87,7 +87,7 @@ public abstract class AbstractCassandraConfiguration extends AbstractSessionConf * @see #keyspaceCleaner() */ @Bean - public SessionFactoryFactoryBean sessionFactory(CqlSession cqlSession) { + public SessionFactoryFactoryBean cassandraSessionFactory(CqlSession cqlSession) { SessionFactoryFactoryBean bean = new SessionFactoryFactoryBean(); diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractReactiveCassandraConfiguration.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractReactiveCassandraConfiguration.java index c20c9a0e7..cfcaa392f 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractReactiveCassandraConfiguration.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractReactiveCassandraConfiguration.java @@ -45,24 +45,24 @@ public abstract class AbstractReactiveCassandraConfiguration extends AbstractCas * expose Cassandra access in a reactive style. * * @return the {@link ReactiveSession}. - * @see #session() + * @see #cassandraSession() * @see DefaultBridgedReactiveSession */ @Bean - public ReactiveSession reactiveSession() { + public ReactiveSession reactiveCassandraSession() { return new DefaultBridgedReactiveSession(getRequiredSession()); } /** * Creates a {@link ReactiveSessionFactory} to be used by the {@link ReactiveCassandraTemplate}. Uses the - * {@link ReactiveSession} instance configured in {@link #reactiveSession()}. + * {@link ReactiveSession} instance configured in {@link #reactiveCassandraSession()}. * * @return the {@link ReactiveSessionFactory}. - * @see #reactiveSession() + * @see #reactiveCassandraSession() * @see #reactiveCassandraTemplate() */ @Bean - public ReactiveSessionFactory reactiveSessionFactory() { + public ReactiveSessionFactory reactiveCassandraSessionFactory() { return new DefaultReactiveSessionFactory(beanFactory.getBean(ReactiveSession.class)); } @@ -70,7 +70,7 @@ public abstract class AbstractReactiveCassandraConfiguration extends AbstractCas * Creates a {@link CassandraAdminTemplate}. * * @return the {@link ReactiveCassandraTemplate}. - * @see #reactiveSessionFactory() + * @see #reactiveCassandraSessionFactory() * @see #cassandraConverter() */ @Bean @@ -83,7 +83,7 @@ public abstract class AbstractReactiveCassandraConfiguration extends AbstractCas * Creates a {@link ReactiveCqlTemplate} using the configured {@link ReactiveSessionFactory}. * * @return the {@link ReactiveCqlOperations}. - * @see #reactiveSessionFactory() + * @see #reactiveCassandraSessionFactory() */ @Bean public ReactiveCqlTemplate reactiveCqlTemplate() { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractSessionConfiguration.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractSessionConfiguration.java index fa6dbac55..a7043695d 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractSessionConfiguration.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractSessionConfiguration.java @@ -220,7 +220,7 @@ public abstract class AbstractSessionConfiguration implements BeanFactoryAware { * @see #getShutdownScripts() */ @Bean - public CqlSessionFactoryBean session() { + public CqlSessionFactoryBean cassandraSession() { CqlSessionFactoryBean bean = new CqlSessionFactoryBean(); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/config/JavaConfigAuditingTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/config/JavaConfigAuditingTests.java index ad112d7e8..c447be30c 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/config/JavaConfigAuditingTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/config/JavaConfigAuditingTests.java @@ -54,7 +54,7 @@ public class JavaConfigAuditingTests extends AbstractAuditingTests { } @Bean - public CqlSessionFactoryBean session() { + public CqlSessionFactoryBean cassandraSession() { CqlSessionFactoryBean sessionFactoryBean = mock(CqlSessionFactoryBean.class); CqlSession session = mock(CqlSession.class); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/config/ReactiveCassandraConfigurationIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/config/ReactiveCassandraConfigurationIntegrationTests.java new file mode 100644 index 000000000..ab12fd008 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/config/ReactiveCassandraConfigurationIntegrationTests.java @@ -0,0 +1,60 @@ +/* + * Copyright 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.data.cassandra.config; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; +import org.springframework.data.cassandra.repository.support.IntegrationTestConfig; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration tests for {@link AbstractReactiveCassandraConfiguration}. + * + * @author Mark Paluch + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = IntegrationTestConfig.class) +public class ReactiveCassandraConfigurationIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { + + @Autowired BeanFactory beanFactory; + + @Test // DATACASS-713 + public void shouldContainCassandraSessionBean() { + assertThat(beanFactory.containsBean(DefaultCqlBeanNames.SESSION)).isTrue(); + } + + @Test // DATACASS-713 + public void shouldContainCassandraSessionFactoryBean() { + assertThat(beanFactory.containsBean(DefaultCqlBeanNames.SESSION_FACTORY)).isTrue(); + } + + @Test // DATACASS-713 + public void shouldContainReactiveCassandraSessionBean() { + assertThat(beanFactory.containsBean("reactiveCassandraSession")).isTrue(); + } + + @Test // DATACASS-713 + public void shouldContainReactiveCassandraSessionFactoryBean() { + assertThat(beanFactory.containsBean("reactiveCassandraSessionFactory")).isTrue(); + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/IntegrationTestConfig.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/IntegrationTestConfig.java index b38bb6cb4..005c458d2 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/IntegrationTestConfig.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/IntegrationTestConfig.java @@ -53,7 +53,7 @@ public class IntegrationTestConfig extends AbstractReactiveCassandraConfiguratio @Bean @Override - public CqlSessionFactoryBean session() { + public CqlSessionFactoryBean cassandraSession() { SharedCqlSessionFactoryBean bean = new SharedCqlSessionFactoryBean(); @@ -72,8 +72,8 @@ public class IntegrationTestConfig extends AbstractReactiveCassandraConfiguratio @Bean(destroyMethod = "") @Override - public ReactiveSession reactiveSession() { - return super.reactiveSession(); + public ReactiveSession reactiveCassandraSession() { + return super.reactiveCassandraSession(); } @Override diff --git a/src/main/asciidoc/reference/cassandra.adoc b/src/main/asciidoc/reference/cassandra.adoc index d0355b72e..051b79dc1 100644 --- a/src/main/asciidoc/reference/cassandra.adoc +++ b/src/main/asciidoc/reference/cassandra.adoc @@ -355,7 +355,7 @@ If you want to initialize a database using XML configuration and you can provide ==== [source,xml,indent=0,subs="verbatim,quotes"] ---- - + @@ -380,7 +380,7 @@ The following example gets a value from a system property: ==== [source,xml,indent=0,subs="verbatim,quotes"] ---- - <1> @@ -394,7 +394,7 @@ To this end, you can control the ability of the initializer to ignore certain er ==== [source,xml,indent=0,subs="verbatim,quotes"] ---- - + ---- @@ -422,7 +422,7 @@ Alternatively, you can use XML to configure the `SessionFactoryInitializer`: ==== [source,xml,indent=0,subs="verbatim,quotes"] ---- - <1> + <1> <2> diff --git a/src/main/asciidoc/reference/migration-guide-2.2-to-3.0.adoc b/src/main/asciidoc/reference/migration-guide-2.2-to-3.0.adoc index 59fac897c..8569d039d 100644 --- a/src/main/asciidoc/reference/migration-guide-2.2-to-3.0.adoc +++ b/src/main/asciidoc/reference/migration-guide-2.2-to-3.0.adoc @@ -136,7 +136,9 @@ Please also migrate raw UDT and tuple types to the new driver types `UdtValue` r Paging state now uses `ByteBuffer`. * `SimpleUserTypeResolver` accepts `CqlSession` instead of `Cluster`. * `SimpleTupleTypeFactory` was migrated to `enum`. `SimpleTupleTypeFactory.INSTANCE` no longer requires a `Cluster`/`CqlSession` context. -* Introduction of `StatementBuilder` to functionally build statements as the QueryBuilder API uses immutable statement types +* Introduction of `StatementBuilder` to functionally build statements as the QueryBuilder API uses immutable statement types. +* `Session` bean renamed from `session` to `cassandraSession` and `SessionFactory` bean renamed from `sessionFactory` to `cassandraSessionFactory`. +* `ReactiveSession` bean renamed from `reactiveSession` to `reactiveCassandraSession` and `ReactiveSessionFactory` bean renamed from `reactiveSessionFactory` to `reactiveCassandraSessionFactory`. == Deprecations