MultiGet

The code for “MultiGet” that fetches record like Friend of Friend is as:

public class FriendOfFriend {

public static void main(String[] args) {

final KVStore store;
String storeName = “kvstore”;
String hostName = “localhost”;
String hostPort = “5000”;

store = KVStoreFactory.getStore
(new KVStoreConfig(storeName, hostName + “:” + hostPort));

ArrayList<String> majorKey = new ArrayList<String>();
ArrayList<String> minorKey = new ArrayList<String>();

majorKey.add(“users”);
majorKey.add(“34271”);
majorKey.add(“profile”);
minorKey.add(“Joe”);
store.put(Key.createKey(majorKey, minorKey), Value.createValue(new byte[] {}));

majorKey.clear();
majorKey.clear();
majorKey.add(“users”);
majorKey.add(“67511”);
majorKey.add(“profile”);
minorKey.add(“Sharon”);
store.put(Key.createKey(majorKey, minorKey), Value.createValue(new byte[] {}));

majorKey.clear();
minorKey.clear();
majorKey.add(“users”);
majorKey.add(“89757”);
majorKey.add(“profile”);
minorKey.add(“Vincent”);
store.put(Key.createKey(majorKey, minorKey), Value.createValue(new byte[] {}));

majorKey.clear();
minorKey.clear();
majorKey.add(“users”);
majorKey.add(“34271”);
majorKey.add(“friends”);
minorKey.add(“users”);
minorKey.add(“67511”);
store.put(Key.createKey(majorKey, minorKey), Value.createValue(new byte[] {}));

minorKey.clear();
minorKey.add(“users”);
minorKey.add(“89757”);
store.put(Key.createKey(majorKey, minorKey), Value.createValue(new byte[] {}));

Key Joe = Key.fromString(“/users/34271/friends”);
SortedSet<Key> FrofJoe = store.multiGetKeys(Joe,  null, Depth.DESCENDANTS_ONLY, Consistency.NONE_REQUIRED, 0, null);
Iterator<Key> FrIter = FrofJoe.iterator();

System.out.println(“Joe Friends: “);

while (FrIter.hasNext()) {
ArrayList<String> FrMajor = new ArrayList<String> ();
Iterator <String> i = FrIter.next().getMinorPath().iterator();

while (i.hasNext()) {
FrMajor.add(i.next());
}

FrMajor.add(“profile”);

Key frkey = Key.createKey(FrMajor);
Iterator<Key> frname = store.multiGetKeysIterator(Direction.FORWARD, 10, frkey, null, null);
while (frname.hasNext()) {
Key k = frname.next();
System.out.println(“\t” + k.toString());
}
}
store.close();

}

}

The output for above code is :

FrndofFrnd

Leave A Reply

Your email address will not be published. Required fields are marked *