31
31
/**
32
32
* Implementations and attributes common to all concrete implementations of {@link StorageAdapter}.
33
33
*/
34
- abstract class AbstractStorageAdapter implements StorageAdapter {
35
- public static final byte SUBSPACE_PREFIX_ENTRY_NODE = 0x01 ;
36
- public static final byte SUBSPACE_PREFIX_DATA = 0x02 ;
37
-
34
+ abstract class AbstractStorageAdapter <N extends NodeReference > implements StorageAdapter <N > {
38
35
@ Nonnull
39
36
private final HNSW .Config config ;
40
37
@ Nonnull
38
+ private final NodeFactory <N > nodeFactory ;
39
+ @ Nonnull
41
40
private final Subspace subspace ;
42
41
@ Nonnull
43
42
private final OnWriteListener onWriteListener ;
44
43
@ Nonnull
45
44
private final OnReadListener onReadListener ;
46
45
47
- private final Subspace entryNodeSubspace ;
48
46
private final Subspace dataSubspace ;
49
47
50
- protected AbstractStorageAdapter (@ Nonnull final HNSW .Config config , @ Nonnull final Subspace subspace ,
48
+ protected AbstractStorageAdapter (@ Nonnull final HNSW .Config config , @ Nonnull final NodeFactory <N > nodeFactory ,
49
+ @ Nonnull final Subspace subspace ,
51
50
@ Nonnull final OnWriteListener onWriteListener ,
52
51
@ Nonnull final OnReadListener onReadListener ) {
53
52
this .config = config ;
53
+ this .nodeFactory = nodeFactory ;
54
54
this .subspace = subspace ;
55
55
this .onWriteListener = onWriteListener ;
56
56
this .onReadListener = onReadListener ;
57
-
58
- this .entryNodeSubspace = subspace .subspace (Tuple .from (SUBSPACE_PREFIX_ENTRY_NODE ));
59
57
this .dataSubspace = subspace .subspace (Tuple .from (SUBSPACE_PREFIX_DATA ));
60
58
}
61
59
@@ -65,22 +63,22 @@ public HNSW.Config getConfig() {
65
63
return config ;
66
64
}
67
65
68
- @ Override
69
66
@ Nonnull
70
- public Subspace getSubspace () {
71
- return subspace ;
67
+ @ Override
68
+ public NodeFactory <N > getNodeFactory () {
69
+ return nodeFactory ;
72
70
}
73
71
74
- @ Nullable
72
+ @ Nonnull
75
73
@ Override
76
- public Subspace getSecondarySubspace () {
77
- return null ;
74
+ public NodeKind getNodeKind () {
75
+ return getNodeFactory (). getNodeKind () ;
78
76
}
79
77
80
78
@ Override
81
79
@ Nonnull
82
- public Subspace getEntryNodeSubspace () {
83
- return entryNodeSubspace ;
80
+ public Subspace getSubspace () {
81
+ return subspace ;
84
82
}
85
83
86
84
@ Override
@@ -103,28 +101,25 @@ public OnReadListener getOnReadListener() {
103
101
104
102
@ Nonnull
105
103
@ Override
106
- public <N extends NodeReference > CompletableFuture <Node <N >> fetchNode (@ Nonnull final NodeFactory <N > nodeFactory ,
107
- @ Nonnull final ReadTransaction readTransaction ,
108
- int layer , @ Nonnull Tuple primaryKey ) {
109
- return fetchNodeInternal (nodeFactory , readTransaction , layer , primaryKey ).thenApply (this ::checkNode );
104
+ public CompletableFuture <Node <N >> fetchNode (@ Nonnull final ReadTransaction readTransaction ,
105
+ int layer , @ Nonnull Tuple primaryKey ) {
106
+ return fetchNodeInternal (readTransaction , layer , primaryKey ).thenApply (this ::checkNode );
110
107
}
111
108
112
109
@ Nonnull
113
- protected abstract <N extends NodeReference > CompletableFuture <Node <N >> fetchNodeInternal (@ Nonnull NodeFactory <N > nodeFactory ,
114
- @ Nonnull ReadTransaction readTransaction ,
115
- int layer , @ Nonnull Tuple primaryKey );
110
+ protected abstract CompletableFuture <Node <N >> fetchNodeInternal (@ Nonnull ReadTransaction readTransaction ,
111
+ int layer , @ Nonnull Tuple primaryKey );
116
112
117
113
/**
118
114
* Method to perform basic invariant check(s) on a newly-fetched node.
119
115
*
120
116
* @param node the node to check
121
- * @param <N> the type param for the node in order for this method to not be lossy on the type of the node that
122
117
* was passed in
123
118
*
124
119
* @return the node that was passed in
125
120
*/
126
121
@ Nullable
127
- private < N extends NodeReference > Node <N > checkNode (@ Nullable final Node <N > node ) {
122
+ private Node <N > checkNode (@ Nullable final Node <N > node ) {
128
123
return node ;
129
124
}
130
125
}
0 commit comments