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

Condition improvements: support null params, support in Jmix Data Repositories #2490

Closed
dtaimanov opened this issue Nov 20, 2023 · 1 comment · Fixed by #2873
Closed

Condition improvements: support null params, support in Jmix Data Repositories #2490

dtaimanov opened this issue Nov 20, 2023 · 1 comment · Fixed by #2873
Assignees
Labels
breaking changes Fix brings breaking changes in code or behavior in: data size: L
Milestone

Comments

@dtaimanov
Copy link
Contributor

dtaimanov commented Nov 20, 2023

I. Support conditions in Jmix Data Repositories

io.jmix.core.repository.JmixDataRepositoryContext has been added to pass io.jmix.core.querycondition.Condition and other Jmix-related paramters to Jmix Data Repositories. It allows to dynamically change them at runtime for repository methods.

Implementation:

  • Supported by io.jmix.core.repository.JmixDataRepository standard methods.
  • Supported as paramter of user-defined methods, e.g.:
     // ---------- Repository: ----------
     public interface CustomerRepository extends JmixDataRepository<Customer, UUID> {
         List<Customer> loadByName(String name, JmixDataRepositoryContext context);
         //...
     }
    
     // ---------- Usage: ----------
     customerRepository.loadByName("John", JmixDataRepositoryContext.of(condition))
     customerRepository.loadByName("Rincewind", JmixDataRepositoryContext.plan(getSomeFetchPlan()).condition(condition).build())
     // or using static imports:
     customerRepository.loadByName("Kel", hints(PersistenceHints.SOFT_DELETION, false)).condition(condition).build())

Priorities of parameter values (from highest to lowest):

FetchPlan:

  1. FetchPlan parameter
  2. JmixDataRepositoryContext#fetchPlan parameter
  3. @FetchPlan annotatin value

Hints (different keys will be merged, the same key value will be overridden):

  1. JmixDataRepositoryContext parameter
  2. @QueryHints annotation value

II. Do not ignore conditions if parameter is null or empty:

See forum topic

Problem:

Jmix Data Repositories use io.jmix.core.querycondition.Condition under the hood. Condition originally have been designed to work with UI filter conditions where null value in field means that no filtering needed because value is not specified.

Unfortunately this is not correct behaviour for Data Repositories.

Solution:

Rework Conditions and Repositories in order to take nulls as parameters

Implementation:

  • Conditions in UI: old behaviour, conditions with absent, null or empty parameter will be skipped.
  • [breaking changes] JmixDataRepositories in new projects: derived methods will no longer skip conditions with null or empty values. Set jmix.core.skip-null-or-empty-conditions-by-default=true to return old behaviour for project
  • [breaking changes] Manually created conditions in app code of new projects: will be applied even when parameter absent, null or empty.
    Set jmix.core.skip-null-or-empty-conditions-by-default=true to return old behaviour for all project or set ParameterCondition/JpqlCondition#skipNullOrEmpty = true to return old behaviour for particular condition.

Studio issue: JST-4693

QA Notes

I. Support conditions in Jmix Data Repositories

  • Check JmixDataRepositoryContext parameter works for standard and query methods of repositories

II. Do not ignore conditions if parameter is null or empty

  • Check that UI filter still do not filter entities out if no value specified
  • Check that manually created conditions condider nulls in values
  • Check that jmix.core.skip-null-or-empty-conditions-by-default toggles this behaviour
  • (Additionally) Check that migration from old Jmix version automatically sets jmix.core.skip-null-or-empty-conditions-by-default=true
@dtaimanov dtaimanov self-assigned this Nov 20, 2023
@gorbunkov gorbunkov added candidate Possible candidate for future releases size: M labels Nov 24, 2023
@dtaimanov dtaimanov added breaking changes Fix brings breaking changes in code or behavior and removed candidate Possible candidate for future releases labels Feb 7, 2024
@dtaimanov dtaimanov changed the title Jmix Data Repository ignores nulls in parameters Conditnion improvements: support null params, support by Jmix Data Repositories Feb 9, 2024
@dtaimanov dtaimanov changed the title Conditnion improvements: support null params, support by Jmix Data Repositories Condition improvements: support null params, support by Jmix Data Repositories Feb 9, 2024
@dtaimanov dtaimanov changed the title Condition improvements: support null params, support by Jmix Data Repositories Condition improvements: support null params, support in Jmix Data Repositories Feb 9, 2024
@dtaimanov dtaimanov added size: L and removed size: M labels Feb 9, 2024
@dtaimanov dtaimanov reopened this Feb 14, 2024
@rusiaikinat rusiaikinat reopened this Feb 15, 2024
@MaxKatyshev
Copy link

Jmix version: 2.2.999-SNAPSHOT
Jmix Studio plugin version: 2.2.SNAPSHOT6075-233
IntelliJ version: IntelliJ IDEA 2023.3.2 (Ultimate Edition)
verified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking changes Fix brings breaking changes in code or behavior in: data size: L
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants