v-ladynev / fluent-hibernate

Library to work with Hibernate by fluent API
Other
48 stars 12 forks source link

AND OR concept #16

Closed aleksey-pchelnikov closed 8 years ago

aleksey-pchelnikov commented 9 years ago

1

WHERE (E1 AND E2) OR (E3 AND E4)

//it's like Querydsl e1.and(e2).or(e3.and(e4))

or(and(e1, e2), and(e3, e4))

2

WHERE (E1 OR E2) AND (E3 OR E4)

e1.or(e2).and(e3.or(e4))

and( or(e1, e2), or(e3, e4) )

3

WHERE (E1 OR E2) AND E3

e1.or(e2).and(e3))

and( or(e1, e2), e3 )

4

WHERE E1 AND E2 AND E3 AND E4

e1.and(e2).and(e3).and(e4)

and(e1, e2, e3, e4)

5

WHERE E1 OR E2 OR E3 OR E4

e1.or(e2).or(e3).or(e4)

or(e1, e2, e3, e4)

v-ladynev commented 9 years ago

I like the second variant at every item because there is not noise from dots and brackets there.

samsonych commented 9 years ago

I think usecase #1 (like Querydsl ) more logical. OR and AND clauses should be as methods.

v-ladynev commented 9 years ago

samsonych, development is not about a logic, but about a convenience.

2 is convenient to read but it is hard to write cause of static imports.

v-ladynev commented 9 years ago

Ok, I think we can divide a problem on some parts. For an example we can use "and(e1, e2, e3, e4)" in #4 and "or(e1, e2, e3, e4)" in #5 any way.

v-ladynev commented 9 years ago

In #1 and #2 in the first variant left and right part is the same e1.and(e2).or(e3.and(e4))

but on the left we use "e1.and(e2).or" and "or(e3.and(e4))" on the right :)

v-ladynev commented 9 years ago

aleksey-pchelnikov, can you show how this "e1.and(e2).or(e3.and(e4))" will be in real code?