StringBuffer q = dbm.getSelect();  q.append("WHERE "); q.append(dbm.getTableName()); q.append("."); q.append(idfield); q.append(" = ");
StringBuffer q = dbm.getSelect().append("WHERE ") .append(dbm.getTableName()) .append(".") .append(idfield) .append(" = ");
    private Node getNodeByKey(ITransaction txn, DbKey key)                       throws Exception {        // Note: Key must be a DbKey, otherwise will not work for relational objects        Node node = null;        DbMapping dbm = app.getDbMapping(key.getStorageName());        String kstr = key.getID();        if ((dbm == null) || !dbm.isRelational()) {            node = (Node) db.getNode(txn, kstr);            node.nmgr = safe;            if ((node != null) && (dbm != null)) {                node.setDbMapping(dbm);            }        } else {            String idfield = dbm.getIDField();            Statement stmt = null;            try {                Connection con = dbm.getConnection();                stmt = con.createStatement();                DbColumn[] columns = dbm.getColumns();                Relation[] joins = dbm.getJoins();                StringBuffer q = dbm.getSelect();                q.append("WHERE ");                q.append(dbm.getTableName());                q.append(".");                q.append(idfield);                q.append(" = ");                if (dbm.needsQuotes(idfield)) {                    q.append("'");                    q.append(escape(kstr));                    q.append("'");                } else {                    q.append(kstr);                }                if (logSql) {                    app.logEvent("### getNodeByKey: " + q.toString());                }                ResultSet rs = stmt.executeQuery(q.toString());                if (!rs.next()) {                    return null;                }                node = createNode(dbm, rs, columns, 0);                fetchJoinedNodes(rs, joins, columns.length);                if (rs.next()) {                    throw new RuntimeException("More than one value returned by query.");                }            } finally {                if (stmt != null) {                    try {                        stmt.close();                    } catch (Exception ignore) {                    }                }            }        }        return node;    }