Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/DBListClass.java =================================================================== --- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/DBListClass.java (revision 7290) +++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/DBListClass.java (working copy) @@ -146,7 +146,7 @@ } return map; } - + public String getQuery(XWikiContext context) { String sql = getSql(); @@ -163,33 +163,37 @@ valueField = idField; } if (context.getWiki().getHibernateStore() != null) { - String select = "select "; - String tables = " from XWikiDocument as doc, BaseObject as obj"; - String where = - " where doc.fullName=obj.name and obj.className='" + classname + "'"; + StringBuffer select = new StringBuffer("select "); + StringBuffer tables = new StringBuffer(" from XWikiDocument as doc, BaseObject as obj"); + StringBuffer where = new StringBuffer(" where doc.fullName=obj.name and obj.className='"); + where.append(classname).append("'"); + if (idField.startsWith("doc.") || idField.startsWith("obj.")) { - select += idField + ","; + select.append(idField); } else { - select += "idprop.value,"; - tables += ", StringProperty as idprop"; - where += " and obj.id=idprop.id.id and idprop.id.name='" + idField + "'"; + select.append("idprop.value"); + tables.append(", StringProperty as idprop"); + where.append(" and obj.id=idprop.id.id and idprop.id.name='") + .append(idField) + .append("'"); } + if (valueField.startsWith("doc.") || valueField.startsWith("obj.")) { - select += valueField + ","; + select.append(", ").append(valueField); } else { if (idField.equals(valueField)) { - select += "idprop.value,"; + select.append(", idprop.value"); } else { - select += "valueprop.value,"; - tables += ", StringProperty as valueprop"; - where += - " and obj.id=valueprop.id.id and valueprop.id.name='" + valueField - + "'"; + select.append(", valueprop.value"); + tables.append(", StringProperty as valueprop"); + where.append(" and obj.id=valueprop.id.id and valueprop.id.name='") + .append(valueField) + .append("'"); } } // Let's create the sql - sql = select + tables + where; + sql = select.append(tables).append(where).toString(); } else { // TODO: query plugin impl. // We need to generate the right query for the query plugin Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/DBTreeListClass.java =================================================================== --- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/DBTreeListClass.java (revision 7290) +++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/DBTreeListClass.java (working copy) @@ -277,55 +277,68 @@ public String getQuery(XWikiContext context) { String sql = getSql(); try { - sql = context.getDoc().getRenderedContent(sql, context); + sql = context.getDoc().getRenderedContent(sql, context); } catch (Exception e) { e.printStackTrace(); } - if ((sql==null)||(sql.trim().equals(""))) { + if ((sql == null) || (sql.trim().equals(""))) { String classname = getClassname(); String idField = getIdField(); String valueField = getValueField(); - String parentField = getParentField(); - if ((valueField==null)||(valueField.trim().equals(""))) - valueField = idField; - if (context.getWiki().getHibernateStore()!=null) { - String select = "select "; - String tables = " from XWikiDocument as doc, BaseObject as obj"; - String where = " where doc.fullName=obj.name and obj.className='" + classname + "'"; - if (idField.startsWith("doc.")||idField.startsWith("obj.")) - select += idField + ","; - else { - select += "idprop.value,"; - tables += ", StringProperty as idprop"; - where += " and obj.id=idprop.id.id and idprop.id.name='" + idField + "'"; + if ((valueField == null) || (valueField.trim().equals(""))) { + valueField = idField; + } + if (context.getWiki().getHibernateStore() != null) { + StringBuffer select = new StringBuffer("select "); + StringBuffer tables = new StringBuffer(" from XWikiDocument as doc, BaseObject as obj"); + StringBuffer where = new StringBuffer(" where doc.fullName=obj.name and obj.className='"); + where.append(classname).append("'"); + + if (idField.startsWith("doc.") || idField.startsWith("obj.")) { + select.append(idField); + } else { + select.append("idprop.value"); + tables.append(", StringProperty as idprop"); + where.append(" and obj.id=idprop.id.id and idprop.id.name='") + .append(idField) + .append("'"); } - if (valueField.startsWith("doc.")||valueField.startsWith("obj.")) - select += valueField + ","; + + if (valueField.startsWith("doc.") || valueField.startsWith("obj.")) { + select.append(", ").append(valueField); + } else { if (idField.equals(valueField)) { - select += "idprop.value,"; + select.append(", idprop.value"); } else { - select += "valueprop.value,"; - tables += ", StringProperty as valueprop"; - where += " and obj.id=valueprop.id.id and valueprop.id.name='" + valueField + "'"; + select.append(", valueprop.value"); + tables.append(", StringProperty as valueprop"); + where.append(" and obj.id=valueprop.id.id and valueprop.id.name='") + .append(valueField) + .append("'"); } } - + + // DBTreeList specific part + String parentField = getParentField(); if (parentField.startsWith("doc.")||parentField.startsWith("obj.")) - select += parentField + ","; + select.append(", ").append(parentField); else { if (idField.equals(parentField)) { - select += "idprop.value,"; + select.append(", idprop.value"); } else if (valueField.equals(parentField)) { - select += "valueprop.value,"; + select.append(", valueprop.value"); } else { - select += "parentprop.value,"; - tables += ", StringProperty as parentprop"; - where += " and obj.id=parentprop.id.id and parentprop.id.name='" + parentField + "'"; + select.append(", parentprop.value"); + tables.append(", StringProperty as parentprop"); + where.append(" and obj.id=parentprop.id.id and parentprop.id.name='") + .append(parentField) + .append("'"); } } + // Let's create the sql - sql = select + tables + where; + sql = select.append(tables).append(where).toString(); } else { // TODO: query plugin impl. // We need to generate the right query for the query plugin