Re: [xwiki-devs] [xwiki-notifications] [VOTE] Include in 1.1.1? (was Re: r5094 - in xwiki-platform: core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/sto
+1 (this new api concept would also be great to add to com.xpn.xwiki.store.XWikiStoreInterface.searchDocuments and not just searchDocumentsNames) 2007/9/26, Vincent Massol <[email protected]>:
Hi,
I'd like to include the following commit in 1.1.1. The reason is that it fixes a bug (XWIKI-1768: Cannot delete Space with a simple quote in its name). However it also introduces a new API.
The only risk would be that I've introduced a regression in my changes below (I've refactored one existing method so that the newly added implementation can share 90% of its code).
WDYT?
Here's my +1
Thanks -Vincent
On Sep 26, 2007, at 12:04 PM, Vincent Massol wrote:
Author: vmassol Date: 2007-09-26 12:04:32 +0200 (Wed, 26 Sep 2007) New Revision: 5094
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/ api/XWiki.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/ store/XWikiCacheStore.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/ store/XWikiHibernateStore.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/ store/XWikiStoreInterface.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/ store/jcr/XWikiJcrStore.java xwiki-platform/web/trunk/standard/src/main/webapp/skins/ albatross/delete.vm Log: XWIKI-1770: Add new searchDocuments() API that accepts named HQL queries XWIKI-1768: Cannot delete Space with a simple quote in its name
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/ xpn/xwiki/api/XWiki.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/api/XWiki.java 2007-09-26 08:44:21 UTC (rev 5093) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/api/XWiki.java 2007-09-26 10:04:32 UTC (rev 5094) @@ -464,6 +464,20 @@ return wrapDocs(xwiki.getStore().searchDocuments(wheresql, nb, start, getXWikiContext())); }
+ public List searchDocuments(String parametrizedSqlClause, int nb, int start, + List parameterValues) throws XWikiException + { + return xwiki.getStore().searchDocumentsNames (parametrizedSqlClause, nb, start, + parameterValues, getXWikiContext()); + } + + public List searchDocuments(String parametrizedSqlClause, List parameterValues) + throws XWikiException + { + return xwiki.getStore().searchDocumentsNames (parametrizedSqlClause, + parameterValues, getXWikiContext()); + } + /** * Function to wrap a list of XWikiDocument into Document objects *
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/ xpn/xwiki/store/XWikiCacheStore.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/XWikiCacheStore.java 2007-09-26 08:44:21 UTC (rev 5093) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/XWikiCacheStore.java 2007-09-26 10:04:32 UTC (rev 5094) @@ -248,6 +248,18 @@ return store.searchDocuments(wheresql, distinctbyname, customMapping, checkRight, nb, start, context); }
+ public List searchDocumentsNames(String parametrizedSqlClause, int nb, int start, + List parameterValues, XWikiContext context) throws XWikiException + { + return store.searchDocumentsNames(parametrizedSqlClause, nb, start, parameterValues, context); + } + + public List searchDocumentsNames(String parametrizedSqlClause, List parameterValues, + XWikiContext context) throws XWikiException + { + return store.searchDocumentsNames(parametrizedSqlClause, parameterValues, context); + } + public XWikiLock loadLock(long docId, XWikiContext context, boolean bTransaction) throws XWikiException { return store.loadLock(docId, context, bTransaction); }
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/ xpn/xwiki/store/XWikiHibernateStore.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/XWikiHibernateStore.java 2007-09-26 08:44:21 UTC (rev 5093) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/XWikiHibernateStore.java 2007-09-26 10:04:32 UTC (rev 5094) @@ -1622,6 +1622,19 @@ return ("1".equals(context.getWiki().Param(param + ".read", "1"))); }
+ public List searchDocumentsNames(String parametrizedSqlClause, List parameterValues, + XWikiContext context) throws XWikiException + { + return searchDocumentsNames(parametrizedSqlClause, 0, 0, parameterValues, context); + } + + public List searchDocumentsNames(String parametrizedSqlClause, int nb, int start, + List parameterValues, XWikiContext context) throws XWikiException + { + String sql = createSQLQuery("select distinct doc.web, doc.name", parametrizedSqlClause); + return searchDocumentsNamesInternal(sql, nb, start, parameterValues, context); + } + public List search(String sql, int nb, int start, Object[][] whereParams, XWikiContext context) throws XWikiException { boolean bTransaction = true;
@@ -1750,12 +1763,18 @@ } }
- public List searchDocumentsNames(String wheresql, int nb, int start, String selectColumns, XWikiContext context) throws XWikiException { + public List searchDocumentsNames(String wheresql, int nb, int start, String selectColumns, XWikiContext context) throws XWikiException + { + String sql = createSQLQuery("select distinct doc.web, doc.name", wheresql); + return searchDocumentsNamesInternal(sql, nb, start, Collections.EMPTY_LIST, context); + } + + private List searchDocumentsNamesInternal(String sql, int nb, int start, List parameterValues, + XWikiContext context) throws XWikiException + { boolean bTransaction = false; MonitorPlugin monitor = Util.getMonitorPlugin(context); try { - String sql = createSQLQuery("select distinct doc.web, doc.name", wheresql); - // Start monitoring timer if (monitor!=null) monitor.startTimer("hibernate", sql); @@ -1764,6 +1783,16 @@ bTransaction = beginTransaction(false, context); Session session = getSession(context); Query query = session.createQuery(sql); + + if (parameterValues != null) + { + int i = 0; + for (Iterator values = parameterValues.iterator(); values.hasNext();) { + query.setString(i, (String) values.next()); + i++; + } + } + if (start!=0) query.setFirstResult(start); if (nb!=0) @@ -1780,7 +1809,7 @@ catch (Exception e) { throw new XWikiException (XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SEARCH, - "Exception while searching documents with sql [{0}]", e, new Object[]{ wheresql }); + "Exception while searching documents with SQL [{0}]", e, new Object[]{ sql }); } finally { try { if (bTransaction) @@ -1793,6 +1822,7 @@ } }
+ /** * @todo refactor it to remove duplications with the searchDocument API without the distrinctbylanguage parameter */
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/ xpn/xwiki/store/XWikiStoreInterface.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/XWikiStoreInterface.java 2007-09-26 08:44:21 UTC (rev 5093) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/XWikiStoreInterface.java 2007-09-26 10:04:32 UTC (rev 5094) @@ -40,6 +40,8 @@ public List searchDocumentsNames(String wheresql, XWikiContext context) throws XWikiException; public List searchDocumentsNames(String wheresql, int nb, int start, XWikiContext context) throws XWikiException; public List searchDocumentsNames(String wheresql, int nb, int start, String selectColumns, XWikiContext context) throws XWikiException; + public List searchDocumentsNames(String parametrizedSqlClause, int nb, int start, List parameterValues, XWikiContext context) throws XWikiException; + public List searchDocumentsNames(String parametrizedSqlClause, List parameterValues, XWikiContext context) throws XWikiException; public List searchDocuments(String wheresql, boolean distinctbyname, XWikiContext context) throws XWikiException; public List searchDocuments(String wheresql, boolean distinctbyname, boolean customMapping, XWikiContext context) throws XWikiException; public List searchDocuments(String wheresql, boolean distinctbyname, int nb, int start, XWikiContext context) throws XWikiException;
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/ xpn/xwiki/store/jcr/XWikiJcrStore.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/jcr/XWikiJcrStore.java 2007-09-26 08:44:21 UTC (rev 5093) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/jcr/XWikiJcrStore.java 2007-09-26 10:04:32 UTC (rev 5094) @@ -929,7 +929,21 @@ return null; }
- public List search(String sql, int nb, int start, XWikiContext context) throws XWikiException { + public List searchDocumentsNames(String parametrizedSqlClause, int nb, int start, + List parameterValues, XWikiContext context) throws XWikiException + { + notSupportedCall(); + return null; + } + + public List searchDocumentsNames(String parametrizedSqlClause, List parameterValues, + XWikiContext context) throws XWikiException + { + notSupportedCall(); + return null; + } + + public List search(String sql, int nb, int start, XWikiContext context) throws XWikiException { notSupportedCall(); return null; }
Modified: xwiki-platform/web/trunk/standard/src/main/webapp/skins/ albatross/delete.vm =================================================================== --- xwiki-platform/web/trunk/standard/src/main/webapp/skins/ albatross/delete.vm 2007-09-26 08:44:21 UTC (rev 5093) +++ xwiki-platform/web/trunk/standard/src/main/webapp/skins/ albatross/delete.vm 2007-09-26 10:04:32 UTC (rev 5094) @@ -8,7 +8,7 @@ <div id="xwikimessage">$message</div> #end #set($links=$doc.getBacklinks()) -#set($orphans = $xwiki.searchDocuments(" where doc.fullName <> '$ {doc.fullName}as' and (doc.parent = '${doc.fullName}' or (doc.parent = '${doc.name}' and doc.web = '${doc.web}'))")) +#set($orphans = $xwiki.searchDocuments(" where doc.fullName <> ? and (doc.parent = ? or (doc.parent = ? and doc.web = ?))", ["$ {doc.fullName}as", ${doc.fullName}, ${doc.name}, ${doc.web}])) #if($request.xredirect) #set($redirectparam = "&xredirect=$request.xredirect") #end
_______________________________________________ notifications mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/notifications
-- Thomas Mortagne
On Sep 26, 2007, at 3:19 PM, Thomas Mortagne wrote:
+1
(this new api concept would also be great to add to com.xpn.xwiki.store.XWikiStoreInterface.searchDocuments and not just searchDocumentsNames)
Yes, I know... but I always like to only introduce new APIs that are used at least in one place and since I have had that need yet... -Vincent
2007/9/26, Vincent Massol <[email protected]>:
Hi,
I'd like to include the following commit in 1.1.1. The reason is that it fixes a bug (XWIKI-1768: Cannot delete Space with a simple quote in its name). However it also introduces a new API.
The only risk would be that I've introduced a regression in my changes below (I've refactored one existing method so that the newly added implementation can share 90% of its code).
WDYT?
Here's my +1
Thanks -Vincent
On Sep 26, 2007, at 12:04 PM, Vincent Massol wrote:
Author: vmassol Date: 2007-09-26 12:04:32 +0200 (Wed, 26 Sep 2007) New Revision: 5094
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/ api/XWiki.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/ store/XWikiCacheStore.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/ store/XWikiHibernateStore.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/ store/XWikiStoreInterface.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/ store/jcr/XWikiJcrStore.java xwiki-platform/web/trunk/standard/src/main/webapp/skins/ albatross/delete.vm Log: XWIKI-1770: Add new searchDocuments() API that accepts named HQL queries XWIKI-1768: Cannot delete Space with a simple quote in its name
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/ xpn/xwiki/api/XWiki.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/api/XWiki.java 2007-09-26 08:44:21 UTC (rev 5093) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/api/XWiki.java 2007-09-26 10:04:32 UTC (rev 5094) @@ -464,6 +464,20 @@ return wrapDocs(xwiki.getStore().searchDocuments(wheresql, nb, start, getXWikiContext())); }
+ public List searchDocuments(String parametrizedSqlClause, int nb, int start, + List parameterValues) throws XWikiException + { + return xwiki.getStore().searchDocumentsNames (parametrizedSqlClause, nb, start, + parameterValues, getXWikiContext()); + } + + public List searchDocuments(String parametrizedSqlClause, List parameterValues) + throws XWikiException + { + return xwiki.getStore().searchDocumentsNames (parametrizedSqlClause, + parameterValues, getXWikiContext()); + } + /** * Function to wrap a list of XWikiDocument into Document objects *
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/ xpn/xwiki/store/XWikiCacheStore.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/XWikiCacheStore.java 2007-09-26 08:44:21 UTC (rev 5093) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/XWikiCacheStore.java 2007-09-26 10:04:32 UTC (rev 5094) @@ -248,6 +248,18 @@ return store.searchDocuments(wheresql, distinctbyname, customMapping, checkRight, nb, start, context); }
+ public List searchDocumentsNames(String parametrizedSqlClause, int nb, int start, + List parameterValues, XWikiContext context) throws XWikiException + { + return store.searchDocumentsNames(parametrizedSqlClause, nb, start, parameterValues, context); + } + + public List searchDocumentsNames(String parametrizedSqlClause, List parameterValues, + XWikiContext context) throws XWikiException + { + return store.searchDocumentsNames(parametrizedSqlClause, parameterValues, context); + } + public XWikiLock loadLock(long docId, XWikiContext context, boolean bTransaction) throws XWikiException { return store.loadLock(docId, context, bTransaction); }
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/ xpn/xwiki/store/XWikiHibernateStore.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/XWikiHibernateStore.java 2007-09-26 08:44:21 UTC (rev 5093) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/XWikiHibernateStore.java 2007-09-26 10:04:32 UTC (rev 5094) @@ -1622,6 +1622,19 @@ return ("1".equals(context.getWiki().Param(param + ".read", "1"))); }
+ public List searchDocumentsNames(String parametrizedSqlClause, List parameterValues, + XWikiContext context) throws XWikiException + { + return searchDocumentsNames(parametrizedSqlClause, 0, 0, parameterValues, context); + } + + public List searchDocumentsNames(String parametrizedSqlClause, int nb, int start, + List parameterValues, XWikiContext context) throws XWikiException + { + String sql = createSQLQuery("select distinct doc.web, doc.name", parametrizedSqlClause); + return searchDocumentsNamesInternal(sql, nb, start, parameterValues, context); + } + public List search(String sql, int nb, int start, Object[][] whereParams, XWikiContext context) throws XWikiException { boolean bTransaction = true;
@@ -1750,12 +1763,18 @@ } }
- public List searchDocumentsNames(String wheresql, int nb, int start, String selectColumns, XWikiContext context) throws XWikiException { + public List searchDocumentsNames(String wheresql, int nb, int start, String selectColumns, XWikiContext context) throws XWikiException + { + String sql = createSQLQuery("select distinct doc.web, doc.name", wheresql); + return searchDocumentsNamesInternal(sql, nb, start, Collections.EMPTY_LIST, context); + } + + private List searchDocumentsNamesInternal(String sql, int nb, int start, List parameterValues, + XWikiContext context) throws XWikiException + { boolean bTransaction = false; MonitorPlugin monitor = Util.getMonitorPlugin(context); try { - String sql = createSQLQuery("select distinct doc.web, doc.name", wheresql); - // Start monitoring timer if (monitor!=null) monitor.startTimer("hibernate", sql); @@ -1764,6 +1783,16 @@ bTransaction = beginTransaction(false, context); Session session = getSession(context); Query query = session.createQuery(sql); + + if (parameterValues != null) + { + int i = 0; + for (Iterator values = parameterValues.iterator(); values.hasNext();) { + query.setString(i, (String) values.next()); + i++; + } + } + if (start!=0) query.setFirstResult(start); if (nb!=0) @@ -1780,7 +1809,7 @@ catch (Exception e) { throw new XWikiException (XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SEARCH, - "Exception while searching documents with sql [{0}]", e, new Object[]{ wheresql }); + "Exception while searching documents with SQL [{0}]", e, new Object[]{ sql }); } finally { try { if (bTransaction) @@ -1793,6 +1822,7 @@ } }
+ /** * @todo refactor it to remove duplications with the searchDocument API without the distrinctbylanguage parameter */
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/ xpn/xwiki/store/XWikiStoreInterface.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/XWikiStoreInterface.java 2007-09-26 08:44:21 UTC (rev 5093) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/XWikiStoreInterface.java 2007-09-26 10:04:32 UTC (rev 5094) @@ -40,6 +40,8 @@ public List searchDocumentsNames(String wheresql, XWikiContext context) throws XWikiException; public List searchDocumentsNames(String wheresql, int nb, int start, XWikiContext context) throws XWikiException; public List searchDocumentsNames(String wheresql, int nb, int start, String selectColumns, XWikiContext context) throws XWikiException; + public List searchDocumentsNames(String parametrizedSqlClause, int nb, int start, List parameterValues, XWikiContext context) throws XWikiException; + public List searchDocumentsNames(String parametrizedSqlClause, List parameterValues, XWikiContext context) throws XWikiException; public List searchDocuments(String wheresql, boolean distinctbyname, XWikiContext context) throws XWikiException; public List searchDocuments(String wheresql, boolean distinctbyname, boolean customMapping, XWikiContext context) throws XWikiException; public List searchDocuments(String wheresql, boolean distinctbyname, int nb, int start, XWikiContext context) throws XWikiException;
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/ xpn/xwiki/store/jcr/XWikiJcrStore.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/jcr/XWikiJcrStore.java 2007-09-26 08:44:21 UTC (rev 5093) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/ xwiki/store/jcr/XWikiJcrStore.java 2007-09-26 10:04:32 UTC (rev 5094) @@ -929,7 +929,21 @@ return null; }
- public List search(String sql, int nb, int start, XWikiContext context) throws XWikiException { + public List searchDocumentsNames(String parametrizedSqlClause, int nb, int start, + List parameterValues, XWikiContext context) throws XWikiException + { + notSupportedCall(); + return null; + } + + public List searchDocumentsNames(String parametrizedSqlClause, List parameterValues, + XWikiContext context) throws XWikiException + { + notSupportedCall(); + return null; + } + + public List search(String sql, int nb, int start, XWikiContext context) throws XWikiException { notSupportedCall(); return null; }
Modified: xwiki-platform/web/trunk/standard/src/main/webapp/skins/ albatross/delete.vm =================================================================== --- xwiki-platform/web/trunk/standard/src/main/webapp/skins/ albatross/delete.vm 2007-09-26 08:44:21 UTC (rev 5093) +++ xwiki-platform/web/trunk/standard/src/main/webapp/skins/ albatross/delete.vm 2007-09-26 10:04:32 UTC (rev 5094) @@ -8,7 +8,7 @@ <div id="xwikimessage">$message</div> #end #set($links=$doc.getBacklinks()) -#set($orphans = $xwiki.searchDocuments(" where doc.fullName <> '$ {doc.fullName}as' and (doc.parent = '${doc.fullName}' or (doc.parent = '${doc.name}' and doc.web = '${doc.web}'))")) +#set($orphans = $xwiki.searchDocuments(" where doc.fullName <> ? and (doc.parent = ? or (doc.parent = ? and doc.web = ?))", ["$ {doc.fullName}as", ${doc.fullName}, ${doc.name}, ${doc.web}])) #if($request.xredirect) #set($redirectparam = "&xredirect=$request.xredirect") #end
_______________________________________________ notifications mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/notifications
-- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On Sep 26, 2007, at 4:13 PM, Vincent Massol wrote:
On Sep 26, 2007, at 3:19 PM, Thomas Mortagne wrote:
+1
(this new api concept would also be great to add to com.xpn.xwiki.store.XWikiStoreInterface.searchDocuments and not just searchDocumentsNames)
Yes, I know... but I always like to only introduce new APIs that are used at least in one place and since I have had that need yet...
Sorry, I meant: "since I haven't had that need yet..." -Vincent [snip]
participants (2)
-
Thomas Mortagne -
Vincent Massol