private Person getPerson(Key key, Record record) { Person person = new Person((String) record.bins.get("firstname"), (String) record.bins.get("lastname")); if (key.userKey != null) { person.uuid = key.userKey.toString(); } return person; }
public Person get(String uuid) { Key key = new Key("test", "demo", uuid); Record record = client.get(null, key); if (record == null) { throw new IllegalArgumentException("Wrong uuid:" + uuid); } Map<String, Object> bins = record.bins; Person person = new Person((String) bins.get("firstname"), (String) bins.get("lastname")); person.uuid = uuid; return person; }
public String save(Person person) { Key key; if (person.uuid == null) { key = new Key("test", "demo", UUID.randomUUID().toString()); person.uuid = key.userKey.toString(); } else { key = new Key("test", "demo", person.uuid); } Bin binF = new Bin("firstname", person.firstname); Bin binL = new Bin("lastname", person.lastname); // Write a record client.put(null, key, binF, binL); // Read a record Record record = client.get(null, key); Map<String, Object> bins = record.bins; assert bins.get("firstname") == person.firstname; assert bins.get("lastname") == person.lastname; return person.uuid; }