3131/**
3232 * Implementations and attributes common to all concrete implementations of {@link StorageAdapter}.
3333 */
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 > {
3835 @ Nonnull
3936 private final HNSW .Config config ;
4037 @ Nonnull
38+ private final NodeFactory <N > nodeFactory ;
39+ @ Nonnull
4140 private final Subspace subspace ;
4241 @ Nonnull
4342 private final OnWriteListener onWriteListener ;
4443 @ Nonnull
4544 private final OnReadListener onReadListener ;
4645
47- private final Subspace entryNodeSubspace ;
4846 private final Subspace dataSubspace ;
4947
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 ,
5150 @ Nonnull final OnWriteListener onWriteListener ,
5251 @ Nonnull final OnReadListener onReadListener ) {
5352 this .config = config ;
53+ this .nodeFactory = nodeFactory ;
5454 this .subspace = subspace ;
5555 this .onWriteListener = onWriteListener ;
5656 this .onReadListener = onReadListener ;
57-
58- this .entryNodeSubspace = subspace .subspace (Tuple .from (SUBSPACE_PREFIX_ENTRY_NODE ));
5957 this .dataSubspace = subspace .subspace (Tuple .from (SUBSPACE_PREFIX_DATA ));
6058 }
6159
@@ -65,22 +63,22 @@ public HNSW.Config getConfig() {
6563 return config ;
6664 }
6765
68- @ Override
6966 @ Nonnull
70- public Subspace getSubspace () {
71- return subspace ;
67+ @ Override
68+ public NodeFactory <N > getNodeFactory () {
69+ return nodeFactory ;
7270 }
7371
74- @ Nullable
72+ @ Nonnull
7573 @ Override
76- public Subspace getSecondarySubspace () {
77- return null ;
74+ public NodeKind getNodeKind () {
75+ return getNodeFactory (). getNodeKind () ;
7876 }
7977
8078 @ Override
8179 @ Nonnull
82- public Subspace getEntryNodeSubspace () {
83- return entryNodeSubspace ;
80+ public Subspace getSubspace () {
81+ return subspace ;
8482 }
8583
8684 @ Override
@@ -103,28 +101,25 @@ public OnReadListener getOnReadListener() {
103101
104102 @ Nonnull
105103 @ 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 );
110107 }
111108
112109 @ 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 );
116112
117113 /**
118114 * Method to perform basic invariant check(s) on a newly-fetched node.
119115 *
120116 * @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
122117 * was passed in
123118 *
124119 * @return the node that was passed in
125120 */
126121 @ Nullable
127- private < N extends NodeReference > Node <N > checkNode (@ Nullable final Node <N > node ) {
122+ private Node <N > checkNode (@ Nullable final Node <N > node ) {
128123 return node ;
129124 }
130125}
0 commit comments