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

Allow to configure fetch batch size when using FetchGroups #3313

Closed
apflieger opened this issue Jan 25, 2024 · 2 comments · Fixed by #3348
Closed

Allow to configure fetch batch size when using FetchGroups #3313

apflieger opened this issue Jan 25, 2024 · 2 comments · Fixed by #3348
Assignees
Milestone

Comments

@apflieger
Copy link

We use extensivly a pattern like this

DB.getDefault().createQuery(User.class).select(
        FetchGroup.of(User.class)
                .fetchQuery("tickets", FetchGroup.of(Ticket.class).build())
                .build()
);

But we can't configure this fetch on 'tickets' (like the fetch method allow on query with query.fetch(String, FetchConfig)).
It might make sens to have:

DB.getDefault().createQuery(User.class).select(
        FetchGroup.of(User.class)
                .fetchQuery("tickets", FetchGroup.of(Ticket.class).build(), FetchConfig.ofQuery(1000))
                .build()
);

Or did I miss an alternative way to do this?

Btw thank you a lot for your work on this project that we use for years now 🙏

@rob-bygrave
Copy link
Contributor

We use extensively a pattern like this

FetchGroup can be static final so what I'd expect to see is instead:

// create the FetchGroup once
static final FetchGroup<User> MY_FETCH_GROUP = FetchGroup.of(User.class)
  . tickets.fetchQuery()
  .build()

Query<User> query = DB.getDefault().createQuery(User.class)
  .select(MY_FETCH_GROUP)
  .build()

But we can't configure this fetch ... [to use] FetchConfig.ofQuery(1000)

Yes, we are missing the ability to do this is a strong typed way like:

A) specify the FetchConfig

static final FetchGroup<User> MY_FETCH_GROUP = FetchGroup.of(User.class)
  .tickets.fetch(FetchConfig.ofQuery(1000)) // <!-- specify the FetchConfig here
  .build()

B) specify the FetchConfig with properties

static final QTicket TICKET = QTicket.alias();

static final FetchGroup<User> MY_FETCH_GROUP = FetchGroup.of(User.class)
  // specify the FetchConfig with properties
  .tickets.fetch(FetchConfig.ofQuery(1000), TICKET.price, TICKET.availableFrom) 
  .build()

alternative way to do this?

Yes, we can do this using the fetch() method on query beans that matches fetch(String,String,FetchConfig)

static final FetchGroup<User> MY_FETCH_GROUP = FetchGroup.of(User.class)
   // WORKAROUND (with specific properties)
  .fetch("tickets", "price, availableFrom", FetchConfig.ofQuery(1000))

   // or without properties
   // .fetch("tickets", FetchConfig.ofQuery(1000))
  .build()

rbygrave added a commit that referenced this issue Mar 3, 2024
…d query beans

We can do this currently using string paths and properties, this adds support for doing this when using query beans and strong types
@rbygrave
Copy link
Member

rbygrave commented Mar 3, 2024

Supporting this via fetch(FetchConfig config, TQProperty<QB,?>... properties)

For example:

private static final FetchGroup<Customer> FETCHGROUP_CustomerWithContacts = 
      QCustomer.forFetchGroup()
        .select(cu.name, cu.phoneNumber)
        .contacts.fetch(FetchConfig.ofQuery(1000), co.firstName, co.lastName, co.email)
        .buildFetchGroup();


new QCustomer()
    .select(FETCHGROUP_CustomerWithContacts)
    .findList();

rbygrave added a commit that referenced this issue Mar 3, 2024
…config

#3313 Ability to configure fetch batch size when using FetchGroups and query beans
@rbygrave rbygrave self-assigned this Mar 3, 2024
@rbygrave rbygrave added this to the 14.0.1 milestone Mar 3, 2024
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 a pull request may close this issue.

3 participants