|
Home > Archive > Apache JDO Project > October 2005 > Query question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Karan Malhi 2005-10-20, 5:45 pm |
| Hi,
First of all, I am sorry, I could not contribute much in the past two or
three weeks. Hopefully, I should be able to start contributing some things
this weekend.
I had a question regarding queries.
I have two classes , Address and Customer. Customer has many Addresses
class Address{
private String city;
}
class Customer{
Set address = new HashSet(); //contains collection of Address objects
}
I want to find those customers , which belong to cities which are contained
in a collection. For example, if i had a collection of String objects,
containing city values like PA, CA , LA, and I wanted to find customers
belonging to one of those cities, then would the following work. if this
doesnt work, then what would be the solution for this query .
Set allowed = new HashSet(); // allowed collection contains cities (String)
allowed.add('ny');
allowed.add('pa');
query.setFilter("address.contains(add) && allowedCities.contains(add.city
)");
query.declareParameter(Set allowedCities);
query.setImports("import java.util.*");
query.setVariable(Address add);
query.execute(allowed);
--
Karan Malhi
| |
| Craig L Russell 2005-10-20, 5:45 pm |
| Hi Karan,
On Oct 14, 2005, at 7:10 AM, Karan Malhi wrote:
> Hi,
> First of all, I am sorry, I could not contribute much in the past
> two or
> three weeks. Hopefully, I should be able to start contributing some
> things
> this weekend.
> I had a question regarding queries.
> I have two classes , Address and Customer. Customer has many Addresses
>
> class Address{
> private String city;
> }
>
> class Customer{
> Set address = new HashSet(); //contains collection of Address objects
> }
>
> I want to find those customers , which belong to cities which are
> contained
> in a collection. For example, if i had a collection of String objects,
> containing city values like PA, CA , LA, and I wanted to find
> customers
> belonging to one of those cities, then would the following work. if
> this
> doesnt work, then what would be the solution for this query .
>
> Set allowed = new HashSet(); // allowed collection contains cities
> (String)
> allowed.add('ny');
> allowed.add('pa');
> query.setFilter("address.contains(add) && allowedCities.contains
> (add.city
> )");
> query.declareParameter(Set allowedCities);
> query.setImports("import java.util.*");
> query.setVariable(Address add);
> query.execute(allowed);
Yes, this is a proper JDOQL query.
Craig
>
>
> --
> Karan Malhi
>
|
|
|
|
|