You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Aristedes Maniatis <ar...@maniatis.org> on 2011/09/16 02:31:23 UTC

Re: Type safe queries & more

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

Re: Type safe queries & more

Posted by Joseph Senecal <se...@apple.com>.
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


Re: Type safe queries & more

Posted by Hugi Thordarson <hu...@karlmenn.is>.
I actually started out with a ChainableExpression, but I had problems creating a wrapper for an Expression since Expression has a couple of protected methods that required overriding in a subclass. Simple to get around, I guess, but I haven't had the time to check it out again :).

But that's definitely desirable, so you can write, as you say expression.count( ObjectContext ) or expression.fetch( ObjectContext ).

Cheers,
- hugi



On 18.9.2011, at 11:12, Aristedes Maniatis wrote:

> On 16/09/11 11:36 PM, Hugi Thordarson wrote:
>> We've committed the code as a Maven project on Bitbucket:
>> 
>> https://bitbucket.org/hugi/jambalaya
> 
> I'm curious about your choice to create ChainableOrdering and not ChainableExpression. The later would let us equally write:
> 
>  debtors = User.where("owing > 0").order("firstname")
> 
> and then later on
> 
>  debtors.count()
> 
> or
> 
>  debtors.where("firstname LIKE joe%")
> 
> 
> Adding an ordering to an expression need not then preclude adding further WHERE clauses.
> 
> 
> Ari
> 
> -- 
> -------------------------->
> Aristedes Maniatis
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A


Re: Type safe queries & more

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 16/09/11 11:36 PM, Hugi Thordarson wrote:
> We've committed the code as a Maven project on Bitbucket:
>
> https://bitbucket.org/hugi/jambalaya

I'm curious about your choice to create ChainableOrdering and not ChainableExpression. The later would let us equally write:

   debtors = User.where("owing > 0").order("firstname")

and then later on

   debtors.count()

or

   debtors.where("firstname LIKE joe%")


Adding an ordering to an expression need not then preclude adding further WHERE clauses.


Ari

-- 
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

Re: Type safe queries & more

Posted by Hugi Thordarson <hu...@karlmenn.is>.
Hi Ari.

> Welcome to Cayenne. The work you have done is extremely welcome and has been discussed before:

Thank you :).

> 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.

Glad to hear that :-).

We've committed the code as a Maven project on Bitbucket:

https://bitbucket.org/hugi/jambalaya

I added a license element to the POM stating ASL 2.0. Once we've worked a little more on this and written test cases we'll happily submit a JIRA.

Cheers,
- hugi

Re: Type safe queries & more

Posted by Hugi Thordarson <hu...@karlmenn.is>.
Hi Ari.

> Welcome to Cayenne. The work you have done is extremely welcome and has been discussed before:

Thank you :).

> 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.

Glad to hear that :-).

We've committed the code as a Maven project on Bitbucket:

https://bitbucket.org/hugi/jambalaya

I added a license element to the POM stating ASL 2.0. Once we've worked a little more on this and written test cases we'll happily submit a JIRA.

Cheers,
- hugi

Re: Type safe queries & more [moved from cayenne-users]

Posted by Hugi Thordarson <hu...@karlmenn.is>.
Hi Andrus

> The ERXKeys were created well past my EOF days, but I saw the code based on it on a few projects and it looked quite impressive. 

Yes, I've been using them for many years, and I really like the syntax


> Type-safe queries are very high on the Cayenne priority list. Since we planned deeper internal support of generics, I am expecting it will be fully done around 3.2 (we are now developing 3.1). However as you show, with some cgen magic current users can have some of it right away. 

Happy to hear that :). I'm a little curious about what you're currently planning for 3.2—can you point me to some previous discussions so I can take a peek?


> And yes - welcome to Cayenne :)

Thank you! I'm liking the community already :).

Cheers,
- hugi

Re: Type safe queries & more

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Hugi,

I second Ari on this. 

The ERXKeys were created well past my EOF days, but I saw the code based on it on a few projects and it looked quite impressive. 

Type-safe queries are very high on the Cayenne priority list. Since we planned deeper internal support of generics, I am expecting it will be fully done around 3.2 (we are now developing 3.1). However as you show, with some cgen magic current users can have some of it right away. 

So yeah, if we are going to have more technical discussions re: integrating it in Cayenne somehow, let's do it on the devl list.

And yes - welcome to Cayenne :)

Andrus

On Sep 16, 2011, at 3:31 AM, 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
>