Updating Records

The following code shows how to “Update” the value in Key-Value store :

public class UpdateRecord {

public static void main(String[] args) {

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

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

ArrayList<String> majorList = new ArrayList<String>();
ArrayList<String> minorList = new ArrayList<String>();

majorList.add(“Tanya”);
majorList.add(“Smith”);
majorList.add(“1006”);

minorList.add(“Texas”);
minorList.add(“YAMAHA”);
minorList.add(“YZF999”);
minorList.add(“sportsBike”);

Key myKey = Key.createKey(majorList, minorList);

String st = “YAHOO”;
String newSt = “YAH999”;
Value myValue = Value.createValue(st.getBytes());

oracle.kv.Version ver = store.putIfAbsent(myKey, myValue);
if (ver == null) {
ValueVersion vv = store.get(myKey);
System.out.println(“Current Version of key is “+vv.getVersion().getVLSN());
System.out.println(“The key and current value is “+myKey.toString()+” “+new String(vv.getValue().getValue()));

oracle.kv.Version newVer = store.putIfVersion(myKey, Value.createValue(newSt.getBytes()), vv.getVersion());
System.out.println(“The version of updated record is “+newVer.getVersion());

vv = store.get(myKey);
System.out.println(“The key and value of updated record is ” +myKey.toString() +” “+ new String(vv.getValue().getValue()));
}
else {
System.out.println(“The current version of key is “+ver.getVersion());
System.out.println(“The key and current Value is “+myKey.toString()+ ” “+new String(myValue.toByteArray()));
}
myKey = Key.createKey(majorList);

store.close();
}
}

The output for above code is :

Update

Leave A Reply

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