mirror of
https://github.com/berkeleydb/je.git
synced 2024-11-15 01:46:24 +00:00
157 lines
6.4 KiB
HTML
157 lines
6.4 KiB
HTML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||
<title>Administrative Methods</title>
|
||
<link rel="stylesheet" href="gettingStarted.css" type="text/css" />
|
||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
|
||
<link rel="start" href="index.html" title="Getting Started with Berkeley DB Java Edition" />
|
||
<link rel="up" href="databases.html" title="Chapter 7. Databases" />
|
||
<link rel="prev" href="dbprops.html" title="Database Properties" />
|
||
<link rel="next" href="dbUsage.html" title="Database Example" />
|
||
</head>
|
||
<body>
|
||
<div xmlns="" class="navheader">
|
||
<div class="libver">
|
||
<p>Library Version 12.2.7.5</p>
|
||
</div>
|
||
<table width="100%" summary="Navigation header">
|
||
<tr>
|
||
<th colspan="3" align="center">Administrative Methods</th>
|
||
</tr>
|
||
<tr>
|
||
<td width="20%" align="left"><a accesskey="p" href="dbprops.html">Prev</a> </td>
|
||
<th width="60%" align="center">Chapter 7. Databases</th>
|
||
<td width="20%" align="right"> <a accesskey="n" href="dbUsage.html">Next</a></td>
|
||
</tr>
|
||
</table>
|
||
<hr />
|
||
</div>
|
||
<div class="sect1" lang="en" xml:lang="en">
|
||
<div class="titlepage">
|
||
<div>
|
||
<div>
|
||
<h2 class="title" style="clear: both"><a id="DBAdmin"></a>Administrative Methods</h2>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>
|
||
Both the <code class="classname">Environment</code> and
|
||
<code class="classname">Database</code> classes provide methods that are useful
|
||
for manipulating databases. These methods are:
|
||
</p>
|
||
<div class="itemizedlist">
|
||
<ul type="disc">
|
||
<li>
|
||
<p>
|
||
<code class="methodname">Database.getDatabaseName()</code>
|
||
</p>
|
||
<p>Returns the database's name.</p>
|
||
<a id="je_db3.1"></a>
|
||
<pre class="programlisting">String dbName = myDatabase.getDatabaseName();</pre>
|
||
<span>
|
||
</span>
|
||
</li>
|
||
<li>
|
||
<p>
|
||
<code class="methodname">Database.getEnvironment()</code>
|
||
</p>
|
||
<p>Returns the <code class="classname">Environment</code> that contains this database.</p>
|
||
<a id="je_db4"></a>
|
||
<pre class="programlisting">Environment theEnv = myDatabase.getEnvironment();</pre>
|
||
</li>
|
||
<li>
|
||
<p>
|
||
<code class="methodname">Database.preload()</code>
|
||
</p>
|
||
<p>Preloads the database into the in-memory cache. Optionally takes
|
||
a <code class="literal">long</code> that identifies the maximum number of bytes to load into the
|
||
cache. If this parameter is not supplied, the maximum memory usage
|
||
allowed by the evictor thread is used.
|
||
</p>
|
||
<a id="je_db6"></a>
|
||
<pre class="programlisting">myDatabase.preload(1048576l); // 1024*1024</pre>
|
||
</li>
|
||
<li>
|
||
<p>
|
||
<code class="methodname">Environment.getDatabaseNames()</code>
|
||
</p>
|
||
<p>Returns a list of Strings of all the databases contained by the
|
||
environment.</p>
|
||
<a id="je_db7"></a>
|
||
<pre class="programlisting">import java.util.List;
|
||
...
|
||
List myDbNames = myDbEnv.getDatabaseNames();
|
||
for(int i=0; i < myDbNames.size(); i++) {
|
||
System.out.println("Database Name: " + (String)myDbNames.get(i));
|
||
}</pre>
|
||
</li>
|
||
<li>
|
||
<p>
|
||
<code class="methodname">Environment.removeDatabase()</code>
|
||
</p>
|
||
<p>Deletes the database. The database must be closed when you
|
||
perform this action on it.</p>
|
||
<a id="je_db8"></a>
|
||
<pre class="programlisting">String dbName = myDatabase.getDatabaseName();
|
||
myDatabase.close();
|
||
myDbEnv.removeDatabase(null, dbName);</pre>
|
||
</li>
|
||
<li>
|
||
<p>
|
||
<code class="methodname">Environment.renameDatabase()</code>
|
||
</p>
|
||
<p>Renames the database. The database must be closed when you
|
||
perform this action on it.</p>
|
||
<a id="je_db9"></a>
|
||
<pre class="programlisting">String oldName = myDatabase.getDatabaseName();
|
||
String newName = new String(oldName + ".new", "UTF-8");
|
||
myDatabase.close();
|
||
myDbEnv.renameDatabase(null, oldName, newName);</pre>
|
||
</li>
|
||
<li>
|
||
<p>
|
||
<code class="methodname">Environment.truncateDatabase()</code>
|
||
</p>
|
||
<p>
|
||
Deletes every record in the database and optionally returns the
|
||
number of records that were deleted. Note that it is much less
|
||
expensive to truncate a database without counting the number of
|
||
records deleted than it is to truncate and count.
|
||
</p>
|
||
<a id="je_db5"></a>
|
||
<pre class="programlisting">int numDiscarded =
|
||
myEnv.truncate(null, // txn handle
|
||
myDatabase.getDatabaseName(), // database name
|
||
true); // If true, then the
|
||
// number of records
|
||
// deleted are counted.
|
||
System.out.println("Discarded " + numDiscarded +
|
||
" records from database " +
|
||
myDatabase.getDatabaseName()); </pre>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div class="navfooter">
|
||
<hr />
|
||
<table width="100%" summary="Navigation footer">
|
||
<tr>
|
||
<td width="40%" align="left"><a accesskey="p" href="dbprops.html">Prev</a> </td>
|
||
<td width="20%" align="center">
|
||
<a accesskey="u" href="databases.html">Up</a>
|
||
</td>
|
||
<td width="40%" align="right"> <a accesskey="n" href="dbUsage.html">Next</a></td>
|
||
</tr>
|
||
<tr>
|
||
<td width="40%" align="left" valign="top">Database Properties </td>
|
||
<td width="20%" align="center">
|
||
<a accesskey="h" href="index.html">Home</a>
|
||
</td>
|
||
<td width="40%" align="right" valign="top"> Database Example</td>
|
||
</tr>
|
||
</table>
|
||
</div>
|
||
</body>
|
||
</html>
|