1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>Environment Properties</title> 7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.62.4" /> 9 <link rel="home" href="index.html" title="Getting Started with Berkeley DB" /> 10 <link rel="up" href="Env.html" title="Chapter��2.��Database Environments" /> 11 <link rel="previous" href="EnvClose.html" title="Closing Database Environments" /> 12 <link rel="next" href="dpl.html" title="Part��I.��Programming with the Direct Persistence Layer" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Environment Properties</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="EnvClose.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��2.��Database Environments</th> 23 <td width="20%" align="right">��<a accesskey="n" href="dpl.html">Next</a></td> 24 </tr> 25 </table> 26 <hr /> 27 </div> 28 <div class="sect1" lang="en" xml:lang="en"> 29 <div class="titlepage"> 30 <div> 31 <div> 32 <h2 class="title" style="clear: both"><a id="EnvProps"></a>Environment Properties</h2> 33 </div> 34 </div> 35 <div></div> 36 </div> 37 <p>You set properties for the <tt class="classname">Environment</tt> using 38 the <tt class="classname">EnvironmentConfig</tt> class. You can also set properties for a specific 39 <tt class="classname">Environment</tt> instance using <tt class="classname">EnvironmentMutableConfig</tt>. 40 </p> 41 <div class="sect2" lang="en" xml:lang="en"> 42 <div class="titlepage"> 43 <div> 44 <div> 45 <h3 class="title"><a id="envconfig"></a>The EnvironmentConfig Class</h3> 46 </div> 47 </div> 48 <div></div> 49 </div> 50 <p> 51 The <tt class="classname">EnvironmentConfig</tt> class makes a 52 large number of fields and methods available to you. Describing all of these 53 tuning parameters is beyond the scope of this manual. However, there are a 54 few properties that you are likely to want to set. They are described 55 here.</p> 56 <p>Note that for each of the properties that you can commonly set, there is a 57 corresponding getter method. Also, you can always retrieve the 58 <tt class="classname">EnvironmentConfig</tt> object used by your environment 59 using the <tt class="methodname">Environment.getConfig()</tt> method. 60 </p> 61 <p> 62 You set environment configuration parameters using the following methods on the 63 <tt class="classname">EnvironmentConfig</tt> class: 64 </p> 65 <div class="itemizedlist"> 66 <ul type="disc"> 67 <li> 68 <p> 69 <tt class="methodname">EnvironmentConfig.setAllowCreate()</tt> 70 </p> 71 <p>If <tt class="literal">true</tt>, the database environment is created 72 when it is opened. If <tt class="literal">false</tt>, environment open fails if the environment 73 does not exist. This property has no meaning if the database 74 environment already exists. Default is <tt class="literal">false</tt>.</p> 75 </li> 76 <li> 77 <p> 78 <tt class="methodname">EnvironmentConfig.setReadOnly()</tt> 79 </p> 80 <p>If <tt class="literal">true</tt>, then all databases opened in this 81 environment must be opened as read-only. If you are writing a 82 multi-process application, then all but one of your processes must set 83 this value to <tt class="literal">true</tt>. Default is <tt class="literal">false</tt>.</p> 84 </li> 85 <li> 86 <p> 87 <tt class="methodname">EnvironmentConfig.setTransactional()</tt> 88 </p> 89 <p>If <tt class="literal">true</tt>, configures the database environment 90 to support transactions. Default is <tt class="literal">false</tt>.</p> 91 </li> 92 </ul> 93 </div> 94 <p>For example:</p> 95 <pre class="programlisting">package db.gettingStarted; 96 97import com.sleepycat.db.DatabaseException; 98import com.sleepycat.db.Environment; 99import com.sleepycat.db.EnvironmentConfig; 100 101import java.io.File; 102import java.io.FileNotFoundException; 103 104... 105 106Environment myDatabaseEnvironment = null; 107try { 108 EnvironmentConfig envConfig = new EnvironmentConfig(); 109 envConfig.setAllowCreate(true); 110 envConfig.setTransactional(true); 111 myDatabaseEnvironment = 112 new Environment(new File("/export/dbEnv"), envConfig); 113} catch (DatabaseException dbe) { 114 System.err.println(dbe.toString()); 115 System.exit(1); 116} catch (FileNotFoundException fnfe) { 117 System.err.println(fnfe.toString()); 118 System.exit(-1); 119} </pre> 120 </div> 121 <div class="sect2" lang="en" xml:lang="en"> 122 <div class="titlepage"> 123 <div> 124 <div> 125 <h3 class="title"><a id="envhandleconfig"></a>EnvironmentMutableConfig</h3> 126 </div> 127 </div> 128 <div></div> 129 </div> 130 <p> 131 <tt class="classname">EnvironmentMutableConfig</tt> manages properties that can be reset after the 132 <tt class="classname">Environment</tt> object has been constructed. In addition, <tt class="classname">EnvironmentConfig</tt> 133 extends <tt class="classname">EnvironmentMutableConfig</tt>, so you can set these mutable properties at 134 <tt class="classname">Environment</tt> construction time if necessary. 135 </p> 136 <p> 137 The <tt class="classname">EnvironmentMutableConfig</tt> class allows you to set the following 138 properties: 139 </p> 140 <div class="itemizedlist"> 141 <ul type="disc"> 142 <li> 143 <p> 144 <tt class="literal">setCachePercent()</tt> 145 </p> 146 <p> 147 Determines the percentage of JVM memory available to the DB cache. 148 See <a href="cachesize.html">Selecting the Cache Size</a> 149 for more information. 150 </p> 151 </li> 152 <li> 153 <p> 154 <tt class="literal">setCacheSize()</tt> 155 </p> 156 <p> 157 Determines the total amount of memory available to the database cache. 158 See <a href="cachesize.html">Selecting the Cache Size</a> 159 for more information. 160 </p> 161 </li> 162 <li> 163 <p> 164 <tt class="literal">setTxnNoSync()</tt> 165 </p> 166 <p> 167 Determines whether change records created due to a transaction commit are written to the backing 168 log files on disk. A value of <tt class="literal">true</tt> causes 169 the data to not be flushed to 170 disk. See the 171 172 <i class="citetitle">Getting Started with Transaction Processing for Java</i> 173 guide for more information. 174 </p> 175 </li> 176 <li> 177 <p> 178 <tt class="literal">setTxnWriteNoSync()</tt> 179 </p> 180 <p> 181 Determines whether logs are flushed on transaction commit (the logs are still written, however). 182 By setting this value to <tt class="literal">true</tt>, you potentially gain better performance than if 183 you flush the logs on commit, but you do so by losing some of your transaction durability guarantees. 184 See the 185 186 <i class="citetitle">Getting Started with Transaction Processing for Java</i> 187 guide for more information. 188 </p> 189 </li> 190 </ul> 191 </div> 192 <p> 193 There is also a corresponding getter method (<tt class="methodname">getTxnNoSync()</tt>). 194 Moreover, you can always retrieve your environment's 195 <tt class="classname">EnvironmentMutableConfig</tt> object by 196 using the <tt class="methodname">Environment.getMutableConfig()</tt> method. 197 </p> 198 <p> 199 For example: 200 </p> 201 <pre class="programlisting">package db.gettingStarted; 202 203import com.sleepycat.db.DatabaseException; 204import com.sleepycat.db.Environment; 205import com.sleepycat.db.EnvironmentMutableConfig; 206 207import java.io.File; 208import java.io.FileNotFoundException; 209 210 211... 212 213try { 214 Environment myEnv = new Environment(new File("/export/dbEnv"), null); 215 EnvironmentMutableConfig envMutableConfig = 216 new EnvironmentMutableConfig(); 217 envMutableConfig.setTxnNoSync(true); 218 myEnv.setMutableConfig(envMutableConfig); 219} catch (DatabaseException dbe) { 220 // Exception handling goes here 221} catch (FileNotFoundException fnfe) { 222 // Exception handling goes here 223}</pre> 224 </div> 225 </div> 226 <div class="navfooter"> 227 <hr /> 228 <table width="100%" summary="Navigation footer"> 229 <tr> 230 <td width="40%" align="left"><a accesskey="p" href="EnvClose.html">Prev</a>��</td> 231 <td width="20%" align="center"> 232 <a accesskey="u" href="Env.html">Up</a> 233 </td> 234 <td width="40%" align="right">��<a accesskey="n" href="dpl.html">Next</a></td> 235 </tr> 236 <tr> 237 <td width="40%" align="left" valign="top">Closing Database Environments��</td> 238 <td width="20%" align="center"> 239 <a accesskey="h" href="index.html">Home</a> 240 </td> 241 <td width="40%" align="right" valign="top">��Part��I.��Programming with the Direct Persistence Layer</td> 242 </tr> 243 </table> 244 </div> 245 </body> 246</html> 247