The query to get the tree from the db depends on how you are accessing it.

If you were to get the entire tree from the db in a single request then the
best approach is to do a single query for all the tree nodes and then join
them in java (see my earlier code example). The biggest no-no here would be
to recursively query the same table.

Since tapestry's tree supports ajax, each query will get a single node and
it's first level children. There would be two methods required:

public Node getRootNode() {
  Node rootNode =
session.createCriteria(Node.class).add(Restrictions.isNull("parentId")).uniqueResult();
  rootNode.setChildren(getChildren(rootNode.getNodeId());
  return rootNode;
}

public Node getNode(Int nodeId) {
  Node node =
session.createCriteria(Node.class).add(Restrictions.eq("nodeId",
nodeId)).uniqueResult();
  node.setChildren(getChildren(nodeId));
  return node;
}

private List<Node> getChildren(int nodeId) {
  return session.createCriteria(Node.class).add(Restrictions.eq("parentId",
nodeId)).list();
}

On Tuesday, 7 February 2012, tgupta1419 <tgu...@yahoo.com> wrote:
> How will the relation query look like to get this tree from the database.
>
> --
> View this message in context:
http://tapestry.1045711.n5.nabble.com/Tapestry-TreeGrid-tp5462126p5464526.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to