Polishing.

Reflect that prepared statements do not inherit query options to avoid cache pollution.

See #1335
This commit is contained in:
Mark Paluch
2023-01-03 15:19:16 +01:00
parent 515bffc784
commit 86f8528077
3 changed files with 9 additions and 0 deletions

View File

@@ -982,6 +982,9 @@ public class CassandraTemplate implements CassandraOperations, ApplicationEventP
@Override
public PreparedStatement createPreparedStatement(CqlSession session) throws DriverException {
// Note that prepared statement settings like the keyspace are gone because using the prepare method with a
// statement object causes cache pollution
return session.prepare(statement.getQuery());
}

View File

@@ -966,6 +966,9 @@ public class ReactiveCassandraTemplate
@Override
public Mono<PreparedStatement> createPreparedStatement(ReactiveSession session) throws DriverException {
// Note that prepared statement settings like the keyspace are gone because using the prepare method with a
// statement object causes cache pollution
return session.prepare(statement.getQuery());
}

View File

@@ -492,11 +492,14 @@ class CassandraTemplateIntegrationTests extends AbstractKeyspaceCreatingIntegrat
User user = new User("heisenberg", "Walter", "White");
template.insert(user);
template.setUsePreparedStatements(false);
Query query = Query.query(where("id").is("heisenberg")).queryOptions(queryOptions);
assertThatThrownBy(() -> assertThat(template.select(query, User.class)).isEmpty())
.isInstanceOf(CassandraInvalidQueryException.class)
.hasMessageContaining("Keyspace 'non_existing' does not exist");
template.setUsePreparedStatements(true);
}
@Test // DATACASS-182