jackrabbit-oak-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jukka Zitting <jukka.zitt...@gmail.com>
Subject Interface for modifying trees
Date Fri, 09 Mar 2012 15:56:23 GMT
Hi,

When talking about the internal tree model before [1], we left it
unspecified how such trees are created and modified. Currently that's
done directly by the MicroKernel implementation talking with the lower
level .mk.store.RevisionStore interface, but also here I think it
would be useful to come up with a less detailed abstraction to allow
better separation of concerns.

Thus I started drafting two new interfaces, called NodeStore and
NodeBuilder, for this. See https://gist.github.com/2007178 or below
for the details. Basically the idea is that the NodeStore
implementation keeps track of the latest (persisted) state of the
content tree. NodeBuilder instances returned by
NodeStore.getNodeBuilder() can be used to create new or modify
existing node states. And finally the NodeStore.setRoot() method
updates the content tree to the given new state.

Note that this is meant as a fairly low-level interface since it
doesn't cover features like merging or validating content changes. I'm
not yet 100% sure if that's the correct level for an interface like
this, but we can update the draft to match alternative design if and
as needed.

[1] http://markmail.org/message/qdvl5zz5cpkoxz3j

BR,

Jukka Zitting


/**
 * Builder interface for constructing new {@link NodeState node states}.
 */
public interface NodeBuilder {

    /**
     * Sets or removes the named property.
     *
     * @param name property name
     * @param encodedValue encoded value of the property,
     *                     or <code>null</code> to remove the named property
     */
    void setProperty(String name, String encodedValue);

    /**
     * Sets or removes the named child node.
     *
     * @param name child node name
     * @param childNode new child node state,
     *                  or <code>null</code> to remove the named child node
     */
    void setChildNode(String name, NodeState childNode);

    /**
     * Returns an immutable node state that matches the current state of
     * the builder.
     *
     * @return immutable node state
     */
    NodeState getNodeState();

}


/**
 * Storage abstraction for content trees. At any given point in time
 * the stored content tree is rooted at a single immutable node state.
 * Changes in the tree are constructed using {@link NodeBuilder} instances
 * based on the root and other node states in the tree. The state of the
 * entire tree can then be changed by setting the resulting modified root
 * node state as the new root of the tree.
 * <p>
 * This is a low-level interface that doesn't cover functionality like
 * merging concurrent changes or rejecting new tree states based on some
 * higher-level consistency constraints.
 */
public interface NodeStore {

    /**
     * Returns the latest state of the content tree.
     *
     * @return root node state
     */
    NodeState getRoot();

    /**
     * Updates the state of the content tree.
     *
     * @param newRoot new root node state
     */
    void setRoot(NodeState newRoot);

    /**
     * Returns a builder for constructing a new or modified node state.
     * The builder is initialized with all the properties and child nodes
     * from the given base node state, or with no properties or child nodes
     * if no base node state is given.
     *
     * @param base base node state,
     *             or <code>null</code> to construct a new node state
     * @return builder instance
     */
    NodeBuilder getNodeBuilder(NodeState base);

}

Mime
View raw message