com.sleepycat.compat
Class DbCompat

java.lang.Object
  extended by com.sleepycat.compat.DbCompat

public class DbCompat
extends Object

A minimal set of BDB DB-JE compatibility constants and static methods, for internal use only. Two versions of this class, with the same public interface but different implementations, are maintained in parallel in the DB and JE source trees. By the use of the constants and methods in this class, along with a script that moves the source code from JE to DB, the source code in certain packages is kept "portable" and is shared by the two products. The script translates the package names from com.sleepycat.je to com.sleepycat.db, and perform other fix-ups as described further below. The JE directories that contain portable code are: src/com/sleepycat/bind /collections /persist /util test/com/sleepycat/bind /collections /persist /util In DB, these sources are stored in the following locations: Sources: src/java Tests: test/java/compat To keep this source code portable there are additional coding rules, above and beyond the standard rules (such as coding style) for all JE code. + In general we should try to use the JE/DB public API, since it is usually the same or similar in both products. If we use internal APIs, they will always be different and will require special handling. + When there are differences between products, the first choice for handling the difference is to use a DbCompat static method or constant. This keeps the source code the same for both products (except in this DbCompat class). + When JE-only code is needed -- for example, some APIs only exist in JE, and special handling of JE exceptions is sometimes needed -- the following special comment syntax can be used to bracket the JE-only code: JE-only code goes here This syntax must be used inside of a comment: either inside a javadoc section as shown above, or inside a single-line comment (space before last slash is to prevent ending this javadoc comment): /* * / JE-only code goes here /* * / All lines between the and lines, and including these lines, will be removed by the script that transfers code from JE to DB. + When DB-only code is needed, the code will exist in the JE product but will never be executed. For DB-only APIs, we hide the API from the user with the @hidden javadoc tag. The @hidden tag is ignored on the DB side. We do not have a way to remove DB-only code completely from the JE product, because we do not use a proprocessor for building JE. + Because DatabaseException (and all subclasses) are checked exceptions in DB but runtime exceptions in JE, we cannot omit the 'throws' declaration. Another difference is that DB normally throws DatabaseException for all errors, while JE has many specific subclasses for specific errors. Therefore, any method that calls a DB API method (for example, Database.get or put) will have a "throws DatabaseException" clause. + Special consideration is needed for the @throws clauses in javadoc. We do want to javadoc the JE-only exceptions that are thrown, so the @throws for these exceptions should be inside the "begin/end JE only" brackets. We also need to document the fact that DB may throw DatabaseException for almost any method, so we do that with a final @throws clause that looks like this:


Field Summary
static boolean BTREE_RECNUM_METHOD
           
static boolean CDB
           
static boolean DATABASE_COUNT
           
static boolean HASH_METHOD
           
static boolean INSERTION_ORDERED_DUPLICATES
           
static boolean JOIN
           
static boolean LOCK_SUBSYSTEM
           
static boolean MEMORY_SUBSYSTEM
           
static boolean NESTED_TRANSACTIONS
           
static boolean NEW_JE_EXCEPTIONS
           
static boolean OPTIONAL_READ_UNCOMMITTED
           
static boolean POPULATE_ENFORCES_CONSTRAINTS
           
static boolean QUEUE_METHOD
           
static TransactionConfig READ_ONLY_TXN_CONFIG
          For read-only cursor operations on a replicated node, we must use a transaction to satisfy HA requirements.
static boolean RECNO_METHOD
           
static boolean SECONDARIES
           
static boolean SEPARATE_DATABASE_FILES
           
static boolean TRANSACTION_RUNNER_PRINT_STACK_TRACES
           
 
Constructor Summary
DbCompat()
           
 
Method Summary
static OperationStatus append(Database db, Transaction txn, DatabaseEntry key, DatabaseEntry data)
           
static CursorConfig cloneCursorConfig(CursorConfig config)
           
static boolean databaseExists(Environment env, String fileName, String dbName)
           
static boolean getBtreeRecordNumbers(DatabaseConfig dbConfig)
           
static ClassLoader getClassLoader(Environment env)
           
static OperationStatus getCurrentRecordNumber(Cursor cursor, DatabaseEntry key, LockMode lockMode)
           
static long getDatabaseCount(Database db)
           
static String getDatabaseFile(Database db)
           
static boolean getDeferredWrite(DatabaseConfig dbConfig)
           
static boolean getInitializeCache(EnvironmentConfig config)
           
static boolean getInitializeCDB(EnvironmentConfig config)
           
static boolean getInitializeLocking(EnvironmentConfig config)
           
static boolean getReadUncommitted(DatabaseConfig dbConfig)
           
static int getRecordNumber(DatabaseEntry entry)
           
static boolean getRenumbering(DatabaseConfig dbConfig)
           
static OperationStatus getSearchRecordNumber(Cursor cursor, DatabaseEntry key, DatabaseEntry data, LockMode lockMode)
           
static OperationStatus getSearchRecordNumber(SecondaryCursor cursor, DatabaseEntry key, DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
           
static boolean getSortedDuplicates(DatabaseConfig dbConfig)
           
static Transaction getThreadTransaction(Environment env)
           
static boolean getUnsortedDuplicates(DatabaseConfig dbConfig)
           
static boolean getWriteCursor(CursorConfig config)
           
static boolean isDalvik()
           
static boolean isReplicated(Environment env)
           
static boolean isTypeBtree(DatabaseConfig dbConfig)
           
static boolean isTypeHash(DatabaseConfig dbConfig)
           
static boolean isTypeQueue(DatabaseConfig dbConfig)
           
static boolean isTypeRecno(DatabaseConfig dbConfig)
           
static Database openDatabase(Environment env, Transaction txn, String fileName, String dbName, DatabaseConfig config)
          Returns null if the database is not found (and AllowCreate is false) or already exists (and ExclusiveCreate is true).
static SecondaryDatabase openSecondaryDatabase(Environment env, Transaction txn, String fileName, String dbName, Database primaryDatabase, SecondaryConfig config)
          Returns null if the database is not found (and AllowCreate is false) or already exists (and ExclusiveCreate is true).
static OperationStatus putAfter(Cursor cursor, DatabaseEntry key, DatabaseEntry data)
           
static OperationStatus putBefore(Cursor cursor, DatabaseEntry key, DatabaseEntry data)
           
static boolean removeDatabase(Environment env, Transaction txn, String fileName, String dbName)
          Returns false if the database is not found.
static boolean renameDatabase(Environment env, Transaction txn, String oldFileName, String oldDbName, String newFileName, String newDbName)
          Returns false if the database is not found.
static void setBtreeComparator(DatabaseConfig dbConfig, Comparator<byte[]> comparator)
           
static void setBtreeRecordNumbers(DatabaseConfig dbConfig, boolean val)
           
static void setDeferredWrite(DatabaseConfig dbConfig, boolean val)
           
static boolean setImportunate(Transaction txn, boolean importunate)
           
static void setInitializeCache(EnvironmentConfig config, boolean val)
           
static void setInitializeCDB(EnvironmentConfig config, boolean val)
           
static void setInitializeLocking(EnvironmentConfig config, boolean val)
           
static void setLockDetectModeOldest(EnvironmentConfig config)
           
static void setReadUncommitted(DatabaseConfig dbConfig, boolean val)
           
static void setRecordLength(DatabaseConfig dbConfig, int val)
           
static void setRecordNumber(DatabaseEntry entry, int recNum)
           
static void setRecordPad(DatabaseConfig dbConfig, int val)
           
static void setRenumbering(DatabaseConfig dbConfig, boolean val)
           
static void setSerializableIsolation(TransactionConfig config, boolean val)
           
static void setSortedDuplicates(DatabaseConfig dbConfig, boolean val)
           
static void setTypeBtree(DatabaseConfig dbConfig)
           
static void setTypeHash(DatabaseConfig dbConfig)
           
static void setTypeQueue(DatabaseConfig dbConfig)
           
static void setTypeRecno(DatabaseConfig dbConfig)
           
static void setUnsortedDuplicates(DatabaseConfig dbConfig, boolean val)
           
static void setWriteCursor(CursorConfig config, boolean write)
           
static Database testOpenDatabase(Environment env, Transaction txn, String file, String name, DatabaseConfig config)
          Fires an assertion if the database is not found (and AllowCreate is false) or already exists (and ExclusiveCreate is true).
static SecondaryDatabase testOpenSecondaryDatabase(Environment env, Transaction txn, String file, String name, Database primary, SecondaryConfig config)
          Fires an assertion if the database is not found (and AllowCreate is false) or already exists (and ExclusiveCreate is true).
static boolean truncateDatabase(Environment env, Transaction txn, String fileName, String dbName)
          Returns false if the database is not found.
static RuntimeException unexpectedException(Exception cause)
           
static RuntimeException unexpectedException(String msg, Exception cause)
           
static RuntimeException unexpectedState()
           
static RuntimeException unexpectedState(String msg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CDB

public static final boolean CDB
See Also:
Constant Field Values

JOIN

public static final boolean JOIN
See Also:
Constant Field Values

NESTED_TRANSACTIONS

public static final boolean NESTED_TRANSACTIONS
See Also:
Constant Field Values

INSERTION_ORDERED_DUPLICATES

public static final boolean INSERTION_ORDERED_DUPLICATES
See Also:
Constant Field Values

SEPARATE_DATABASE_FILES

public static final boolean SEPARATE_DATABASE_FILES
See Also:
Constant Field Values

MEMORY_SUBSYSTEM

public static final boolean MEMORY_SUBSYSTEM
See Also:
Constant Field Values

LOCK_SUBSYSTEM

public static final boolean LOCK_SUBSYSTEM
See Also:
Constant Field Values

HASH_METHOD

public static final boolean HASH_METHOD
See Also:
Constant Field Values

RECNO_METHOD

public static final boolean RECNO_METHOD
See Also:
Constant Field Values

QUEUE_METHOD

public static final boolean QUEUE_METHOD
See Also:
Constant Field Values

BTREE_RECNUM_METHOD

public static final boolean BTREE_RECNUM_METHOD
See Also:
Constant Field Values

OPTIONAL_READ_UNCOMMITTED

public static final boolean OPTIONAL_READ_UNCOMMITTED
See Also:
Constant Field Values

SECONDARIES

public static final boolean SECONDARIES
See Also:
Constant Field Values

TRANSACTION_RUNNER_PRINT_STACK_TRACES

public static boolean TRANSACTION_RUNNER_PRINT_STACK_TRACES

DATABASE_COUNT

public static final boolean DATABASE_COUNT
See Also:
Constant Field Values

NEW_JE_EXCEPTIONS

public static final boolean NEW_JE_EXCEPTIONS
See Also:
Constant Field Values

POPULATE_ENFORCES_CONSTRAINTS

public static final boolean POPULATE_ENFORCES_CONSTRAINTS
See Also:
Constant Field Values

READ_ONLY_TXN_CONFIG

public static final TransactionConfig READ_ONLY_TXN_CONFIG
For read-only cursor operations on a replicated node, we must use a transaction to satisfy HA requirements. However, we use a Durability that avoids consistency checks on the Master, and we use ReadCommitted isolation since that gives the same behavior as a non-transactional cursor: locks are released when the cursor is moved or closed.

Constructor Detail

DbCompat

public DbCompat()
Method Detail

getInitializeCache

public static boolean getInitializeCache(EnvironmentConfig config)

getInitializeLocking

public static boolean getInitializeLocking(EnvironmentConfig config)

getInitializeCDB

public static boolean getInitializeCDB(EnvironmentConfig config)

isReplicated

public static boolean isReplicated(Environment env)

isTypeBtree

public static boolean isTypeBtree(DatabaseConfig dbConfig)

isTypeHash

public static boolean isTypeHash(DatabaseConfig dbConfig)

isTypeQueue

public static boolean isTypeQueue(DatabaseConfig dbConfig)

isTypeRecno

public static boolean isTypeRecno(DatabaseConfig dbConfig)

getBtreeRecordNumbers

public static boolean getBtreeRecordNumbers(DatabaseConfig dbConfig)

getReadUncommitted

public static boolean getReadUncommitted(DatabaseConfig dbConfig)

getRenumbering

public static boolean getRenumbering(DatabaseConfig dbConfig)

getSortedDuplicates

public static boolean getSortedDuplicates(DatabaseConfig dbConfig)

getUnsortedDuplicates

public static boolean getUnsortedDuplicates(DatabaseConfig dbConfig)

getDeferredWrite

public static boolean getDeferredWrite(DatabaseConfig dbConfig)

cloneCursorConfig

public static CursorConfig cloneCursorConfig(CursorConfig config)

getWriteCursor

public static boolean getWriteCursor(CursorConfig config)

setWriteCursor

public static void setWriteCursor(CursorConfig config,
                                  boolean write)

setRecordNumber

public static void setRecordNumber(DatabaseEntry entry,
                                   int recNum)

getRecordNumber

public static int getRecordNumber(DatabaseEntry entry)

getDatabaseFile

public static String getDatabaseFile(Database db)

getDatabaseCount

public static long getDatabaseCount(Database db)
                             throws DatabaseException
Throws:
DatabaseException

getCurrentRecordNumber

public static OperationStatus getCurrentRecordNumber(Cursor cursor,
                                                     DatabaseEntry key,
                                                     LockMode lockMode)
                                              throws DatabaseException
Throws:
DatabaseException - from DB core.

getSearchRecordNumber

public static OperationStatus getSearchRecordNumber(Cursor cursor,
                                                    DatabaseEntry key,
                                                    DatabaseEntry data,
                                                    LockMode lockMode)
                                             throws DatabaseException
Throws:
DatabaseException - from DB core.

getSearchRecordNumber

public static OperationStatus getSearchRecordNumber(SecondaryCursor cursor,
                                                    DatabaseEntry key,
                                                    DatabaseEntry pKey,
                                                    DatabaseEntry data,
                                                    LockMode lockMode)
                                             throws DatabaseException
Throws:
DatabaseException - from DB core.

putAfter

public static OperationStatus putAfter(Cursor cursor,
                                       DatabaseEntry key,
                                       DatabaseEntry data)
                                throws DatabaseException
Throws:
DatabaseException - from DB core.

putBefore

public static OperationStatus putBefore(Cursor cursor,
                                        DatabaseEntry key,
                                        DatabaseEntry data)
                                 throws DatabaseException
Throws:
DatabaseException - from DB core.

append

public static OperationStatus append(Database db,
                                     Transaction txn,
                                     DatabaseEntry key,
                                     DatabaseEntry data)

getThreadTransaction

public static Transaction getThreadTransaction(Environment env)
                                        throws DatabaseException
Throws:
DatabaseException

getClassLoader

public static ClassLoader getClassLoader(Environment env)

setInitializeCache

public static void setInitializeCache(EnvironmentConfig config,
                                      boolean val)

setInitializeLocking

public static void setInitializeLocking(EnvironmentConfig config,
                                        boolean val)

setInitializeCDB

public static void setInitializeCDB(EnvironmentConfig config,
                                    boolean val)

setLockDetectModeOldest

public static void setLockDetectModeOldest(EnvironmentConfig config)

setSerializableIsolation

public static void setSerializableIsolation(TransactionConfig config,
                                            boolean val)

setImportunate

public static boolean setImportunate(Transaction txn,
                                     boolean importunate)

setBtreeComparator

public static void setBtreeComparator(DatabaseConfig dbConfig,
                                      Comparator<byte[]> comparator)

setTypeBtree

public static void setTypeBtree(DatabaseConfig dbConfig)

setTypeHash

public static void setTypeHash(DatabaseConfig dbConfig)

setTypeRecno

public static void setTypeRecno(DatabaseConfig dbConfig)

setTypeQueue

public static void setTypeQueue(DatabaseConfig dbConfig)

setBtreeRecordNumbers

public static void setBtreeRecordNumbers(DatabaseConfig dbConfig,
                                         boolean val)

setReadUncommitted

public static void setReadUncommitted(DatabaseConfig dbConfig,
                                      boolean val)

setRenumbering

public static void setRenumbering(DatabaseConfig dbConfig,
                                  boolean val)

setSortedDuplicates

public static void setSortedDuplicates(DatabaseConfig dbConfig,
                                       boolean val)

setUnsortedDuplicates

public static void setUnsortedDuplicates(DatabaseConfig dbConfig,
                                         boolean val)

setDeferredWrite

public static void setDeferredWrite(DatabaseConfig dbConfig,
                                    boolean val)

setRecordLength

public static void setRecordLength(DatabaseConfig dbConfig,
                                   int val)

setRecordPad

public static void setRecordPad(DatabaseConfig dbConfig,
                                int val)

databaseExists

public static boolean databaseExists(Environment env,
                                     String fileName,
                                     String dbName)

openDatabase

public static Database openDatabase(Environment env,
                                    Transaction txn,
                                    String fileName,
                                    String dbName,
                                    DatabaseConfig config)
Returns null if the database is not found (and AllowCreate is false) or already exists (and ExclusiveCreate is true).


openSecondaryDatabase

public static SecondaryDatabase openSecondaryDatabase(Environment env,
                                                      Transaction txn,
                                                      String fileName,
                                                      String dbName,
                                                      Database primaryDatabase,
                                                      SecondaryConfig config)
Returns null if the database is not found (and AllowCreate is false) or already exists (and ExclusiveCreate is true).


truncateDatabase

public static boolean truncateDatabase(Environment env,
                                       Transaction txn,
                                       String fileName,
                                       String dbName)
Returns false if the database is not found.


removeDatabase

public static boolean removeDatabase(Environment env,
                                     Transaction txn,
                                     String fileName,
                                     String dbName)
Returns false if the database is not found.


renameDatabase

public static boolean renameDatabase(Environment env,
                                     Transaction txn,
                                     String oldFileName,
                                     String oldDbName,
                                     String newFileName,
                                     String newDbName)
Returns false if the database is not found.


testOpenDatabase

public static Database testOpenDatabase(Environment env,
                                        Transaction txn,
                                        String file,
                                        String name,
                                        DatabaseConfig config)
Fires an assertion if the database is not found (and AllowCreate is false) or already exists (and ExclusiveCreate is true).


testOpenSecondaryDatabase

public static SecondaryDatabase testOpenSecondaryDatabase(Environment env,
                                                          Transaction txn,
                                                          String file,
                                                          String name,
                                                          Database primary,
                                                          SecondaryConfig config)
Fires an assertion if the database is not found (and AllowCreate is false) or already exists (and ExclusiveCreate is true).


isDalvik

public static boolean isDalvik()

unexpectedException

public static RuntimeException unexpectedException(Exception cause)

unexpectedException

public static RuntimeException unexpectedException(String msg,
                                                   Exception cause)

unexpectedState

public static RuntimeException unexpectedState(String msg)

unexpectedState

public static RuntimeException unexpectedState()


Copyright (c) 2004-2012 Oracle. All rights reserved.