public class SEnvironment extends java.lang.Object implements TxnHelper, java.lang.AutoCloseable
To open an existing environment with default attributes the application may use a default environment configuration object or null:
// Open an environment handle with default attributes. BdbServerConnection conn = BdbServerConnection.connect(host, port); SEnvironment env = conn.openEnvironment(home, new SEnvironmentConfig());or
SEnvironment env = conn.openEnvironment(home, null);Note that many SEnvironment objects may access a single environment.
To create an environment or customize attributes, the application should customize the configuration class. For example:
SEnvironmentConfig envConfig = new SEnvironmentConfig(); envConfig.setAllowCreate(true).setCacheSize(1000000); ... SEnvironment env = conn.openEnvironment(home, envConfig);An environment handle is an SEnvironment instance. More than one SEnvironment instance may be created for the same physical directory, which is the same as saying that more than one SEnvironment handle may be open at one time for a given environment.
The SEnvironment handle should not be closed while any other handle remains open that is using it as a reference (for example, SDatabase or STransaction). Once SEnvironment.close is called, this object may not be accessed again, regardless of whether or not it throws an exception.
TxnHelper.TransactionOperations<V>
Modifier | Constructor and Description |
---|---|
protected |
SEnvironment(SEnvironment env)
Create a shallow copy of the given environment.
|
Modifier and Type | Method and Description |
---|---|
STransaction |
beginTransaction(STransaction parent,
STransactionConfig config)
Create a new transaction in the database environment.
|
void |
checkpoint(SCheckpointConfig config)
Synchronously checkpoint the database environment.
|
void |
close()
Close the database environment, freeing any allocated resources and
closing any underlying subsystems.
|
SCacheFileStats[] |
getCacheFileStats(SStatsConfig config)
Return statistics for individual files in the cache.
|
SCacheStats |
getCacheStats(SStatsConfig config)
Returns the memory pool (that is, the buffer cache) subsystem
statistics.
|
SEnvironmentConfig |
getConfig()
Return this object's configuration.
|
SEnvironment |
getEnvironment()
Return this environment.
|
java.lang.String |
getHome()
Return the database environment home directory.
|
SLockStats |
getLockStats(SStatsConfig config)
Return the database environment's locking statistics.
|
SLogStats |
getLogStats(SStatsConfig config)
Return the database environment's logging statistics.
|
SMultiStats |
getMultipleStats(SMultiStatsConfig config)
Return multiple database environment's statistics.
|
SMutexStats |
getMutexStats(SStatsConfig config)
Return the database environment's mutex statistics.
|
java.nio.ByteOrder |
getServerByteOrder()
Return the native byte order of the connected server.
|
STransactionStats |
getTransactionStats(SStatsConfig config)
Return the database environment's transactional statistics.
|
default <V> V |
handleRuntimeExceptions(com.sleepycat.client.RemoteServiceCallable<V> remote) |
SDatabase |
openDatabase(STransaction txn,
java.lang.String fileName,
java.lang.String databaseName,
SDatabaseConfig config)
Open a database.
|
SSecondaryDatabase |
openSecondaryDatabase(STransaction txn,
java.lang.String fileName,
java.lang.String databaseName,
SDatabase primaryDatabase,
SSecondaryConfig config)
Open a secondary database.
|
default <V> V |
remoteCall(com.sleepycat.client.RemoteServiceCallable<V> remote) |
default <V> V |
remoteCallWithIOException(com.sleepycat.client.RemoteServiceCallable<V> remote) |
void |
removeDatabase(STransaction txn,
java.lang.String fileName,
java.lang.String databaseName,
boolean force)
Remove the database specified by the fileName and databaseName
parameters.
|
void |
renameDatabase(STransaction txn,
java.lang.String fileName,
java.lang.String databaseName,
java.lang.String newName,
boolean force)
Rename a database.
|
void |
setConfig(SEnvironmentConfig config)
Change the settings in an existing environment handle.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
runInSingleTxn, runInSingleTxnWithIOException
protected SEnvironment(SEnvironment env)
env
- the environmentpublic void close() throws SDatabaseException
When you call this method, all open database and cursor handles that depend on this are closed automatically, and should not be reused.
The SEnvironment handle should not be closed while any other handle that refers to it is not yet closed.
Closing the environment aborts any unresolved transactions. Applications should not depend on this behavior for transactions involving databases; all such transactions should be explicitly resolved. The problem with depending on this semantic is that aborting an unresolved transaction involving database operations requires a database handle. Because the database handles should have been closed before closing the environment, it will not be possible to abort the transaction, and recovery will have to be run on the database environment before further operations are done.
After this method has been called, regardless of its return, the SEnvironment handle may not be accessed again.
close
in interface java.lang.AutoCloseable
SDatabaseException
- if any error occurspublic SEnvironment getEnvironment()
getEnvironment
in interface TxnHelper
public java.nio.ByteOrder getServerByteOrder()
public SEnvironmentConfig getConfig() throws SDatabaseException
SDatabaseException
- if any error occurspublic void setConfig(SEnvironmentConfig config) throws SDatabaseException
getConfig()
to get the current setting because unset attributes are
not changed.config
- the database environment attributes; if null, no attribute
is changedSDatabaseException
- if any error occurspublic java.lang.String getHome()
BdbServerConnection.openEnvironment(String,
SEnvironmentConfig)
.public SDatabase openDatabase(STransaction txn, java.lang.String fileName, java.lang.String databaseName, SDatabaseConfig config) throws java.io.IOException, SDatabaseException
The database is represented by the file and database parameters.
The currently supported database file formats (or access methods) are Btree, Hash, Queue, and Recno. The Btree format is a representation of a sorted, balanced tree structure. The Hash format is an extensible, dynamic hashing scheme. The Queue format supports fast access to fixed-length records accessed sequentially or by logical record number. The Recno format supports fixed- or variable-length records, accessed sequentially or by logical record number.
Storage and retrieval are based on key/data pairs; see SDatabaseEntry
for more information.
Opening a database is a relatively expensive operation, and maintaining a set of open databases will normally be preferable to repeatedly opening and closing the database for each new query.
txn
- for a transactional database, an explicit transaction may be
specified, or null may be specified to use auto-commitfileName
- the name of an underlying file that will be used to back
the databasedatabaseName
- an optional parameter that allows applications to
have multiple databases in a single file. Although no databaseName
parameter needs to be specified, it is an error to attempt to open a
second database in a physical file that was not initially created using
a databaseName parameter; further, the databaseName parameter is not
supported by the Queue formatconfig
- the database open attributes; if null, default attributes
are used.java.io.IOException
- if the database file cannot be accessedSResourceInUseException
- if the database is being renamed or
removedSDatabaseException
- if any error occurspublic SSecondaryDatabase openSecondaryDatabase(STransaction txn, java.lang.String fileName, java.lang.String databaseName, SDatabase primaryDatabase, SSecondaryConfig config) throws java.io.IOException, SDatabaseException
The database is represented by the file and database parameters.
The currently supported database file formats (or access methods) are Btree, Hash, Queue, and Recno. The Btree format is a representation of a sorted, balanced tree structure. The Hash format is an extensible, dynamic hashing scheme. The Queue format supports fast access to fixed-length records accessed sequentially or by logical record number. The Recno format supports fixed- or variable-length records, accessed sequentially or by logical record number.
Storage and retrieval are based on key/data pairs; see SDatabaseEntry
for more information.
Opening a database is a relatively expensive operation, and maintaining a set of open databases will normally be preferable to repeatedly opening and closing the database for each new query.
txn
- for a transactional database, an explicit transaction may be
specified, or null may be specified to use auto-commitfileName
- the name of an underlying file that will be used to back
the databasedatabaseName
- an optional parameter that allows applications to
have multiple databases in a single file. Although no databaseName
parameter needs to be specified, it is an error to attempt to open a
second database in a physical file that was not initially created using
a databaseName parameter; further, the databaseName parameter is not
supported by the Queue formatprimaryDatabase
- a database handle for the primary database that
is to be indexedconfig
- the secondary database open attributes; if null, default
attributes are usedjava.io.IOException
- if the database file cannot be accessedSResourceInUseException
- if the database is being renamed or
removedSDatabaseException
- if any error occurspublic void removeDatabase(STransaction txn, java.lang.String fileName, java.lang.String databaseName, boolean force) throws java.io.IOException, SDatabaseException
If no database is specified, the underlying file specified is removed, incidentally removing all of the databases it contained.
Applications should never remove databases with open SDatabase
handles, or in the case of removing a file, when any database in the
file has an open handle.
If force
is set to true, all open handles for the database, or
in the case of removing a file, all open handles for any database in the
file are closed so that the remove can proceed. If force
is
false, and there is at least one open handle for the database, SResourceInUseException
is thrown.
txn
- if the operation is part of an application-specified
transaction, the txn parameter is a STransaction
object returned
from the beginTransaction(com.sleepycat.client.STransaction, com.sleepycat.client.STransactionConfig)
method; otherwise null.
For a transactional database, an explicit transaction may be specified,
or null may be specified to use auto-commit.fileName
- the physical file which contains the database to be
removeddatabaseName
- the database to be removedforce
- if true, open handles are closed as necessary to allow the
remove operation to proceed; otherwise, throw SResourceInUseException
if the database has at least one open handlejava.io.IOException
- the database file cannot be accessedSResourceInUseException
- if force
is false and there is
at
least one open handle for the databaseSDatabaseException
- if any error occurspublic void renameDatabase(STransaction txn, java.lang.String fileName, java.lang.String databaseName, java.lang.String newName, boolean force) throws java.io.IOException, SDatabaseException
If no database name is specified, the underlying file specified is renamed, incidentally renaming all of the databases it contains.
Applications should never rename databases that are currently in use. If an underlying file is being renamed and logging is currently enabled in the database environment, no database in the file may be open when this method is called.
If force
is set to true, all open handles for the database, or
in the case of removing a file, all open handles for any database in the
file are closed so that the rename can proceed. If force
is
false, and there is at least one open handle for the database, SResourceInUseException
is thrown.
txn
- if the operation is part of an application-specified
transaction, the txn parameter is a STransaction
object returned
from the beginTransaction(com.sleepycat.client.STransaction, com.sleepycat.client.STransactionConfig)
method; otherwise null.
For a transactional database, an explicit transaction may be specified,
or null may be specified to use auto-commit.fileName
- the physical file which contains the database to be
renameddatabaseName
- the database to be renamednewName
- the new name of the database or fileforce
- if true, open handles are closed as necessary to allow the
remove operation to proceed; otherwise, throw SResourceInUseException
if the database has at least one open handlejava.io.IOException
- the database file cannot be accessedSResourceInUseException
- if force
is false and there is
at
least one open handle for the databaseSDatabaseException
- if any error occurspublic STransaction beginTransaction(STransaction parent, STransactionConfig config) throws SDatabaseException
A parent transaction may not issue any Berkeley DB driver operations --
except for beginTransaction(com.sleepycat.client.STransaction, com.sleepycat.client.STransactionConfig)
, STransaction.abort()
and
STransaction.commit()
-- while it has active child transactions
(child transactions that have not yet been committed or aborted).
parent
- if the parent parameter is non-null, the new transaction
will be a nested transaction, with the transaction indicated by parent
as its parent; transactions may be nested to any levelconfig
- the transaction attributes; if null, default attributes
are
used.SDatabaseException
- if any error occurspublic void checkpoint(SCheckpointConfig config) throws SDatabaseException
config
- the checkpoint attributes; if null, default attributes are
used.SDatabaseException
- if any error occurspublic SCacheFileStats[] getCacheFileStats(SStatsConfig config) throws SDatabaseException
config
- the statistics attributes; if null, default attributes are
used.SDatabaseException
- if any error occurspublic SCacheStats getCacheStats(SStatsConfig config) throws SDatabaseException
config
- the statistics attributesSDatabaseException
- if any error occurspublic SLockStats getLockStats(SStatsConfig config) throws SDatabaseException
config
- the statistics attributesSDatabaseException
- if any error occurspublic SLogStats getLogStats(SStatsConfig config) throws SDatabaseException
config
- the statistics attributesSDatabaseException
- if any error occurspublic SMutexStats getMutexStats(SStatsConfig config) throws SDatabaseException
config
- the statistics attributesSDatabaseException
- if any error occurspublic STransactionStats getTransactionStats(SStatsConfig config) throws SDatabaseException
config
- the statistics attributesSDatabaseException
- if any error occurspublic SMultiStats getMultipleStats(SMultiStatsConfig config) throws SDatabaseException
The config
parameter specifies which statistics are retrieved
and what attributes apply for each statistics retrieval operation.
Compared to other statistics retrieval operations that retrieve only a single statistics, this method can save a few network round trips when multiple statistics are retrieved.
config
- the multiple statistics attributesSDatabaseException
- if any error occurspublic <V> V remoteCallWithIOException(com.sleepycat.client.RemoteServiceCallable<V> remote) throws java.io.IOException
java.io.IOException
public <V> V remoteCall(com.sleepycat.client.RemoteServiceCallable<V> remote)
public <V> V handleRuntimeExceptions(com.sleepycat.client.RemoteServiceCallable<V> remote) throws org.apache.thrift.TException
org.apache.thrift.TException
Copyright (c) 2016, 2019 Oracle and/or its affiliates. All rights reserved.