State and intention of QueryBeans #2874
Replies: 6 comments 12 replies
-
I did an analysis of the queries of the non-trival applications I had access to at the time. I'd suggest these apps only have one use of "effective dating" / "Type 2 temporal design" so I'd suggest less use of
My gut says that 85% for me is actually conservative. To some extent that is probably because I designed and maintain query beans so I am quite prepared to enhance and extend them as I see need or common convenience expressions in order to support the "fluid style" and minimise the general weakness around OR/Disjunction. That is, if I see a case where query beans are "not awesome" I'm typically addressing it.
Query beans as I see them are "truely awesome" (as long as we can reasonably express the vast majority of our predicates). I give them the "truely awesome" tag because imo they are the simplest possible and easiest to read query construction I have seen (again, as long as we can reasonably express the vast majority of predicates). They get this simplicity by abstracting over EQL (Ebean query language) which is based on "orm graph paths" and means that we don't explicitly deal with sql joins (for predicates, projection, and breaking queries into multiple sql queries).
Yes, I see that.
Sure. It looks likes the app you are working on uses a lot of effective dating (hence In terms of the subquery issue, that really looks like a simple case of offering more operators other an
JOOQ is targeting SQL and to HAS to be more expressive. Query beans are targeting EQL (Ebean query language) which is a higher abstraction level and orders of magnitude simpler than SQL (and to some extent boils down to "path based predicate/expressions"). |
Beta Was this translation helpful? Give feedback.
-
Yes, they are very readable but priority number one should be type safety. Personally I would generally be fine with "reasonably readable" if it brings full type safety. Well and with JPA's Criteria Builder being the worst readable solution in comparison. Because Ebean uses JPA annotations and I would guess there are people coming from JPA to Ebean I would expect Ebean's Query Beans to be as expressive as JPQL / Criteria Builder. Otherwise Ebean code might end up being less type-safe if someone really has done full JPA Criteria Builder and now regularly has to fall back to use
Hm yes I mixed a few things here. What I wanted to say is that core SQL features need to exist in Query Beans and thus EQL or generally any SQL abstraction layer that does not want to loose too much expressiveness. Maybe EQL already supports:
I have skimmed through some queries and I guess the majority of use cases are covered by both issues I have created. Some examples that I have found:
I think my major disappointment is that the current code is string based JPQL and during migration to Ebean the plan is to make it type-safe as much as possible since Query beans are much easier to read than JPA criteria builder. JPA criteria builder is only used in a few situations when building queries dynamically. But realizing that I still have to fall back to strings a lot with Ebean caused me starting this discussion. Especially because Query Beans are treated as the preferred way to query data in Ebean. If nothing helps I guess I can still use JOOQ as SQL builder + Ebean's findNative though. However minimizing dependencies is also valuable. |
Beta Was this translation helpful? Give feedback.
-
Excellent. With that we can see:
I'd suggest the next steps are to firstly knock off the obvious and simple cases first and then prototype the more interesting cases and see how far that gets us.
I'm thinking those are very doable and yes I agree they would provide a lot of value. I think where we are heading with this part is a new interface type (say I need to do a couple of things to clear the decks then we can hop into some of this and see how we go. |
Beta Was this translation helpful? Give feedback.
-
PR with initial look at StdFunctions - https://github.com/ebean-orm/ebean/pull/2881/files
Ponderings:
Still Pondering the cases of:
We should be adding generic type query examples tests into ebean-querybean and can look to put Postgres specific function test in with ebean-postgis (but unit tests should reasonably cover things in PgFunctions as well) |
Beta Was this translation helpful? Give feedback.
-
No, it is not possible but ... that is kind of what we are doing in the PR now in that we use Temporal as a sort of "marker type" for
For example, with public static Expression eq(Property<Temporal> property, Temporal value) ...
// we need the overloaded method taking a java.util.Date
public static Expression eq(Property<Temporal> property, java.util.Date value) ...
// we need the overloaded method taking a java.util.Calendar
public static Expression eq(Property<Temporal> property, java.util.Calendar value) ... ... but to some extent people really shouldn't be using Calendar, java.util.Date or Joda types anyway. The overloaded methods for these types could be put into a |
Beta Was this translation helpful? Give feedback.
-
I agree - I actually pushed another change that got rid of the "extra type parameter" design so the
Yes and that was the intention per say in order to be able to compare a LocalDate property with java.sql.Date property and similarly compare properties Timestamp, Instance, OffsetDateTime with each other ... but playing around with it I didn't really like the result and I have ditched that idea and I think it's much better now. So now it's back to the single specific java type and that means we can't compare a LocalDate property with java.sql.Date property but I think that is ok. It should be reasonably unlikely that people will mix their "date types" like that. There is however a reasonable chance that people use a mix their 'datetime types' with a mixture of java.sql.Timestamp, Instant, OffsetDateTime and ZonedDateTime ... and folks that do that might hit that restriction where they want to compare an Instant property and OffsetDateTime property and can't (or at least it isn't going to be obvious and easy) but I don't think this is too unreasonable. So I do like where this PR is at now but I don't think we are perfect here in the case with a mixture of java.sql.Timestamp, Instant, OffsetDateTime and ZonedDateTime but I think its ok - I'd be ok merging this if people were keen to try it.
Ah ok. I can hopefully have a look at that later. |
Beta Was this translation helpful? Give feedback.
-
In Ebean documentation it says
In typical recent applications around 85% of queries were "pure" ORM queries.
.I am wondering what
typical recent applications
means? In my experience I need to useraw
nearly everywhere because QueryBeans are only really useful for the simplest queries possible. To me it is more like 15% can be used with "pure" ORM queries and the rest needs to mix-in string based sql. In extreme cases I am writingnew QEntity()
out of habit just to realize that I can only really donew QEntity().raw().findList()
, even though the query itself isn't long and complicated.I feel like that is very sad because type-safety is very valuable for queries to spot refactoring issues easily.
So I am wondering what is the goal of query beans? Are they so limited on purpose? Were they a nice idea that won't be expanded on? When first sawing them in the docs and used them with very simple queries I really liked them but today they usually give a bad feeling since they are so limited and you constantly loose type-safety, the main goal of QueryBeans.
I have already created two issues to provide two very basic things:
in
Without these QueryBeans are super limited in its use. I am really thinking about ditching QueryBeans completely just to have the database layer consistently use string based queries.
Have you ever considered generating QueryBean API in a similar way as JOOQ does? JOOQ is way more expressive and IMHO Ebean should reach a very similar level before it can say that it has a type-safe SQL API. Maybe Ebean and JOOQ can be joined together somehow, so that the work JOOQ has already done does not need to be done again for Ebean? I know I can use JOOQ as SQL builder but I don't want to use pure SQL with Ebean since I loose a lot of Ebean functionalities.
Beta Was this translation helpful? Give feedback.
All reactions