001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: EnvironmentConfig.java,v 1.35.2.3 2008/01/07 15:14:08 cwl Exp $
007: */
008:
009: package com.sleepycat.je;
010:
011: import java.util.Properties;
012:
013: import com.sleepycat.je.config.EnvironmentParams;
014: import com.sleepycat.je.dbi.DbConfigManager;
015:
016: /**
017: * Javadoc for this public class is generated
018: * via the doc templates in the doc_src directory.
019: */
020: public class EnvironmentConfig extends EnvironmentMutableConfig {
021: /*
022: * For internal use, to allow null as a valid value for
023: * the config parameter.
024: */
025: public static final EnvironmentConfig DEFAULT = new EnvironmentConfig();
026:
027: /**
028: * For unit testing, to prevent creating the utilization profile DB.
029: */
030: private boolean createUP = true;
031:
032: /**
033: * For unit testing, to prevent writing utilization data during checkpoint.
034: */
035: private boolean checkpointUP = true;
036:
037: private boolean allowCreate = false;
038:
039: /**
040: * For unit testing, to set readCommitted as the default.
041: */
042: private boolean txnReadCommitted = false;
043:
044: private ExceptionListener exceptionListener = null;
045:
046: /**
047: * Javadoc for this public method is generated via
048: * the doc templates in the doc_src directory.
049: */
050: public EnvironmentConfig() {
051: super ();
052: }
053:
054: /**
055: * Javadoc for this public method is generated via
056: * the doc templates in the doc_src directory.
057: */
058: public EnvironmentConfig(Properties properties)
059: throws IllegalArgumentException {
060:
061: super (properties);
062: }
063:
064: /**
065: * Javadoc for this public method is generated via
066: * the doc templates in the doc_src directory.
067: */
068: public void setAllowCreate(boolean allowCreate) {
069:
070: this .allowCreate = allowCreate;
071: }
072:
073: /**
074: * Javadoc for this public method is generated via
075: * the doc templates in the doc_src directory.
076: */
077: public boolean getAllowCreate() {
078:
079: return allowCreate;
080: }
081:
082: /**
083: * Javadoc for this public method is generated via
084: * the doc templates in the doc_src directory.
085: */
086: public void setLockTimeout(long timeout)
087: throws IllegalArgumentException {
088:
089: DbConfigManager.setVal(props, EnvironmentParams.LOCK_TIMEOUT,
090: Long.toString(timeout), validateParams);
091: }
092:
093: /**
094: * Javadoc for this public method is generated via
095: * the doc templates in the doc_src directory.
096: */
097: public long getLockTimeout() {
098:
099: String val = DbConfigManager.getVal(props,
100: EnvironmentParams.LOCK_TIMEOUT);
101: long timeout = 0;
102: try {
103: timeout = Long.parseLong(val);
104: } catch (NumberFormatException e) {
105: throw new IllegalArgumentException("Bad value for timeout:"
106: + e.getMessage());
107: }
108: return timeout;
109: }
110:
111: /**
112: * Javadoc for this public method is generated via
113: * the doc templates in the doc_src directory.
114: */
115: public void setReadOnly(boolean readOnly) {
116:
117: DbConfigManager.setVal(props, EnvironmentParams.ENV_RDONLY,
118: Boolean.toString(readOnly), validateParams);
119: }
120:
121: /**
122: * Javadoc for this public method is generated via
123: * the doc templates in the doc_src directory.
124: */
125: public boolean getReadOnly() {
126:
127: String val = DbConfigManager.getVal(props,
128: EnvironmentParams.ENV_RDONLY);
129: return (Boolean.valueOf(val)).booleanValue();
130: }
131:
132: /**
133: * Javadoc for this public method is generated via
134: * the doc templates in the doc_src directory.
135: */
136: public void setTransactional(boolean transactional) {
137:
138: DbConfigManager.setVal(props, EnvironmentParams.ENV_INIT_TXN,
139: Boolean.toString(transactional), validateParams);
140: }
141:
142: /**
143: * Javadoc for this public method is generated via
144: * the doc templates in the doc_src directory.
145: */
146: public boolean getTransactional() {
147:
148: String val = DbConfigManager.getVal(props,
149: EnvironmentParams.ENV_INIT_TXN);
150: return (Boolean.valueOf(val)).booleanValue();
151: }
152:
153: /**
154: * Javadoc for this public method is generated via
155: * the doc templates in the doc_src directory.
156: */
157: public void setLocking(boolean locking) {
158:
159: DbConfigManager.setVal(props,
160: EnvironmentParams.ENV_INIT_LOCKING, Boolean
161: .toString(locking), validateParams);
162: }
163:
164: /**
165: * Javadoc for this public method is generated via
166: * the doc templates in the doc_src directory.
167: */
168: public boolean getLocking() {
169:
170: String val = DbConfigManager.getVal(props,
171: EnvironmentParams.ENV_INIT_LOCKING);
172: return (Boolean.valueOf(val)).booleanValue();
173: }
174:
175: /**
176: * Javadoc for this public method is generated via
177: * the doc templates in the doc_src directory.
178: */
179: public void setTxnTimeout(long timeout)
180: throws IllegalArgumentException {
181:
182: DbConfigManager.setVal(props, EnvironmentParams.TXN_TIMEOUT,
183: Long.toString(timeout), validateParams);
184: }
185:
186: /**
187: * Javadoc for this public method is generated via
188: * the doc templates in the doc_src directory.
189: */
190: public long getTxnTimeout() {
191:
192: String val = DbConfigManager.getVal(props,
193: EnvironmentParams.TXN_TIMEOUT);
194: long timeout = 0;
195: try {
196: timeout = Long.parseLong(val);
197: } catch (NumberFormatException e) {
198: throw new IllegalArgumentException("Bad value for timeout:"
199: + e.getMessage());
200: }
201: return timeout;
202: }
203:
204: /**
205: * Javadoc for this public method is generated via
206: * the doc templates in the doc_src directory.
207: */
208: public void setTxnSerializableIsolation(
209: boolean txnSerializableIsolation) {
210:
211: DbConfigManager.setVal(props,
212: EnvironmentParams.TXN_SERIALIZABLE_ISOLATION, Boolean
213: .toString(txnSerializableIsolation),
214: validateParams);
215: }
216:
217: /**
218: * Javadoc for this public method is generated via
219: * the doc templates in the doc_src directory.
220: */
221: public boolean getTxnSerializableIsolation() {
222:
223: String val = DbConfigManager.getVal(props,
224: EnvironmentParams.TXN_SERIALIZABLE_ISOLATION);
225: return (Boolean.valueOf(val)).booleanValue();
226: }
227:
228: /**
229: * Javadoc for this public method is generated via
230: * the doc templates in the doc_src directory.
231: */
232: public void setExceptionListener(ExceptionListener exceptionListener) {
233: this .exceptionListener = exceptionListener;
234: }
235:
236: /**
237: * Javadoc for this public method is generated via
238: * the doc templates in the doc_src directory.
239: */
240: public ExceptionListener getExceptionListener() {
241: return exceptionListener;
242: }
243:
244: /**
245: * For unit testing, to set readCommitted as the default.
246: */
247: void setTxnReadCommitted(boolean txnReadCommitted) {
248:
249: this .txnReadCommitted = txnReadCommitted;
250: }
251:
252: /**
253: * For unit testing, to set readCommitted as the default.
254: */
255: boolean getTxnReadCommitted() {
256:
257: return txnReadCommitted;
258: }
259:
260: /**
261: * Javadoc for this public method is generated via
262: * the doc templates in the doc_src directory.
263: */
264: public void setConfigParam(String paramName, String value)
265: throws IllegalArgumentException {
266:
267: DbConfigManager.setConfigParam(props, paramName, value, false, /* requireMutablity */
268: validateParams, false /* forReplication */);
269: }
270:
271: /**
272: * For unit testing, to prevent creating the utilization profile DB.
273: */
274: void setCreateUP(boolean createUP) {
275: this .createUP = createUP;
276: }
277:
278: /**
279: * For unit testing, to prevent creating the utilization profile DB.
280: */
281: boolean getCreateUP() {
282: return createUP;
283: }
284:
285: /**
286: * For unit testing, to prevent writing utilization data during checkpoint.
287: */
288: void setCheckpointUP(boolean checkpointUP) {
289: this .checkpointUP = checkpointUP;
290: }
291:
292: /**
293: * For unit testing, to prevent writing utilization data during checkpoint.
294: */
295: boolean getCheckpointUP() {
296: return checkpointUP;
297: }
298:
299: /**
300: * Used by Environment to create a copy of the application
301: * supplied configuration.
302: */
303: EnvironmentConfig cloneConfig() {
304: try {
305: return (EnvironmentConfig) clone();
306: } catch (CloneNotSupportedException willNeverOccur) {
307: return null;
308: }
309: }
310:
311: public String toString() {
312: return ("allowCreate=" + allowCreate + "\n" + super.toString());
313: }
314: }
|