Class XWikiCacheStore

  • All Implemented Interfaces:
    XWikiCacheStoreInterface, XWikiStoreInterface, org.xwiki.component.phase.Initializable, org.xwiki.observation.EventListener

    @Component(roles=XWikiStoreInterface.class)
    @Named("cache")
    @InstantiationStrategy(PER_LOOKUP)
    public class XWikiCacheStore
    extends com.xpn.xwiki.internal.store.AbstractXWikiStore
    implements XWikiCacheStoreInterface, org.xwiki.observation.EventListener, org.xwiki.component.phase.Initializable
    A proxy store implementation that caches Documents when they are first fetched and subsequently return them from a cache. It delegates all write and search operations to an underlying store without doing any caching on them.
    Version:
    $Id: 65c2a7c78c06503eb35485e751a97f434b9fa938 $
    • Constructor Detail

      • XWikiCacheStore

        public XWikiCacheStore()
        Default constructor generally used by the Component Manager.
    • Method Detail

      • initialize

        public void initialize()
                        throws org.xwiki.component.phase.InitializationException
        Specified by:
        initialize in interface org.xwiki.component.phase.Initializable
        Throws:
        org.xwiki.component.phase.InitializationException
      • getName

        public String getName()
        Specified by:
        getName in interface org.xwiki.observation.EventListener
      • getEvents

        public List<Event> getEvents()
        Specified by:
        getEvents in interface org.xwiki.observation.EventListener
      • renameXWikiDoc

        public void renameXWikiDoc​(XWikiDocument doc,
                                   DocumentReference newReference,
                                   XWikiContext inputxcontext)
                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Atomic operation for renaming a document. This operation will rename the document in DB by performing updates in all tables the document name is used.
        Specified by:
        renameXWikiDoc in interface XWikiStoreInterface
        Parameters:
        doc - the actual document instance to rename.
        newReference - the new reference to use for renaming.
        inputxcontext - the current context.
        Throws:
        XWikiException - in case of problem during the rename.
      • onEvent

        public void onEvent​(Event event,
                            Object source,
                            Object data)
        Specified by:
        onEvent in interface org.xwiki.observation.EventListener
      • searchDocumentReferences

        public List<DocumentReference> searchDocumentReferences​(String parametrizedSqlClause,
                                                                int nb,
                                                                int start,
                                                                List<?> parameterValues,
                                                                XWikiContext context)
                                                         throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents by passing HQL where clause values as parameters. This allows generating a Named HQL query which will automatically encode the passed values (like escaping single quotes). This API is recommended to be used over the other similar methods where the values are passed inside the where clause and for which you'll need to do the encoding/escaping yourself before calling them.

        Example:

         
         #set($orphans = $xwiki.searchDocuments(" where doc.fullName <> ?1 and (doc.parent = ?2 or "
             + "(doc.parent = ?3 and doc.space = ?4))",
             ["${doc.fullName}as", ${doc.fullName}, ${doc.name}, ${doc.space}]))
         
         
        Specified by:
        searchDocumentReferences in interface XWikiStoreInterface
        Parameters:
        parametrizedSqlClause - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        nb - the number of rows to return. If 0 then all rows are returned
        start - the number of rows to skip. If 0 don't skip any row
        parameterValues - the where clause values that replace the question marks (?)
        context - the XWiki context required for getting information about the execution context
        Returns:
        a list of document references
        Throws:
        XWikiException - in case of error while performing the query
      • searchDocuments

        public List<XWikiDocument> searchDocuments​(String wheresql,
                                                   boolean distinctbyname,
                                                   XWikiContext context)
                                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents in the storing system.
        Specified by:
        searchDocuments in interface XWikiStoreInterface
        Parameters:
        wheresql - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        distinctbyname - when a document has multiple version for each language it is returned as one document a language.
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • searchDocuments

        public List<XWikiDocument> searchDocuments​(String wheresql,
                                                   boolean distinctbyname,
                                                   boolean customMapping,
                                                   XWikiContext context)
                                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents in the storing system.
        Specified by:
        searchDocuments in interface XWikiStoreInterface
        Parameters:
        wheresql - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        distinctbyname - when a document has multiple version for each language it is returned as one document a language.
        customMapping - inject custom mapping in session.
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • searchDocuments

        public List<XWikiDocument> searchDocuments​(String wheresql,
                                                   boolean distinctbyname,
                                                   int nb,
                                                   int start,
                                                   XWikiContext context)
                                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents in the storing system.
        Specified by:
        searchDocuments in interface XWikiStoreInterface
        Parameters:
        wheresql - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        distinctbyname - when a document has multiple version for each language it is returned as one document a language.
        nb - the number of rows to return. If 0 then all rows are returned.
        start - the number of rows to skip. If 0 don't skip any row.
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • searchDocuments

        public List<XWikiDocument> searchDocuments​(String wheresql,
                                                   boolean distinctbyname,
                                                   boolean customMapping,
                                                   int nb,
                                                   int start,
                                                   XWikiContext context)
                                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents in the storing system.
        Specified by:
        searchDocuments in interface XWikiStoreInterface
        Parameters:
        wheresql - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        distinctbyname - when a document has multiple version for each language it is returned as one document a language.
        customMapping - inject custom mapping in session.
        nb - the number of rows to return. If 0 then all rows are returned.
        start - the number of rows to skip. If 0 don't skip any row.
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • searchDocuments

        public List<XWikiDocument> searchDocuments​(String wheresql,
                                                   XWikiContext context)
                                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents in the storing system.
        Specified by:
        searchDocuments in interface XWikiStoreInterface
        Parameters:
        wheresql - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • searchDocuments

        public List<XWikiDocument> searchDocuments​(String wheresql,
                                                   int nb,
                                                   int start,
                                                   XWikiContext context)
                                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents in the storing system.
        Specified by:
        searchDocuments in interface XWikiStoreInterface
        Parameters:
        wheresql - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        nb - the number of rows to return. If 0 then all rows are returned.
        start - the number of rows to skip. If 0 don't skip any row.
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • searchDocuments

        public List<XWikiDocument> searchDocuments​(String wheresql,
                                                   boolean distinctbyname,
                                                   boolean customMapping,
                                                   boolean checkRight,
                                                   int nb,
                                                   int start,
                                                   XWikiContext context)
                                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents in the storing system.
        Specified by:
        searchDocuments in interface XWikiStoreInterface
        Parameters:
        wheresql - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        distinctbyname - when a document has multiple version for each language it is returned as one document a language.
        customMapping - inject custom mapping in session.
        checkRight - if true check for each found document if context's user has "view" rights for it.
        nb - the number of rows to return. If 0 then all rows are returned.
        start - the number of rows to skip. If 0 don't skip any row.
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • searchDocuments

        public List<XWikiDocument> searchDocuments​(String wheresql,
                                                   boolean distinctbylanguage,
                                                   int nb,
                                                   int start,
                                                   List<?> parameterValues,
                                                   XWikiContext context)
                                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents in the storing system.
        Specified by:
        searchDocuments in interface XWikiStoreInterface
        Parameters:
        wheresql - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        distinctbylanguage - when a document has multiple version for each language it is returned as one document a language.
        nb - the number of rows to return. If 0 then all rows are returned.
        start - the number of rows to skip. If 0 don't skip any row.
        parameterValues - the where clause values that replace the question marks (?).
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • searchDocuments

        public List<XWikiDocument> searchDocuments​(String wheresql,
                                                   List<?> parameterValues,
                                                   XWikiContext context)
                                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents in the storing system.

        Search documents by passing HQL where clause values as parameters. This allows generating a Named HQL query which will automatically encode the passed values (like escaping single quotes). This API is recommended to be used over the other similar methods where the values are passed inside the where clause and for which you'll need to do the encoding/escpaing yourself before calling them.

        Specified by:
        searchDocuments in interface XWikiStoreInterface
        Parameters:
        wheresql - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        parameterValues - the where clause values that replace the question marks (?).
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • searchDocuments

        public List<XWikiDocument> searchDocuments​(String wheresql,
                                                   boolean distinctbylanguage,
                                                   boolean customMapping,
                                                   int nb,
                                                   int start,
                                                   List<?> parameterValues,
                                                   XWikiContext context)
                                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents in the storing system.

        Search documents by passing HQL where clause values as parameters. This allows generating a Named HQL query which will automatically encode the passed values (like escaping single quotes). This API is recommended to be used over the other similar methods where the values are passed inside the where clause and for which you'll need to do the encoding/escpaing yourself before calling them.

        Specified by:
        searchDocuments in interface XWikiStoreInterface
        Parameters:
        wheresql - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        distinctbylanguage - when a document has multiple version for each language it is returned as one document a language.
        customMapping - inject custom mapping in session.
        nb - the number of rows to return. If 0 then all rows are returned.
        start - the number of rows to skip. If 0 don't skip any row.
        parameterValues - the where clause values that replace the question marks (?).
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • searchDocuments

        public List<XWikiDocument> searchDocuments​(String wheresql,
                                                   int nb,
                                                   int start,
                                                   List<?> parameterValues,
                                                   XWikiContext context)
                                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents in the storing system.

        Search documents by passing HQL where clause values as parameters. This allows generating a Named HQL query which will automatically encode the passed values (like escaping single quotes). This API is recommended to be used over the other similar methods where the values are passed inside the where clause and for which you'll need to do the encoding/escpaing yourself before calling them.

        Specified by:
        searchDocuments in interface XWikiStoreInterface
        Parameters:
        wheresql - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        nb - the number of rows to return. If 0 then all rows are returned.
        start - the number of rows to skip. If 0 don't skip any row.
        parameterValues - the where clause values that replace the question marks (?).
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • searchDocuments

        public List<XWikiDocument> searchDocuments​(String wheresql,
                                                   boolean distinctbylanguage,
                                                   boolean customMapping,
                                                   boolean checkRight,
                                                   int nb,
                                                   int start,
                                                   List<?> parameterValues,
                                                   XWikiContext context)
                                            throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Search documents in the storing system.

        Search documents by passing HQL where clause values as parameters. This allows generating a Named HQL query which will automatically encode the passed values (like escaping single quotes). This API is recommended to be used over the other similar methods where the values are passed inside the where clause and for which you'll need to do the encoding/escpaing yourself before calling them.

        Specified by:
        searchDocuments in interface XWikiStoreInterface
        Parameters:
        wheresql - the HQL where clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        distinctbylanguage - when a document has multiple version for each language it is returned as one document a language.
        customMapping - inject custom mapping in session.
        checkRight - if true check for each found document if context's user has "view" rights for it.
        nb - the number of rows to return. If 0 then all rows are returned.
        start - the number of rows to skip. If 0 don't skip any row.
        parameterValues - the where clause values that replace the question marks (?).
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • countDocuments

        public int countDocuments​(String parametrizedSqlClause,
                                  List<?> parameterValues,
                                  XWikiContext context)
                           throws XWikiException
        Description copied from interface: XWikiStoreInterface
        API allowing to count the total number of documents that would be returned by a parameterized query.
        Specified by:
        countDocuments in interface XWikiStoreInterface
        Parameters:
        parametrizedSqlClause - Parameterized query to use, similar to the ones accepted by XWikiStoreInterface.searchDocuments(String, List, XWikiContext). It should not contain order by or group clauses, since this kind of queries are not portable.
        parameterValues - The parameter values that replace the question marks.
        context - The current request context.
        Returns:
        The number of documents that matched the query.
        Throws:
        XWikiException - if there was a problem executing the query.
      • search

        public <T> List<T> search​(String sql,
                                  int nb,
                                  int start,
                                  XWikiContext context)
                           throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Execute a reading request and return result.
        Specified by:
        search in interface XWikiStoreInterface
        Parameters:
        sql - the HQL request clause. For example: where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        nb - the number of rows to return. If 0 then all rows are returned.
        start - the number of rows to skip. If 0 don't skip any row.
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • search

        public <T> List<T> search​(String sql,
                                  int nb,
                                  int start,
                                  Object[][] whereParams,
                                  XWikiContext context)
                           throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Execute a reading request and return result.
        Specified by:
        search in interface XWikiStoreInterface
        Parameters:
        sql - the HQL request.
        nb - the number of rows to return. If 0 then all rows are returned.
        start - the number of rows to skip. If 0 don't skip any row.
        whereParams - if not null add to sql a where clause based on a table of table containing field name, field value and compared symbol (=, >, etc.).
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • search

        public <T> List<T> search​(String sql,
                                  int nb,
                                  int start,
                                  List<?> parameterValues,
                                  XWikiContext context)
                           throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Execute a reading request with parameters and return result.

        Execute query by passing HQL request values as parameters. This allows generating a Named HQL query which will automatically encode the passed values (like escaping single quotes). This API is recommended to be used over the other similar methods where the values are passed inside the where clause and for which you'll need to do the encoding/escaping yourself before calling them.

        Specified by:
        search in interface XWikiStoreInterface
        Parameters:
        sql - the HQL request.
        nb - the number of rows to return. If 0 then all rows are returned.
        start - the number of rows to skip. If 0 don't skip any row.
        parameterValues - the where clause values that replace the question marks (?).
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • search

        public <T> List<T> search​(String sql,
                                  int nb,
                                  int start,
                                  Object[][] whereParams,
                                  List<?> parameterValues,
                                  XWikiContext context)
                           throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Execute a reading request with parameters and return result.

        Execute query by passing HQL request values as parameters. This allows generating a Named HQL query which will automatically encode the passed values (like escaping single quotes). This API is recommended to be used over the other similar methods where the values are passed inside the where clause and for which you'll need to do the encoding/escaping yourself before calling them.

        Specified by:
        search in interface XWikiStoreInterface
        Parameters:
        sql - the HQL request.
        nb - the number of rows to return. If 0 then all rows are returned.
        start - the number of rows to skip. If 0 don't skip any row.
        whereParams - if not null add to sql a where clause based on a table of table containing field name, field value and compared symbol (=, >, etc.).
        parameterValues - the where clause values that replace the question marks (?).
        context - the XWiki context required for getting information about the execution context.
        Returns:
        a list of XWikiDocument.
        Throws:
        XWikiException - in case of error while performing the query.
      • isWikiNameAvailable

        public boolean isWikiNameAvailable​(String wikiName,
                                           XWikiContext context)
                                    throws XWikiException
        Description copied from interface: XWikiStoreInterface
        Indicate if the provided wiki name could be used to create a new wiki.
        Specified by:
        isWikiNameAvailable in interface XWikiStoreInterface
        Parameters:
        wikiName - the name of the wiki.
        context - the XWiki context.
        Returns:
        true if the name is already used, false otherwise.
        Throws:
        XWikiException - error when looking if wiki name already used.
      • getCache

        public org.xwiki.cache.Cache<XWikiDocument> getCache()
      • setCache

        public void setCache​(org.xwiki.cache.Cache<XWikiDocument> cache)
      • getPageExistCache

        public org.xwiki.cache.Cache<Boolean> getPageExistCache()
      • setPageExistCache

        public void setPageExistCache​(org.xwiki.cache.Cache<Boolean> pageExistCache)
      • getLimitSizePropertyCache

        public org.xwiki.cache.Cache<Integer> getLimitSizePropertyCache()
        Returns:
        the cache that handle the limit size properties.
        Since:
        11.4RC1
      • getQueryManager

        public QueryManager getQueryManager()
        Specified by:
        getQueryManager in interface XWikiStoreInterface
        Returns:
        QueryManager used for creating queries to store. Use QueryManager instead of #search* methods because it is more abstract from store implementation and support multiple query languages.
      • getLimitSize

        public int getLimitSize​(XWikiContext context,
                                Class<?> entityType,
                                String propertyName)
        Description copied from interface: XWikiStoreInterface
        Get the limit size of a property.
        Specified by:
        getLimitSize in interface XWikiStoreInterface
        Parameters:
        context - the context of the wiki to retrieve the property
        entityType - the entityType where the property is located.
        propertyName - the property on which we want the limit size.
        Returns:
        an integer representing the limit size.