1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache; |
8 |
| |
9 |
| import org.jboss.cache.optimistic.TransactionWorkspace; |
10 |
| import org.jboss.cache.optimistic.WorkspaceNode; |
11 |
| import org.jboss.cache.optimistic.WorkspaceNodeImpl; |
12 |
| |
13 |
| import java.util.Map; |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| public class NodeFactory<K, V> |
21 |
| { |
22 |
| public enum NodeType |
23 |
| { |
24 |
| UNVERSIONED_NODE, VERSIONED_NODE, WORKSPACE_NODE |
25 |
| } |
26 |
| |
27 |
| private CacheSPI<K, V> cache; |
28 |
| private boolean optimistic; |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
2806
| public NodeFactory(CacheSPI<K, V> cache)
|
34 |
| { |
35 |
2806
| this.cache = cache;
|
36 |
2806
| init();
|
37 |
| } |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
2832
| public void init()
|
43 |
| { |
44 |
2832
| optimistic = cache.getConfiguration().isNodeLockingOptimistic();
|
45 |
| } |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
181022
| public NodeSPI<K, V> createDataNode(Object childName, Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, boolean mapSafe)
|
62 |
| { |
63 |
181022
| return optimistic ? new VersionedNode<K, V>(fqn, parent, data, cache) : new UnversionedNode<K, V>(childName, fqn, data, mapSafe, cache);
|
64 |
| } |
65 |
| |
66 |
166116
| public Node<K, V> createNode(Object childName, Node<K, V> parent, Map<K, V> data)
|
67 |
| { |
68 |
166125
| return createNodeOfType(parent, childName, parent, data);
|
69 |
| } |
70 |
| |
71 |
167528
| public Node<K, V> createNodeOfType(Node<K, V> template, Object childName, Node<K, V> parent, Map<K, V> data)
|
72 |
| { |
73 |
167528
| if (template instanceof WorkspaceNode)
|
74 |
| { |
75 |
0
| NodeSPI<K, V> dataNodeParent = ((WorkspaceNode<K, V>) parent).getNode();
|
76 |
0
| TransactionWorkspace workspace = ((WorkspaceNode) template).getTransactionWorkspace();
|
77 |
0
| return createWorkspaceNode(dataNodeParent, workspace);
|
78 |
| } |
79 |
| |
80 |
| |
81 |
167528
| return createDataNode(childName, new Fqn(parent.getFqn(), childName), (NodeSPI<K, V>) parent, data, false);
|
82 |
| } |
83 |
| |
84 |
1053958
| public WorkspaceNode<K, V> createWorkspaceNode(NodeSPI<K, V> dataNode, TransactionWorkspace workspace)
|
85 |
| { |
86 |
1053958
| return new WorkspaceNodeImpl<K, V>(dataNode, workspace);
|
87 |
| } |
88 |
| |
89 |
2832
| public NodeSPI<K, V> createRootDataNode()
|
90 |
| { |
91 |
2832
| return createDataNode(null, Fqn.ROOT, null, null, false);
|
92 |
| } |
93 |
| |
94 |
| } |