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

Add support to pass parameters in crossJoin #51

Open
oberien opened this issue Mar 27, 2017 · 3 comments
Open

Add support to pass parameters in crossJoin #51

oberien opened this issue Mar 27, 2017 · 3 comments

Comments

@oberien
Copy link

oberien commented Mar 27, 2017

Is possible / feasible to implement crossJoin in a way that allows passing parameters while cross-joining?

Given these methods:

public JPAJinqStream<Customer> getCustomer(long id) {
    return streams.streamAll(em, Customer.class)
        .where(c -> c.getId() == id);
}

public JPAJinqStream<Sale> getSales(List<Long> ids) {
    return streams.streamAll(em, Sale.class)
        .where(s -> JPQL.isInList(s.getId(), ids));
}

Would it be possible to implement a crossJoin taking a lambda which takes the current type as parameter and returns the new stream to join with like this?

getCustomer(1337)
    .crossJoin(c -> getSales(c.getSales()));
@my2iu
Copy link
Owner

my2iu commented Mar 27, 2017

If you need a lambda, you can just use the normal join() syntax. I think it would be something like this:

getCustomer(1337).join(
    (c, source) -> source.stream(Sale.class)
        .where(s -> JPQL.isInList(s.getId(), c.getSales()) );

@oberien
Copy link
Author

oberien commented Mar 28, 2017

This case is highly simplified. In reality we are talking about both methods having 20+ lines of Jinq code. While I could copy the code and create a third method (which I will do if you say that this is not possible), it would be code duplication which I would like to avoid.

@my2iu
Copy link
Owner

my2iu commented Mar 28, 2017

It's not really possible since Jinq currently can't trace into other method calls when trying to decode a lambda.

You can maybe make a method that returns the lambda you need, but I'm not sure if that would work for your code. Something like

JoinWithSource<...> createJoin() {
   return (c, source) -> source.stream(Sale.class)
        .where(s -> JPQL.isInList(s.getId(), c.getSales())
}

getCustomer(1337).join( createJoin() );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants