You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Chris Mylonas <ch...@opencsta.org> on 2013/11/07 01:39:43 UTC

Tree, jumpstart tree from database and zone demo

Hi Tapestry Users,

Geoff - what a brilliant demo of tapestry's tree/zone/ajax goodness you
have at
http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/treefromdatabasewithzones


I ran into a couple of things that slowed my day yesterday, all in the
service layer - just relaying them here.

I'm using subnets instead of dewey classification system.

=======
in jumpstart node children query (classificationNodeInfo)
NOTE: I'm using glassfish v3.1.2 which has eclipselink.  that native query
for finding children was particularly nasty for fetching results with
parameter substitution.  I did this hackily for it to work, otherwise would
only ever get 1 result - you'll note that i just put the parameter in the
buf.append at the correct spot.  yes, very ugly - reminds me of the 90s
stringbuffer protocol stuff i used to do :)

            Set<Long> setOfIds = subnetNodeHelpersById.keySet();
            String tmp = "";
            for (Long ll : setOfIds) {
                tmp += ll.toString() + ",";
            }
            String queryParameterCorrected = tmp.substring(0, (tmp.length()
- 1));

            // This JPQL query should have worked but Hibernate translates
the count to "count(.)" which is invalid SQL
            // (a Hibernate bug?)...
            // buf.append("select c1.id, count(c1.children) from
Classification c1");
            // buf.append(" where c1.id in (:catIds) ");
            // buf.append(" group by c1.id");
            // Query q = em.createQuery(buf.toString());

            // ...so we use a native query instead
            buf.append("select c1.id, count(c2.id) from subnet c1");
            buf.append(" left join subnet c2 on c2.parentId = c1.id");
            buf.append(" where c1.id in (");
            buf.append(queryParameterCorrected);
            buf.append(") ");
            buf.append(" group by c1.id");
            Query q = em.createNativeQuery(buf.toString());

========

return lists of findChildren() and findSubnetsWithNoParent() needed to be
cast, i was getting exceptions in my env

    @SuppressWarnings("unchecked")
    private List<Subnet> findChildren(Long id) {
        return (List<Subnet>)
em.createNamedQuery(Subnet.QUERY_FINDBYPARENTID).setParameter("id",
id).getResultList();
    }

    @SuppressWarnings("unchecked")
    private List<Subnet> findSubnetsWithNoParent() {
        return (List<Subnet>)
em.createNamedQuery(Subnet.QUERY_PARENTISNULL).getResultList();
    }

==========

Cheers
Chris

Re: Tree, jumpstart tree from database and zone demo

Posted by Chris Mylonas <ch...@opencsta.org>.
Thanks Lance,


A few of those components are now on the exploration list :)


On Thu, Nov 7, 2013 at 6:22 PM, Lance Java <la...@googlemail.com>wrote:

> FYI you might be interested in this:
> http://tapestry-stitch.uklance.cloudbees.net/databasetreedemo
>

Re: Tree, jumpstart tree from database and zone demo

Posted by Lance Java <la...@googlemail.com>.
FYI you might be interested in this:
http://tapestry-stitch.uklance.cloudbees.net/databasetreedemo