org.opends.server.backends.jeb
Class EntryContainer

java.lang.Object
  extended by org.opends.server.backends.jeb.EntryContainer
All Implemented Interfaces:
ConfigurationChangeListener<LocalDBBackendCfg>

public class EntryContainer
extends java.lang.Object
implements ConfigurationChangeListener<LocalDBBackendCfg>

Storage container for LDAP entries. Each base DN of a JE backend is given its own entry container. The entry container is the object that implements the guts of the backend API methods for LDAP operations.


Nested Class Summary
 class EntryContainer.AttributeJEIndexCfgManager
          This class is responsible for managing the configuraiton for attribute indexes used within this entry container.
static class EntryContainer.KeyReverseComparator
          A lexicographic byte array comparator that compares in reverse byte order.
 class EntryContainer.VLVJEIndexCfgManager
          This class is responsible for managing the configuraiton for VLV indexes used within this entry container.
 
Field Summary
static java.lang.String ATTR_DEBUG_SEARCH_INDEX
          The attribute used to return a search index debug string to the client.
 EntryContainer.AttributeJEIndexCfgManager attributeJEIndexCfgManager
          The attribute index configuration manager.
static java.lang.String DN2ID_DATABASE_NAME
          The name of the DN database.
static java.lang.String ID2CHILDREN_DATABASE_NAME
          The name of the children index database.
static java.lang.String ID2ENTRY_DATABASE_NAME
          The name of the entry database.
static java.lang.String ID2SUBTREE_DATABASE_NAME
          The name of the subtree index database.
static java.lang.String REFERRAL_DATABASE_NAME
          The name of the referral database.
static java.lang.String STATE_DATABASE_NAME
          The name of the state database.
 EntryContainer.VLVJEIndexCfgManager vlvJEIndexCfgManager
          The vlv index configuration manager.
 
Constructor Summary
EntryContainer(DN baseDN, java.lang.String databasePrefix, Backend backend, LocalDBBackendCfg config, com.sleepycat.je.Environment env, RootContainer rootContainer)
          Create a new entry entryContainer object.
 
Method Summary
 void addEntry(Entry entry, AddOperation addOperation)
          Adds the provided entry to this database.
 ConfigChangeResult applyConfigurationChange(LocalDBBackendCfg cfg)
          Applies the configuration changes to this change listener.
 com.sleepycat.je.Transaction beginTransaction()
          Begin a leaf transaction using the default configuration.
 long clear()
          Clear the contents of this entry container.
 long clearAttributeIndex(AttributeIndex index)
          Clear the contents for a attribute index from disk.
 long clearDatabase(DatabaseContainer database)
          Clear the contents for a database from disk.
 void close()
          Closes the entry entryContainer.
 void delete()
          Delete this entry container from disk.
 void deleteAttributeIndex(AttributeIndex index)
          Removes a attribute index from disk.
 void deleteDatabase(DatabaseContainer database)
          Remove a database from disk.
 void deleteEntry(DN entryDN, DeleteOperation deleteOperation)
          Removes the specified entry from this database.
 boolean entryExists(DN entryDN)
          Indicates whether an entry with the specified DN exists.
 AttributeIndex getAttributeIndex(AttributeType attrType)
          Look for an attribute index for the given attribute type.
 java.util.Collection<AttributeIndex> getAttributeIndexes()
          Retrieve all attribute indexes.
 java.util.Map<AttributeType,AttributeIndex> getAttributeIndexMap()
          Return attribute index map.
 DN getBaseDN()
          Get the baseDN this entry container is responsible for.
 java.lang.String getDatabasePrefix()
          This method constructs a container name from a base DN.
 DN2ID getDN2ID()
          Get the DN database used by this entry entryContainer.
 DN2URI getDN2URI()
          Get the referral database used by this entry entryContainer.
 Entry getEntry(DN entryDN)
          Fetch an entry by DN, trying the entry cache first, then the database.
 long getEntryCount()
          Get a count of the number of entries stored in this entry entryContainer.
 int getEntryLimitExceededCount()
          Get the number of values for which the entry limit has been exceeded since the entry entryContainer was opened.
 com.sleepycat.je.EnvironmentConfig getEnvironmentConfig()
          Get the environment config of the JE environment used in this entry container.
 EntryID getHighestEntryID()
          Determine the highest entryID in the entryContainer.
 Index getID2Children()
          Get the children database used by this entry entryContainer.
 ID2Entry getID2Entry()
          Get the entry database used by this entry entryContainer.
 Index getID2Subtree()
          Get the subtree database used by this entry entryContainer.
 long getNumSubordinates(DN entryDN, boolean subtree)
          Determine the number of subordinate entries for a given entry.
 DN getParentWithinBase(DN dn)
          Get the parent of a DN in the scope of the base DN.
 RootContainer getRootContainer()
          Retrieves a reference to the root container in which this entry container exists.
 State getState()
          Get the state database used by this entry container.
 int getSubtreeDeleteBatchSize()
          Get the subtree delete batch size.
 VLVIndex getVLVIndex(java.lang.String vlvIndexName)
          Look for an VLV index for the given index name.
 java.util.Collection<VLVIndex> getVLVIndexes()
          Retrieve all VLV indexes.
 boolean isConfigurationChangeAcceptable(LocalDBBackendCfg cfg, java.util.List<Message> unacceptableReasons)
          Indicates whether the proposed change to the configuration is acceptable to this change listener.
static boolean isManageDsaITOperation(Operation operation)
          Determine whether the provided operation has the ManageDsaIT request control.
 void listDatabases(java.util.List<DatabaseContainer> dbList)
          Get a list of the databases opened by this entryContainer.
 void lock()
          Get the exclusive lock.
static DN modDN(DN oldDN, int oldSuffixLen, DN newSuffixDN)
          Make a new DN for a subordinate entry of a renamed or moved entry.
 void open()
          Opens the entryContainer for reading and writing.
 void renameEntry(DN currentDN, Entry entry, ModifyDNOperation modifyDNOperation)
          Moves and/or renames the provided entry in this backend, altering any subordinate entries as necessary.
 void replaceEntry(Entry entry, ModifyOperation modifyOperation)
          The simplest case of replacing an entry in which the entry DN has not changed.
 void search(SearchOperation searchOperation)
          Processes the specified search in this entryContainer.
 void setDatabasePrefix(java.lang.String newDatabasePrefix)
          Sets a new database prefix for this entry container and rename all existing databases in use by this entry container.
static void transactionAbort(com.sleepycat.je.Transaction txn)
          Abort a transaction.
static void transactionCommit(com.sleepycat.je.Transaction txn)
          Commit a transaction.
 void unlock()
          Unlock the exclusive lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID2ENTRY_DATABASE_NAME

public static final java.lang.String ID2ENTRY_DATABASE_NAME
The name of the entry database.

See Also:
Constant Field Values

DN2ID_DATABASE_NAME

public static final java.lang.String DN2ID_DATABASE_NAME
The name of the DN database.

See Also:
Constant Field Values

ID2CHILDREN_DATABASE_NAME

public static final java.lang.String ID2CHILDREN_DATABASE_NAME
The name of the children index database.

See Also:
Constant Field Values

ID2SUBTREE_DATABASE_NAME

public static final java.lang.String ID2SUBTREE_DATABASE_NAME
The name of the subtree index database.

See Also:
Constant Field Values

REFERRAL_DATABASE_NAME

public static final java.lang.String REFERRAL_DATABASE_NAME
The name of the referral database.

See Also:
Constant Field Values

STATE_DATABASE_NAME

public static final java.lang.String STATE_DATABASE_NAME
The name of the state database.

See Also:
Constant Field Values

ATTR_DEBUG_SEARCH_INDEX

public static final java.lang.String ATTR_DEBUG_SEARCH_INDEX
The attribute used to return a search index debug string to the client.

See Also:
Constant Field Values

attributeJEIndexCfgManager

public EntryContainer.AttributeJEIndexCfgManager attributeJEIndexCfgManager
The attribute index configuration manager.


vlvJEIndexCfgManager

public EntryContainer.VLVJEIndexCfgManager vlvJEIndexCfgManager
The vlv index configuration manager.

Constructor Detail

EntryContainer

public EntryContainer(DN baseDN,
                      java.lang.String databasePrefix,
                      Backend backend,
                      LocalDBBackendCfg config,
                      com.sleepycat.je.Environment env,
                      RootContainer rootContainer)
               throws ConfigException
Create a new entry entryContainer object.

Parameters:
baseDN - The baseDN this entry container will be responsible for storing on disk.
databasePrefix - The prefix to use in the database names used by this entry container.
backend - A reference to the JE backend that is creating this entry container. It is needed by the Directory Server entry cache methods.
config - The configuration of the JE backend.
env - The JE environment to create this entryContainer in.
rootContainer - The root container this entry container is in.
Throws:
ConfigException - if a configuration related error occurs.
Method Detail

open

public void open()
          throws com.sleepycat.je.DatabaseException,
                 ConfigException
Opens the entryContainer for reading and writing.

Throws:
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.
ConfigException - if a configuration related error occurs.

close

public void close()
           throws com.sleepycat.je.DatabaseException
Closes the entry entryContainer.

Throws:
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.

getRootContainer

public RootContainer getRootContainer()
Retrieves a reference to the root container in which this entry container exists.

Returns:
A reference to the root container in which this entry container exists.

getDN2ID

public DN2ID getDN2ID()
Get the DN database used by this entry entryContainer. The entryContainer must have been opened.

Returns:
The DN database.

getID2Entry

public ID2Entry getID2Entry()
Get the entry database used by this entry entryContainer. The entryContainer must have been opened.

Returns:
The entry database.

getDN2URI

public DN2URI getDN2URI()
Get the referral database used by this entry entryContainer. The entryContainer must have been opened.

Returns:
The referral database.

getID2Children

public Index getID2Children()
Get the children database used by this entry entryContainer. The entryContainer must have been opened.

Returns:
The children database.

getID2Subtree

public Index getID2Subtree()
Get the subtree database used by this entry entryContainer. The entryContainer must have been opened.

Returns:
The subtree database.

getState

public State getState()
Get the state database used by this entry container. The entry container must have been opened.

Returns:
The state database.

getAttributeIndex

public AttributeIndex getAttributeIndex(AttributeType attrType)
Look for an attribute index for the given attribute type.

Parameters:
attrType - The attribute type for which an attribute index is needed.
Returns:
The attribute index or null if there is none for that type.

getAttributeIndexMap

public java.util.Map<AttributeType,AttributeIndex> getAttributeIndexMap()
Return attribute index map.

Returns:
The attribute index map.

getVLVIndex

public VLVIndex getVLVIndex(java.lang.String vlvIndexName)
Look for an VLV index for the given index name.

Parameters:
vlvIndexName - The vlv index name for which an vlv index is needed.
Returns:
The VLV index or null if there is none with that name.

getAttributeIndexes

public java.util.Collection<AttributeIndex> getAttributeIndexes()
Retrieve all attribute indexes.

Returns:
All attribute indexes defined in this entry container.

getVLVIndexes

public java.util.Collection<VLVIndex> getVLVIndexes()
Retrieve all VLV indexes.

Returns:
The collection of VLV indexes defined in this entry container.

getHighestEntryID

public EntryID getHighestEntryID()
                          throws com.sleepycat.je.DatabaseException
Determine the highest entryID in the entryContainer. The entryContainer must already be open.

Returns:
The highest entry ID.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.

getNumSubordinates

public long getNumSubordinates(DN entryDN,
                               boolean subtree)
                        throws com.sleepycat.je.DatabaseException
Determine the number of subordinate entries for a given entry.

Parameters:
entryDN - The distinguished name of the entry.
subtree - true will include all the entries under the given entries. false will only return the number of entries immediately under the given entry.
Returns:
The number of subordinate entries for the given entry or -1 if the entry does not exist.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.

search

public void search(SearchOperation searchOperation)
            throws DirectoryException,
                   com.sleepycat.je.DatabaseException,
                   JebException
Processes the specified search in this entryContainer. Matching entries should be provided back to the core server using the SearchOperation.returnEntry method.

Parameters:
searchOperation - The search operation to be processed.
Throws:
DirectoryException - If a problem occurs while processing the search.
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.
JebException - If an error occurs in the JE database.

addEntry

public void addEntry(Entry entry,
                     AddOperation addOperation)
              throws com.sleepycat.je.DatabaseException,
                     DirectoryException,
                     JebException
Adds the provided entry to this database. This method must ensure that the entry is appropriate for the database and that no entry already exists with the same DN. The caller must hold a write lock on the DN of the provided entry.

Parameters:
entry - The entry to add to this database.
addOperation - The add operation with which the new entry is associated. This may be null for adds performed internally.
Throws:
DirectoryException - If a problem occurs while trying to add the entry.
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.
JebException - If an error occurs in the JE backend.

deleteEntry

public void deleteEntry(DN entryDN,
                        DeleteOperation deleteOperation)
                 throws DirectoryException,
                        com.sleepycat.je.DatabaseException,
                        JebException
Removes the specified entry from this database. This method must ensure that the entry exists and that it does not have any subordinate entries (unless the database supports a subtree delete operation and the client included the appropriate information in the request). The caller must hold a write lock on the provided entry DN.

Parameters:
entryDN - The DN of the entry to remove from this database.
deleteOperation - The delete operation with which this action is associated. This may be null for deletes performed internally.
Throws:
DirectoryException - If a problem occurs while trying to remove the entry.
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.
JebException - If an error occurs in the JE backend.

entryExists

public boolean entryExists(DN entryDN)
                    throws DirectoryException
Indicates whether an entry with the specified DN exists.

Parameters:
entryDN - The DN of the entry for which to determine existence.
Returns:
true if the specified entry exists, or false if it does not.
Throws:
DirectoryException - If a problem occurs while trying to make the determination.

getEntry

public Entry getEntry(DN entryDN)
               throws JebException,
                      com.sleepycat.je.DatabaseException,
                      DirectoryException
Fetch an entry by DN, trying the entry cache first, then the database. Retrieves the requested entry, trying the entry cache first, then the database. Note that the caller must hold a read or write lock on the specified DN.

Parameters:
entryDN - The distinguished name of the entry to retrieve.
Returns:
The requested entry, or null if the entry does not exist.
Throws:
DirectoryException - If a problem occurs while trying to retrieve the entry.
JebException - If an error occurs in the JE backend.
com.sleepycat.je.DatabaseException - An error occurred during a database operation.

replaceEntry

public void replaceEntry(Entry entry,
                         ModifyOperation modifyOperation)
                  throws com.sleepycat.je.DatabaseException,
                         DirectoryException,
                         JebException
The simplest case of replacing an entry in which the entry DN has not changed.

Parameters:
entry - The new contents of the entry
modifyOperation - The modify operation with which this action is associated. This may be null for modifications performed internally.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.
DirectoryException - If a Directory Server error occurs.
JebException - If an error occurs in the JE backend.

renameEntry

public void renameEntry(DN currentDN,
                        Entry entry,
                        ModifyDNOperation modifyDNOperation)
                 throws com.sleepycat.je.DatabaseException,
                        JebException,
                        DirectoryException,
                        CanceledOperationException
Moves and/or renames the provided entry in this backend, altering any subordinate entries as necessary. This must ensure that an entry already exists with the provided current DN, and that no entry exists with the target DN of the provided entry. The caller must hold write locks on both the current DN and the new DN for the entry.

Parameters:
currentDN - The current DN of the entry to be replaced.
entry - The new content to use for the entry.
modifyDNOperation - The modify DN operation with which this action is associated. This may be null for modify DN operations performed internally.
Throws:
DirectoryException - If a problem occurs while trying to perform the rename.
CanceledOperationException - If this backend noticed and reacted to a request to cancel or abandon the modify DN operation.
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.
JebException - If an error occurs in the JE backend.

modDN

public static DN modDN(DN oldDN,
                       int oldSuffixLen,
                       DN newSuffixDN)
Make a new DN for a subordinate entry of a renamed or moved entry.

Parameters:
oldDN - The current DN of the subordinate entry.
oldSuffixLen - The current DN length of the renamed or moved entry.
newSuffixDN - The new DN of the renamed or moved entry.
Returns:
The new DN of the subordinate entry.

getEntryCount

public long getEntryCount()
                   throws com.sleepycat.je.DatabaseException
Get a count of the number of entries stored in this entry entryContainer.

Returns:
The number of entries stored in this entry entryContainer.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.

getEntryLimitExceededCount

public int getEntryLimitExceededCount()
Get the number of values for which the entry limit has been exceeded since the entry entryContainer was opened.

Returns:
The number of values for which the entry limit has been exceeded.

listDatabases

public void listDatabases(java.util.List<DatabaseContainer> dbList)
Get a list of the databases opened by this entryContainer.

Parameters:
dbList - A list of database containers.

isManageDsaITOperation

public static boolean isManageDsaITOperation(Operation operation)
Determine whether the provided operation has the ManageDsaIT request control.

Parameters:
operation - The operation for which the determination is to be made.
Returns:
true if the operation has the ManageDsaIT request control, or false if not.

beginTransaction

public com.sleepycat.je.Transaction beginTransaction()
                                              throws com.sleepycat.je.DatabaseException
Begin a leaf transaction using the default configuration. Provides assertion debug logging.

Returns:
A JE transaction handle.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs while attempting to begin a new transaction.

transactionCommit

public static void transactionCommit(com.sleepycat.je.Transaction txn)
                              throws com.sleepycat.je.DatabaseException
Commit a transaction. Provides assertion debug logging.

Parameters:
txn - The JE transaction handle.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs while attempting to commit the transaction.

transactionAbort

public static void transactionAbort(com.sleepycat.je.Transaction txn)
                             throws com.sleepycat.je.DatabaseException
Abort a transaction. Provides assertion debug logging.

Parameters:
txn - The JE transaction handle.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs while attempting to abort the transaction.

delete

public void delete()
            throws com.sleepycat.je.DatabaseException
Delete this entry container from disk. The entry container should be closed before calling this method.

Throws:
com.sleepycat.je.DatabaseException - If an error occurs while removing the entry container.

deleteDatabase

public void deleteDatabase(DatabaseContainer database)
                    throws com.sleepycat.je.DatabaseException
Remove a database from disk.

Parameters:
database - The database container to remove.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs while attempting to delete the database.

deleteAttributeIndex

public void deleteAttributeIndex(AttributeIndex index)
                          throws com.sleepycat.je.DatabaseException
Removes a attribute index from disk.

Parameters:
index - The attribute index to remove.
Throws:
com.sleepycat.je.DatabaseException - If an JE database error occurs while attempting to delete the index.

getDatabasePrefix

public java.lang.String getDatabasePrefix()
This method constructs a container name from a base DN. Only alphanumeric characters are preserved, all other characters are replaced with an underscore.

Returns:
The container name for the base DN.

setDatabasePrefix

public void setDatabasePrefix(java.lang.String newDatabasePrefix)
                       throws com.sleepycat.je.DatabaseException,
                              JebException
Sets a new database prefix for this entry container and rename all existing databases in use by this entry container.

Parameters:
newDatabasePrefix - The new database prefix to use.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs in the JE database.
JebException - If an error occurs in the JE backend.

getBaseDN

public DN getBaseDN()
Get the baseDN this entry container is responsible for.

Returns:
The Base DN for this entry container.

getParentWithinBase

public DN getParentWithinBase(DN dn)
Get the parent of a DN in the scope of the base DN.

Parameters:
dn - A DN which is in the scope of the base DN.
Returns:
The parent DN, or null if the given DN is the base DN.

isConfigurationChangeAcceptable

public boolean isConfigurationChangeAcceptable(LocalDBBackendCfg cfg,
                                               java.util.List<Message> unacceptableReasons)
Indicates whether the proposed change to the configuration is acceptable to this change listener.

Specified by:
isConfigurationChangeAcceptable in interface ConfigurationChangeListener<LocalDBBackendCfg>
Parameters:
cfg - The new configuration containing the changes.
unacceptableReasons - A list that can be used to hold messages about why the provided configuration is not acceptable.
Returns:
Returns true if the proposed change is acceptable, or false if it is not.

applyConfigurationChange

public ConfigChangeResult applyConfigurationChange(LocalDBBackendCfg cfg)
Applies the configuration changes to this change listener.

Specified by:
applyConfigurationChange in interface ConfigurationChangeListener<LocalDBBackendCfg>
Parameters:
cfg - The new configuration containing the changes.
Returns:
Returns information about the result of changing the configuration.

getEnvironmentConfig

public com.sleepycat.je.EnvironmentConfig getEnvironmentConfig()
                                                        throws com.sleepycat.je.DatabaseException
Get the environment config of the JE environment used in this entry container.

Returns:
The environment config of the JE environment.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs while retriving the configuration object.

clear

public long clear()
           throws com.sleepycat.je.DatabaseException
Clear the contents of this entry container.

Returns:
The number of records deleted.
Throws:
com.sleepycat.je.DatabaseException - If an error occurs while removing the entry container.

clearDatabase

public long clearDatabase(DatabaseContainer database)
                   throws com.sleepycat.je.DatabaseException
Clear the contents for a database from disk.

Parameters:
database - The database to clear.
Returns:
The number of records deleted.
Throws:
com.sleepycat.je.DatabaseException - if a JE database error occurs.

clearAttributeIndex

public long clearAttributeIndex(AttributeIndex index)
                         throws com.sleepycat.je.DatabaseException
Clear the contents for a attribute index from disk.

Parameters:
index - The attribute index to clear.
Returns:
The number of records deleted.
Throws:
com.sleepycat.je.DatabaseException - if a JE database error occurs.

lock

public void lock()
Get the exclusive lock.


unlock

public void unlock()
Unlock the exclusive lock.


getSubtreeDeleteBatchSize

public int getSubtreeDeleteBatchSize()
Get the subtree delete batch size.

Returns:
The subtree delete batch size.