Skip to content

Commit 403bad9

Browse files
committed
Polishing.
Reflect that prepared statements do not inherit query options to avoid cache pollution. See #1335
1 parent 2143ba4 commit 403bad9

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,9 @@ public PreparedStatementHandler(Statement<?> statement) {
10911091
*/
10921092
@Override
10931093
public PreparedStatement createPreparedStatement(CqlSession session) throws DriverException {
1094+
1095+
// Note that prepared statement settings like the keyspace are gone because using the prepare method with a
1096+
// statement object causes cache pollution
10941097
return session.prepare(statement.getQuery());
10951098
}
10961099

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/ReactiveCassandraTemplate.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,9 @@ public PreparedStatementHandler(Statement<?> statement) {
10601060
*/
10611061
@Override
10621062
public Mono<PreparedStatement> createPreparedStatement(ReactiveSession session) throws DriverException {
1063+
1064+
// Note that prepared statement settings like the keyspace are gone because using the prepare method with a
1065+
// statement object causes cache pollution
10631066
return session.prepare(statement.getQuery());
10641067
}
10651068

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/CassandraTemplateIntegrationTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,14 @@ void selectByQueryWithNonExistingKeyspaceShouldThrowThatKeyspaceDoesNotExists()
492492

493493
User user = new User("heisenberg", "Walter", "White");
494494
template.insert(user);
495+
template.setUsePreparedStatements(false);
495496

496497
Query query = Query.query(where("id").is("heisenberg")).queryOptions(queryOptions);
497498
assertThatThrownBy(() -> assertThat(template.select(query, User.class)).isEmpty())
498499
.isInstanceOf(CassandraInvalidQueryException.class)
499500
.hasMessageContaining("Keyspace 'non_existing' does not exist");
501+
502+
template.setUsePreparedStatements(true);
500503
}
501504

502505
@Test // DATACASS-182

0 commit comments

Comments
 (0)