Answers below:
How about Filters? Maybe just “Where” and have an uber “find”
function that takes in different combinations of arguments to form the
query. list() already uses the criteria argument so hopefully what is
used is consistent in all the functions.
Here are some other thoughts about BaseORMService.cfc
- What is the difference between findIt() and findAll()
find() always returns 1 entity
findAll() always returns an array of entities
- findAll() and list() seem to be very similar too
list() returns queries by default and is powered by entityLoad(),
findAll() is powered by HQL queries, so it is much more powerful
- How does one use the OR and IN WHERE operators?
I don’t think the current HQL implementation in CF allows for IN operators, as for OR, that can only be used on HQL and not on entityLoad() does not support OR’s just ANDs. For those complex queries, use the executeQuery() in the base service.
- getAll() executes a entityLoadByPK for each ID in the array. Is
this for performance reasons since certain entities might be already
cached in the ORM session?
Yes, and also because you are retrieved by PK, basically doing the work for you instead of loading multiple entities.
- deleteByID() - would be cool if you could pass in an array of ids.
Interesting, trying to see if it would be better to do the array of ids as an HQL query so it is then batched by hibernate. However, I have not tried the IN clauses yet. Maybe Curt can shed some light here. So if we do this:
deleteByID(“User”, [1,2,3]);
Then if the ID is an array, we would execute an hql query like: “delete from User where PK IN (1,2,3)”
Because if we just iterate over the array and do: entityLoad() and then delete(), it could be potentially slow since you are doing 1 query to load the entity, and then delete it. However, if we do it via HQL it is just 1 query but we need the PK, which is trivial to get from hibernate. Thoughts?
- I wish there was an interception point called in save(). I ran
into some issues when using the ORM handlers when inserting and
updating entities. (I couldn’t use ORMPreInsert to set an assigned
key, cf would error compaining of the missing ID before the event was
called ). This would also be useful for adding functionality outside
of the transaction (for example - checking to make sure the entity is
valid before attempting to save it).
Ok, how about creating one called, ORMPreSave() and another one ORMPostSave(). The preSave occurs before the transaction and saving, and the postSave after the commit or rollback.