1<?xml version="1.0" encoding="ISO-8859-1" 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=ISO-8859-1" />
6    <title>Database 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="DB.html" title="Chapter�2.�Databases" />
11    <link rel="previous" href="coredbclose.html" title="Closing Databases" />
12    <link rel="next" href="DBAdmin.html" title="Administrative Methods" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Database Properties</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="coredbclose.html">Prev</a>�</td>
22          <th width="60%" align="center">Chapter�2.�Databases</th>
23          <td width="20%" align="right">�<a accesskey="n" href="DBAdmin.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="db_config"></a>Database Properties</h2>
33          </div>
34        </div>
35        <div></div>
36      </div>
37      <p>You can set database properties using the <tt class="classname">DatabaseConfig</tt>
38    class. For each of the properties that you can set, there is a
39    corresponding getter method. Also, you can always retrieve the
40    <tt class="classname">DatabaseConfig</tt> object used by your database using
41    the <tt class="methodname">Database.getConfig()</tt> method.</p>
42      <p>
43        There are a large number of properties that you can set using this
44        class (see the javadoc for a complete listing). From the perspective of
45        this manual, some of the more interesting properties are:
46    </p>
47      <div class="itemizedlist">
48        <ul type="disc">
49          <li>
50            <p>
51              <tt class="methodname">DatabaseConfig.setAllowCreate()</tt>
52            </p>
53            <p>If <tt class="literal">true</tt>, the database is created when it is
54        opened. If false, the database open fails if the database does not
55        exist. This property has no meaning if the database currently exists.
56        Default is <tt class="literal">false</tt>.</p>
57          </li>
58          <li>
59            <p>
60              <tt class="methodname">DatabaseConfig.setBtreeComparator()</tt>
61            </p>
62            <p>Sets the class that is used to compare the keys found on two
63        database records. This class is used to determine the sort order for
64        two records in the database. For more information, see 
65        
66        <span><a href="btree.html#comparators">Setting Comparison Functions</a>.</span>
67        </p>
68          </li>
69          <li>
70            <p>
71              <tt class="methodname">DatabaseConfig.setDuplicateComparator()</tt>
72            </p>
73            <p>
74            Sets the class that is used to compare two duplicate records in
75            the database.  For more information, see 
76            
77            <span><a href="btree.html#comparators">Setting Comparison Functions</a>.</span>
78        </p>
79          </li>
80          <li>
81            <p>
82              <tt class="methodname">DatabaseConfig.setSortedDuplicates()</tt>
83            </p>
84            <p>If <tt class="literal">true</tt>, duplicate records are allowed in the
85        database.  If this value is <tt class="literal">false</tt>, then putting a duplicate record into the database
86        results in the replacement of the old record with the new record.
87        Note that this property can be set only at database creation time. Default is <tt class="literal">false</tt>. 
88        </p>
89          </li>
90          <li>
91            <p>
92              <tt class="methodname">DatabaseConfig.setExclusiveCreate()</tt>
93            </p>
94            <p>If <tt class="literal">true</tt>, the database open fails if the
95        database currently exists. That is, the open must result in the
96        creation of a new database. Default is <tt class="literal">false</tt>.</p>
97          </li>
98          <li>
99            <p>
100              <tt class="methodname">DatabaseConfig.setReadOnly()</tt>
101            </p>
102            <p>If true, the database is opened for read activities only.
103        Default is <tt class="literal">false</tt>.</p>
104          </li>
105          <li>
106            <p>
107              <tt class="methodname">DatabaseConfig.setTruncate()</tt>
108            </p>
109            <p>If true, the database is truncated; that is, it is emptied of all
110        content.
111        </p>
112          </li>
113          <li>
114            <p>
115              <tt class="methodname">DatabaseConfig.setType()</tt>
116            </p>
117            <p>Identifies the type of database that you want to create. This
118        manual will exclusively use <tt class="literal">DatabaseType.BTREE</tt>. 
119        </p>
120          </li>
121        </ul>
122      </div>
123      <p>
124        In addition to these, there are also methods that allow you to
125        control the IO stream used for error reporting purposes. 
126        These are described later in this manual.
127    </p>
128      <p>For example:</p>
129      <a id="java_db3"></a>
130      <pre class="programlisting">package com.sleepycat.examples.db.GettingStarted;
131
132import com.sleepycat.db.Database;
133import com.sleepycat.db.DatabaseConfig;
134import com.sleepycat.db.DatabaseException;
135import com.sleepycat.db.DatabaseType;
136
137import java.io.FileNotFoundException;
138
139...
140Database myDatabase = null;
141try {
142    DatabaseConfig dbConfig = new DatabaseConfig();
143    dbConfig.setAllowCreate(true);
144    dbConfig.setSortedDuplicates(true);
145    dbConfig.setType(DatabaseType.BTREE);
146    myDatabase = new Database("sampleDatabase.db",
147                              null,
148                              dbConfig); 
149} catch (DatabaseException dbe) {
150    // Exception handling goes here.
151} catch (FileNotFoundException fnfe) {
152    // Exception handling goes here
153}</pre>
154    </div>
155    <div class="navfooter">
156      <hr />
157      <table width="100%" summary="Navigation footer">
158        <tr>
159          <td width="40%" align="left"><a accesskey="p" href="coredbclose.html">Prev</a>�</td>
160          <td width="20%" align="center">
161            <a accesskey="u" href="DB.html">Up</a>
162          </td>
163          <td width="40%" align="right">�<a accesskey="n" href="DBAdmin.html">Next</a></td>
164        </tr>
165        <tr>
166          <td width="40%" align="left" valign="top">Closing Databases�</td>
167          <td width="20%" align="center">
168            <a accesskey="h" href="index.html">Home</a>
169          </td>
170          <td width="40%" align="right" valign="top">�Administrative Methods</td>
171        </tr>
172      </table>
173    </div>
174  </body>
175</html>
176