-
Notifications
You must be signed in to change notification settings - Fork 132
#220 - Introduce R2dbcEntityTemplate #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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 don't seem to be able to rebase this onto master due to the introduction of SqlIdentifier
.
One ends up with SqlIdentifier
on one side (SelectSpec
) and expecting String
values on the other side (Table
and Column
). I'm not sure where you want to make the conversion.
Do you mind rebasing this?
This PR depends on spring-projects/spring-data-relational#187. Otherwise, we would be required to do the rebase twice. |
We now provide a Template API that exposes entity-centric methods. It complements DatabaseClient's simple object mapper methods.
c6fcbfb
to
a8d46de
Compare
Use limit/offset instead of Page and accept Expression objects to declare a select list. Use SqlIdentifier in Update, Query, Criteria and fluent API.
a8d46de
to
9669497
Compare
Formatting. Fix warnings. JavaDoc.
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 have a couple of complains but nothing serious.
Let's discuss in Slack.
src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java
Show resolved
Hide resolved
src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java
Show resolved
Hide resolved
src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java
Show resolved
Hide resolved
* @return the mapped {@link Expression}. | ||
* @since 1.1 | ||
*/ | ||
public Expression getMappedObject(Expression expression, @Nullable RelationalPersistentEntity<?> entity) { |
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.
Since this method is quite complex I'd love to have some unit tests.
Cases that should be covered IMHO:
- entity =/!= null
- column w/wo alias
- demonstrating what the column-> field+table -> column roundtrip does.
- SimpleFunction w/wo recursion
- Aliased or not
- Error case.
|
||
this.entity = entity; | ||
this.entityOperations = entityOperations; | ||
this.idProperty = Lazy.of(() -> converter // |
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.
Is the Lazy
worth it?
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.
The lazy init was required for deferred interaction with the mapping context.
Column column = (Column) expression; | ||
Field field = createPropertyField(entity, column.getName()); | ||
Table table = column.getTable(); | ||
|
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.
table
might be null
which would cause a NPE.
I can't tell if this prevented by construction, but an assert statement might be a good idea.
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 the NPE originates from @Nullable
on Column.getTable
. In Spring Data Relational, we made the Table mandatory, so we should fix the nullability annotations there.
@@ -212,17 +219,49 @@ public static SelectSpec create(String table) { | |||
* @since 1.1 | |||
*/ | |||
public static SelectSpec create(SqlIdentifier table) { |
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.
StatementMapper
contains lots of public
stuff although the class it self is package private.
Is that intentional?
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.
The class is public
as it is declared within an interface.
Reverted removal of null check that is marked as superfluous and adjusted nullability annotations instead.
We now provide a Template API that exposes entity-centric methods. It complements DatabaseClient's simple object mapper methods. Original pull request: #287.
Use limit/offset instead of Page and accept Expression objects to declare a select list. Use SqlIdentifier in Update, Query, Criteria and fluent API. Original pull request: #287.
Formatting. Fix warnings. JavaDoc. Adjusted nullability annotations. Original pull request: #287.
That's merged and polished now. |
We now provide an
R2dbcEntityTemplate
that allows entity-centric interaction. Entities can be loaded, inserted, updated and deleted. AdditionalQuery
andUpdate
methods allow fine-grained changes to entities. It features a fluent API that is similar toDatabaseClient
.The main difference is that
DatabaseClient
is intended for simple mapped objects whileR2dbcEntityTemplate
has an entity-centric focus that could expand into the usage with aggregate roots.Open issues: