| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions Copyright 2006 Sun Microsystems, Inc. |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.backends; |
| | | |
| | |
| | | import org.opends.server.util.LDIFReader; |
| | | import org.opends.server.util.LDIFWriter; |
| | | |
| | | import static org.opends.server.loggers.Debug.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugCought; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugEnabled; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import static org.opends.server.messages.BackendMessages.*; |
| | | import static org.opends.server.messages.MessageHandler.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | |
| | | public class MemoryBackend |
| | | extends Backend |
| | | { |
| | | /** |
| | | * The fully-qualified name of this class for debugging purposes. |
| | | */ |
| | | private static final String CLASS_NAME = |
| | | "org.opends.server.backends.MemoryBackend"; |
| | | |
| | | |
| | | |
| | |
| | | { |
| | | super(); |
| | | |
| | | assert debugConstructor(CLASS_NAME); |
| | | |
| | | |
| | | // Perform all initialization in initializeBackend. |
| | |
| | | DN[] baseDNs) |
| | | throws ConfigException, InitializationException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "initializeBackend", |
| | | String.valueOf(configEntry), String.valueOf(baseDNs)); |
| | | |
| | | |
| | | // We won't support anything other than exactly one base DN in this |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "initializeBackend", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_BACKEND_CANNOT_REGISTER_BASEDN; |
| | | String message = getMessage(msgID, dn.toString(), |
| | |
| | | */ |
| | | public synchronized void finalizeBackend() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "finalizeBackend"); |
| | | |
| | | clearMemoryBackend(); |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "finalizeBackend", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | */ |
| | | public DN[] getBaseDNs() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getBaseDNs"); |
| | | |
| | | return baseDNs; |
| | | } |
| | |
| | | */ |
| | | public synchronized long getEntryCount() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getEntryCount"); |
| | | |
| | | if (entryMap != null) |
| | | { |
| | |
| | | */ |
| | | public boolean isLocal() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "isLocal"); |
| | | |
| | | // For the purposes of this method, this is a local backend. |
| | | return true; |
| | |
| | | */ |
| | | public synchronized Entry getEntry(DN entryDN) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getEntry", String.valueOf(entryDN)); |
| | | |
| | | return entryMap.get(entryDN); |
| | | } |
| | |
| | | */ |
| | | public synchronized boolean entryExists(DN entryDN) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "entryExists", String.valueOf(entryDN)); |
| | | |
| | | return entryMap.containsKey(entryDN); |
| | | } |
| | |
| | | public synchronized void addEntry(Entry entry, AddOperation addOperation) |
| | | throws DirectoryException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "addEntry", String.valueOf(entry), |
| | | String.valueOf(addOperation)); |
| | | |
| | | |
| | | // See if the target entry already exists. If so, then fail. |
| | |
| | | DeleteOperation deleteOperation) |
| | | throws DirectoryException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "deleteEntry", String.valueOf(entryDN), |
| | | String.valueOf(deleteOperation)); |
| | | |
| | | |
| | | // Make sure the entry exists. If not, then throw an exception. |
| | |
| | | { |
| | | // This shouldn't happen, but we want the delete to continue anyway |
| | | // so just ignore it if it does for some reason. |
| | | assert debugException(CLASS_NAME, "deleteEntry", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | ModifyOperation modifyOperation) |
| | | throws DirectoryException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "replaceEntry", String.valueOf(entry), |
| | | String.valueOf(modifyOperation)); |
| | | |
| | | |
| | | // Make sure the entry exists. If not, then throw an exception. |
| | |
| | | ModifyDNOperation modifyDNOperation) |
| | | throws DirectoryException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "renameEntry", String.valueOf(currentDN), |
| | | String.valueOf(entry), String.valueOf(modifyDNOperation)); |
| | | |
| | | |
| | | // Make sure that the target entry exists. |
| | |
| | | public synchronized void search(SearchOperation searchOperation) |
| | | throws DirectoryException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "search", String.valueOf(searchOperation)); |
| | | |
| | | |
| | | // Get the base DN, scope, and filter for the search. |
| | |
| | | */ |
| | | public HashSet<String> getSupportedControls() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getSupportedControls"); |
| | | |
| | | return supportedControls; |
| | | } |
| | |
| | | */ |
| | | public HashSet<String> getSupportedFeatures() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getSupportedFeatures"); |
| | | |
| | | return supportedFeatures; |
| | | } |
| | |
| | | */ |
| | | public boolean supportsLDIFExport() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "supportsLDIFExport"); |
| | | |
| | | return true; |
| | | } |
| | |
| | | LDIFExportConfig exportConfig) |
| | | throws DirectoryException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "exportLDIF", String.valueOf(exportConfig)); |
| | | |
| | | |
| | | // Create the LDIF writer. |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "exportLDIF", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_MEMORYBACKEND_CANNOT_CREATE_LDIF_WRITER; |
| | | int msgID = MSGID_MEMORYBACKEND_CANNOT_CREATE_LDIF_WRITER; |
| | | String message = getMessage(msgID, String.valueOf(e)); |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, msgID, e); |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "exportLDIF", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | */ |
| | | public boolean supportsLDIFImport() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "supportsLDIFImport"); |
| | | |
| | | return true; |
| | | } |
| | |
| | | LDIFImportConfig importConfig) |
| | | throws DirectoryException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "importLDIF", String.valueOf(importConfig)); |
| | | |
| | | |
| | | clearMemoryBackend(); |
| | |
| | | */ |
| | | public boolean supportsBackup() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "supportsBackup"); |
| | | |
| | | // This backend does not provide a backup/restore mechanism. |
| | | return false; |
| | |
| | | public boolean supportsBackup(BackupConfig backupConfig, |
| | | StringBuilder unsupportedReason) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "supportsBackup"); |
| | | |
| | | |
| | | // This backend does not provide a backup/restore mechanism. |
| | |
| | | public void createBackup(ConfigEntry configEntry, BackupConfig backupConfig) |
| | | throws DirectoryException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "createBackup", String.valueOf(backupConfig)); |
| | | |
| | | |
| | | int msgID = MSGID_MEMORYBACKEND_BACKUP_RESTORE_NOT_SUPPORTED; |
| | |
| | | String backupID) |
| | | throws DirectoryException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "removeBackup", |
| | | String.valueOf(backupDirectory), |
| | | String.valueOf(backupID)); |
| | | |
| | | |
| | | int msgID = MSGID_MEMORYBACKEND_BACKUP_RESTORE_NOT_SUPPORTED; |
| | |
| | | */ |
| | | public boolean supportsRestore() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "supportsRestore"); |
| | | |
| | | |
| | | // This backend does not provide a backup/restore mechanism. |
| | |
| | | RestoreConfig restoreConfig) |
| | | throws DirectoryException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "restoreBackup", |
| | | String.valueOf(restoreConfig)); |
| | | |
| | | |
| | | int msgID = MSGID_MEMORYBACKEND_BACKUP_RESTORE_NOT_SUPPORTED; |