-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
DATACASS-751: Allow keyspace customization for CassandraPersistentEntity #179
Conversation
I am opening this as a draft PR to discuss if the changes are in the right direction. Right now I modified only
methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR goes into a good direction. Introducing the keyspace as additional element surfaces the fact that we suddenly deal with two components to address a particular table (getKeyspaceName()
, getTableName()
).
Having both pieces of information can lead to a disjoint when one of them isn't matching the other one (e.g. ks1.mytable
, where ks1
gets resolved to a different value and then mytable
can't be found anymore).
The natural fix is to introduce a value object which encapsulates both values so that they are bundled together. However, we should also consider the getTableName()
method which currently returns CqlIdentifier
instead of e.g. TableName
. Such a change would have two consequences:
- It would break existing API
- It creates another problem, that
setTableName(…)
acceptsCqlIdentifier
whilegetTableName(…)
would returnTableName
.
I think we can solve this issue by coming up with a better name.
...-cassandra/src/main/java/org/springframework/data/cassandra/core/AsyncCassandraTemplate.java
Outdated
Show resolved
Hide resolved
...ssandra/src/main/java/org/springframework/data/cassandra/core/ExecutableSelectOperation.java
Show resolved
Hide resolved
...a/src/main/java/org/springframework/data/cassandra/core/mapping/CassandraMappingContext.java
Outdated
Show resolved
Hide resolved
...ain/java/org/springframework/data/cassandra/core/mapping/BasicCassandraPersistentEntity.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/springframework/data/cassandra/core/mapping/CassandraPersistentEntity.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/springframework/data/cassandra/core/mapping/CassandraPersistentEntity.java
Show resolved
Hide resolved
...-cassandra/src/main/java/org/springframework/data/cassandra/core/mapping/NamingStrategy.java
Outdated
Show resolved
Hide resolved
One more question @mp911de.
It seems that we would need to modify events to send TableCoordinates instead of only |
Let's keep events and entity callbacks for a future step in mind so we don't change these yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: getMapper()
method and it's invocations.
The mapper currently is created per Table
as we discussed. It creates one problem.
For example, looking at a place where TableCoordinates
are used:
<T> List<T> doSelect(Query query, Class<?> entityClass, TableCoordinates tableCoordinates,
Class<T> returnType) {
and the actual logic of getting mapper is happening per table:
Function<Row, T> mapper = getMapper(entityClass, returnType, tableCoordinates.getTableName());
So it basically means that TableCoordinates.keyspaceName
is ignored for all CassandraTemplate
methods that are using the mapper.
It means that the behavior of methods that are using mapper vs those that are using statements directly (created by the StatementFactory
) is different.
It may lead to in-deterministic behavior if the client has a table with the same name in two different keyspaces. The client will be able to execute per ks queries using Statements, but when it comes to a mapper, only one table could be retrieved and the keyspace
is inherited from the CqlSession
. Are we ok with this behavior? Or should we create mapper per keyspace-table as well?
@@ -226,6 +230,16 @@ public CqlIdentifier getTableName() { | |||
return Optional.ofNullable(this.tableName).orElseGet(this::determineTableName); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should consider adding the getTableCoordinates()
at the level of CassandraPersistentEntity
.
The reason for this is that the TableCooordinates
are used now in a lot of places in code, and the callers of this class need to wrap tableName
and keyspaceName
into TableCoordinates
. This wrapping (constructing TableCooordinates
) is happening in a lot of places and having this method one level higher will remove the need to construct it a lot of times, wdyt?
What do you mean by the future step? Do you want to do it in a separate ticket (PR)? |
question regarding testing: |
Yes, I'd like to not introduce another level of complexity with this pull request but rather to postpone changes to events and entity callbacks to after this PR is merged. |
It makes sense to extend I'm also wondering whether our In the Cassandra case, we're referencing to the Driver The gist here is, if |
Superseded as per #921 (comment). Thank you for your contribution that inspired the design of customizing keyspaces. |
todo:
BeforeDeleteEvent
,BeforeSaveEvent
,AfterSaveEvent
, etc) toTableCoordinates
TableCoordinates
with keyspace with more IT and UnitTestsCassandraTemplate#getMapper
to work perTableCoordinates
(not onlytableName
)CassandraPersistentEntity#getTableCoordinates()
ANDBasicCassandraPersistentEntity