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