Removing and Renaming Objects

Operations that remove or rename an environment, a database or a sequence object require care. First, operations on the same object must be serialized. For example, you cannot rename and remove a database simultaneously. Second, they cannot be performed if there are still open handles on the object. To solve the first issue, operations on the same objects are serialized explicitly by the server program. To solve the second issue, the driver APIs for these operations behave slightly differently from the Java base APIs.

In the driver APIs, each of these functions has a boolean argument force. If this argument is set to true, all handles opened on the object to be removed or renamed are automatically closed by the server, so the operation can proceed. If this argument is set to false, the operation is executed only if there is no open handle on the object; otherwise, the function throws a SResourceInUseException exception.

For example, if you want to remove a database even if someone is still using it, you can call SEnvironment.removeDatabase with the force parameter set to true:

BdbServerConnection conn = ...;
SEnvironment env = conn.openEnvironment("env", null);

// Force the database to be deleted.
env.removeDatabase(null, "db", null, true);

If you want to remove a database, but only when no one is using it, you can call the same function with the force parameter set to false:

BdbServerConnection conn = ...;
SEnvironment env = conn.openEnvironment("env", null);

try {
    // Try to remove the database if no one is using it.
    env.removeDatabase(null, "db", null, false);
    // The database is removed successfully.
} catch (SResourceInUseException e) {
    // Someone is still using the database and the database
    // is not removed
}