Skip to content
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

Cayenne entity ID part represented by a DB column to be prefixed with "db:" #521

Closed
andrus opened this issue Jan 1, 2022 · 0 comments
Closed
Milestone

Comments

@andrus
Copy link
Contributor

andrus commented Jan 1, 2022

Background - ID representation in Agrest

Entities can have single-value and multi-value IDs. Single-value id is represented in JSON as "id":val. Multi-value - as "id":{"p1":v1, "p2":v2}. This representation is used for both request bodies (POST, PUT), and responses (GET, POST, PUT).

Problem

This task is concerned with a specific case - multi-value ID representation with Cayenne backend, when one or more values in the ID map are not present as object properties. In this case Cayenne uses names of DB columns as keys in the ID map: "id":{"col1":v1, "col2":v2}.

This is both confusing, and can potentially (though unlikely) cause naming conflicts between Java properties and DB column names in the same id map. Additionally, since 5.0 (per #520) attributes and "id part" attributes no longer maintain "path expression" property separate from the attribute/id part name. So the name itself should contain sufficient information for the backend to make sense of it.

Solution

While we can keep building workarounds in the Cayenne backend, I think we should change the encoding of the column-based id parts to be in a form of Cayenne DB expression, i.e. prefixed with "db:" - "id":{"db:col1":v1, "db:col2":v2}. This will add both visual clarity and disambiguate the ID structure for the framework.

Upgrade Notes

This change only affects Cayenne entities that have a multi-column ID, and only a subset of id properties that are not mapped as object properties. Property names that are column names will now be prefixed with "db:". E.g.: "id":{"db:col1":v1, "db:col2":v2, "prop":v3}.

On the client this affects the following requests:

  • Those that submit updates for entities with such ids
  • Those that parse responses with such ids for individual id values (instead of treating the ID as opaque)

On the server this affects the following user-facing APIs:

  • SelectBuilder.byId(Map)
  • SelectBuilder.parent(Class,Map,String)
  • UpdateBuilder.parent(Class,Map,String)
  • DeleteBuilder.parent(Class,Map,String)
andrus added a commit that referenced this issue Jan 7, 2022
…h "db:" #521

.. the actual implementation was done per #520, here
we are adjusting the unit tests to use the new encoding
andrus added a commit that referenced this issue Jan 7, 2022
andrus added a commit that referenced this issue Jan 7, 2022
andrus added a commit that referenced this issue Jan 7, 2022
andrus added a commit that referenced this issue Jan 7, 2022
andrus added a commit that referenced this issue Jan 7, 2022
andrus added a commit that referenced this issue Jan 7, 2022
… "db:" #521

.. parent ID handling
.. more id cases
andrus added a commit that referenced this issue Jan 7, 2022
andrus added a commit that referenced this issue Jan 7, 2022
andrus added a commit that referenced this issue Jan 7, 2022
andrus added a commit that referenced this issue Jan 7, 2022
@andrus andrus added this to the 5.0 milestone Jan 7, 2022
@andrus andrus closed this as completed Jan 7, 2022
andrus added a commit that referenced this issue Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant