KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > optimistic > WorkspaceNode


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.optimistic;
8
9 import org.jboss.cache.CacheSPI;
10 import org.jboss.cache.Fqn;
11 import org.jboss.cache.Node;
12 import org.jboss.cache.NodeSPI;
13
14 import java.util.Map JavaDoc;
15 import java.util.Set JavaDoc;
16
17 /**
18  * Represents a type of {@link org.jboss.cache.Node} that is to be copied into a {@link TransactionWorkspace} for optimistically locked
19  * nodes. Adds versioning and dirty flags over conventional Nodes.
20  *
21  * @author Manik Surtani (<a HREF="mailto:manik@jboss.org">manik@jboss.org</a>)
22  * @author Steve Woodcock (<a HREF="mailto:stevew@jofti.com">stevew@jofti.com</a>)
23  */

24 public interface WorkspaceNode extends Node
25 {
26    /**
27     * Attempts to merge children created during the transaction with underlying children in the tree.
28     *
29     * @return a merged map of child names and Nodes
30     */

31    public Map JavaDoc<Object JavaDoc, NodeSPI> getMergedChildren();
32
33    /**
34     * Retrieves the data version of the in-memory node.
35     *
36     * @return A data version
37     */

38    public DataVersion getVersion();
39
40    /**
41     * Sets the data version of this workspace node.
42     *
43     * @param version a {@link org.jboss.cache.optimistic.DataVersion} implementation.
44     */

45    public void setVersion(DataVersion version);
46
47    /**
48     * Retrieves all data keys
49     *
50     * @return an immutable set.
51     */

52    public Set JavaDoc<Object JavaDoc> getKeys();
53
54    /**
55     * Returns true if this node needs to be merged when the transaction commits.
56     *
57     * @return true if needs merging, false otherwise.
58     */

59    public boolean isDirty();
60
61    /**
62     * Attempts to merge data changed during the current transaction with the data in the underlying tree.
63     *
64     * @return a merged map of key/value pairs.
65     */

66    public Map JavaDoc<Object JavaDoc, Object JavaDoc> getMergedData();
67
68    /**
69     * Retrieves a reference to the underlying {@link NodeSPI} instance.
70     *
71     * @return a node
72     */

73    public NodeSPI getNode();
74
75    public Set JavaDoc<Object JavaDoc> getChildrenNames();
76
77    /**
78     * Retrieves a TransactionWorkspace instance associated with the current transaction, which the current WorkspaceNode instance
79     * lives in.
80     *
81     * @return a TransactionWorkspace.
82     */

83    public TransactionWorkspace getTransactionWorkspace();
84
85    /**
86     * @return true if the instance was created in the current transaction; i.e., it did not exist in the underlying data tree.
87     */

88    public boolean isCreated();
89
90    /**
91     * Marks the instance as having been created in the current transaction.
92     */

93    public void markAsCreated();
94
95    /**
96     * Creates a child node.
97     *
98     * @param child_name Object name of the child to create
99     * @param parent A reference to the parent node
100     * @param cache CacheSPI instance to create this node in
101     * @param version DataVersion to apply to the child. If null, {@link DefaultDataVersion#ZERO} will be used.
102     * @return a NodeSPI pointing to the newly created child.
103     */

104    public NodeSPI createChild(Object JavaDoc child_name, NodeSPI parent, CacheSPI cache, DataVersion version);
105
106    /**
107     * Tests whether versioning for the WorkspaceNode instance in the current transaction is implicit (i.e., using {@link org.jboss.cache.optimistic.DefaultDataVersion}
108     * rather than a custom {@link org.jboss.cache.optimistic.DataVersion} passed in using {@link org.jboss.cache.config.Option#setDataVersion(DataVersion)})
109     *
110     * @return true if versioning is implicit.
111     */

112    boolean isVersioningImplicit();
113
114    /**
115     * Sets whether versioning for the WorkspaceNode instance in the current transaction is implicit (i.e., using {@link org.jboss.cache.optimistic.DefaultDataVersion}
116     * rather than a custom {@link org.jboss.cache.optimistic.DataVersion} passed in using {@link org.jboss.cache.config.Option#setDataVersion(DataVersion)})
117     *
118     * @param b set to true if versioning is implicit, false otherwise.
119     */

120    void setVersioningImplicit(boolean b);
121
122    /**
123     * @return true if the instance has been deleted in the current transaction.
124     */

125    boolean isDeleted();
126
127    /**
128     * Marks the node as being deleted (or not) in the current transaction. This is not recursive, child nodes are not affected.
129     *
130     * @param marker true if the node has been deleted, false if not.
131     */

132    void markAsDeleted(boolean marker);
133
134    /**
135     * Same as {@link #markAsDeleted(boolean)} except that the option to recurse into children is provided.
136     *
137     * @param marker true if the node has been deleted, false if not.
138     * @param recursive if true, child nodes (and their children) are marked as well.
139     */

140    void markAsDeleted(boolean marker, boolean recursive);
141
142    /**
143     * Overrides {@link Node#getChild(Object)} to return a {@link org.jboss.cache.NodeSPI} rather than a {@link org.jboss.cache.Node}
144     *
145     * @param o node name
146     * @return a child node
147     */

148    NodeSPI getChild(Object JavaDoc o);
149
150    /**
151     * Overrides {@link Node#getChild(Fqn)} to return a {@link org.jboss.cache.NodeSPI} rather than a {@link org.jboss.cache.Node}
152     *
153     * @param f node fqn
154     * @return a child node
155     */

156    NodeSPI getChild(Fqn f);
157 }
158
Popular Tags