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

SecondaryDatabase.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: SecondaryDatabase.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.Db;
00013 import com.sleepycat.db.internal.DbConstants;
00014 
00015 public class SecondaryDatabase extends Database {
00016     private final Database primaryDatabase;
00017 
00018     /* package */
00019     SecondaryDatabase(final Db db, final Database primaryDatabase)
00020         throws DatabaseException {
00021 
00022         super(db);
00023         this.primaryDatabase = primaryDatabase;
00024     }
00025 
00026     public SecondaryDatabase(final String fileName,
00027                              final String databaseName,
00028                              final Database primaryDatabase,
00029                              final SecondaryConfig config)
00030         throws DatabaseException, java.io.FileNotFoundException {
00031 
00032         this(SecondaryConfig.checkNull(config).openSecondaryDatabase(
00033                 null, null, fileName, databaseName, primaryDatabase.db),
00034             primaryDatabase);
00035     }
00036 
00037     public Cursor openCursor(final Transaction txn, final CursorConfig config)
00038         throws DatabaseException {
00039 
00040         return openSecondaryCursor(txn, config);
00041     }
00042 
00043     public SecondaryCursor openSecondaryCursor(final Transaction txn,
00044                                                final CursorConfig config)
00045         throws DatabaseException {
00046 
00047         return new SecondaryCursor(this,
00048             CursorConfig.checkNull(config).openCursor(db,
00049                 (txn == null) ? null : txn.txn), config);
00050     }
00051 
00052     public Database getPrimaryDatabase() {
00053         return primaryDatabase;
00054     }
00055 
00056     public DatabaseConfig getConfig()
00057         throws DatabaseException {
00058 
00059         return getSecondaryConfig();
00060     }
00061 
00062     public SecondaryConfig getSecondaryConfig()
00063         throws DatabaseException {
00064 
00065         return new SecondaryConfig(db);
00066     }
00067 
00068     public OperationStatus get(final Transaction txn,
00069                                final DatabaseEntry key,
00070                                final DatabaseEntry pKey,
00071                                final DatabaseEntry data,
00072                                final LockMode lockMode)
00073         throws DatabaseException {
00074 
00075         return OperationStatus.fromInt(
00076             db.pget((txn == null) ? null : txn.txn, key, pKey, data,
00077                 LockMode.getFlag(lockMode) |
00078                 ((data == null) ? 0 : data.getMultiFlag())));
00079     }
00080 
00081     public OperationStatus getSearchBoth(final Transaction txn,
00082                                          final DatabaseEntry key,
00083                                          final DatabaseEntry pKey,
00084                                          final DatabaseEntry data,
00085                                          final LockMode lockMode)
00086         throws DatabaseException {
00087 
00088         return OperationStatus.fromInt(
00089             db.pget((txn == null) ? null : txn.txn, key, pKey, data,
00090                 DbConstants.DB_GET_BOTH | LockMode.getFlag(lockMode) |
00091                 ((data == null) ? 0 : data.getMultiFlag())));
00092     }
00093 
00094     public OperationStatus getSearchRecordNumber(final Transaction txn,
00095                                                  final DatabaseEntry key,
00096                                                  final DatabaseEntry pKey,
00097                                                  final DatabaseEntry data,
00098                                                  final LockMode lockMode)
00099         throws DatabaseException {
00100 
00101         return OperationStatus.fromInt(
00102             db.pget((txn == null) ? null : txn.txn, key, pKey, data,
00103                 DbConstants.DB_SET_RECNO | LockMode.getFlag(lockMode) |
00104                 ((data == null) ? 0 : data.getMultiFlag())));
00105     }
00106 }

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