cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joseph Senecal <sene...@apple.com>
Subject Re: Type safe queries & more
Date Fri, 16 Sep 2011 02:07:45 GMT
In reference to making typesafe queries, I think the easiest way to do that is to have the
subclass template generate typesafe helper methods, something like this:

    @SuppressWarnings("unchecked")
    public static List<User> fetchUserList(ObjectContext context, Query query) {
        return (List<User>) context.performQuery(query);
    }

My template actually generates several variations of this helper method with various parameters.
It be tedious to make these by hand for each class, but it's easy when the code is generated
by a template.

Joe

On Sep 15, 2011, at 5:31 PM, Aristedes Maniatis wrote:

> Hello Hugi
> 
> Welcome to Cayenne. The work you have done is extremely welcome and has been discussed
before:
> 
>  http://markmail.org/thread/nnnj2ezvpzamphdn
> 
> It just is that no-one has had the time to work on it. This syntax is also very similar
to the way Ruby Rails queries are constructed: very clean and easy to read.
> 
> I encourage you to do a couple of things to follow this through and see if we can get
this approach into Cayenne:
> 
> 1. Take this over to the dev list (I'm copying that list in now)
> 2. Put your code somewhere. Jira is a very good option (no matter how basic the code
is) because you will agree to a license agreement releasing the code under the ASL which makes
it possible for us to include your code in Cayenne. You could also use something like gist
(github.com) to put code in a more visible place for now, but ultimately it will need to come
back through Jira.
> 
> Again, welcome. Getting type safety into object keys has always been a goal here.
> 
> Ari
> 
> 
> On 16/09/11 4:29 AM, Hugi Thordarson wrote:
>> Hi all.
>> 
>> Cayenne beginner here. I come from an EOF/WebObjects background, so when I started
using Cayenne (yesterday) I kinda missed the type safety and conciseness of using Mike Schrag's
ERXKeys when constructing qualifiers and Orderings.
>> 
>> So me and another EOF guy (@atlipall) sat down today and recreated/reverse-engineered
some of Mike's work to be usable with Cayenne. We're sharing this early, hoping it might be
useful for someone elseā€”and  since we're total beginners and don't know much about Cayenne
yet, comments are appreciated. (Perhaps we're even implementing pre-existing functionality;
we just don't know :).
>> 
>> Anyway, by using the two attached classes and superclass template, you can write
type safe code such as:
>> 
>> List<User>  users = User.fetch( dataContext, User.FIRSTNAME.like( "joe%" ).and(
User.AGE.between( 20, 30 ), User.FIRSTNAME.asc().then( User.LASTNAME.asc() ) );
>> 
>> (this would fetch all users named "joe"-something, aged betweeen 20 and 30, and order
the list by first name, then last name.
>> 
>> We also added some convenience methods to the superclass template. These are:
>> 
>> fetchAll( ObjectContext );
>> fetchAll( ObjectContext, List<Ordering>  );
>> fetch( ObjectContext, Expression );
>> fetch( ObjectContext, Expression, List<Ordering>  );
>> fetchOne( ObjectContext, Expression );
>> create{relationship_name}Relationship();
>> delete{relationship_name}Relationship();
>> 
>> That's all for now.
>> 
>> Cheers,
>> - hugi
>> 
> 
> -- 
> -------------------------->
> Aristedes Maniatis
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A


Mime
View raw message