JDO Question : Is it possible to get unique values like DISTINCT in SQL?

K

Klixx0r

Hi all,

I use DISTINCT in my SQL queries to get unique values where there
are duplicates in my DB tables. As JDO is a layer on top on JDBC
and it has its own query syntax (I don't think it allows SQL) ... I
was wondering if something like the effect of DISTINCT is possible?

Like if I had a field in my persitance enabled class called
customerName, and it 5 instances had values of
"A","B","B","C","D" ... i would want it to get all of them but only
one of the "B". Is this possible with JDO?

Thanks
 
G

Gerbrand van Dieijen

Klixx0r said:
Hi all,

I use DISTINCT in my SQL queries to get unique values where there
are duplicates in my DB tables. As JDO is a layer on top on JDBC
and it has its own query syntax (I don't think it allows SQL) ... I
was wondering if something like the effect of DISTINCT is possible?

Like if I had a field in my persitance enabled class called
customerName, and it 5 instances had values of
"A","B","B","C","D" ... i would want it to get all of them but only
one of the "B". Is this possible with JDO?


You could get a list of unique object by:
List list=(List)pm.newQuery(Customer.class,true)

SortedSet unqueset=new TreeSet(<my own Comparator>,list)

The comparator class can be constructed as such that Customers with the
same name are equal:
int compareTo(customer1, customer2) {
return customer2.getName().compareTo(customer1.getName())
}

JDO doesn't have a DISTINCT however. I think this is because it is less
needed, because you can't/don't have to use joints anyway. (like SELECT
Customer.name from Customer,Account where
Customer.NAME=Account.CustomerName).

It's best to specify in the JDO xml file package.jdo that CustomerName
has to be unique for the class Customer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top