if (logSql) { long logTimeStop = System.currentTimeMillis(); logSqlStatement("SQL SELECT_COUNT", table, logTimeStart, logTimeStop, q); }
    public int countNodes(Node home, Relation rel) throws Exception {        // Transactor tx = (Transactor) Thread.currentThread ();        // tx.timer.beginEvent ("countNodes "+home);        if ((rel == null) || (rel.otherType == null) || !rel.otherType.isRelational()) {            // this should never be called for embedded nodes            throw new RuntimeException("NodeMgr.countNodes called for non-relational node " +                                       home);        } else {            int retval = 0;            Connection con = rel.otherType.getConnection();            String table = rel.otherType.getTableName();            Statement stmt = null;            try {                String q = null;                StringBuffer tables = new StringBuffer(table);                if (rel.additionalTables != null) {                     tables.append(',').append(rel.additionalTables);                }                // NOTE: we explicitly convert tables StringBuffer to a String                // before appending to be compatible with JDK 1.3                StringBuffer b = new StringBuffer("SELECT count(*) FROM ")                        .append(tables.toString());                if (home.getSubnodeRelation() != null) {                    // use the manually set subnoderelation of the home node                    q = b.append(" ").append(home.getSubnodeRelation()).toString();                } else {                    // let relation object build the query                    q = b.append(rel.buildQuery(home,                                                home.getNonVirtualParent(),                                                null,                                                " WHERE ",                                                false)).toString();                }                if (logSql) {                    app.logEvent("### countNodes: " + q);                }                stmt = con.createStatement();                ResultSet rs = stmt.executeQuery(q);                if (!rs.next()) {                    retval = 0;                } else {                    retval = rs.getInt(1);                }            } finally {                // tx.timer.endEvent ("countNodes "+home);                if (stmt != null) {                    try {                        stmt.close();                    } catch (Exception ignore) {                    }                }            }            return (rel.maxSize > 0) ? Math.min(rel.maxSize, retval) : retval;        }    }