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

Check persistence metadata when sorting #554

Merged

Conversation

nscuro
Copy link
Collaborator

@nscuro nscuro commented Apr 21, 2024

Only persistent fields can be queried and sorted by. Trying to sort by a non-persistent field will cause an exception to be thrown in the persistence layer.

To users it is not immediately obvious which field is persistent, and which is computed. It would be good to provide a helpful error message as to what went wrong when a sorting request can not be fulfilled.

Instead of checking the candidate classes' fields directly, leverage the type metadata of DataNucleus to figure out which field is persistent.

Use specific exception messages for whether a field is not persistent, or doesn't exist at all.

Applications built on Alpine can then define a custom ExceptionMapper to transform the new NotSortableException into an API-friendly format if desired. Alternatively, it can be handled with any generic IllegalArgumentException handling logic.

Only persistent fields can be queried and sorted by. Trying to sort by a non-persistent field will cause an exception to be thrown in the persistence layer.

To users it is not immediately obvious which field is persistent, and which is computed. It would be good to provide a helpful error message as to what went wrong when a sorting request can not be fulfilled.

Instead of checking the candidate classes' fields directly, leverage the type metadata of DataNucleus to figure out which field is persistent.

Use specific exception messages for whether a field is not persistent, or doesn't exist at all.

Applications built on Alpine can then define a custom `ExceptionMapper` to transform the new `NotSortableException` into an API-friendly format if desired. Alternatively, it can be handled with any generic `IllegalArgumentException` handling logic.

Signed-off-by: nscuro <nscuro@protonmail.com>
@stevespringett stevespringett merged commit 031f5c8 into stevespringett:master May 5, 2024
2 checks passed
@nscuro nscuro deleted the sort-persistence-check branch May 6, 2024 12:08
nscuro added a commit to nscuro/dependency-track that referenced this pull request May 16, 2024
Adds a JAX-RS `ExceptionMapper` for `NotSortableException`, which was introduced in stevespringett/Alpine#554.

Signed-off-by: nscuro <nscuro@protonmail.com>
MM-msr pushed a commit to MM-msr/dependency-track that referenced this pull request Jun 18, 2024
Adds a JAX-RS `ExceptionMapper` for `NotSortableException`, which was introduced in stevespringett/Alpine#554.

Signed-off-by: nscuro <nscuro@protonmail.com>
netomi pushed a commit to netomi/dependency-track that referenced this pull request Aug 8, 2024
Adds a JAX-RS `ExceptionMapper` for `NotSortableException`, which was introduced in stevespringett/Alpine#554.

Signed-off-by: nscuro <nscuro@protonmail.com>
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

Successfully merging this pull request may close these issues.

2 participants