On Mar 14, 2009, at 3/144:22 PM , Joe Baldwin wrote:
Robert,
I am attempting a test but lost you on your Qualifier step.
SelectQuery query = new SelectQuery(Entity1.class);
This is easy.
query.setQualifier(ExpressionFactory.matchExp(Entity1.EN|
TITY2_PROPERTY,entity2));//where ENTITY2_PROPERTY is the name of
object property in entity1 that points to entity2
I don't follow this step. You are obviously using the
ExpressionFactory to create a qualifier expression for the query but
I don't follow the match expression.
Lets say that entity1 is "Customer" and entity2 is "Detail". So the
code snippet would be
ExpressionFactory.matchExp(Customer.DETAIL_PROPERTY, entity2)
I don't understand what entity2 stands for in this example. In
addition, I am trying to select based on the contents of the entity2
field, so I am even more confused as to how this would accomplish
that objective.
Ok, Customer -> Detail.
I'm still a little unclear on exactly what you're trying to do, based
on your comment "based on the contents of the entity2 field", so I'll
step through two scenarios:
1) You have a "detail" object reference, and you want to get the
corresponding "customer".
Then entity2 would be your detail object.
ExpressionFactory.matchExp() takes a property path as its first
argument and the corresponding value to match as its second.
So,
ExpressionFactory
.matchExp(Customer.DETAIL_PROPERTY,someDetailForWhichYouHaveAReference);
Of course, if this is a two-sided one-to-one (detail has a property
for customer, as well as customer having a property for detail), then
you could always just do:
detail.getCustomer(); :)
2) You have some information related to a property of detail, say,
"description".
So the property path, from customer, might look like:
"detail.description" (assuming customer is the root object of the
property path).
Or, you could write it as:
Customer.DETAIL_PROPERTY + "." + Detail.DESCRIPTION_PROPERTY
So you could do:
ExpressionFactory.matchExp(Customer.DETAIL_PROPERTY + "." +
Detail.DESCRIPTION_PROPERTY,"the description string")
Or you could use a like expression:
ExpressionFactory.likeExp(Customer.DETAIL_PROPERTY + "." +
Detail.DESCRIPTION_PROPERTY,"the description to partial match");//<--
add % wildcards yourself here.
HTH,
Robert
List<Entity1> e1 = objectContext.performQuery(query);//note:
perform query is NOT generified, so you'll get a warning here.
This seems easy as well.
Thanks,
Joe
On Mar 14, 2009, at 3:53 PM, Robert Zeigler wrote:
Hi Joe,
How about:
SelectQuery query = new SelectQuery(Entity1.class);
query.setQualifier(ExpressionFactory.matchExp(Entity1.EN|
TITY2_PROPERTY,entity2));//where ENTITY2_PROPERTY is the name of
object property in entity1 that points to entity2
List<Entity1> e1 = objectContext.performQuery(query);//note:
perform query is NOT generified, so you'll get a warning here.
Robert
On Mar 14, 2009, at 3/141:29 PM , Joe Baldwin wrote:
I am attempting to create the simplest Cayenne-expedient method of
doing the following query. (I can easily do this in SQL but am a
tad confused with the Cayenne Expression method.)
I have an Entity (E1) with a one to one relationship with a second
entity (E2). I would like to perform a SELECT Query with a filter
on one of the fields of the relationship-entity (E2.F1) and return
a list of the first entity (E1List).
What is the most efficient Cayenne way to do this? (I am still a
bit confused concerning how to construct efficient queries in the
object domain vs the relational domain.)
Thanks,
Joe