Skip to Main Content

Berkeley DB Family

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Javadoc clarification: SecondaryCursor.dup() fails if not initialized

archie172Feb 24 2009 — edited Feb 24 2009
Problem: the API Javadoc for Cursor.dup() and SecondaryCursor.dup() are basically the same. However, they behave very differently, as shown by the output of the test program below: Cursor.dup(false) succeeds when the cursor is not initialized, while SecondaryCursor.dup(false) throws an exception.

Please fix the Javadoc for SecondaryCursor.dup() to clarify when an exception will be thrown.

Program output:
Testing Cursor.dup(false) on uninitialized cursor: SUCCESS
Testing SecondaryCursor.dup(false) on uninitialized cursor: FAIL: (JE 3.3.75) Cursor Not Initialized.
Test program:
import com.sleepycat.je.*;
import java.io.File;

public class cursortest {
    public static void main(String[] args) throws Exception {

        // Create temp dir
        File dir = new File("/tmp/cursortest");
        if (!dir.mkdir())
            throw new Exception("can't create directory: " + dir);

        // Create environment
        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setAllowCreate(true);
        envConfig.setTransactional(true);
        Environment env = new Environment(dir, envConfig);

        // Open primary db
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        dbConfig.setTransactional(true);
        Database db = env.openDatabase(null, "primary", dbConfig);

        // Open secondary db
        SecondaryConfig sdbConfig = new SecondaryConfig();
        sdbConfig.setAllowCreate(true);
        sdbConfig.setAllowPopulate(true);
        sdbConfig.setTransactional(true);
        sdbConfig.setKeyCreator(new SecondaryKeyCreator() {
            public boolean createSecondaryKey(SecondaryDatabase sdb,
              DatabaseEntry key, DatabaseEntry data, DatabaseEntry result) {
                return false;
            }
        });
        SecondaryDatabase sdb = env.openSecondaryDatabase(null, "secondary", db, sdbConfig);

        // Test primary cursor
        Cursor cursor = db.openCursor(null, new CursorConfig());
        testDup(cursor);
        cursor.close();

        // Test secondary cursor
        cursor = sdb.openSecondaryCursor(null, new CursorConfig());
        testDup(cursor);
        cursor.close();
    }

    public static void testDup(Cursor cursor) throws DatabaseException {
        System.out.print("Testing " + cursor.getClass().getSimpleName() + ".dup(false) on uninitialized cursor: ");
        Cursor dup = null;
        try {
            dup = cursor.dup(false);
            System.out.println("SUCCESS");
        } catch (DatabaseException e) {
            System.out.println("FAIL: " + e.getMessage());
        }
        if (dup != null)
            dup.close();
    }
}
Added better code formatting.
This post has been answered by Greybird-Oracle on Feb 24 2009
Jump to Answer

Comments

archie172
On second thought, this really seems like a functional bug rather than a documentation bug. Why shouldn't SecondaryCursor.dup(false) succeed when the cursor is not initialized?
archie172
Patch to fix.... ?
--- bdb/com/sleepycat/je/SecondaryCursor.java   2008-06-10 10:52:08.000000000 -0500
+++ src/java/com/sleepycat/je/SecondaryCursor.java      2009-02-24 12:11:56.531382458 -0600
@@ -117,7 +117,7 @@
     public Cursor dup(boolean samePosition)
         throws DatabaseException {

-        checkState(true);
+        checkState(false);
         return new SecondaryCursor(this, samePosition);
     }
Edited by: archie172 on Feb 24, 2009 10:53 AM (added better code formatting)
524761
archie172 wrote:

P.S. when is this forum going to add a pre-formatted (fixed-width) text option?
You mean like this?
diff -r 671c95c08dd4 src/com/sleepycat/je/SecondaryCursor.java
--- a/src/com/sleepycat/je/SecondaryCursor.java
+++ b/src/com/sleepycat/je/SecondaryCursor.java
@@ -117,7 +117,7 @@
     public Cursor dup(boolean samePosition)
         throws DatabaseException {
 
-        checkState(true);
+        checkState(false);
         return new SecondaryCursor(this, samePosition);
     }
 
Please see the forum FAQ.
Greybird-Oracle
Answer
Archie,

Yes and yes -- this is a bug and that is the correct fix.

Thanks!! We'll fix this in the next patch release.

--mark
Marked as Answer by archie172 · Sep 27 2020
1 - 4
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 24 2009
Added on Feb 24 2009
4 comments
3,077 views