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

DbCompat.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2000-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: DbCompat.java,v 12.5 2005/08/01 20:25:20 mark Exp $
00008  */
00009 
00010 package com.sleepycat.compat;
00011 
00012 import java.io.FileNotFoundException;
00013 import java.util.Comparator;
00014 
00015 import com.sleepycat.db.Cursor;
00016 import com.sleepycat.db.CursorConfig;
00017 import com.sleepycat.db.Database;
00018 import com.sleepycat.db.DatabaseConfig;
00019 import com.sleepycat.db.DatabaseEntry;
00020 import com.sleepycat.db.DatabaseException;
00021 import com.sleepycat.db.DatabaseType;
00022 import com.sleepycat.db.Environment;
00023 import com.sleepycat.db.EnvironmentConfig;
00024 import com.sleepycat.db.LockDetectMode;
00025 import com.sleepycat.db.LockMode;
00026 import com.sleepycat.db.OperationStatus;
00027 import com.sleepycat.db.SecondaryConfig;
00028 import com.sleepycat.db.SecondaryCursor;
00029 import com.sleepycat.db.SecondaryDatabase;
00030 import com.sleepycat.db.Transaction;
00031 import com.sleepycat.db.TransactionConfig;
00032 
00038 public class DbCompat {
00039 
00040     /* Capabilities */
00041 
00042     public static final boolean CDB = true;
00043     public static final boolean JOIN = true;
00044     public static final boolean NESTED_TRANSACTIONS = true;
00045     public static final boolean INSERTION_ORDERED_DUPLICATES = true;
00046     public static final boolean SEPARATE_DATABASE_FILES = true;
00047     public static final boolean MEMORY_SUBSYSTEM = true;
00048     public static final boolean LOCK_SUBSYSTEM = true;
00049     public static final boolean HASH_METHOD = true;
00050     public static final boolean RECNO_METHOD = true;
00051     public static final boolean QUEUE_METHOD = true;
00052     public static final boolean BTREE_RECNUM_METHOD = true;
00053     public static final boolean OPTIONAL_READ_UNCOMMITTED = true;
00054     public static final boolean SECONDARIES = true;
00055 
00056     /* Methods used by the collections package. */
00057 
00058     public static boolean getInitializeLocking(EnvironmentConfig config) {
00059         return config.getInitializeLocking();
00060     }
00061 
00062     public static boolean getInitializeCDB(EnvironmentConfig config) {
00063         return config.getInitializeCDB();
00064     }
00065 
00066     public static boolean isTypeBtree(DatabaseConfig dbConfig) {
00067         return dbConfig.getType() == DatabaseType.BTREE;
00068     }
00069 
00070     public static boolean isTypeHash(DatabaseConfig dbConfig) {
00071         return dbConfig.getType() == DatabaseType.HASH;
00072     }
00073 
00074     public static boolean isTypeQueue(DatabaseConfig dbConfig) {
00075         return dbConfig.getType() == DatabaseType.QUEUE;
00076     }
00077 
00078     public static boolean isTypeRecno(DatabaseConfig dbConfig) {
00079         return dbConfig.getType() == DatabaseType.RECNO;
00080     }
00081 
00082     public static boolean getBtreeRecordNumbers(DatabaseConfig dbConfig) {
00083         return dbConfig.getBtreeRecordNumbers();
00084     }
00085 
00086     public static boolean getReadUncommitted(DatabaseConfig dbConfig) {
00087         return dbConfig.getReadUncommitted();
00088     }
00089 
00090     public static boolean getRenumbering(DatabaseConfig dbConfig) {
00091         return dbConfig.getRenumbering();
00092     }
00093 
00094     public static boolean getSortedDuplicates(DatabaseConfig dbConfig) {
00095         return dbConfig.getSortedDuplicates();
00096     }
00097 
00098     public static boolean getUnsortedDuplicates(DatabaseConfig dbConfig) {
00099         return dbConfig.getUnsortedDuplicates();
00100     }
00101 
00102     // XXX Remove this when DB and JE support CursorConfig.cloneConfig
00103     public static CursorConfig cloneCursorConfig(CursorConfig config) {
00104         CursorConfig newConfig = new CursorConfig();
00105         newConfig.setReadCommitted(config.getReadCommitted());
00106         newConfig.setReadUncommitted(config.getReadUncommitted());
00107         newConfig.setWriteCursor(config.getWriteCursor());
00108         return newConfig;
00109     }
00110 
00111     public static boolean getWriteCursor(CursorConfig config) {
00112         return config.getWriteCursor();
00113     }
00114 
00115     public static void setWriteCursor(CursorConfig config, boolean val) {
00116         config.setWriteCursor(val);
00117     }
00118 
00119     public static void setRecordNumber(DatabaseEntry entry, int recNum) {
00120         entry.setRecordNumber(recNum);
00121     }
00122 
00123     public static int getRecordNumber(DatabaseEntry entry) {
00124         return entry.getRecordNumber();
00125     }
00126 
00127     public static String getDatabaseFile(Database db)
00128         throws DatabaseException {
00129         return db.getDatabaseFile();
00130     }
00131 
00132     public static OperationStatus getCurrentRecordNumber(Cursor cursor,
00133                                                          DatabaseEntry key,
00134                                                          LockMode lockMode)
00135         throws DatabaseException {
00136         return cursor.getRecordNumber(key, lockMode);
00137     }
00138 
00139     public static OperationStatus getSearchRecordNumber(Cursor cursor,
00140                                                         DatabaseEntry key,
00141                                                         DatabaseEntry data,
00142                                                         LockMode lockMode)
00143         throws DatabaseException {
00144         return cursor.getSearchRecordNumber(key, data, lockMode);
00145     }
00146 
00147     public static OperationStatus getSearchRecordNumber(SecondaryCursor cursor,
00148                                                         DatabaseEntry key,
00149                                                         DatabaseEntry pKey,
00150                                                         DatabaseEntry data,
00151                                                         LockMode lockMode)
00152         throws DatabaseException {
00153         return cursor.getSearchRecordNumber(key, pKey, data, lockMode);
00154     }
00155 
00156     public static OperationStatus putAfter(Cursor cursor,
00157                                            DatabaseEntry key,
00158                                            DatabaseEntry data)
00159         throws DatabaseException {
00160         return cursor.putAfter(key, data);
00161     }
00162 
00163     public static OperationStatus putBefore(Cursor cursor,
00164                                             DatabaseEntry key,
00165                                             DatabaseEntry data)
00166         throws DatabaseException {
00167         return cursor.putBefore(key, data);
00168     }
00169 
00170     public static OperationStatus append(Database db,
00171                                          Transaction txn,
00172                                          DatabaseEntry key,
00173                                          DatabaseEntry data)
00174         throws DatabaseException {
00175         return db.append(txn, key, data);
00176     }
00177 
00178     public static Transaction getThreadTransaction(Environment env)
00179         throws DatabaseException {
00180         return null;
00181     }
00182 
00183     /* Methods used by the collections tests. */
00184 
00185     public static void setInitializeCache(EnvironmentConfig config,
00186                                           boolean val) {
00187         config.setInitializeCache(val);
00188     }
00189 
00190     public static void setInitializeLocking(EnvironmentConfig config,
00191                                             boolean val) {
00192         config.setInitializeLocking(val);
00193     }
00194 
00195     public static void setInitializeCDB(EnvironmentConfig config,
00196                                         boolean val) {
00197         config.setInitializeCDB(val);
00198     }
00199 
00200     public static void setLockDetectModeOldest(EnvironmentConfig config) {
00201 
00202         config.setLockDetectMode(LockDetectMode.OLDEST);
00203     }
00204 
00205     public static void setBtreeComparator(DatabaseConfig dbConfig,
00206                                           Comparator comparator) {
00207         dbConfig.setBtreeComparator(comparator);
00208     }
00209 
00210     public static void setTypeBtree(DatabaseConfig dbConfig) {
00211         dbConfig.setType(DatabaseType.BTREE);
00212     }
00213 
00214     public static void setTypeHash(DatabaseConfig dbConfig) {
00215         dbConfig.setType(DatabaseType.HASH);
00216     }
00217 
00218     public static void setTypeRecno(DatabaseConfig dbConfig) {
00219         dbConfig.setType(DatabaseType.RECNO);
00220     }
00221 
00222     public static void setTypeQueue(DatabaseConfig dbConfig) {
00223         dbConfig.setType(DatabaseType.QUEUE);
00224     }
00225 
00226     public static void setBtreeRecordNumbers(DatabaseConfig dbConfig,
00227                                              boolean val) {
00228         dbConfig.setBtreeRecordNumbers(val);
00229     }
00230 
00231     public static void setReadUncommitted(DatabaseConfig dbConfig,
00232                                           boolean val) {
00233         dbConfig.setReadUncommitted(val);
00234     }
00235 
00236     public static void setRenumbering(DatabaseConfig dbConfig,
00237                                       boolean val) {
00238         dbConfig.setRenumbering(val);
00239     }
00240 
00241     public static void setSortedDuplicates(DatabaseConfig dbConfig,
00242                                            boolean val) {
00243         dbConfig.setSortedDuplicates(val);
00244     }
00245 
00246     public static void setUnsortedDuplicates(DatabaseConfig dbConfig,
00247                                              boolean val) {
00248         dbConfig.setUnsortedDuplicates(val);
00249     }
00250 
00251     public static void setRecordLength(DatabaseConfig dbConfig, int val) {
00252         dbConfig.setRecordLength(val);
00253     }
00254 
00255     public static void setRecordPad(DatabaseConfig dbConfig, int val) {
00256         dbConfig.setRecordPad(val);
00257     }
00258 
00259     public static Database openDatabase(Environment env,
00260                                         Transaction txn,
00261                                         String file,
00262                                         String name,
00263                                         DatabaseConfig config)
00264         throws DatabaseException, FileNotFoundException {
00265         return env.openDatabase(txn, file, name, config);
00266     }
00267 
00268     public static SecondaryDatabase
00269                   openSecondaryDatabase(Environment env,
00270                                         Transaction txn,
00271                                         String file,
00272                                         String name,
00273                                         Database primary,
00274                                         SecondaryConfig config)
00275         throws DatabaseException, FileNotFoundException {
00276         return env.openSecondaryDatabase(txn, file, name, primary, config);
00277     }
00278 }

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