001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2000,2008 Oracle. All rights reserved.
005: *
006: * $Id: DbCompat.java,v 1.21.2.3 2008/01/07 15:14:07 cwl Exp $
007: */
008:
009: package com.sleepycat.compat;
010:
011: import java.io.FileNotFoundException;
012: import java.util.Comparator;
013:
014: import com.sleepycat.je.Cursor;
015: import com.sleepycat.je.CursorConfig;
016: import com.sleepycat.je.Database;
017: import com.sleepycat.je.DatabaseConfig;
018: import com.sleepycat.je.DatabaseEntry;
019: import com.sleepycat.je.DatabaseException;
020: import com.sleepycat.je.DbInternal;
021: import com.sleepycat.je.Environment;
022: import com.sleepycat.je.EnvironmentConfig;
023: import com.sleepycat.je.LockMode;
024: import com.sleepycat.je.OperationStatus;
025: import com.sleepycat.je.SecondaryConfig;
026: import com.sleepycat.je.SecondaryCursor;
027: import com.sleepycat.je.SecondaryDatabase;
028: import com.sleepycat.je.Transaction;
029: import com.sleepycat.je.TransactionConfig;
030:
031: /**
032: * A minimal set of DB-JE compatibility methods for internal use only.
033: * Two versions are maintained in parallel in the DB and JE source trees.
034: * Used by the collections package.
035: */
036: public class DbCompat {
037:
038: /* Capabilities */
039:
040: public static final boolean CDB = false;
041: public static final boolean JOIN = true;
042: public static final boolean NESTED_TRANSACTIONS = false;
043: public static final boolean INSERTION_ORDERED_DUPLICATES = false;
044: public static final boolean SEPARATE_DATABASE_FILES = false;
045: public static final boolean MEMORY_SUBSYSTEM = false;
046: public static final boolean LOCK_SUBSYSTEM = false;
047: public static final boolean HASH_METHOD = false;
048: public static final boolean RECNO_METHOD = false;
049: public static final boolean QUEUE_METHOD = false;
050: public static final boolean BTREE_RECNUM_METHOD = false;
051: public static final boolean OPTIONAL_READ_UNCOMMITTED = false;
052: public static final boolean SECONDARIES = true;
053: public static boolean TRANSACTION_RUNNER_PRINT_STACK_TRACES = true;
054: public static final boolean DATABASE_COUNT = true;
055:
056: /* Methods used by the collections package. */
057:
058: public static boolean getInitializeLocking(EnvironmentConfig config) {
059: return config.getLocking();
060: }
061:
062: public static boolean getInitializeCDB(EnvironmentConfig config) {
063: return false;
064: }
065:
066: public static boolean isTypeBtree(DatabaseConfig dbConfig) {
067: return true;
068: }
069:
070: public static boolean isTypeHash(DatabaseConfig dbConfig) {
071: return false;
072: }
073:
074: public static boolean isTypeQueue(DatabaseConfig dbConfig) {
075: return false;
076: }
077:
078: public static boolean isTypeRecno(DatabaseConfig dbConfig) {
079: return false;
080: }
081:
082: public static boolean getBtreeRecordNumbers(DatabaseConfig dbConfig) {
083: return false;
084: }
085:
086: public static boolean getReadUncommitted(DatabaseConfig dbConfig) {
087: return true;
088: }
089:
090: public static boolean getRenumbering(DatabaseConfig dbConfig) {
091: return false;
092: }
093:
094: public static boolean getSortedDuplicates(DatabaseConfig dbConfig) {
095: return dbConfig.getSortedDuplicates();
096: }
097:
098: public static boolean getUnsortedDuplicates(DatabaseConfig dbConfig) {
099: return false;
100: }
101:
102: public static boolean getDeferredWrite(DatabaseConfig dbConfig) {
103: return dbConfig.getDeferredWrite();
104: }
105:
106: // XXX Remove this when DB and JE support CursorConfig.cloneConfig
107: public static CursorConfig cloneCursorConfig(CursorConfig config) {
108: CursorConfig newConfig = new CursorConfig();
109: newConfig.setReadCommitted(config.getReadCommitted());
110: newConfig.setReadUncommitted(config.getReadUncommitted());
111: return newConfig;
112: }
113:
114: public static boolean getWriteCursor(CursorConfig config) {
115: return false;
116: }
117:
118: public static void setWriteCursor(CursorConfig config, boolean write) {
119: if (write) {
120: throw new UnsupportedOperationException();
121: }
122: }
123:
124: public static void setRecordNumber(DatabaseEntry entry, int recNum) {
125: throw new UnsupportedOperationException();
126: }
127:
128: public static int getRecordNumber(DatabaseEntry entry) {
129: throw new UnsupportedOperationException();
130: }
131:
132: public static String getDatabaseFile(Database db)
133: throws DatabaseException {
134:
135: return null;
136: }
137:
138: public static long getDatabaseCount(Database db)
139: throws DatabaseException {
140:
141: return db.count();
142: }
143:
144: public static void syncDeferredWrite(Database db, boolean flushLog)
145: throws DatabaseException {
146:
147: DbInternal.dbGetDatabaseImpl(db).sync(flushLog);
148: }
149:
150: public static OperationStatus getCurrentRecordNumber(Cursor cursor,
151: DatabaseEntry key, LockMode lockMode)
152: throws DatabaseException {
153:
154: throw new UnsupportedOperationException();
155: }
156:
157: public static OperationStatus getSearchRecordNumber(Cursor cursor,
158: DatabaseEntry key, DatabaseEntry data, LockMode lockMode)
159: throws DatabaseException {
160:
161: throw new UnsupportedOperationException();
162: }
163:
164: public static OperationStatus getSearchRecordNumber(
165: SecondaryCursor cursor, DatabaseEntry key,
166: DatabaseEntry pKey, DatabaseEntry data, LockMode lockMode)
167: throws DatabaseException {
168:
169: throw new UnsupportedOperationException();
170: }
171:
172: public static OperationStatus putAfter(Cursor cursor,
173: DatabaseEntry key, DatabaseEntry data)
174: throws DatabaseException {
175:
176: throw new UnsupportedOperationException();
177: }
178:
179: public static OperationStatus putBefore(Cursor cursor,
180: DatabaseEntry key, DatabaseEntry data)
181: throws DatabaseException {
182:
183: throw new UnsupportedOperationException();
184: }
185:
186: public static OperationStatus append(Database db, Transaction txn,
187: DatabaseEntry key, DatabaseEntry data)
188: throws DatabaseException {
189:
190: throw new UnsupportedOperationException();
191: }
192:
193: public static Transaction getThreadTransaction(Environment env)
194: throws DatabaseException {
195:
196: return env.getThreadTransaction();
197: }
198:
199: /* Methods used by the collections tests. */
200:
201: public static void setInitializeCache(EnvironmentConfig config,
202: boolean val) {
203: if (!val) {
204: throw new UnsupportedOperationException();
205: }
206: }
207:
208: public static void setInitializeLocking(EnvironmentConfig config,
209: boolean val) {
210: if (!val) {
211: throw new UnsupportedOperationException();
212: }
213: }
214:
215: public static void setInitializeCDB(EnvironmentConfig config,
216: boolean val) {
217: if (val) {
218: throw new UnsupportedOperationException();
219: }
220: }
221:
222: public static void setLockDetectModeOldest(EnvironmentConfig config) {
223: /* JE does this by default, since it uses timeouts. */
224: }
225:
226: public static void setSerializableIsolation(
227: TransactionConfig config, boolean val) {
228: config.setSerializableIsolation(val);
229: }
230:
231: public static void setBtreeComparator(DatabaseConfig dbConfig,
232: Comparator comparator) {
233: dbConfig.setBtreeComparator(comparator.getClass());
234: }
235:
236: public static void setTypeBtree(DatabaseConfig dbConfig) {
237: }
238:
239: public static void setTypeHash(DatabaseConfig dbConfig) {
240: throw new UnsupportedOperationException();
241: }
242:
243: public static void setTypeRecno(DatabaseConfig dbConfig) {
244: throw new UnsupportedOperationException();
245: }
246:
247: public static void setTypeQueue(DatabaseConfig dbConfig) {
248: throw new UnsupportedOperationException();
249: }
250:
251: public static void setBtreeRecordNumbers(DatabaseConfig dbConfig,
252: boolean val) {
253: throw new UnsupportedOperationException();
254: }
255:
256: public static void setReadUncommitted(DatabaseConfig dbConfig,
257: boolean val) {
258: }
259:
260: public static void setRenumbering(DatabaseConfig dbConfig,
261: boolean val) {
262: throw new UnsupportedOperationException();
263: }
264:
265: public static void setSortedDuplicates(DatabaseConfig dbConfig,
266: boolean val) {
267: dbConfig.setSortedDuplicates(val);
268: }
269:
270: public static void setUnsortedDuplicates(DatabaseConfig dbConfig,
271: boolean val) {
272: if (val) {
273: throw new UnsupportedOperationException();
274: }
275: }
276:
277: public static void setDeferredWrite(DatabaseConfig dbConfig,
278: boolean val) {
279: dbConfig.setDeferredWrite(val);
280: }
281:
282: public static void setRecordLength(DatabaseConfig dbConfig, int val) {
283: if (val != 0) {
284: throw new UnsupportedOperationException();
285: }
286: }
287:
288: public static void setRecordPad(DatabaseConfig dbConfig, int val) {
289: throw new UnsupportedOperationException();
290: }
291:
292: public static Database openDatabase(Environment env,
293: Transaction txn, String file, String name,
294: DatabaseConfig config) throws DatabaseException,
295: FileNotFoundException {
296:
297: return env.openDatabase(txn, makeDbName(file, name), config);
298: }
299:
300: public static SecondaryDatabase openSecondaryDatabase(
301: Environment env, Transaction txn, String file, String name,
302: Database primary, SecondaryConfig config)
303: throws DatabaseException, FileNotFoundException {
304:
305: return env.openSecondaryDatabase(txn, makeDbName(file, name),
306: primary, config);
307: }
308:
309: private static String makeDbName(String file, String name) {
310: if (file == null) {
311: return name;
312: } else {
313: if (name != null) {
314: return file + '.' + name;
315: } else {
316: return file;
317: }
318: }
319: }
320: }
|