Manipulate data in a tree cache
Manipulating data in a Tree Cache The Tree API effectively provides two ways to interact with the data: Â 1. Via TreeCache convenience methods: These methods are located within the TreeCache interface and enable users to store, retrieve, move, remove...etc data with a single call that takes the Fqn, in String or Fqn format, and the data involved in the call. For example: treeCache.put("/persons/john", "surname", "Smith"); Â Or: import org.infinispan.tree.Fqn; ... Fqn johnFqn = Fqn.fromString("persons/john"); Calendar calendar = Calendar.getInstance(); calendar.set(1980, 5, 2); treeCache.put(johnFqn, "birthdate", calendar.getTime())); Â 2. Via Node API: It allows finer control over the individual nodes that form the FQN, allowing manipulation of nodes relative to a particular node. For example: import org.infinispan.tree.Node; ... TreeCache treeCache = ... Fqn johnFqn = Fqn.fromElements("persons", "john"); Node john = treeCache.getRoot().addChild(johnFqn); john.put("surname", "Smith"); Â Or: Node persons = treeCache.getRoot().addChild(Fqn.fromString("persons")); Node john = persons.addChild(Fqn.fromString("john")); john.put("surname", "Smith"); Â Or even: Fqn personsFqn = Fqn.fromString("persons"); Fqn johnFqn = Fqn.fromRelative(personsFqn, Fqn.fromString("john")); Node john = treeCache.getRoot().addChild(johnFqn); john.put("surname", "Smith"); Â A node also provides the ability to access its parent or children. For example: Node john = ... Node persons = john.getParent(); Â Or: Set> personsChildren = persons.getChildren();