Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
* @author Matthew T. Adams
* @author John Blum
* @author Mark Paluch
* @author Ammar Khaku
*/
@Configuration
@SuppressWarnings("unused")
Expand All @@ -71,14 +72,11 @@ public CassandraConverter cassandraConverter() {

CqlSession cqlSession = getRequiredSession();

UserTypeResolver userTypeResolver =
new SimpleUserTypeResolver(cqlSession, CqlIdentifier.fromCql(getKeyspaceName()));

MappingCassandraConverter converter =
new MappingCassandraConverter(requireBeanOfType(CassandraMappingContext.class));

converter.setCodecRegistry(cqlSession.getContext().getCodecRegistry());
converter.setUserTypeResolver(userTypeResolver);
converter.setUserTypeResolver(userTypeResolver(cqlSession));
converter.setCustomConversions(requireBeanOfType(CassandraCustomConversions.class));

return converter;
Expand All @@ -96,11 +94,8 @@ public CassandraMappingContext cassandraMapping() throws ClassNotFoundException

CqlSession cqlSession = getRequiredSession();

UserTypeResolver userTypeResolver =
new SimpleUserTypeResolver(cqlSession, CqlIdentifier.fromCql(getKeyspaceName()));

CassandraMappingContext mappingContext =
new CassandraMappingContext(userTypeResolver, SimpleTupleTypeFactory.DEFAULT);
new CassandraMappingContext(userTypeResolver(cqlSession), SimpleTupleTypeFactory.DEFAULT);

CustomConversions customConversions = requireBeanOfType(CassandraCustomConversions.class);

Expand Down Expand Up @@ -260,4 +255,8 @@ protected KeyspacePopulator keyspacePopulator() {
protected ByteArrayResource scriptOf(String content) {
return new ByteArrayResource(content.getBytes());
}

protected UserTypeResolver userTypeResolver(CqlSession cqlSession) {
return new SimpleUserTypeResolver(cqlSession, CqlIdentifier.fromCql(getKeyspaceName()));
Copy link
Contributor Author

@akhaku akhaku Aug 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should mention that really what I'm trying to do is allow getKeyspaceName() to be null, but right now the docs in AbstractSessionConfiguration are explicit that it should be non-null... We already override the session factory bean and the only piece that's causing problems with the null keyspace right now is the UserTypeResolver, so moving the constructor to a protected method will let me override it without trying to unravel getKeyspace()'s nullability in AbstractSessionConfiguration

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for merging and polishing! I'm not entirely sure what you're getting at, are you just saying that this change is reasonable or that we should explore making a change in spring-boot's CassandraDataAutoConfiguration as well? Or are you saying it would be worth exploring allowing getKeyspace to return null?

}
}