KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > compat > DbCompat


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2000,2006 Oracle. All rights reserved.
5  *
6  * $Id: DbCompat.java,v 1.21 2006/11/27 22:44:18 mark Exp $
7  */

8
9 package com.sleepycat.compat;
10
11 import java.io.FileNotFoundException JavaDoc;
12 import java.util.Comparator JavaDoc;
13
14 import com.sleepycat.je.Cursor;
15 import com.sleepycat.je.CursorConfig;
16 import com.sleepycat.je.Database;
17 import com.sleepycat.je.DatabaseConfig;
18 import com.sleepycat.je.DatabaseEntry;
19 import com.sleepycat.je.DatabaseException;
20 import com.sleepycat.je.DbInternal;
21 import com.sleepycat.je.Environment;
22 import com.sleepycat.je.EnvironmentConfig;
23 import com.sleepycat.je.LockMode;
24 import com.sleepycat.je.OperationStatus;
25 import com.sleepycat.je.SecondaryConfig;
26 import com.sleepycat.je.SecondaryCursor;
27 import com.sleepycat.je.SecondaryDatabase;
28 import com.sleepycat.je.Transaction;
29 import com.sleepycat.je.TransactionConfig;
30
31 /**
32  * A minimal set of DB-JE compatibility methods for internal use only.
33  * Two versions are maintained in parallel in the DB and JE source trees.
34  * Used by the collections package.
35  */

36 public class DbCompat {
37
38     /* Capabilities */
39
40     public static final boolean CDB = false;
41     public static final boolean JOIN = true;
42     public static final boolean NESTED_TRANSACTIONS = false;
43     public static final boolean INSERTION_ORDERED_DUPLICATES = false;
44     public static final boolean SEPARATE_DATABASE_FILES = false;
45     public static final boolean MEMORY_SUBSYSTEM = false;
46     public static final boolean LOCK_SUBSYSTEM = false;
47     public static final boolean HASH_METHOD = false;
48     public static final boolean RECNO_METHOD = false;
49     public static final boolean QUEUE_METHOD = false;
50     public static final boolean BTREE_RECNUM_METHOD = false;
51     public static final boolean OPTIONAL_READ_UNCOMMITTED = false;
52     public static final boolean SECONDARIES = true;
53     public static boolean TRANSACTION_RUNNER_PRINT_STACK_TRACES = true;
54     public static final boolean DATABASE_COUNT = true;
55
56     /* Methods used by the collections package. */
57
58     public static boolean getInitializeLocking(EnvironmentConfig config) {
59         return config.getLocking();
60     }
61
62     public static boolean getInitializeCDB(EnvironmentConfig config) {
63         return false;
64     }
65
66     public static boolean isTypeBtree(DatabaseConfig dbConfig) {
67         return true;
68     }
69
70     public static boolean isTypeHash(DatabaseConfig dbConfig) {
71         return false;
72     }
73
74     public static boolean isTypeQueue(DatabaseConfig dbConfig) {
75         return false;
76     }
77
78     public static boolean isTypeRecno(DatabaseConfig dbConfig) {
79         return false;
80     }
81
82     public static boolean getBtreeRecordNumbers(DatabaseConfig dbConfig) {
83         return false;
84     }
85
86     public static boolean getReadUncommitted(DatabaseConfig dbConfig) {
87         return true;
88     }
89
90     public static boolean getRenumbering(DatabaseConfig dbConfig) {
91         return false;
92     }
93
94     public static boolean getSortedDuplicates(DatabaseConfig dbConfig) {
95         return dbConfig.getSortedDuplicates();
96     }
97
98     public static boolean getUnsortedDuplicates(DatabaseConfig dbConfig) {
99         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 JavaDoc();
121         }
122     }
123
124     public static void setRecordNumber(DatabaseEntry entry, int recNum) {
125         throw new UnsupportedOperationException JavaDoc();
126     }
127
128     public static int getRecordNumber(DatabaseEntry entry) {
129         throw new UnsupportedOperationException JavaDoc();
130     }
131
132     public static String JavaDoc 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,
152                                                          LockMode lockMode)
153         throws DatabaseException {
154
155         throw new UnsupportedOperationException JavaDoc();
156     }
157     
158     public static OperationStatus getSearchRecordNumber(Cursor cursor,
159                                                         DatabaseEntry key,
160                                                         DatabaseEntry data,
161                                                         LockMode lockMode)
162         throws DatabaseException {
163
164         throw new UnsupportedOperationException JavaDoc();
165     }
166     
167     public static OperationStatus getSearchRecordNumber(SecondaryCursor cursor,
168                                                         DatabaseEntry key,
169                                                         DatabaseEntry pKey,
170                                                         DatabaseEntry data,
171                                                         LockMode lockMode)
172         throws DatabaseException {
173
174         throw new UnsupportedOperationException JavaDoc();
175     }
176     
177     public static OperationStatus putAfter(Cursor cursor,
178                                            DatabaseEntry key,
179                                            DatabaseEntry data)
180         throws DatabaseException {
181
182         throw new UnsupportedOperationException JavaDoc();
183     }
184     
185     public static OperationStatus putBefore(Cursor cursor,
186                                             DatabaseEntry key,
187                                             DatabaseEntry data)
188         throws DatabaseException {
189
190         throw new UnsupportedOperationException JavaDoc();
191     }
192     
193     public static OperationStatus append(Database db,
194                                          Transaction txn,
195                                          DatabaseEntry key,
196                                          DatabaseEntry data)
197         throws DatabaseException {
198
199         throw new UnsupportedOperationException JavaDoc();
200     }
201
202     public static Transaction getThreadTransaction(Environment env)
203     throws DatabaseException {
204
205         return env.getThreadTransaction();
206     }
207
208     /* Methods used by the collections tests. */
209
210     public static void setInitializeCache(EnvironmentConfig config,
211                                           boolean val) {
212         if (!val) {
213             throw new UnsupportedOperationException JavaDoc();
214         }
215     }
216
217     public static void setInitializeLocking(EnvironmentConfig config,
218                                             boolean val) {
219         if (!val) {
220             throw new UnsupportedOperationException JavaDoc();
221         }
222     }
223
224     public static void setInitializeCDB(EnvironmentConfig config,
225                                         boolean val) {
226         if (val) {
227             throw new UnsupportedOperationException JavaDoc();
228         }
229     }
230
231     public static void setLockDetectModeOldest(EnvironmentConfig config) {
232         /* JE does this by default, since it uses timeouts. */
233     }
234
235     public static void setSerializableIsolation(TransactionConfig config,
236                                                 boolean val) {
237         config.setSerializableIsolation(val);
238     }
239
240
241     public static void setBtreeComparator(DatabaseConfig dbConfig,
242                                           Comparator JavaDoc comparator) {
243         dbConfig.setBtreeComparator(comparator.getClass());
244     }
245
246     public static void setTypeBtree(DatabaseConfig dbConfig) {
247     }
248
249     public static void setTypeHash(DatabaseConfig dbConfig) {
250         throw new UnsupportedOperationException JavaDoc();
251     }
252
253     public static void setTypeRecno(DatabaseConfig dbConfig) {
254         throw new UnsupportedOperationException JavaDoc();
255     }
256
257     public static void setTypeQueue(DatabaseConfig dbConfig) {
258         throw new UnsupportedOperationException JavaDoc();
259     }
260
261     public static void setBtreeRecordNumbers(DatabaseConfig dbConfig,
262                                              boolean val) {
263         throw new UnsupportedOperationException JavaDoc();
264     }
265
266     public static void setReadUncommitted(DatabaseConfig dbConfig,
267                                           boolean val) {
268     }
269
270     public static void setRenumbering(DatabaseConfig dbConfig,
271                                       boolean val) {
272         throw new UnsupportedOperationException JavaDoc();
273     }
274
275     public static void setSortedDuplicates(DatabaseConfig dbConfig,
276                                            boolean val) {
277         dbConfig.setSortedDuplicates(val);
278     }
279
280     public static void setUnsortedDuplicates(DatabaseConfig dbConfig,
281                                              boolean val) {
282         if (val) {
283             throw new UnsupportedOperationException JavaDoc();
284         }
285     }
286
287     public static void setDeferredWrite(DatabaseConfig dbConfig, boolean val) {
288         dbConfig.setDeferredWrite(val);
289     }
290
291     public static void setRecordLength(DatabaseConfig dbConfig, int val) {
292         if (val != 0) {
293             throw new UnsupportedOperationException JavaDoc();
294         }
295     }
296
297     public static void setRecordPad(DatabaseConfig dbConfig, int val) {
298         throw new UnsupportedOperationException JavaDoc();
299     }
300
301     public static Database openDatabase(Environment env,
302                                         Transaction txn,
303                                         String JavaDoc file,
304                                         String JavaDoc name,
305                                         DatabaseConfig config)
306         throws DatabaseException, FileNotFoundException JavaDoc {
307
308         return env.openDatabase(txn, makeDbName(file, name), config);
309     }
310
311     public static SecondaryDatabase
312                   openSecondaryDatabase(Environment env,
313                                         Transaction txn,
314                                         String JavaDoc file,
315                                         String JavaDoc name,
316                                         Database primary,
317                                         SecondaryConfig config)
318         throws DatabaseException, FileNotFoundException JavaDoc {
319
320         return env.openSecondaryDatabase(txn, makeDbName(file, name),
321                                          primary, config);
322     }
323
324     private static String JavaDoc makeDbName(String JavaDoc file, String JavaDoc name) {
325         if (file == null) {
326             return name;
327         } else {
328             if (name != null) {
329                 return file + '.' + name;
330             } else {
331                 return file;
332             }
333         }
334     }
335 }
336
Popular Tags