Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changing NodeStore API to allow a user implementing a NodeStore to ge…

…nerate a key based on a user value when provided.
  • Loading branch information...
commit edad8672021d4a12f786ba2218c118b229e0eaaf 1 parent e056a6c
Sam authored
4 src/main/java/org/sdsai/dsds/BTree.java
View
@@ -984,8 +984,8 @@ public boolean conditionallySplit(
assert(right.getChildren().size() == minData+1);
}
- final STOREKEY leftKey = nodeStore.generateKey(left);
- final STOREKEY rightKey = nodeStore.generateKey(right);
+ final STOREKEY leftKey = nodeStore.generateKey(left, null);
+ final STOREKEY rightKey = nodeStore.generateKey(right, null);
final K dataKey = node.getData().get(middleData);
if ( atRoot() ) {
8 src/main/java/org/sdsai/dsds/PagedList.java
View
@@ -225,7 +225,7 @@ private PagedListLocation insertPage(final STOREKEY prevKey,
final Node<STOREKEY, STOREKEY> nextNode)
{
final Node<STOREKEY, STOREKEY> node = newNode(prevKey, nextKey);
- final STOREKEY key = nodeStore.generateKey(node);
+ final STOREKEY key = nodeStore.generateKey(node, null);
if ( prevKey.equals(nextKey) )
{
@@ -263,7 +263,7 @@ private PagedListLocation split(final STOREKEY prevKey,
{
final Node<STOREKEY, STOREKEY> node = newNode(prevKey, nextKey);
- final STOREKEY key = nodeStore.generateKey(node);
+ final STOREKEY key = nodeStore.generateKey(node, null);
final List<STOREKEY> l =
prevNode.getData().subList(pageSize/2, prevNode.getData().size());
@@ -526,7 +526,7 @@ private boolean addAll(PagedListLocation<STOREKEY> ctx,
{
for (final V v : c)
{
- final STOREKEY vkey = nodeStore.generateKey(null);
+ final STOREKEY vkey = nodeStore.generateKey(null, v);
// If there is no room we must insert an empty page
// replacing ctx with it.
@@ -550,7 +550,7 @@ private boolean addAll(PagedListLocation<STOREKEY> ctx,
private boolean add(PagedListLocation<STOREKEY> ctx, final V v)
{
- final STOREKEY vkey = nodeStore.generateKey(null);
+ final STOREKEY vkey = nodeStore.generateKey(null, v);
// If there is no room we must insert an empty page
// replacing ctx with it.
2  src/main/java/org/sdsai/dsds/fs/DirectoryNodeStore.java
View
@@ -159,7 +159,7 @@ public void store(final File key, final D data) throws NodeStoreException {
* {@inheritDoc}
*/
@Override
- public File generateKey(final Node<K,File> node)
+ public File generateKey(final Node<K,File> node, final D d)
{
File f;
2  src/main/java/org/sdsai/dsds/mongo/MongoNodeStore.java
View
@@ -175,7 +175,7 @@ public void removeData(String key) {
* {@inheritDoc}
*/
@Override
- public String generateKey(Node<USERKEY, String> node) {
+ public String generateKey(Node<USERKEY, String> node, VALUE value) {
try
{
return new ObjectId().toString();
8 src/main/java/org/sdsai/dsds/node/NodeStore.java
View
@@ -92,10 +92,14 @@
* @param node This is provided to implementations for some context.
* If generateKey is being called for the purposes of
* storing a user key, this will be null.
- *
+ * @param value If a key is being generated for a user key value, it will
+ * be passed along. This is most useful
+ * when things like a {@link org.sdsai.dsds.PagedList}
+ * are adding a value, but the List API does not
+ * provide a way to specify a key.
* @throws NodeStoreException
*/
- STOREKEY generateKey(Node<USERKEY, STOREKEY> node);
+ STOREKEY generateKey(Node<USERKEY, STOREKEY> node, VALUE value);
/**
* Convert user keys to store keys. This method, given a user's key,
2  src/main/java/org/sdsai/dsds/riak/RiakNodeStore.java
View
@@ -89,7 +89,7 @@ public String convert(final USERKEY key)
* @return the string representation of a call to {@link java.util.UUID#randomUUID()}.
*/
@Override
- public String generateKey(final Node<USERKEY, String> node)
+ public String generateKey(final Node<USERKEY, String> node, VALUE value)
{
return randomUUID().toString();
}
6 src/test/java/org/sdsai/dsds/PagedListTest.java
View
@@ -74,7 +74,7 @@ private void print(final PagedList<File, String> p)
public void testAddRemove()
{
PagedList<File, String> pl =
- new PagedList<File, String>(nodeStore, nodeStore.generateKey(null), 3);
+ new PagedList<File, String>(nodeStore, nodeStore.generateKey(null, null), 3);
try
{
@@ -108,7 +108,7 @@ public void testAddRemove()
public void testAddRandomRemove()
{
PagedList<File, String> pl =
- new PagedList<File, String>(nodeStore, nodeStore.generateKey(null), 3);
+ new PagedList<File, String>(nodeStore, nodeStore.generateKey(null, null), 3);
try
{
@@ -143,7 +143,7 @@ public void testAddRandomRemove()
public void testAddRandom()
{
PagedList<File, String> pl =
- new PagedList<File, String>(nodeStore, nodeStore.generateKey(null), 3);
+ new PagedList<File, String>(nodeStore, nodeStore.generateKey(null, null), 3);
try
{
2  src/test/java/org/sdsai/dsds/mongo/MongoNodeStoreTest.java
View
@@ -92,7 +92,7 @@ public void setup() throws UnknownHostException
@Test
public void testGenerateKey()
{
- ns.generateKey(null);
+ ns.generateKey(null, null);
}
@Test
2  src/test/java/org/sdsai/dsds/riak/RiakNodeStoreTest.java
View
@@ -74,7 +74,7 @@ public void setup() throws UnknownHostException
@Test
public void testGenerateKey()
{
- ns.generateKey(null);
+ ns.generateKey(null, null);
}
@Test
Please sign in to comment.
Something went wrong with that request. Please try again.