This discussion is archived
7 Replies Latest reply: Jun 1, 2013 9:58 AM by user8997135 RSS

getSearchBothRange, how does bothrange read?

user8997135 Newbie
Currently Being Moderated
The API says:
Moves the cursor to the specified key and closest matching data item of the database.

The Getting Started Guide says:
Moves the cursor to the first record in the database whose key is  greater than or equal
to the specified key. If the database supports duplicate records, then on matching
the key, the cursor is moved to the duplicate record with the smallest data that is
greater than or equal to the specified data.

is getSearchBothRange(4,b) going to give me (5,c) or what?

and after it gives me a found, should I do getNext or getNextDup or getNextNoDup?
what do those next mean? are their semantics related to the query before or standalone?
I'm guessing the next may refer to "next value of the same key" "next result regarding to my previous search query" "next key" ...
and the "dup" may also apply to key or value or both

I'm totally confused and I failed to find anything organized and clear anywhere. Please help!
  • 1. Re: getSearchBothRange, how does bothrange read?
    user8997135 Newbie
    Currently Being Moderated
    forgot to mention I'm using secondaryCursor. is there any difference?
  • 2. Re: getSearchBothRange, how does bothrange read?
    Bogdan Coman Journeyer
    Currently Being Moderated
    user8997135 wrote:
    is getSearchBothRange(4,b) going to give me (5,c) or what?
    It will move the cursor to the first record whose key is 4 and whose data is b or greater than b. If you have the (4,b) record, it will move the cursor to (4,b).
    If the cursor is on a secondary, it does not search based on a key/data pair, but on a secondary key and a primary key. The data returned is the primary data that most closely matches the two keys provided for the search.
    and after it gives me a found, should I do getNext or getNextDup or getNextNoDup?
    what do those next mean? are their semantics related to the query before or standalone?
    getNext - shows the next/previous record in the database
    getNextDup - gets the next/previous record that shares the current key
    getNextNoDup - gets the next/previous non-duplicate record in the database
    Their semantics is related to the query before (where the cursor was last positioned).

    If you'd find it easier, maybe we can talk about it on a specific example you have in mind.
    The following documentation is explaining in detail how cursors work, maybe you can find it useful (some examples included):
    Chapter 9. Using Cursors - http://docs.oracle.com/cd/E17277_02/html/GettingStartedGuide/Cursors.html

    Additional documentation:
    Retrieving Multiple Objects - http://docs.oracle.com/cd/E17277_02/html/GettingStartedGuide/getmultiple.html
    Class Cursor - http://docs.oracle.com/cd/E17277_02/html/java/com/sleepycat/je/Cursor.html
    Working with Duplicate Keys - http://docs.oracle.com/cd/E17277_02/html/GettingStartedGuide/getmultiple.html#dpl_dups
    forgot to mention I'm using secondaryCursor. is there any difference?
    Yes, there is a difference. As I said, if the cursor is on a secondary, it does not search based on a key/data pair, but on a secondary key and a primary key. For more info:
    Using Secondary Cursors - http://docs.oracle.com/cd/E17277_02/html/GettingStartedGuide/secondaryCursor.html

    Code examples that are using cursors on the secondary:
    je-5.0.73/examples/je/SecondaryExample.java
    je-5.0.73/examples/je/gettingStarted/ExampleInventoryRead.java
    je-5.0.73/examples/je/ToManyExample.java
  • 3. Re: getSearchBothRange, how does bothrange read?
    greybird Expert
    Currently Being Moderated
    In addition to what Bodgan said, I strongly recommend using the DPL (com.sleepycat.persist package) rather than the base API. The DPL is meant to be an easier-to-use API than the base API.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                           
  • 4. Re: getSearchBothRange, how does bothrange read?
    user8997135 Newbie
    Currently Being Moderated
    Let's try one example. Plz correct me if anything down there does not make sence.

    SecondaryCursor sc;
    sc.getSearchBoth(E,b,data,null);
    // success only if (E,b) exists?

    sc.getSearchBothRange(E,b,data,null);
    // success if (E,b) exists?
    // success if (E,bb) exists?
    // success if (EE,b) exists?
    // success if (EE,bb) exists?

    //assuming cursor is on (E,b,data8), are the following results possible?
    sc.getNext();
    //(E,b,data9)?
    //(E,bb,data10)?
    //(EE,b,data11)?
    //(EE,bb,data12)?

    sc.getNextDup();
    //(E,b,data9)?
    //(E,bb,data10)?
    //(EE,b,data11)?
    //(EE,bb,data12)?

    sc.getNextNoDup();
    //(E,b,data9)?
    //(E,bb,data10)?
    //(EE,b,data11)?
    //(EE,bb,data12)?

    Edited by: user8997135 on Jun 1, 2013 12:44 AM
  • 5. Re: getSearchBothRange, how does bothrange read?
    user8997135 Newbie
    Currently Being Moderated
    edited last post

    Edited by: user8997135 on Jun 1, 2013 12:50 AM
  • 6. Re: getSearchBothRange, how does bothrange read?
    greybird Expert
    Currently Being Moderated
    SecondaryCursor sc;
    First note that "both" with a secondary cursor refers to both secondary key and primary key. The data is not searched on.
    sc.getSearchBoth(E,b,data,null);
    // success only if (E,b) exists?
    Correct.
    sc.getSearchBothRange(E,b,data,null);
    // success if (E,b) exists?
    // success if (E,bb) exists?
    // success if (EE,b) exists?
    // success if (EE,bb) exists?
    No, only the first two would be found. It matches the secondary key exactly, according to the javadoc.
    //assuming cursor is on (E,b,data8), are the following results possible?
    sc.getNext();
    //(E,b,data9)?
    No, because there cannot be two (E, b, ...) records in a single database.
    //(E,bb,data10)?
    //(EE,b,data11)?
    //(EE,bb,data12)?
    Correct.
    sc.getNextDup();
    //(E,b,data9)?
    No, see above.
    //(E,bb,data10)?
    Yes.
    //(EE,b,data11)?
    //(EE,bb,data12)?
    No, since NextDup only returns records with the same secondarykey.
    sc.getNextNoDup();
    //(E,b,data9)?
    No, see above.
    //(E,bb,data10)?
    No, since NexNotDup only returns records with a different secondarykey
    //(EE,b,data11)?
    Yes.
    //(EE,bb,data12)?
    No, secondary key is the same as above.

    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
  • 7. Re: getSearchBothRange, how does bothrange read?
    user8997135 Newbie
    Currently Being Moderated
    Thanks! Now everything is clear.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points