Coder Social home page Coder Social logo

spring-data-cassandra's People

Contributors

lankydan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spring-data-cassandra's Issues

multiple Keyspaces not working with different package structure

Hello,

First of all, I waned to say thank you for the blog post and his project.

Even 3 years after its creation, the content is still very relevant. Many thanks.

I am working on a similar problem, where we need to use a Spring Boot 2.4.0 reactive WebFlux + Reactive Cassandra on two difference keyspaces.

We managed to come up with a solution where we have three config files, one abstract, and two for each keyspace, very similar to what you are doing.

Then, we have two repository classes, where all the queries are written with the @query annotation, and we write the keysapce name hardcoded there.

This solution is working, but it is rather ugly. This is why I went to look at your blog post.

Your solution is quite elegant!

However, as soon as we change the package structure: I put
CassandraConfig
KeyspaceACassandraConfig
KeyspaceBCassandraConfig

Under package config.

KeyspaceAPersonRepository
KeyspaceBPersonRepository
PersonRepository
Under package repository

(Which is really a default and most common packaging structure for Spring), it is not working anymore.
It is always defaulting to keyspace A.

May I ask what is the issue? Can this solution ou propose, which is very elegant, be package agnostic?

Thank you

Consider using Spring Boot's auto configuration

Wide parts of the config are already provided by Spring Boot (contact points, schema actions, enabling reactive repositories). The only feature not provided by Boot is setup/drop of keyspaces. Maybe you want to outline that particular aspect to explain why that is โ€“ btw. filing a Boot ticket to customize keyspace creation/drop is never a bad idea ๐Ÿ˜ธ

@Configuration
@EnableReactiveCassandraRepositories
public class CassandraConfig extends AbstractReactiveCassandraConfiguration {
@Value("${cassandra.contactpoints}")
private String contactPoints;
@Value("${cassandra.port}")
private int port;
@Value("${cassandra.keyspace}")
private String keyspace;
@Value("${cassandra.basepackages}")
private String basePackages;
@Override
protected String getKeyspaceName() {
return keyspace;
}
@Override
protected String getContactPoints() {
return contactPoints;
}
@Override
protected int getPort() {
return port;
}
@Override
public SchemaAction getSchemaAction() {
return SchemaAction.CREATE_IF_NOT_EXISTS;
}
@Override
public String[] getEntityBasePackages() {
return new String[] {basePackages};
}
@Override
protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
final CreateKeyspaceSpecification specification =
CreateKeyspaceSpecification.createKeyspace(keyspace)
.ifNotExists()
.with(KeyspaceOption.DURABLE_WRITES, true)
.withSimpleReplication();
return List.of(specification);
}
@Override
protected List<DropKeyspaceSpecification> getKeyspaceDrops() {
return List.of(DropKeyspaceSpecification.dropKeyspace(keyspace));
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.