Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

SecondaryCursor.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2002-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: SecondaryCursor.java,v 12.1 2005/06/16 20:23:03 bostic Exp $
00008  */
00009 
00010 package com.sleepycat.db;
00011 
00012 import com.sleepycat.db.internal.DbConstants;
00013 import com.sleepycat.db.internal.Dbc;
00014 
00015 public class SecondaryCursor extends Cursor {
00016     /* package */
00017     SecondaryCursor(final SecondaryDatabase database,
00018                     final Dbc dbc,
00019                     final CursorConfig config)
00020         throws DatabaseException {
00021 
00022         super(database, dbc, config);
00023     }
00024 
00025     public SecondaryDatabase getSecondaryDatabase() {
00026         return (SecondaryDatabase)super.getDatabase();
00027     }
00028 
00029     public Cursor dup(final boolean samePosition)
00030         throws DatabaseException {
00031 
00032         return dupSecondary(samePosition);
00033     }
00034 
00035     public SecondaryCursor dupSecondary(final boolean samePosition)
00036         throws DatabaseException {
00037 
00038         return new SecondaryCursor(getSecondaryDatabase(),
00039             dbc.dup(samePosition ? DbConstants.DB_POSITION : 0), config);
00040     }
00041 
00042     public OperationStatus getCurrent(final DatabaseEntry key,
00043                                       final DatabaseEntry pKey,
00044                                       final DatabaseEntry data,
00045                                       LockMode lockMode)
00046         throws DatabaseException {
00047 
00048         return OperationStatus.fromInt(
00049             dbc.pget(key, pKey, data,
00050                 DbConstants.DB_CURRENT | LockMode.getFlag(lockMode) |
00051                 ((data == null) ? 0 : data.getMultiFlag())));
00052     }
00053 
00054     public OperationStatus getFirst(final DatabaseEntry key,
00055                                     final DatabaseEntry pKey,
00056                                     final DatabaseEntry data,
00057                                     LockMode lockMode)
00058         throws DatabaseException {
00059 
00060         return OperationStatus.fromInt(
00061             dbc.pget(key, pKey, data,
00062                 DbConstants.DB_FIRST | LockMode.getFlag(lockMode) |
00063                 ((data == null) ? 0 : data.getMultiFlag())));
00064     }
00065 
00066     public OperationStatus getLast(final DatabaseEntry key,
00067                                    final DatabaseEntry pKey,
00068                                    final DatabaseEntry data,
00069                                    LockMode lockMode)
00070         throws DatabaseException {
00071 
00072         return OperationStatus.fromInt(
00073             dbc.pget(key, pKey, data,
00074                 DbConstants.DB_LAST | LockMode.getFlag(lockMode) |
00075                 ((data == null) ? 0 : data.getMultiFlag())));
00076     }
00077 
00078     public OperationStatus getNext(final DatabaseEntry key,
00079                                    final DatabaseEntry pKey,
00080                                    final DatabaseEntry data,
00081                                    LockMode lockMode)
00082         throws DatabaseException {
00083 
00084         return OperationStatus.fromInt(
00085             dbc.pget(key, pKey, data,
00086                 DbConstants.DB_NEXT | LockMode.getFlag(lockMode) |
00087                 ((data == null) ? 0 : data.getMultiFlag())));
00088     }
00089 
00090     public OperationStatus getNextDup(final DatabaseEntry key,
00091                                       final DatabaseEntry pKey,
00092                                       final DatabaseEntry data,
00093                                       LockMode lockMode)
00094         throws DatabaseException {
00095 
00096        return OperationStatus.fromInt(
00097             dbc.pget(key, pKey, data,
00098                 DbConstants.DB_NEXT_DUP | LockMode.getFlag(lockMode) |
00099                 ((data == null) ? 0 : data.getMultiFlag())));
00100     }
00101 
00102     public OperationStatus getNextNoDup(final DatabaseEntry key,
00103                                         final DatabaseEntry pKey,
00104                                         final DatabaseEntry data,
00105                                         LockMode lockMode)
00106         throws DatabaseException {
00107 
00108         return OperationStatus.fromInt(
00109             dbc.pget(key, pKey, data,
00110                 DbConstants.DB_NEXT_NODUP | LockMode.getFlag(lockMode) |
00111                 ((data == null) ? 0 : data.getMultiFlag())));
00112     }
00113 
00114     public OperationStatus getPrev(final DatabaseEntry key,
00115                                    final DatabaseEntry pKey,
00116                                    final DatabaseEntry data,
00117                                    LockMode lockMode)
00118         throws DatabaseException {
00119 
00120         return OperationStatus.fromInt(
00121             dbc.pget(key, pKey, data,
00122                 DbConstants.DB_PREV | LockMode.getFlag(lockMode) |
00123                 ((data == null) ? 0 : data.getMultiFlag())));
00124     }
00125 
00126     public OperationStatus getPrevDup(final DatabaseEntry key,
00127                                       final DatabaseEntry pKey,
00128                                       final DatabaseEntry data,
00129                                       LockMode lockMode)
00130         throws DatabaseException {
00131 
00132         /*
00133          * "Get the previous duplicate" isn't directly supported by the C API,
00134          * so here's how to get it: dup the cursor and call getPrev, then dup
00135          * the result and call getNextDup.  If both succeed then there was a
00136          * previous duplicate and the first dup is sitting on it.  Keep that,
00137          * and call getCurrent to fill in the user's buffers.
00138          */
00139         Dbc dup1 = dbc.dup(DbConstants.DB_POSITION);
00140         try {
00141             int errCode = dup1.get(DatabaseEntry.IGNORE, DatabaseEntry.IGNORE,
00142                 DbConstants.DB_PREV | LockMode.getFlag(lockMode));
00143             if (errCode == 0) {
00144                 Dbc dup2 = dup1.dup(DbConstants.DB_POSITION);
00145                 try {
00146                     errCode = dup2.get(DatabaseEntry.IGNORE,
00147                         DatabaseEntry.IGNORE,
00148                         DbConstants.DB_NEXT_DUP | LockMode.getFlag(lockMode));
00149                 } finally {
00150                     dup2.close();
00151                 }
00152             }
00153             if (errCode == 0)
00154                 errCode = dup1.pget(key, pKey, data,
00155                     DbConstants.DB_CURRENT | LockMode.getFlag(lockMode) |
00156                     ((data == null) ? 0 : data.getMultiFlag()));
00157             if (errCode == 0) {
00158                 Dbc tdbc = dbc;
00159                 dbc = dup1;
00160                 dup1 = tdbc;
00161             }
00162             return OperationStatus.fromInt(errCode);
00163         } finally {
00164             dup1.close();
00165         }
00166     }
00167 
00168     public OperationStatus getPrevNoDup(final DatabaseEntry key,
00169                                         final DatabaseEntry pKey,
00170                                         final DatabaseEntry data,
00171                                         LockMode lockMode)
00172         throws DatabaseException {
00173 
00174         return OperationStatus.fromInt(
00175             dbc.pget(key, pKey, data,
00176                 DbConstants.DB_PREV_NODUP | LockMode.getFlag(lockMode) |
00177                 ((data == null) ? 0 : data.getMultiFlag())));
00178     }
00179 
00180     public OperationStatus getRecordNumber(final DatabaseEntry secondaryRecno,
00181                                            final DatabaseEntry primaryRecno,
00182                                            LockMode lockMode)
00183         throws DatabaseException {
00184 
00185         return OperationStatus.fromInt(
00186             dbc.pget(DatabaseEntry.IGNORE, secondaryRecno, primaryRecno,
00187                 DbConstants.DB_GET_RECNO | LockMode.getFlag(lockMode)));
00188     }
00189 
00190     public OperationStatus getSearchKey(final DatabaseEntry key,
00191                                         final DatabaseEntry pKey,
00192                                         final DatabaseEntry data,
00193                                         LockMode lockMode)
00194         throws DatabaseException {
00195 
00196         return OperationStatus.fromInt(
00197             dbc.pget(key, pKey, data,
00198                 DbConstants.DB_SET | LockMode.getFlag(lockMode) |
00199                 ((data == null) ? 0 : data.getMultiFlag())));
00200     }
00201 
00202     public OperationStatus getSearchKeyRange(final DatabaseEntry key,
00203                                              final DatabaseEntry pKey,
00204                                              final DatabaseEntry data,
00205                                              LockMode lockMode)
00206         throws DatabaseException {
00207 
00208         return OperationStatus.fromInt(
00209             dbc.pget(key, pKey, data,
00210                 DbConstants.DB_SET_RANGE | LockMode.getFlag(lockMode) |
00211                 ((data == null) ? 0 : data.getMultiFlag())));
00212     }
00213 
00214     public OperationStatus getSearchBoth(final DatabaseEntry key,
00215                                          final DatabaseEntry pKey,
00216                                          final DatabaseEntry data,
00217                                          LockMode lockMode)
00218         throws DatabaseException {
00219 
00220         return OperationStatus.fromInt(
00221             dbc.pget(key, pKey, data,
00222                 DbConstants.DB_GET_BOTH | LockMode.getFlag(lockMode) |
00223                 ((data == null) ? 0 : data.getMultiFlag())));
00224     }
00225 
00226     public OperationStatus getSearchBothRange(final DatabaseEntry key,
00227                                               final DatabaseEntry pKey,
00228                                               final DatabaseEntry data,
00229                                               LockMode lockMode)
00230         throws DatabaseException {
00231 
00232         return OperationStatus.fromInt(
00233             dbc.pget(key, pKey, data,
00234                 DbConstants.DB_GET_BOTH_RANGE | LockMode.getFlag(lockMode) |
00235                 ((data == null) ? 0 : data.getMultiFlag())));
00236     }
00237 
00238     public OperationStatus getSearchRecordNumber(
00239             final DatabaseEntry secondaryRecno,
00240             final DatabaseEntry pKey,
00241             final DatabaseEntry data,
00242             LockMode lockMode)
00243         throws DatabaseException {
00244 
00245         return OperationStatus.fromInt(
00246             dbc.pget(secondaryRecno, pKey, data,
00247                 DbConstants.DB_SET_RECNO | LockMode.getFlag(lockMode) |
00248                 ((data == null) ? 0 : data.getMultiFlag())));
00249     }
00250 }

Generated on Sun Dec 25 12:14:33 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2