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

CloudDB
YES

You can directly connect using jdbc thin method without install the oracle client in your local.

SQL Developer's default connection to the database is using the thin JDBC driver.
Defaulting to using the JDBC thin driver means there is no requirement for an Oracle
client install minimizing the configuration and footprint.

http://www.oracle.com/technetwork/developer-tools/sql-developer/what-is-sqldev-093866.html

Edited by: hitgon on Jan 2, 2013 5:36 PM
Reddy G
Thanks for ur replay..

can you tell me what information i need to provide for JDBC...in SQL developer I can see Custom JDBC URL option in Advanced part..
is there doc which will provide the step by step..
Jim Smith
Youdon't need to use the Advanced connection, Basic connection is sufficient.

You just need to provide a host, port number (probably 1521), and a SID or SERVICE. You can get these from the tnsnames file if you have one or from your DBA.
1 - 3
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,080 views