ID2Entry.java revision 763a75aeed1a7731ddb95b99496aa7c1bf206ed0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2012-2015 ForgeRock AS.
*/
/**
* Represents the database containing the LDAP entries. The database key is
* the entry ID and the value is the entry contents.
*/
class ID2Entry extends DatabaseContainer
{
/** Parameters for compression and encryption. */
private DataConfig dataConfig;
/** Cached encoding buffers. */
{
protected EntryCodec initialValue()
{
return new EntryCodec();
}
};
private static EntryCodec acquireEntryCodec()
{
{
// Setting has changed, so recreate the codec.
codec = new EntryCodec();
}
return codec;
}
/**
* A cached set of ByteStringBuilder buffers and ASN1Writer used to encode
* entries.
*/
private static final class EntryCodec
{
/** The ASN1 tag for the ByteString type. */
private static final byte TAG_DATABASE_ENTRY = 0x60;
private static final int BUFFER_INIT_SIZE = 512;
private final ASN1Writer writer;
private final int maxBufferSize;
private EntryCodec()
{
this.maxBufferSize = getMaxInternalBufferSize();
}
private void release()
{
}
{
// Get the format version.
{
}
// Read the ASN1 sequence.
// See if it was compressed.
if(uncompressedSize > 0)
{
// It was compressed.
try
{
// TODO: Should handle the case where uncompress fails
}
finally {
}
// Since we are used the cached buffers (ByteStringBuilders),
// the decoded attribute values will not refer back to the
// original buffer.
}
else
{
// Since we don't have to do any decompression, we can just decode
// the entry directly.
}
}
throws DirectoryException
{
return encodedBuffer.toByteString();
}
throws DirectoryException
{
return encodedBuffer.toByteString();
}
{
// Encode the entry for later use.
// First write the DB format version byte.
try
{
// Then start the ASN1 sequence.
if (dataConfig.isCompressed())
{
try {
}
finally {
}
// Compression needed and successful.
}
else
{
}
}
catch(IOException ioe)
{
// TODO: This should never happen with byte buffer.
}
}
}
/**
* Create a new ID2Entry object.
*
* @param name The name of the entry database.
* @param dataConfig The desired compression and encryption options for data
* stored in the entry database.
* @param storage The JE Storage.
* @param entryContainer The entryContainer of the entry database.
* @throws StorageRuntimeException If an error occurs in the JE database.
*
*/
throws StorageRuntimeException
{
this.dataConfig = dataConfig;
}
/**
* Decodes an entry from its database representation.
* <p>
* An entry on disk is ASN1 encoded in this format:
*
* <pre>
* ByteString ::= [APPLICATION 0] IMPLICIT SEQUENCE {
* uncompressedSize INTEGER, -- A zero value means not compressed.
* dataBytes OCTET STRING -- Optionally compressed encoding of
* the data bytes.
* }
*
* ID2EntryValue ::= ByteString
* -- Where dataBytes contains an encoding of DirectoryServerEntry.
*
* DirectoryServerEntry ::= [APPLICATION 1] IMPLICIT SEQUENCE {
* dn LDAPDN,
* objectClasses SET OF LDAPString,
* userAttributes AttributeList,
* operationalAttributes AttributeList
* }
* </pre>
*
* @param bytes A byte array containing the encoded database value.
* @param compressedSchema The compressed schema manager to use when decoding.
* @return The decoded entry.
* @throws DecodeException If the data is not in the expected ASN.1 encoding
* format.
* @throws LDAPException If the data is not in the expected ASN.1 encoding
* format.
* @throws DataFormatException If an error occurs while trying to decompress
* compressed data.
* @throws DirectoryException If a Directory Server error occurs.
* @throws IOException if an error occurs while reading the ASN1 sequence.
*/
{
try
{
}
finally
{
}
}
/**
* Encodes an entry to the raw database format, with optional compression.
*
* @param entry The entry to encode.
* @param dataConfig Compression and cryptographic options.
* @return A ByteSTring containing the encoded database value.
*
* @throws DirectoryException If a problem occurs while attempting to encode
* the entry.
*/
{
try
{
}
finally
{
}
}
/**
* Insert a record into the entry database.
*
* @param txn The database transaction or null if none.
* @param id The entry ID which forms the key.
* @param entry The LDAP entry.
* @return true if the entry was inserted, false if a record with that
* ID already existed.
* @throws StorageRuntimeException If an error occurs in the JE database.
* @throws DirectoryException If a problem occurs while attempting to encode
* the entry.
*/
boolean insert(WriteableStorage txn, EntryID id, Entry entry) throws StorageRuntimeException, DirectoryException
{
try
{
}
finally
{
}
}
/**
* Write a record in the entry database.
*
* @param txn The database transaction or null if none.
* @param id The entry ID which forms the key.
* @param entry The LDAP entry.
* @throws StorageRuntimeException If an error occurs in the JE database.
* @throws DirectoryException If a problem occurs while attempting to encode
* the entry.
*/
{
try
{
}
finally
{
}
}
/**
* Remove a record from the entry database.
*
* @param txn The database transaction or null if none.
* @param id The entry ID which forms the key.
* @return true if the entry was removed, false if it was not.
* @throws StorageRuntimeException If an error occurs in the JE database.
*/
{
}
/**
* Fetch a record from the entry database.
*
* @param txn The database transaction or null if none.
* @param id The desired entry ID which forms the key.
* @param isRMW whether the read operation is part of a larger read-modify-write operation
* @return The requested entry, or null if there is no such record.
* @throws DirectoryException If a problem occurs while getting the entry.
* @throws StorageRuntimeException If an error occurs in the JE database.
*/
{
{
return null;
}
try
{
return entry;
}
catch (Exception e)
{
}
}
/**
* Set the desired compression and encryption options for data
* stored in the entry database.
*
* @param dataConfig The desired compression and encryption options for data
* stored in the entry database.
*/
{
this.dataConfig = dataConfig;
}
}