1 8 9 package com.sleepycat.je; 10 11 import java.util.Properties ; 12 13 import com.sleepycat.je.config.EnvironmentParams; 14 import com.sleepycat.je.dbi.DbConfigManager; 15 16 20 public class EnvironmentConfig extends EnvironmentMutableConfig { 21 25 public static final EnvironmentConfig DEFAULT = new EnvironmentConfig(); 26 27 30 private boolean createUP = true; 31 32 35 private boolean checkpointUP = true; 36 37 private boolean allowCreate = false; 38 39 42 private boolean txnReadCommitted = false; 43 44 private ExceptionListener exceptionListener = null; 45 46 50 public EnvironmentConfig() { 51 super(); 52 } 53 54 58 public EnvironmentConfig(Properties properties) 59 throws IllegalArgumentException { 60 61 super(properties); 62 } 63 64 68 public void setAllowCreate(boolean allowCreate) { 69 70 this.allowCreate = allowCreate; 71 } 72 73 77 public boolean getAllowCreate() { 78 79 return allowCreate; 80 } 81 82 86 public void setLockTimeout(long timeout) 87 throws IllegalArgumentException { 88 89 DbConfigManager.setVal(props, 90 EnvironmentParams.LOCK_TIMEOUT, 91 Long.toString(timeout), 92 validateParams); 93 } 94 95 99 public long getLockTimeout() { 100 101 String val = DbConfigManager.getVal(props, 102 EnvironmentParams.LOCK_TIMEOUT); 103 long timeout = 0; 104 try { 105 timeout = Long.parseLong(val); 106 } catch (NumberFormatException e) { 107 throw new IllegalArgumentException 108 ("Bad value for timeout:" + e.getMessage()); 109 } 110 return timeout; 111 } 112 113 117 public void setReadOnly(boolean readOnly) { 118 119 DbConfigManager.setVal(props, 120 EnvironmentParams.ENV_RDONLY, 121 Boolean.toString(readOnly), 122 validateParams); 123 } 124 125 129 public boolean getReadOnly() { 130 131 String val = DbConfigManager.getVal(props, 132 EnvironmentParams.ENV_RDONLY); 133 return (Boolean.valueOf(val)).booleanValue(); 134 } 135 136 140 public void setTransactional(boolean transactional) { 141 142 DbConfigManager.setVal(props, 143 EnvironmentParams.ENV_INIT_TXN, 144 Boolean.toString(transactional), 145 validateParams); 146 } 147 148 152 public boolean getTransactional() { 153 154 String val = DbConfigManager.getVal(props, 155 EnvironmentParams.ENV_INIT_TXN); 156 return (Boolean.valueOf(val)).booleanValue(); 157 } 158 159 163 public void setLocking(boolean locking) { 164 165 DbConfigManager.setVal(props, 166 EnvironmentParams.ENV_INIT_LOCKING, 167 Boolean.toString(locking), 168 validateParams); 169 } 170 171 175 public boolean getLocking() { 176 177 String val = 178 DbConfigManager.getVal(props, EnvironmentParams.ENV_INIT_LOCKING); 179 return (Boolean.valueOf(val)).booleanValue(); 180 } 181 182 186 public void setTxnTimeout(long timeout) 187 throws IllegalArgumentException { 188 189 DbConfigManager.setVal(props, 190 EnvironmentParams.TXN_TIMEOUT, 191 Long.toString(timeout), 192 validateParams); 193 } 194 195 199 public long getTxnTimeout() { 200 201 String val = DbConfigManager.getVal(props, 202 EnvironmentParams.TXN_TIMEOUT); 203 long timeout = 0; 204 try { 205 timeout = Long.parseLong(val); 206 } catch (NumberFormatException e) { 207 throw new IllegalArgumentException 208 ("Bad value for timeout:" + e.getMessage()); 209 } 210 return timeout; 211 } 212 213 217 public void setTxnSerializableIsolation(boolean txnSerializableIsolation) { 218 219 DbConfigManager.setVal(props, 220 EnvironmentParams.TXN_SERIALIZABLE_ISOLATION, 221 Boolean.toString(txnSerializableIsolation), 222 validateParams); 223 } 224 225 229 public boolean getTxnSerializableIsolation() { 230 231 String val = 232 DbConfigManager.getVal(props, 233 EnvironmentParams.TXN_SERIALIZABLE_ISOLATION); 234 return (Boolean.valueOf(val)).booleanValue(); 235 } 236 237 241 public void setExceptionListener(ExceptionListener exceptionListener) { 242 this.exceptionListener = exceptionListener; 243 } 244 245 249 public ExceptionListener getExceptionListener() { 250 return exceptionListener; 251 } 252 253 256 void setTxnReadCommitted(boolean txnReadCommitted) { 257 258 this.txnReadCommitted = txnReadCommitted; 259 } 260 261 264 boolean getTxnReadCommitted() { 265 266 return txnReadCommitted; 267 } 268 269 273 public void setConfigParam(String paramName, 274 String value) 275 throws IllegalArgumentException { 276 277 DbConfigManager.setConfigParam(props, 278 paramName, 279 value, 280 false, 281 validateParams, 282 false ); 283 } 284 285 288 void setCreateUP(boolean createUP) { 289 this.createUP = createUP; 290 } 291 292 295 boolean getCreateUP() { 296 return createUP; 297 } 298 299 302 void setCheckpointUP(boolean checkpointUP) { 303 this.checkpointUP = checkpointUP; 304 } 305 306 309 boolean getCheckpointUP() { 310 return checkpointUP; 311 } 312 313 317 EnvironmentConfig cloneConfig() { 318 try { 319 return (EnvironmentConfig) clone(); 320 } catch (CloneNotSupportedException willNeverOccur) { 321 return null; 322 } 323 } 324 325 public String toString() { 326 return ("allowCreate=" + allowCreate + "\n" + super.toString()); 327 } 328 } 329 | Popular Tags |