Some more feedback on baseORMService

Few things that came to mind this morning.

1) Can we add a new property to toggle the asQuery attribute service
wide? I prefer to have the array of entities returned and this forces
me to either override the functions to change the default, or provide
all the arguments since the asQuery is the last argument. Would be
nice to turn this on/off service wide similar to the usetransactions
property.

2) findAllWhere() & getAll() do not support the sortorder argument for
entityload.

3) I find findAll(), findAllWhere(), getAll() all confusing as they
all perform the similar tasks but all provide different options.

For example, findAll can support query example but if one isn't
provided it runs the a hql query. Why is this function duel
purposed? Wouldn't it be better if this method was changed to be
findByExample() and if I wanted to run a hql query I'd just use
executeQuery which is a more robust method.

Similarly getAll() is duel purposed too. It can either return all
entities, but does not support any additonal arguments (criteria,
sortorder, etc). So if I wanted to get a set of entities I should
just use list().

It is nice though that getAll supports returning entities from a
provided list of ids but I'd argue that this is all this function
should do.

findAllWhere is just a simplified version of the list() function so I
am not sure why it is even included.

thanks!

.brett

Some more thoughts.

1) I mix and match from query and objects depending on my needs, by doing
what you are asking is going to hinder a lot of code that I have written
that uses this service.

2) I am going to have to agree here, as these are not what I am used to and
have written my own BaseORMService.

3) They provide different options the same as ORMExecuteQuery and
ORMExecuteByExample do different things. But I will agree that this is
confusing though.

I would also like to add that the current BaseORMService is also very much
lacking multi datasource/database support that ORM within ColdFusion allows
for.

So maybe the BaseORMService may need a bit of a makeover.

I started a project a while ago that would be a BaseORMService that also
supported findByColumn() or findByColumnWhere() that mimics how grails does
it. I got as far as being able to add the functionality, and stopped at how
to get the hibernate stuff working. Maybe I can put it out there for someone
else who knows ORM better to have a go.

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Brett
Sent: Friday, 13 May 2011 4:13 AM
To: ColdBox Platform
Subject: [coldbox:10045] Some more feedback on baseORMService

Few things that came to mind this morning.

1) Can we add a new property to toggle the asQuery attribute service wide?
I prefer to have the array of entities returned and this forces me to

either

override the functions to change the default, or provide all the arguments
since the asQuery is the last argument. Would be nice to turn this on/off
service wide similar to the usetransactions property.

2) findAllWhere() & getAll() do not support the sortorder argument for
entityload.

3) I find findAll(), findAllWhere(), getAll() all confusing as they all

perform the

similar tasks but all provide different options.

For example, findAll can support query example but if one isn't provided

it

runs the a hql query. Why is this function duel purposed? Wouldn't it be
better if this method was changed to be
findByExample() and if I wanted to run a hql query I'd just use

executeQuery

which is a more robust method.

Similarly getAll() is duel purposed too. It can either return all

entities, but

does not support any additonal arguments (criteria, sortorder, etc). So

if I

wanted to get a set of entities I should just use list().

It is nice though that getAll supports returning entities from a provided

list of

ids but I'd argue that this is all this function should do.

findAllWhere is just a simplified version of the list() function so I am

not sure

Hi Guys,

This is all really great. The BaseORMService and VirtualEntityService are both awesome tools, one of my favourite things in ColdBox actually.

I've had a rough concept in my mind for a while about a BaseEntity, which extends the functionality of a standard ORM entity.

For instance, if I have two entities, Author and Book, where an author has a collection of books they've written.

In cf I'd have to run a query on the books entity, and filter it by author, something like this:

Author = AuthorService.get('someifofanauthor');

Books = BooksService.findWhere(author=Author, year_printed=2001);

This always seemed a little odd to me, as we already have a collection of that authors books inside the author, why query the database a second time? of have to inject and call a separate service?

In Rails, the 'books' property would be a searchable collection, not just a 'dumb' array or struct, so you could do things like this:

Author = AuthorService.get('someifofanauthor');

Books = Author.books.findWhere(year_printed=2001)

Seems like a nice clean logical approach? Currently working on a SaaS product, where we regularly teather/scope things to a parent account, this sort of functionality would come in really handy.

I wonder if we could do something with the BaseORMService that would introspect the entities it's loading, and inject some form of facade collection for mimicking this kind of behaviour?

This is purely a concept at the moment, I've not really put much thought into it, as I'm sure you can tell.

Robert

Yes! I totally agree that this would improve my life to have a more
natural way to interact with orm relationships.

Great thoughts!

Updates:

  • findAllWhere() and getAll() now support sortOrder

  • findAll() relies on a custom HQL query

  • FindAllWhere() relies on binder parameter search on an entity

  • getAll() - retrieves ever single one

So they are all different.

  • findByExample() great idea, I just added it

difference between findAll() and executequery() comes down to just the asQuery argument, one strictly arrays of objects, the other one queries with a choice. I have also refactored them to share the code.

Similarly getAll() is duel purposed too. It can either return all
entities, but does not support any additonal arguments (criteria,
sortorder, etc). So if I wanted to get a set of entities I should
just use list().
That is the purpose with getAll() it has no filtering, it is a convenience method that will do as it says

I would also like to add that the current BaseORMService is also very much
lacking multi datasource/database support that ORM within ColdFusion allows
for.
Can somebody help with this and contribute it?

relationships like Robert mentions
I think this is a matter of choice. You can easily do this by having your Books inherit from the virtual entity service, so in turn your entity will have all of the virtual service layer capabilities. This is not great because you know rely on inheritance right.

Second approach: Activate the ORM event handler and create an interceptor that listens to ORMPostNew and ORMPostLoad
that can easily inject the incoming entities with all the functions you want at runtime.

http://wiki.coldbox.org/wiki/Extras:ORMEventHandler.cfm#ORM_To_ColdBox_Interceptions

Also, all the changes are on the dev branch now. Except the asQuery default and multi-datasource.

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano