| | |
| | | /** |
| | | * Represents the database containing the LDAP entries. The database key is |
| | | * the entry ID and the value is the entry contents. |
| | | * |
| | | */ |
| | | public class ID2Entry extends DatabaseContainer |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** |
| | | * Parameters for compression and encryption. |
| | | */ |
| | | /** Parameters for compression and encryption. */ |
| | | private DataConfig dataConfig; |
| | | |
| | | /** |
| | | * Cached encoding buffers. |
| | | */ |
| | | private static final ThreadLocal<EntryCodec> ENTRY_CODEC_CACHE = |
| | | new ThreadLocal<EntryCodec>() |
| | | /** Cached encoding buffers. */ |
| | | private static final ThreadLocal<EntryCodec> ENTRY_CODEC_CACHE = new ThreadLocal<EntryCodec>() |
| | | { |
| | | @Override |
| | | protected EntryCodec initialValue() |
| | |
| | | |
| | | private final ByteStringBuilder encodedBuffer = new ByteStringBuilder(); |
| | | private final ByteStringBuilder entryBuffer = new ByteStringBuilder(); |
| | | private final ByteStringBuilder compressedEntryBuffer = |
| | | new ByteStringBuilder(); |
| | | private final ByteStringBuilder compressedEntryBuffer = new ByteStringBuilder(); |
| | | private final ASN1Writer writer; |
| | | private final int maxBufferSize; |
| | | |
| | |
| | | throws DirectoryException |
| | | { |
| | | encodeVolatile(entry, dataConfig); |
| | | return new DatabaseEntry(encodedBuffer.getBackingArray(), 0, |
| | | encodedBuffer.length()); |
| | | return new DatabaseEntry(encodedBuffer.getBackingArray(), 0, encodedBuffer.length()); |
| | | } |
| | | |
| | | private void encodeVolatile(Entry entry, DataConfig dataConfig) |
| | | throws DirectoryException |
| | | private void encodeVolatile(Entry entry, DataConfig dataConfig) throws DirectoryException |
| | | { |
| | | // Encode the entry for later use. |
| | | entry.encode(entryBuffer, dataConfig.getEntryEncodeConfig()); |
| | |
| | | { |
| | | OutputStream compressor = null; |
| | | try { |
| | | compressor = new DeflaterOutputStream( |
| | | compressedEntryBuffer.asOutputStream()); |
| | | compressor = new DeflaterOutputStream(compressedEntryBuffer.asOutputStream()); |
| | | entryBuffer.copyTo(compressor); |
| | | } |
| | | finally { |
| | |
| | | * @throws DatabaseException If an error occurs in the JE database. |
| | | * |
| | | */ |
| | | ID2Entry(String name, DataConfig dataConfig, |
| | | Environment env, EntryContainer entryContainer) |
| | | ID2Entry(String name, DataConfig dataConfig, Environment env, EntryContainer entryContainer) |
| | | throws DatabaseException |
| | | { |
| | | super(name, env, entryContainer); |
| | |
| | | { |
| | | DatabaseEntry data = codec.encodeInternal(entry, dataConfig); |
| | | OperationStatus status = insert(txn, key, data); |
| | | return (status == OperationStatus.SUCCESS); |
| | | return status == OperationStatus.SUCCESS; |
| | | } |
| | | finally |
| | | { |
| | |
| | | { |
| | | DatabaseEntry data = codec.encodeInternal(entry, dataConfig); |
| | | OperationStatus status = put(txn, key, data); |
| | | return (status == OperationStatus.SUCCESS); |
| | | return status == OperationStatus.SUCCESS; |
| | | } |
| | | finally |
| | | { |
| | |
| | | * @throws DatabaseException If an error occurs in the JE database. |
| | | */ |
| | | @Override |
| | | public OperationStatus put(Transaction txn, DatabaseEntry key, |
| | | DatabaseEntry data) |
| | | public OperationStatus put(Transaction txn, DatabaseEntry key, DatabaseEntry data) |
| | | throws DatabaseException |
| | | { |
| | | return super.put(txn, key, data); |
| | |
| | | * @return true if the entry was removed, false if it was not. |
| | | * @throws DatabaseException If an error occurs in the JE database. |
| | | */ |
| | | public boolean remove(Transaction txn, EntryID id) |
| | | throws DatabaseException |
| | | public boolean remove(Transaction txn, EntryID id) throws DatabaseException |
| | | { |
| | | DatabaseEntry key = id.getDatabaseEntry(); |
| | | |
| | | OperationStatus status = delete(txn, key); |
| | | if (status != OperationStatus.SUCCESS) |
| | | { |
| | | return false; |
| | | } |
| | | return true; |
| | | return status == OperationStatus.SUCCESS; |
| | | } |
| | | |
| | | /** |