Skip to content

Commit e9f0a08

Browse files
committed
Document how to use SessionBuilderConfigurer.
Closes #1447
1 parent 2489fe4 commit e9f0a08

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

src/main/antora/modules/ROOT/examples/CassandraConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ public class CassandraConfiguration extends AbstractCassandraConfiguration {
2525
/*
2626
* Provide a contact point to the configuration.
2727
*/
28+
@Override
2829
public String getContactPoints() {
2930
return "localhost";
3031
}
3132

3233
/*
3334
* Provide a keyspace name to the configuration.
3435
*/
36+
@Override
3537
public String getKeyspaceName() {
3638
return "mykeyspace";
3739
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2020-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.cassandra.example;
17+
18+
import org.springframework.context.annotation.Configuration;
19+
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
20+
21+
// tag::class[]
22+
@Configuration
23+
public class CustomizedCassandraConfiguration extends AbstractCassandraConfiguration {
24+
25+
/*
26+
* Customize the CqlSession through CqlSessionBuilder.
27+
*/
28+
@Override
29+
protected SessionBuilderConfigurer getSessionBuilderConfigurer() {
30+
31+
Path connectBundlePath = …;
32+
33+
return builder -> builder
34+
.withCloudSecureConnectBundle(Path.of(connectBundlePath));
35+
}
36+
37+
/*
38+
* Provide a keyspace name to the configuration.
39+
*/
40+
@Override
41+
public String getKeyspaceName() {
42+
return "mykeyspace";
43+
}
44+
45+
}
46+
// end::class[]

src/main/antora/modules/ROOT/pages/cassandra/configuration.adoc

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ https://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/new-in-
1010
as well as the detailed documentation {springDocsUrl}core.html#beans-java-instantiating-container[here].
1111

1212
[[cassandra.cassandra-java-config]]
13-
== Registering a Session Instance by Using Java-based Metadata
13+
== Registering a Session Instance by using Java-based Metadata
1414

1515
The following example shows how to use Java-based bean metadata to register an instance of a `com.datastax.oss.driver.api.core.CqlSession`:
1616

@@ -68,11 +68,26 @@ include::example$CassandraConfiguration.java[tags=class]
6868
----
6969
====
7070

71+
`Abstract…Configuration` classes wire all the necessary beans for using Cassandra from your application.
72+
The configuration assumes a single `CqlSession` and wires it through `SessionFactory` into the related components such as `CqlTemplate`.
73+
If you want to customize the creation of the `CqlSession`, then you can provide a `SessionBuilderConfigurer` function to customize `CqlSessionBuilder`.
74+
This is useful to provide e.g. a Cloud Connection Bundle for Astra.
75+
76+
.Connecting to Astra through `AbstractCassandraConfiguration`
77+
====
78+
[source,java]
79+
----
80+
include::example$CustomizedCassandraConfiguration.java[tags=class]
81+
----
82+
====
83+
7184
[[cassandra-connectors.xmlconfig]]
72-
=== XML Configuration
85+
== XML Configuration
7386

7487
This section describes how to configure Spring Data Cassandra with XML.
7588

89+
WARNING: While we still support Namespace Configuration, we generally recommend using <<cassandra.cassandra-java-config,Java-based Configuration>>.
90+
7691
[[cassandra-connectors.xmlconfig.ext_properties]]
7792
=== Externalizing Connection Properties
7893

0 commit comments

Comments
 (0)