DN2ID.java revision 641e89ef0e15c9edde69f3b8cf82c7dd5f68687a
/*
* 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 2014-2015 ForgeRock AS
*/
/**
* This class represents the dn2id index, which has one record
* for each entry. The key is the normalized entry DN and the value
* is the entry ID.
*/
@SuppressWarnings("javadoc")
class DN2ID extends AbstractTree
{
private static final Function<ByteString, Void, NeverThrowsException> TO_VOID_KEY = Functions.returns(null);
private static final CursorTransformer.ValueTransformer<ByteString, ByteString, EntryID, NeverThrowsException>
{
{
}
};
/**
* Create a DN2ID instance for in a given entryContainer.
*
* @param treeName The name of the DN tree.
* @param baseDN The base DN of the tree.
* @throws StorageRuntimeException If an error occurs in the storage.
*/
{
super(treeName);
}
/**
* Adds a new record into the DN tree replacing any existing record having the same DN.
*
* @param txn a non null transaction
* @param dn The entry DN, which is the key to the record.
* @param entryID The entry ID, which is the value of the record.
* @throws StorageRuntimeException If an error occurred while attempting to insert the new record.
*/
void put(final WriteableTransaction txn, DN dn, final EntryID entryID) throws StorageRuntimeException
{
}
boolean insert(final WriteableTransaction txn, DN dn, final EntryID entryID) throws StorageRuntimeException
{
{
{
if (oldEntryID != null)
{
// no change
return oldEntryID;
}
// it did not exist before, insert the new value
}
});
}
{
}
{
// TODO JNR do we want to use compacted longs?
return entryID.toByteString();
}
/**
* Remove a record from the DN tree.
* @param txn a non null transaction
* @param dn The entry DN, which is the key to the record.
* @return true if the record was removed, false if it was not removed.
* @throws StorageRuntimeException If an error occurred while attempting to remove
* the record.
*/
{
}
/**
* Fetch the entry ID for a given DN.
* @param txn a non null transaction
* @param dn The DN for which the entry ID is desired.
* @return The entry ID, or null if the given DN is not in the DN tree.
* @throws StorageRuntimeException If an error occurs in the storage.
*/
{
}
<V> SequentialCursor<ByteString, ByteString> openCursor(SequentialCursor<ByteString, ByteString> dn2IdCursor,
{
}
{
}
return cursor;
}
{
}
}
/**
* Check if two DN have a parent-child relationship.
*
* @param parent
* The potential parent
* @param child
* The potential child of parent
* @return true if child is a direct children of parent, false otherwise.
*/
{
{
return false;
}
// Immediate children should only have one RDN separator past the parent length
int nbSeparator = 0;
{
{
nbSeparator++;
if (nbSeparator > 1)
{
return false;
}
}
}
return nbSeparator == 1;
}
/**
* Decorator overriding the next() behavior to iterate through children of the entry pointed by the given cursor at
* creation.
*/
private static final class ChildrenCursor extends
{
private final ByteStringBuilder builder;
private final ByteString limit;
private boolean cursorOnParent;
{
super(delegate);
cursorOnParent = true;
}
public boolean next()
{
if (cursorOnParent) {
// Go to the first children
cursorOnParent = false;
} else {
// Go to the next sibling
}
}
private ByteSequence nextSibling()
{
}
}
/**
* Decorator overriding the next() behavior to iterate through subordinates of the entry pointed by the given cursor
* at creation.
*/
private static final class SubtreeCursor extends
{
private final ByteString limit;
{
super(delegate);
}
public boolean next()
{
}
}
/** Keep track of information during the visit. */
private static final class ParentInfo<V>
{
private final ByteString parentDN;
private final V visitorData;
{
this.visitorData = visitorData;
}
}
/** Allows to visit dn2id tree without exposing internal encoding. */
static interface TreeVisitor<V>
{
}
/** Perform dn2id cursoring to expose parent and children to the {@link TreeVisitor} */
{
private final TreeVisitor<V> visitor;
{
this.parentsInfoStack = new LinkedList<>();
}
public boolean next()
{
{
return true;
}
return false;
}
{
}
{
if (!parentsInfoStack.isEmpty())
{
}
}
{
{
}
}
public boolean isDefined()
{
}
{
}
{
}
public void close()
{
}
}
}