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

Discussion in 'Java' started by Klixx0r, Dec 4, 2004.

  1. Klixx0r

    Klixx0r Guest

    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

    ----------------------------------------------
    Posted with NewsLeecher v1.0 Final
    * Binary Usenet Leeching Made Easy
    * http://www.newsleecher.com/?usenet
    ----------------------------------------------
     
    Klixx0r, Dec 4, 2004
    #1
    1. Advertising

  2. Re: JDO Question : Is it possible to get unique values like DISTINCTin SQL?

    Klixx0r wrote:
    > 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.
     
    Gerbrand van Dieijen, Dec 8, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eugen

    distinct values of xml

    Eugen, Sep 22, 2005, in forum: XML
    Replies:
    2
    Views:
    4,961
    yrpchoudary
    Jan 22, 2009
  2. Edvard Majakari
    Replies:
    4
    Views:
    446
    Mitja
    Jun 17, 2004
  3. Johnathan Doe

    How many distinct float values?

    Johnathan Doe, Dec 8, 2004, in forum: C Programming
    Replies:
    7
    Views:
    827
    Kevin Bracey
    Dec 9, 2004
  4. ToshiBoy
    Replies:
    6
    Views:
    886
    ToshiBoy
    Aug 12, 2008
  5. Hicham Mouline
    Replies:
    1
    Views:
    420
    Kai-Uwe Bux
    Apr 11, 2010
Loading...

Share This Page