001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: DbInternal.java,v 1.44.2.3 2008/01/07 15:14:08 cwl Exp $
007: */
008:
009: package com.sleepycat.je;
010:
011: import java.io.File;
012: import java.util.Properties;
013:
014: import com.sleepycat.je.dbi.CursorImpl;
015: import com.sleepycat.je.dbi.DatabaseImpl;
016: import com.sleepycat.je.dbi.EnvironmentImpl;
017: import com.sleepycat.je.dbi.GetMode;
018: import com.sleepycat.je.txn.Locker;
019:
020: /**
021: * For internal use only. It serves to shelter methods that must be public to
022: * be used by other BDBJE packages but that are not part of the public api
023: * available to applications.
024: */
025: public class DbInternal {
026:
027: /**
028: * Proxy to Database.invalidate()
029: */
030: public static void dbInvalidate(Database db) {
031: db.invalidate();
032: }
033:
034: /**
035: * Proxy to Database.setHandleLockOwnerTxn
036: */
037: public static void dbSetHandleLocker(Database db, Locker locker) {
038: db.setHandleLocker(locker);
039: }
040:
041: /**
042: * Proxy to Environment.getDbEnvironment
043: */
044: public static EnvironmentImpl envGetEnvironmentImpl(Environment env) {
045: return env.getEnvironmentImpl();
046: }
047:
048: /**
049: * Proxy to new Cursor(DatabaseImpl, Locker, CursorConfig)
050: */
051: public static Cursor newCursor(DatabaseImpl dbImpl, Locker locker,
052: CursorConfig cursorConfig) throws DatabaseException {
053:
054: return new Cursor(dbImpl, locker, cursorConfig);
055: }
056:
057: /**
058: * Proxy to new Cursor.position().
059: */
060: public static OperationStatus position(Cursor cursor,
061: DatabaseEntry key, DatabaseEntry data, LockMode lockMode,
062: boolean first) throws DatabaseException {
063:
064: return cursor.position(key, data, lockMode, first);
065: }
066:
067: /**
068: * Proxy to new Cursor.retrieveNext().
069: */
070: public static OperationStatus retrieveNext(Cursor cursor,
071: DatabaseEntry key, DatabaseEntry data, LockMode lockMode,
072: GetMode getMode) throws DatabaseException {
073:
074: return cursor.retrieveNext(key, data, lockMode, getMode);
075: }
076:
077: /**
078: * Proxy to Cursor.advanceCursor()
079: */
080: public static boolean advanceCursor(Cursor cursor,
081: DatabaseEntry key, DatabaseEntry data) {
082: return cursor.advanceCursor(key, data);
083: }
084:
085: /**
086: * Proxy to Cursor.getCursorImpl()
087: */
088: public static CursorImpl getCursorImpl(Cursor cursor) {
089: return cursor.getCursorImpl();
090: }
091:
092: /**
093: * Proxy to Database.getDatabase()
094: */
095: public static DatabaseImpl dbGetDatabaseImpl(Database db) {
096: return db.getDatabaseImpl();
097: }
098:
099: /**
100: * Proxy to JoinCursor.getSortedCursors()
101: */
102: public static Cursor[] getSortedCursors(JoinCursor cursor) {
103: return cursor.getSortedCursors();
104: }
105:
106: /**
107: * Proxy to EnvironmentConfig.setLoadPropertyFile()
108: */
109: public static void setLoadPropertyFile(EnvironmentConfig config,
110: boolean loadProperties) {
111: config.setLoadPropertyFile(loadProperties);
112: }
113:
114: /**
115: * Proxy to EnvironmentConfig.setCreateUP()
116: */
117: public static void setCreateUP(EnvironmentConfig config,
118: boolean checkpointUP) {
119: config.setCreateUP(checkpointUP);
120: }
121:
122: /**
123: * Proxy to EnvironmentConfig.getCreateUP()
124: */
125: public static boolean getCreateUP(EnvironmentConfig config) {
126: return config.getCreateUP();
127: }
128:
129: /**
130: * Proxy to EnvironmentConfig.setCheckpointUP()
131: */
132: public static void setCheckpointUP(EnvironmentConfig config,
133: boolean checkpointUP) {
134: config.setCheckpointUP(checkpointUP);
135: }
136:
137: /**
138: * Proxy to EnvironmentConfig.getCheckpointUP()
139: */
140: public static boolean getCheckpointUP(EnvironmentConfig config) {
141: return config.getCheckpointUP();
142: }
143:
144: /**
145: * Proxy to EnvironmentConfig.setTxnReadCommitted()
146: */
147: public static void setTxnReadCommitted(EnvironmentConfig config,
148: boolean txnReadCommitted) {
149: config.setTxnReadCommitted(txnReadCommitted);
150: }
151:
152: /**
153: * Proxy to EnvironmentConfig.setTxnReadCommitted()
154: */
155: public static boolean getTxnReadCommitted(EnvironmentConfig config) {
156: return config.getTxnReadCommitted();
157: }
158:
159: /**
160: * Proxy to EnvironmentConfig.cloneConfig()
161: */
162: public static EnvironmentConfig cloneConfig(EnvironmentConfig config) {
163: return config.cloneConfig();
164: }
165:
166: /**
167: * Proxy to EnvironmentMutableConfig.cloneMutableConfig()
168: */
169: public static EnvironmentMutableConfig cloneMutableConfig(
170: EnvironmentMutableConfig config) {
171: return config.cloneMutableConfig();
172: }
173:
174: /**
175: * Proxy to EnvironmentMutableConfig.checkImmutablePropsForEquality()
176: */
177: public static void checkImmutablePropsForEquality(
178: EnvironmentMutableConfig config,
179: EnvironmentMutableConfig passedConfig)
180: throws IllegalArgumentException {
181:
182: config.checkImmutablePropsForEquality(passedConfig);
183: }
184:
185: /**
186: * Proxy to EnvironmentMutableConfig.copyMutablePropsTo()
187: */
188: public static void copyMutablePropsTo(
189: EnvironmentMutableConfig config,
190: EnvironmentMutableConfig toConfig) {
191: config.copyMutablePropsTo(toConfig);
192: }
193:
194: /**
195: * Proxy to EnvironmentMutableConfig.validateParams.
196: */
197: public static void disableParameterValidation(
198: EnvironmentMutableConfig config) {
199: config.setValidateParams(false);
200: }
201:
202: /**
203: * Proxy to EnvironmentMutableConfig.getProps
204: */
205: public static Properties getProps(EnvironmentMutableConfig config) {
206: return config.getProps();
207: }
208:
209: /**
210: * Proxy to DatabaseConfig.setUseExistingConfig()
211: */
212: public static void setUseExistingConfig(DatabaseConfig config,
213: boolean useExistingConfig) {
214: config.setUseExistingConfig(useExistingConfig);
215: }
216:
217: /**
218: * Proxy to DatabaseConfig.match(DatabaseConfig()
219: */
220: public static void databaseConfigValidate(DatabaseConfig config1,
221: DatabaseConfig config2) throws DatabaseException {
222:
223: config1.validate(config2);
224: }
225:
226: /**
227: * Proxy to Transaction.getLocker()
228: */
229: public static Locker getLocker(Transaction txn)
230: throws DatabaseException {
231:
232: return txn.getLocker();
233: }
234:
235: /**
236: * Proxy to Environment.getDefaultTxnConfig()
237: */
238: public static TransactionConfig getDefaultTxnConfig(Environment env) {
239: return env.getDefaultTxnConfig();
240: }
241:
242: /**
243: * Get an Environment only if the environment is already open. This
244: * will register this Enviroment in the EnvironmentImpl's reference count,
245: * but will not configure the environment.
246: * @return null if the environment is not already open.
247: */
248: public static Environment getEnvironmentShell(File environmentHome) {
249:
250: Environment env = null;
251: try {
252: env = new Environment(environmentHome);
253:
254: /* If the environment is not already open, return a null. */
255: if (env.getEnvironmentImpl() == null) {
256: env = null;
257: }
258: } catch (DatabaseException e) {
259:
260: /*
261: * Klockwork - ok
262: * the environment is not valid.
263: */
264: }
265: return env;
266: }
267:
268: public static RunRecoveryException makeNoArgsRRE() {
269: return new RunRecoveryException();
270: }
271:
272: public static ExceptionEvent makeExceptionEvent(Exception e,
273: String n) {
274: return new ExceptionEvent(e, n);
275: }
276: }
|