On Jan 23, 2010, at 1:10 AM, Sergiu Dumitriu wrote:
On 01/22/2010 07:38 PM, cjdelisle (SVN) wrote:
Author: cjdelisle Date: 2010-01-22 19:38:30 +0100 (Fri, 22 Jan 2010) New Revision: 26312
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateStore.java Log: XWIKI-4754 parameterize query in getTranslationList
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateStore.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateStore.java 2010-01-22 17:49:40 UTC (rev 26311) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateStore.java 2010-01-22 18:38:30 UTC (rev 26312) @@ -3024,11 +3024,12 @@
public List<String> getTranslationList(XWikiDocument doc, XWikiContext context) throws XWikiException { - String hql = - "select doc.language from XWikiDocument as doc where doc.space = '" + Utils.SQLFilter(doc.getSpace()) - + "' and doc.name = '" + Utils.SQLFilter(doc.getName()) - + "' and (doc.language<> '' or (doc.language is not null and '' is null))"; - List<String> list = context.getWiki().search(hql, context); + String hql = "select doc.language from XWikiDocument as doc where doc.space = ? and doc.name = ? " + + "and (doc.language<> '' or (doc.language is not null and '' is null))";
doc.space and doc.name are explicitly used for historical reasons (in the beginning doc.fullName was not stored in the database). For better performance we could just use doc.fullName = ?.
Sergiu can you explain why we store fullName in the DB since there's already page and space. It's duplicated info which increases the risk of sync issues between the the columns. In addition I don't really see any difference in retrieving one field or 2 fields (in term of string size the full name is actually longer than the 2 fields separately so more time for comparison and serialization). Caleb, note that if you wanted to be compliant with references (and not used the deprecated doc.getFullName()) you'd need to use: this.localEntityReferenceSerializer.serialize(doc.getDocumentReference()) For space only it's: doc.getDocumentReference().getLastSpaceReference().getName() For page it's: doc.getDocumentReference().getName() Thanks -Vincent
+ ArrayList<String> params = new ArrayList<String>(); + params.add(doc.getSpace()); + params.add(doc.getName()); + List<String> list = search(hql, 0, 0, params, context); return (list == null) ? new ArrayList<String>() : list; }