Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*-
    * See the file LICENSE for redistribution information.
    *
    * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
    *
    */
   
   package com.sleepycat.je;
   
  import java.util.Arrays;
  import java.util.HashSet;
  import java.util.Set;
  
A database cursor for a secondary database. Cursors are not thread safe and the application is responsible for coordinating any multithreaded access to a single cursor object.

Secondary cursors are returned by SecondaryDatabase.openCursor and SecondaryDatabase.openSecondaryCursor(com.sleepycat.je.Transaction,com.sleepycat.je.CursorConfig). The distinguishing characteristics of a secondary cursor are:

  • Direct calls to put() methods on a secondary cursor are prohibited.
  • The delete() method of a secondary cursor will delete the primary record and as well as all its associated secondary records.
  • Calls to all get methods will return the data from the associated primary database.
  • Additional get method signatures are provided to return the primary key in an additional pKey parameter.
  • Calls to dup(boolean) will return a SecondaryCursor.

To obtain a secondary cursor with default attributes:

     SecondaryCursor cursor = myDb.openSecondaryCursor(txn, null);
 

To customize the attributes of a cursor, use a CursorConfig object.

     CursorConfig config = new CursorConfig();
     config.setReadUncommitted(true);
     SecondaryCursor cursor = myDb.openSecondaryCursor(txn, config);
 
  
  public class SecondaryCursor extends Cursor {
  
      private final SecondaryDatabase secondaryDb;
      private final Database primaryDb;

    
Cursor constructor. Not public. To get a cursor, the user should call SecondaryDatabase.cursor();
  
      SecondaryCursor(final SecondaryDatabase dbHandle,
                      final Transaction txn,
                      final CursorConfig cursorConfig)
          throws DatabaseException {
  
          super(dbHandletxncursorConfig);
           = dbHandle;
           = dbHandle.getPrimaryDatabase();
      }

    
Cursor constructor. Not public. To get a cursor, the user should call SecondaryDatabase.cursor();
  
      SecondaryCursor(final SecondaryDatabase dbHandle,
                      final Locker locker,
                      final CursorConfig cursorConfig)
          throws DatabaseException {
  
          super(dbHandlelockercursorConfig);
           = dbHandle;
           = dbHandle.getPrimaryDatabase();
      }

    
Copy constructor.
  
      private SecondaryCursor(final SecondaryCursor cursor,
                              final boolean samePosition)
          throws DatabaseException {
 
         super(cursorsamePosition);
          = cursor.secondaryDb;
          = cursor.primaryDb;
     }

    
Returns the primary Database associated with this cursor.

Calling this method is the equivalent of the following expression:

         ((SecondaryDatabase) this.getDatabase()).getPrimaryDatabase()
 

Returns:
The primary Database associated with this cursor.
 
     public Database getPrimaryDatabase() {
         return ;
     }

    
Returns a new SecondaryCursor for the same transaction as the original cursor.
 
     @Override
     public SecondaryCursor dup(final boolean samePosition)
         throws DatabaseException {
 
         checkState(false);
         return new SecondaryCursor(thissamePosition);
     }

    
Returns a new copy of the cursor as a SecondaryCursor.

Calling this method is the equivalent of calling dup(boolean) and casting the result to SecondaryCursor.

Deprecated:
As of JE 4.0.13, replaced by Cursor.dup(boolean).
See also:
dup(boolean)
 
     public SecondaryCursor dupSecondary(final boolean samePosition)
         throws DatabaseException {
 
         return (SecondaryCursordup(samePosition);
     }

    
Delete the key/data pair to which the cursor refers from the primary database and all secondary indices.

This method behaves as if Database.delete(com.sleepycat.je.Transaction,com.sleepycat.je.DatabaseEntry) were called for the primary database, using the primary key obtained via the secondary key parameter.

The cursor position is unchanged after a delete, and subsequent calls to cursor functions expecting the cursor to refer to an existing key will fail.
 
     @Override
     public OperationStatus delete()
         throws LockConflictException,
                DatabaseException,
                UnsupportedOperationException,
                IllegalStateException {
 
         checkState(true);
         checkUpdatesAllowed("delete");
         trace(."SecondaryCursor.delete: "null);
 
         /* Read the primary key (the data of a secondary). */
         DatabaseEntry key = new DatabaseEntry();
         DatabaseEntry pKey = new DatabaseEntry();
         OperationStatus status = getCurrentInternal(keypKey,
                                                     .);
 
         /* Delete the primary and all secondaries (including this one). */
         if (status == .) {
             Locker locker = .getLocker();
             status =
                 .deleteInternal(lockerpKeynull);
             if (status != .) {
                 SecondaryDatabase secDb = (SecondaryDatabasegetDatabase();
                 throw secDb.secondaryRefersToMissingPrimaryKey
                     (lockerkeypKey);
             }
         }
         return status;
     }

    
This operation is not allowed on a secondary database. java.lang.UnsupportedOperationException will always be thrown by this method. The corresponding method on the primary database should be used instead.
 
     @Override
     public OperationStatus put(final DatabaseEntry key,
                                final DatabaseEntry data) {
         throw SecondaryDatabase.notAllowedException();
     }

    
This operation is not allowed on a secondary database. java.lang.UnsupportedOperationException will always be thrown by this method. The corresponding method on the primary database should be used instead.
 
     @Override
     public OperationStatus putNoOverwrite(final DatabaseEntry key,
                                           final DatabaseEntry data) {
         throw SecondaryDatabase.notAllowedException();
     }

    
This operation is not allowed on a secondary database. java.lang.UnsupportedOperationException will always be thrown by this method. The corresponding method on the primary database should be used instead.
 
     @Override
     public OperationStatus putNoDupData(final DatabaseEntry key,
                                         final DatabaseEntry data) {
         throw SecondaryDatabase.notAllowedException();
     }

    
This operation is not allowed on a secondary database. java.lang.UnsupportedOperationException will always be thrown by this method. The corresponding method on the primary database should be used instead.
 
     @Override
     public OperationStatus putCurrent(final DatabaseEntry data) {
         throw SecondaryDatabase.notAllowedException();
     }

    

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
 
     @Override
     public OperationStatus getCurrent(final DatabaseEntry key,
                                       final DatabaseEntry data,
                                       final LockMode lockMode)
         throws DatabaseException {
 
         return getCurrent(keynew DatabaseEntry(), datalockMode);
     }

    
Returns the key/data pair to which the cursor refers.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.KEYEMPTY if the key/pair at the cursor position has been deleted; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the cursor is uninitialized (not positioned on a record), or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
 
     public OperationStatus getCurrent(final DatabaseEntry key,
                                       final DatabaseEntry pKey,
                                       final DatabaseEntry data,
                                       final LockMode lockMode)
         throws DatabaseException {
 
         checkState(true);
         checkArgsNoValRequired(keypKeydata);
         trace(."SecondaryCursor.getCurrent: "lockMode);
 
         return getCurrentInternal(keypKeydatalockMode);
     }

    

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
 
     @Override
     public OperationStatus getFirst(final DatabaseEntry key,
                                     final DatabaseEntry data,
                                     final LockMode lockMode)
         throws DatabaseException {
 
         return getFirst(keynew DatabaseEntry(), datalockMode);
     }

    
Move the cursor to the first key/data pair of the database, and return that pair. If the first key has duplicate values, the first data item in the set of duplicates is returned.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
pKey the primary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.NOTFOUND if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
 
     public OperationStatus getFirst(final DatabaseEntry key,
                                     final DatabaseEntry pKey,
                                     final DatabaseEntry data,
                                     final LockMode lockMode)
         throws DatabaseException {
 
         checkState(false);
         checkArgsNoValRequired(keypKeydata);
         trace(."SecondaryCursor.getFirst: "lockMode);
 
         return position(keypKeydatalockModetrue);
     }

    

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
 
     @Override
     public OperationStatus getLast(final DatabaseEntry key,
                                    final DatabaseEntry data,
                                    final LockMode lockMode)
         throws DatabaseException {
 
         return getLast(keynew DatabaseEntry(), datalockMode);
     }

    
Move the cursor to the last key/data pair of the database, and return that pair. If the last key has duplicate values, the last data item in the set of duplicates is returned.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
pKey the primary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.NOTFOUND if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
 
     public OperationStatus getLast(final DatabaseEntry key,
                                    final DatabaseEntry pKey,
                                    final DatabaseEntry data,
                                    final LockMode lockMode)
         throws DatabaseException {
 
         checkState(false);
         checkArgsNoValRequired(keypKeydata);
         trace(."SecondaryCursor.getLast: "lockMode);
 
         return position(keypKeydatalockModefalse);
     }

    

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
 
     @Override
     public OperationStatus getNext(final DatabaseEntry key,
                                    final DatabaseEntry data,
                                    final LockMode lockMode)
         throws DatabaseException {
 
         return getNext(keynew DatabaseEntry(), datalockMode);
     }

    
Move the cursor to the next key/data pair and return that pair. If the matching key has duplicate values, the first data item in the set of duplicates is returned.

If the cursor is not yet initialized, move the cursor to the first key/data pair of the database, and return that pair. Otherwise, the cursor is moved to the next key/data pair of the database, and that pair is returned. In the presence of duplicate key values, the value of the key may not change.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
pKey the primary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.NOTFOUND if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
 
     public OperationStatus getNext(final DatabaseEntry key,
                                    final DatabaseEntry pKey,
                                    final DatabaseEntry data,
                                    final LockMode lockMode)
         throws DatabaseException {
 
         checkState(false);
         checkArgsNoValRequired(keypKeydata);
         trace(."SecondaryCursor.getNext: "lockMode);
 
         if (.isNotInitialized()) {
             return position(keypKeydatalockModetrue);
         } else {
             return retrieveNext(keypKeydatalockMode.);
         }
     }

    

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
 
     @Override
     public OperationStatus getNextDup(final DatabaseEntry key,
                                       final DatabaseEntry data,
                                       final LockMode lockMode)
         throws DatabaseException {
 
         return getNextDup(keynew DatabaseEntry(), datalockMode);
     }

    
If the next key/data pair of the database is a duplicate data record for the current key/data pair, move the cursor to the next key/data pair of the database and return that pair.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
pKey the primary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.NOTFOUND if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the cursor is uninitialized (not positioned on a record), or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
 
     public OperationStatus getNextDup(final DatabaseEntry key,
                                       final DatabaseEntry pKey,
                                       final DatabaseEntry data,
                                       final LockMode lockMode)
         throws DatabaseException {
 
         checkState(true);
         checkArgsNoValRequired(keypKeydata);
         trace(."SecondaryCursor.getNextDup: "lockMode);
 
         return retrieveNext(keypKeydatalockMode.);
     }

    

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
 
     @Override
     public OperationStatus getNextNoDup(final DatabaseEntry key,
                                         final DatabaseEntry data,
                                         final LockMode lockMode)
         throws DatabaseException {
 
         return getNextNoDup(keynew DatabaseEntry(), datalockMode);
     }

    
Move the cursor to the next non-duplicate key/data pair and return that pair. If the matching key has duplicate values, the first data item in the set of duplicates is returned.

If the cursor is not yet initialized, move the cursor to the first key/data pair of the database, and return that pair. Otherwise, the cursor is moved to the next non-duplicate key of the database, and that key/data pair is returned.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
pKey the primary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.NOTFOUND if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
 
     public OperationStatus getNextNoDup(final DatabaseEntry key,
                                         final DatabaseEntry pKey,
                                         final DatabaseEntry data,
                                         final LockMode lockMode)
         throws DatabaseException {
 
         checkState(false);
         checkArgsNoValRequired(keypKeydata);
         trace(."SecondaryCursor.getNextNoDup: "nullnull,
               lockMode);
 
         if (.isNotInitialized()) {
             return position(keypKeydatalockModetrue);
         } else {
             return retrieveNext(keypKeydatalockMode,
                                 .);
         }
     }

    

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
 
     @Override
     public OperationStatus getPrev(final DatabaseEntry key,
                                    final DatabaseEntry data,
                                    final LockMode lockMode)
         throws DatabaseException {
 
         return getPrev(keynew DatabaseEntry(), datalockMode);
     }

    
Move the cursor to the previous key/data pair and return that pair. If the matching key has duplicate values, the last data item in the set of duplicates is returned.

If the cursor is not yet initialized, move the cursor to the last key/data pair of the database, and return that pair. Otherwise, the cursor is moved to the previous key/data pair of the database, and that pair is returned. In the presence of duplicate key values, the value of the key may not change.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
pKey the primary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.NOTFOUND if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
 
     public OperationStatus getPrev(final DatabaseEntry key,
                                    final DatabaseEntry pKey,
                                    final DatabaseEntry data,
                                    final LockMode lockMode)
         throws DatabaseException {
 
         checkState(false);
         checkArgsNoValRequired(keypKeydata);
         trace(."SecondaryCursor.getPrev: "lockMode);
 
         if (.isNotInitialized()) {
             return position(keypKeydatalockModefalse);
         } else {
             return retrieveNext(keypKeydatalockMode.);
         }
     }

    

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
 
     @Override
     public OperationStatus getPrevDup(final DatabaseEntry key,
                                       final DatabaseEntry data,
                                       final LockMode lockMode)
         throws DatabaseException {
 
         return getPrevDup(keynew DatabaseEntry(), datalockMode);
     }

    
If the previous key/data pair of the database is a duplicate data record for the current key/data pair, move the cursor to the previous key/data pair of the database and return that pair.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
pKey the primary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.NOTFOUND if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the cursor is uninitialized (not positioned on a record), or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
 
     public OperationStatus getPrevDup(final DatabaseEntry key,
                                       final DatabaseEntry pKey,
                                       final DatabaseEntry data,
                                       final LockMode lockMode)
         throws DatabaseException {
 
         checkState(true);
         checkArgsNoValRequired(keypKeydata);
         trace(."SecondaryCursor.getPrevDup: "lockMode);
 
         return retrieveNext(keypKeydatalockMode.);
     }

    

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
 
     @Override
     public OperationStatus getPrevNoDup(final DatabaseEntry key,
                                         final DatabaseEntry data,
                                         final LockMode lockMode)
         throws DatabaseException {
 
         return getPrevNoDup(keynew DatabaseEntry(), datalockMode);
     }

    
Move the cursor to the previous non-duplicate key/data pair and return that pair. If the matching key has duplicate values, the last data item in the set of duplicates is returned.

If the cursor is not yet initialized, move the cursor to the last key/data pair of the database, and return that pair. Otherwise, the cursor is moved to the previous non-duplicate key of the database, and that key/data pair is returned.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key returned as output. Its byte array does not need to be initialized by the caller.
pKey the primary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.NOTFOUND if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
 
     public OperationStatus getPrevNoDup(final DatabaseEntry key,
                                         final DatabaseEntry pKey,
                                         final DatabaseEntry data,
                                         final LockMode lockMode)
         throws DatabaseException {
 
         checkState(false);
         checkArgsNoValRequired(keypKeydata);
         trace(."SecondaryCursor.getPrevNoDup: "lockMode);
 
         if (.isNotInitialized()) {
             return position(keypKeydatalockModefalse);
         } else {
             return retrieveNext(keypKeydatalockMode,
                                .);
        }
    }

    

Parameters:
key the secondary key used as input. It must be initialized with a non-null byte array by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
    @Override
    public OperationStatus getSearchKey(final DatabaseEntry key,
                                        final DatabaseEntry data,
                                        final LockMode lockMode)
        throws DatabaseException {
        return getSearchKey(keynew DatabaseEntry(), datalockMode);
    }

    
Move the cursor to the given key of the database, and return the datum associated with the given key. If the matching key has duplicate values, the first data item in the set of duplicates is returned.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key used as input. It must be initialized with a non-null byte array by the caller.
pKey the primary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.NOTFOUND if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
    public OperationStatus getSearchKey(final DatabaseEntry key,
                                        final DatabaseEntry pKey,
                                        final DatabaseEntry data,
                                        final LockMode lockMode)
        throws DatabaseException {
        checkState(false);
        DatabaseUtil.checkForNullDbt(key"key"true);
        DatabaseUtil.checkForNullDbt(pKey"pKey"false);
        DatabaseUtil.checkForNullDbt(data"data"false);
        trace(."SecondaryCursor.getSearchKey: "keynull,
              lockMode);
        return search(keypKeydatalockMode.);
    }

    

Parameters:
key the secondary key used as input and returned as output. It must be initialized with a non-null byte array by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
    @Override
                                             final DatabaseEntry data,
                                             final LockMode lockMode)
        throws DatabaseException {
        return getSearchKeyRange(keynew DatabaseEntry(), datalockMode);
    }

    
Move the cursor to the closest matching key of the database, and return the data item associated with the matching key. If the matching key has duplicate values, the first data item in the set of duplicates is returned.

The returned key/data pair is for the smallest key greater than or equal to the specified key (as determined by the key comparison function), permitting partial key matches and range searches.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key used as input and returned as output. It must be initialized with a non-null byte array by the caller.
pKey the primary key returned as output. Its byte array does not need to be initialized by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller. A partial data item may be specified to optimize for key only or partial data retrieval.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.NOTFOUND if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
                                             final DatabaseEntry pKey,
                                             final DatabaseEntry data,
                                             final LockMode lockMode)
        throws DatabaseException {
        checkState(false);
        DatabaseUtil.checkForNullDbt(key"key"true);
        DatabaseUtil.checkForNullDbt(pKey"pKey"false);
        DatabaseUtil.checkForNullDbt(data"data"false);
        trace(."SecondaryCursor.getSearchKeyRange: "keydata,
              lockMode);
        return search(keypKeydatalockMode.);
    }

    
This operation is not allowed with this method signature. java.lang.UnsupportedOperationException will always be thrown by this method. The corresponding method with the pKey parameter should be used instead.
    @Override
    public OperationStatus getSearchBoth(final DatabaseEntry key,
                                         final DatabaseEntry data,
                                         final LockMode lockMode) {
        throw SecondaryDatabase.notAllowedException();
    }

    
Move the cursor to the specified secondary and primary key, where both the primary and secondary key items must match.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key used as input. It must be initialized with a non-null byte array by the caller.
pKey the primary key used as input. It must be initialized with a non-null byte array by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.NOTFOUND if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
    public OperationStatus getSearchBoth(final DatabaseEntry key,
                                         final DatabaseEntry pKey,
                                         final DatabaseEntry data,
                                         final LockMode lockMode)
        throws DatabaseException {
        checkState(false);
        DatabaseUtil.checkForNullDbt(key"key"true);
        DatabaseUtil.checkForNullDbt(pKey"pKey"true);
        DatabaseUtil.checkForNullDbt(data"data"false);
        trace(."SecondaryCursor.getSearchBoth: "keydata,
              lockMode);
        return search(keypKeydatalockMode.);
    }

    
This operation is not allowed with this method signature. java.lang.UnsupportedOperationException will always be thrown by this method. The corresponding method with the pKey parameter should be used instead.
    @Override
                                              final DatabaseEntry data,
                                              final LockMode lockMode) {
        throw SecondaryDatabase.notAllowedException();
    }

    
Move the cursor to the specified secondary key and closest matching primary key of the database.

In the case of any database supporting sorted duplicate sets, the returned key/data pair is for the smallest primary key greater than or equal to the specified primary key (as determined by the key comparison function), permitting partial matches and range searches in duplicate data sets.

If this method fails for any reason, the position of the cursor will be unchanged.

In a replicated environment, an explicit transaction must have been specified when opening the cursor, unless read-uncommitted isolation is specified via the CursorConfig or LockMode parameter.

Parameters:
key the secondary key used as input and returned as output. It must be initialized with a non-null byte array by the caller.
pKey the primary key used as input and returned as output. It must be initialized with a non-null byte array by the caller.
data the primary data returned as output. Its byte array does not need to be initialized by the caller.
lockMode the locking attributes; if null, default attributes are used. LockMode.READ_COMMITTED is not allowed.
Returns:
OperationStatus.NOTFOUND if no matching key/data pair is found; otherwise, OperationStatus.SUCCESS.
Throws:
OperationFailureException if one of the Read Operation Failures occurs.
EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.IllegalStateException if the cursor or database has been closed, or the non-transactional cursor was created in a different thread.
java.lang.IllegalArgumentException if an invalid parameter is specified, for example, if a DatabaseEntry parameter is null or does not contain a required non-null byte array.
                                              final DatabaseEntry pKey,
                                              final DatabaseEntry data,
                                              final LockMode lockMode)
        throws DatabaseException {
        checkState(false);
        DatabaseUtil.checkForNullDbt(key"key"true);
        DatabaseUtil.checkForNullDbt(pKey"pKey"true);
        DatabaseUtil.checkForNullDbt(data"data"false);
        trace(."SecondaryCursor.getSearchBothRange: "keydata,
              lockMode);
        return search(keypKeydatalockMode.);
    }

    
Returns the current key and data.
                                               final DatabaseEntry pKey,
                                               final DatabaseEntry data,
                                               final LockMode lockMode)
        throws DatabaseException {
        OperationStatus status = getCurrentInternal(keypKeylockMode);
        if (status == .) {
            /*
             * May return KEYEMPTY if read-uncommitted and the primary was
             * deleted.
             */
            status = readPrimaryAfterGet(keypKeydatalockMode, 0);
        }
        return status;
    }

    
Calls search() and retrieves primary data.
                           final DatabaseEntry pKey,
                           final DatabaseEntry data,
                           final LockMode lockMode,
                           final SearchMode searchMode)
        throws DatabaseException {
        /*
         * Perform retries to account for primary updates during a
         * read-uncommitted.
         */
        int retries = 0;
        byte[] lastKey = null;
        while (true) {
            OperationStatus status = search(keypKeylockModesearchMode);
            if (status != .) {
                return status;
            }
            if (!Arrays.equals(lastKeykey.getData())) {
                retries = 0;
                lastKey = key.getData();
            }
            status = readPrimaryAfterGet(keypKeydatalockModeretries);
            if (status == .) {
                return status;
            }
            retries += 1;
            try {
                Thread.sleep();
            } catch (InterruptedException e) {
            }
        }
    }

    
Calls position() and retrieves primary data.
                             final DatabaseEntry pKey,
                             final DatabaseEntry data,
                             final LockMode lockMode,
                             final boolean first)
        throws DatabaseException {
        /*
         * Perform retries to account for primary updates during a
         * read-uncommitted.
         */
        int retries = 0;
        byte[] lastKey = null;
        while (true) {
            OperationStatus status = position(keypKeylockModefirst);
            if (status != .) {
                return status;
            }
            if (!Arrays.equals(lastKeykey.getData())) {
                retries = 0;
                lastKey = key.getData();
            }
            status = readPrimaryAfterGet(keypKeydatalockModeretries);
            if (status == .) {
                return status;
            }
            retries += 1;
            try {
                Thread.sleep();
            } catch (InterruptedException e) {
            }
        }
    }

    
Calls retrieveNext() and retrieves primary data.
                                 final DatabaseEntry pKey,
                                 final DatabaseEntry data,
                                 final LockMode lockMode,
                                 final GetMode getMode)
        throws DatabaseException {
        /*
         * Perform retries to account for primary updates during a
         * read-uncommitted.
         */
        int retries = 0;
        byte[] lastKey = null;
        while (true) {
            OperationStatus status = retrieveNext(keypKeylockMode,
                                                  getMode);
            if (status != .) {
                return status;
            }
            if (!Arrays.equals(lastKeykey.getData())) {
                retries = 0;
                lastKey = key.getData();
            }
            status = readPrimaryAfterGet(keypKeydatalockModeretries);
            if (status == .) {
                return status;
            }
            retries += 1;
            try {
                Thread.sleep();
            } catch (InterruptedException e) {
            }
        }
    }

    
                                                final DatabaseEntry pKey,
                                                final DatabaseEntry data,
                                                final LockMode lockMode,
                                                final int retries)
        throws DatabaseException {
        return readPrimaryAfterGet(keypKeydatalockMode,
                                   retries);
    }

    
    @Override
    boolean checkForPrimaryUpdate(final DatabaseEntry key,
                                  final DatabaseEntry pKey,
                                  final DatabaseEntry data,
                                  final int retries) {
        final SecondaryConfig conf = .getPrivateSecondaryConfig();
        boolean possibleIntegrityError = false;
        /*
         * If the secondary key is immutable, or the key creators are
         * null (the database is read only), then we can skip this
         * check.
         */
        if (conf.getImmutableSecondaryKey()) {
            /* Do nothing. */
        } else if (conf.getKeyCreator() != null) {
            /*
             * Check that the key we're using is equal to the key
             * returned by the key creator.
             */
            final DatabaseEntry secKey = new DatabaseEntry();
            if (!conf.getKeyCreator().createSecondaryKey
                    (pKeydatasecKey) ||
                !secKey.equals(key)) {
                possibleIntegrityError = true;
            }
        } else if (conf.getMultiKeyCreator() != null) {
            /*
             * Check that the key we're using is in the set returned by
             * the key creator.
             */
            final Set<DatabaseEntryresults = new HashSet<DatabaseEntry>();
            conf.getMultiKeyCreator().createSecondaryKeys
                (pKeydataresults);
            if (!results.contains(key)) {
                possibleIntegrityError = true;
            }
        }
        return possibleIntegrityError;
    }

    
Note that this flavor of checkArgs doesn't require that the dbt data is set.
    private void checkArgsNoValRequired(final DatabaseEntry key,
                                        final DatabaseEntry pKey,
                                        final DatabaseEntry data) {
        DatabaseUtil.checkForNullDbt(key"key"false);
        DatabaseUtil.checkForNullDbt(pKey"pKey"false);
        DatabaseUtil.checkForNullDbt(data"data"false);
    }
New to GrepCode? Check out our FAQ X