Conversation
e5678bc to
4672ffd
Compare
|
Rebased on top of current 3.0. |
| } | ||
| ``` | ||
|
|
||
| One powerful advantage of annotating getter methods is that |
There was a problem hiding this comment.
Awesome example, like how it shows polymorphism for both tables and UDTs.
|
Guidelines for reviewers:
If anyone disagrees with these decisions, please chime in. |
|
Sorry but I feel that the JAVA-541 commit is missing the point: it merely adds the ability to inherit field definitions from a parent class. That's useful in itself, but what the ticket asks for is a way to encode inheritance relationships in the model. Borrowing from the Caffinitas terminology, and considering an inheritance hierarchy
|
This is exactly what one of the commenters in the ticket asked for: fields in superclasses. And I think this guy has it right: keep it simple, but extend to class hierarchies. So yes, I went for only that strategy, and as stated in the docs: "Each concrete class must correspond to a table or a UDT, and should be annotated accordingly with @table or @UDT. This is analogous to the so-called "table per concrete class" mapping strategy." Frankly, proposing other strategies is the red line I did not want to cross. Especially the single-table strategy; i wonder if this model is efficient at all for cassandra, given the high number of nulls. There is too much of Hibernate in it IMHO. And while at it, why not propose strategies to map the same entity to many tables, each one "denormalized" differently (JAVA-549 and JAVA-524)? I think we need to draw a clear line here and define the scope of "polymorphism support" and how far we want to go. @al3xandru Could you please give us your insight here? |
|
I agree with your arguments, and polymorphic mapping would certainly cross a line in term of implementation complexity. But at least we should not introduce property inheritance as a fix for JAVA-541, as I feel users watching that ticket are expecting much more. |
|
I find 169e7e0 extremely hard to review. There are at least 3 different changes in there:
What's heartbreaking is that the first two would be trivial to review separately, and they probably represent a large portion of the diff. With everything mixed together, you have to pay attention to each line to determine which change (or combination of changes) impacted it. In the future it would really simply reviews if 1 commit = 1 change. |
Yes, my bad, please accept my apologies. I found myself in that situation and couldn't separate the changeset in two or three distinct commits, and so had to commit everything in one. |
|
|
||
| private static final Comparator<Field> fieldComparator = new Comparator<Field>() { | ||
| @VisibleForTesting | ||
| static final Set<Class<? extends Annotation>> VALID_PROPERTY_ANNOTATIONS = ImmutableSet.of( |
There was a problem hiding this comment.
Wasn't clear to me initially that VALID_FIELD_ANNOTATIONS apply to UDTs while PROPERTY apply to tables, would be good to clarify that here (although it may be somewhere else but haven't gotten to it yet).
This commit also includes a refactoring of the mapper internals: - ColumnMapper renamed to PropertyMapper; - No more factory patterns to create mappers; - ReflectionX classes removed and merged into their parent classes; - QueryType class cleanup.
This commit changes all places where an IllegalStateException was thrown to throw an IllegalArgumentException instead.
The test "should_save_and_retrieve_sphere" was failing because it relied on a setter declared in Sphere that overloads a setter declared in Circle. JDK 7 fails to detect the overloading setter. This fix simply modifies the test to avoid this edge case.
Also reorganized renamed some tests in MapperInvalidAnnotationTests for consistency.
|
I'm using the 3.1.0 driver here (https://mvnrepository.com/artifact/com.datastax.cassandra/cassandra-driver-mapping/3.1.0) and not sure how to take advantage of the polymorphic support from this PR. Is there an updated example that can demonstrate the capabilities? Thanks |
|
Hi @kford, examples can be found in our docs: http://datastax.github.io/java-driver/manual/object_mapper/creating/#polymorphism-support |
|
@newkek and @adutra, It says superclasses are scanned, but it seems not subclasses (by omission in the docs). *edit: should I move this elsewhere since this PR is already merged? I have a use case like the following class Properties{ class UserTaskProperties extends Properties { I created an example application that you can easily run with maven and attached the zip.. It just needs host/user/pass edited in pom.xml.. It demonstrates that saving these mapped subtypes is lossy. Am I doing something wrong? If I'm not, the only alternative I can think of is introducing custom codecs for the sub-types and manage the mapping manually there.. That would create significant maintenance overhead. Thanks in advance update: forgot to attach cql/ddl |
|
Hi @kford, This kind of polymorphism is not currently supported by the Mapper even with this change. From the jira ticket (JAVA-541) we added a note that this doesn't cover all cases:
Unfortunately this case is not covered, but Cassandra doesn't support this either as far as I know. Using the provided schema: I see in your code that you want to be able to have As far as solving this particular issue, a couple ways it could be handled.
|
|
@tolbertam Thank you for the thorough response/explanation. I guess this also means that if I wanted to query by one of the properties that is part of my logical Vehicle class, I'd have to extract that out so it's either not part of the blob, or redundantly stored as (text for example), outside the blob... like... type vehicle (vehicleType text, otherQueryableField text, vehicleBlob blob) where the vehicleBlob may or may not redundantly contain vehicleType and otherQueryableField, depending on how I want to write my custom codec. |
That is correct, you can't query by individual UDT fields (yet: see CASSANDRA-6832). You would have to have an extra column that is part of the primary key or separately indexed to do that. |
Just a quick note since you asked @kford , our mailing is the most appropriate place to ask those kinds of questions: https://groups.google.com/a/lists.datastax.com/forum/#!forum/java-driver-user |
This addresses both JAVA-541, JAVA-636, and JAVA-984.
The second commit and following introduce a refactoring of the mapper internals:
ColumnMapperrenamed toPropertyMapper;ReflectionXclasses removed and merged into their parent classes;QueryTypeclass cleanup.IllegalArgumentExceptionwithIllegalStateExceptionwhere more appropriate.If you want to read the docs first, jump to the new "polymorphism support" section.