On 01/23/2010 09:01 AM, Vincent Massol wrote:
>
> 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).
I'm not sure who and why introduced it, but IMO it's normal. Previously
all the code that wanted to search using a document name had to either:
- manually split the fullname into space and name, with indexOf and
substring
- or use XWiki.getFullNameSQL(), which does a concat
The first one is boring to copy/paste all over the place, while the
second one hurts the performance.
I don't know if you're right about the performance of two fields versus
one longer, I believe the contrary is true. Databases don't work on
string comparison (when the proper indexes are in place), a search on
one index should be close to linear time, while joining two indexes
still requires a join, a costly operation.
> 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())
Ah, yes, we'll all have to get used to the new APIs.
> 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;
>>> }
--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs