cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gentry, Michael \(Contractor\)" <michael_gen...@fanniemae.com>
Subject RE: Query Examples Needed � Expression.fromString() syntax?
Date Thu, 25 May 2006 14:44:09 GMT
Well, if you are fond of BNFs, this might be the best reference:

http://www.objectstyle.org/cayenne/grammar/ExpressionParser.html

It is pretty much the bible for the expression parser.  You can look at these wiki pages,
too:

http://www.objectstyle.org/confluence/display/CAYDOC/Building+Expressions

http://www.objectstyle.org/confluence/display/CAYDOC/Path+Expressions

There are more pages, of course, but that should give you a good start.

/dev/mrg



-----Original Message-----
From: Eric Lazarus [mailto:ericllazarus@yahoo.com] 
Sent: Thursday, May 25, 2006 10:13 AM
To: cayenne-user@incubator.apache.org
Subject: RE: Query Examples Needed � Expression.fromString() syntax?


Oh, that is SO cool! Now I understand why you use
fromString even for UIs.

Thanks for making that clear.

Where do I fnd out about the complete syntax for
Expression.fromString strings?

Is:

http://www.objectstyle.org/confluence/display/CAYDOC/Expressions

http://www.theserverside.com/tt/articles/article.tss?l=Cayenne

the best reference? 

What else should I read about this?

Thanks for all your help!

Eric
--- "Gentry, Michael (Contractor)"
<michael_gentry@fanniemae.com> wrote:

> If by a composite data structure you mean joins
> across multiple tables, yes, Cayenne will handle
> that automatically for you based on your definitions
> of the relationships in the modeler.  It'll include
> all the tables needed and construct the joins as
> part of the where clause.
> 
> I use the fromString() method even for queries
> entered by a user in a web page.  Map the text
> fields to hash map entries and fire it off.  Cayenne
> figures out what parameters are missing in the map
> and will omit them from the final SQL.  This means
> the more text fields the user enters, the more
> specific the query.  The less entered, the more
> general the query.
> 
> From my example yesterday, if you only have:
> 
> expression = Expression.fromString("firstName =
> $firstName and lastName = $lastName");
> parameters.put("lastName", "Gentry");
> 
> Then Cayenne will automatically reduce the query
> string to "lastName = $lastName" when you call
> expWithParameters().  (There is a flag to make all
> fields required, though.)  So you can write your
> query to be detailed and have sections drop out if
> they aren't needed without changing your query --
> just leave them out of the map.  Of course, you can
> glue it together yourself, too.  :-)
> 
> /dev/mrg
> 
> 
> -----Original Message-----
> From: Eric Lazarus [mailto:ericllazarus@yahoo.com] 
> Sent: Wednesday, May 24, 2006 5:14 PM
> To: cayenne-user@incubator.apache.org
> Subject: RE: Query Examples Needed �
> Expression.fromString() syntax?
> 
> 
> Oh, I'm not being clear... what I mean is, we will
> end
> up with a composite data structure. I assume that
> Cayenne does the right thing unpacking the composite
> and turning it into one flat "where" clause in the
> eventual sql, right? That's what I meant: am I doing
> the right thing in terms of generating good SQL?
> 
> It does seem clear to me that for our case where we
> don't know how many causes there will be until we
> see
> which things the user has filled in, it does seem
> that
> the 
> 
> e = e.and(... 
> 
> style will make for pretty simple code. 
> 
> --- "Gentry, Michael (Contractor)"
> <michael_gentry@fanniemae.com> wrote:
> 
> > I don't know which is more efficient as I've never
> > timed them.  I'd be willing to wager that your
> > database latency will be significantly higher than
> > having to choose between Expression and
> > ExpressionFactory, though.  Perhaps a case of
> trying
> > to optimize too early?
> > 
> > I just prefer the way fromString() works so that
> is
> > what I use.  It fits my brain better.  I believe
> > fromString() appeared in Cayenne 1.1, so before
> that
> > you had to do it the other way (unless I'm just
> > totally off here).
> > 
> > Use whichever one feels better to you.  :-)
> > 
> > /dev/mrg
> > 
> > 
> > -----Original Message-----
> > From: Eric Lazarus [mailto:ericllazarus@yahoo.com]
> 
> > Sent: Wednesday, May 24, 2006 3:45 PM
> > To: cayenne-user@incubator.apache.org
> > Subject: Re: Query Examples Needed �
> > Expression.fromString() syntax?
> > 
> > 
> > Thank you, Michael and Joshua! 
> > 
> > What about efficiency? If I want to "and" in a
> bunch
> > of things, like as many as 10 things if the user
> > fills
> > in all the fields of the web query form, then it
> > would
> > look like this? :
> > 
> > Expression e =
> > ExpressionFactory.greaterExp("estimatedPrice", new
> > BigDecimal(100000.0));
> > 
> > e = e.and(
> > ExpressionFactory.lessExp("estimatedPrice",
> > new
> > BigDecimal(5000.0)) );
> > 
> > e = e.and(
> ExpressionFactory.lessExp("productSize",
> > BigDecimal(100.0) );
> > 
> > e = e.and(
> > ExpressionFactory.lessExp("productWeight",
> > new
> > BigDecimal(200.0)) );
> > 
> > I can just keep appending conditions on like this?
> > Will this turn into efficient SQL code if done
> this
> > way? If not, what is the best way?
> > 
> > Thanks,
> > 
> > Eric
> > 
> > --- Joshua Pyle <joshua.t.pyle@gmail.com> wrote:
> > 
> > > I never use fromString any more.
> > > 
> > > But using the expressionFactory to and and or
> > > expressions is very simple...
> > > 
> > > Expression e =
> > > ExpressionFactory.greaterExp("estimatedPrice",
> new
> > > BigDecimal(100000.0));
> > > 
> > > e = e.and(
> > > ExpressionFactory.lessExp("estimatedPrice", new
> > > BigDecimal(5000.0)) );
> > > 
> > > -- 
> > > Joshua T. Pyle
> > > Go has always existed.
> > > 
> > > On 5/24/06, Eric Lazarus
> <ericllazarus@yahoo.com>
> > > wrote:
> > > > Would anyone reply with some nice examples of
> > > > SelectQuery beside the simple one here:
> > > >
> > > >
> > >
> >
>
http://www.objectstyle.org/cayenne/userguide/dataobjects/dataobjects-example.html
> > > >
> > > > Expression e =
> > > >  
> ExpressionFactory.greaterExp("estimatedPrice",
> > > >                         new
> > BigDecimal(100000.0))
> > > >
> > > > I need to do things with ANDS and ORs and I'm
> > not
> > > sure
> > > > how to use expression factory (or should I use
> > > > Expression.fromString() ?) to do it.
> > > >
> > > > Right now my immediate need is to be able to
> > > construct
> > > > a query with an arbitary number of possible
> > "and"
> > > > clauses depending on what the user types.
> > > >
> > > > Seems like fromString() is going to be easy
> and
> > > > powerful but I can't find an example of the
> > syntax
> > > > using google.
> > > >
> > > > Even just a few nice examples would be
> helpful.
> > > >
> > > > Can I look at the attributes of sub objects
> > using
> > > this
> > > > syntax? How?
> > > >
> > > > Thanks!
> > > >
> > > > Eric
> > > >
> > > >
> > > >
> > __________________________________________________
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Mime
View raw message