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

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,076 views