Class XWikiHibernateBaseStore

    • Field Detail

      • loggerManager

        @Inject
        protected org.xwiki.logging.LoggerManager loggerManager
        LoggerManager to suspend logging during normal faulty SQL operation.
      • store

        @Inject
        protected com.xpn.xwiki.internal.store.hibernate.HibernateStore store
      • hibernateConfiguration

        @Inject
        protected com.xpn.xwiki.internal.store.hibernate.HibernateConfiguration hibernateConfiguration
    • Constructor Detail

      • XWikiHibernateBaseStore

        @Deprecated
        public XWikiHibernateBaseStore​(XWiki xwiki,
                                       XWikiContext context)
        Deprecated.
        1.6M1. Use ComponentManager.lookup(String) instead.
        THis allows to initialize our storage engine. The hibernate config file path is taken from xwiki.cfg or directly in the WEB-INF directory.
        Parameters:
        xwiki -
        context -
      • XWikiHibernateBaseStore

        @Deprecated
        public XWikiHibernateBaseStore​(String hibpath)
        Deprecated.
        1.6M1. Use ComponentManager.lookup(String) instead.
        Initialize the storage engine with a specific path This is used for tests.
        Parameters:
        hibpath -
      • XWikiHibernateBaseStore

        public XWikiHibernateBaseStore()
        Empty constructor needed for component manager.
    • Method Detail

      • getHint

        public String getHint()
      • getPath

        public String getPath()
        Allows to get the current hibernate config file path
      • setPath

        public void setPath​(String hibpath)
        Allows to set the current hibernate config file path
        Parameters:
        hibpath -
      • getDatabaseMetaData

        public DatabaseMetaData getDatabaseMetaData()
        Retrieve metadata about the database used (name, version, etc).

        Note that the database metadata is not cached and it's retrieved at each call. If all you need is the database product name you should use getDatabaseProductName() instead, which is cached.

        Returns:
        the database meta data or null if an error occurred
        Since:
        6.1M1
      • getDatabaseProductName

        public DatabaseProduct getDatabaseProductName()
        Retrieve the current database product name.

        Note that the database product name is cached for improved performances.

        Returns:
        the database product name, see DatabaseProduct
        Since:
        4.0M1
      • getSession

        public org.hibernate.Session getSession​(XWikiContext inputxcontext)
        This get's the current session. This is set in beginTransaction
        Parameters:
        inputxcontext -
      • setSession

        public void setSession​(org.hibernate.Session session,
                               XWikiContext inputxcontext)
        Allows to set the current session in the context This is set in beginTransaction
        Parameters:
        session -
        inputxcontext -
      • getTransaction

        public org.hibernate.Transaction getTransaction​(XWikiContext inputxcontext)
        Allows to get the current transaction from the context This is set in beginTransaction
        Parameters:
        inputxcontext -
      • setTransaction

        public void setTransaction​(org.hibernate.Transaction transaction,
                                   XWikiContext inputxcontext)
        Allows to set the current transaction This is set in beginTransaction
        Parameters:
        transaction -
        inputxcontext -
      • shutdownHibernate

        @Deprecated
        public void shutdownHibernate​(XWikiContext inputxcontext)
                               throws org.hibernate.HibernateException
        Deprecated.
        automatically done when the HibernateSessionFactory component is disposed
        Allows to shut down the hibernate configuration Closing all pools and connections
        Parameters:
        inputxcontext -
        Throws:
        org.hibernate.HibernateException
      • updateSchema

        public void updateSchema​(XWikiContext inputxcontext)
                          throws org.hibernate.HibernateException
        Allows to update the schema to match the hibernate mapping
        Parameters:
        inputxcontext -
        Throws:
        org.hibernate.HibernateException
      • updateSchema

        public void updateSchema​(XWikiContext inputxcontext,
                                 boolean force)
                          throws org.hibernate.HibernateException
        Allows to update the schema to match the hibernate mapping
        Parameters:
        inputxcontext -
        force - defines wether or not to force the update despite the xwiki.cfg settings
        Throws:
        org.hibernate.HibernateException
      • getSchemaFromWikiName

        protected String getSchemaFromWikiName​(String wikiName,
                                               DatabaseProduct databaseProduct,
                                               XWikiContext inputxcontext)
        Convert wiki name in database/schema name.
        Parameters:
        wikiName - the wiki name to convert.
        databaseProduct - the database engine type.
        inputxcontext - the XWiki context.
        Returns:
        the database/schema name.
        Since:
        1.1.2, 1.2M2
      • getSchemaFromWikiName

        protected String getSchemaFromWikiName​(String wikiId,
                                               XWikiContext inputxcontext)
        Convert wiki name in database/schema name.

        Need hibernate to be initialized.

        Parameters:
        wikiId - the wiki name to convert.
        inputxcontext - the XWiki context.
        Returns:
        the database/schema name.
        Since:
        1.1.2, 1.2M2
      • getSchemaFromWikiName

        public String getSchemaFromWikiName​(XWikiContext context)
        Convert context's database in real database/schema name.

        Need hibernate to be initialized.

        Parameters:
        context - the XWiki context.
        Returns:
        the database/schema name.
        Since:
        1.1.2, 1.2M2
      • getSchemaUpdateScript

        @Deprecated
        public String[] getSchemaUpdateScript​(org.hibernate.cfg.Configuration config,
                                              XWikiContext inputxcontext)
                                       throws org.hibernate.HibernateException
        Deprecated.
        do nothing since 11.5RC1
        This function gets the schema update scripts generated by comparing the current database with the current hibernate mapping config.
        Parameters:
        config -
        inputxcontext -
        Throws:
        org.hibernate.HibernateException
      • createHibernateSequenceIfRequired

        @Deprecated
        protected void createHibernateSequenceIfRequired​(String[] schemaSQL,
                                                         String schemaName,
                                                         org.hibernate.Session session)
        Deprecated.
        since 11.5RC1
        In the Hibernate mapping file for XWiki we use a "native" generator for some tables (deleted document and deleted attachments for example - The reason we use generated ids and not custom computed ones is because we don't need to address rows from these tables). For a lot of database the Dialect uses an Identity Generator (when the DB supports it). PostgreSQL and Oracle don't support it and Hibernate defaults to a Sequence Generator which uses a sequence named "hibernate_sequence" by default. Hibernate will normally create such a sequence automatically when updating the schema (see #getSchemaUpdateScript). However the problem is that Hibernate maintains a cache of sequence names per catalog and will only generate the sequence creation SQL if the sequence is not in this cache. Since the main wiki is updated first the sequence named "hibernate_sequence" will be put in this cache, thus preventing subwikis to automatically create sequence with the same name (see also https://hibernate.atlassian.net/browse/HHH-1672). As a workaround, we create the required sequence here.
        Parameters:
        schemaSQL - the list of SQL commands to execute to update the schema, possibly containing the "hibernate_sequence" sequence creation
        schemaName - the schema name corresponding to the subwiki being updated
        session - the Hibernate session, used to get the Dialect object
        Since:
        5.2RC1
      • updateSchema

        @Deprecated
        public void updateSchema​(String[] createSQL,
                                 XWikiContext inputxcontext)
                          throws org.hibernate.HibernateException
        Deprecated.
        since 11.5RC1
        Runs the update script on the current database
        Parameters:
        createSQL -
        inputxcontext -
        Throws:
        org.hibernate.HibernateException
      • updateSchema

        public void updateSchema​(BaseClass bclass,
                                 XWikiContext inputxcontext)
                          throws XWikiException,
                                 org.hibernate.HibernateException
        Custom Mapping This function update the schema based on the dynamic custom mapping provided by the class
        Parameters:
        bclass -
        inputxcontext -
        Throws:
        XWikiException
        org.hibernate.HibernateException
      • checkHibernate

        public void checkHibernate​(XWikiContext context)
                            throws org.hibernate.HibernateException
        Initializes Hibernate.
        Parameters:
        context -
        Throws:
        org.hibernate.HibernateException
      • isVirtual

        @Deprecated
        protected boolean isVirtual​(XWikiContext context)
        Deprecated.
        Virtual mode is on by default, starting with XWiki 5.0M2.
        Checks if this xwiki setup is virtual meaning if multiple wikis can be accessed using the same database pool
        Parameters:
        context - the XWiki context.
        Returns:
        true if multi-wiki, false otherwise.
      • setDatabase

        public void setDatabase​(org.hibernate.Session session,
                                XWikiContext inputxcontext)
                         throws XWikiException
        Virtual Wikis Allows to switch database connection
        Parameters:
        session -
        inputxcontext -
        Throws:
        XWikiException
      • escapeSchema

        protected String escapeSchema​(String schema,
                                      XWikiContext context)
        Escape schema name depending of the database engine.
        Parameters:
        schema - the schema name to escape
        context - the XWiki context to get database engine identifier
        Returns:
        the escaped version
      • beginTransaction

        public boolean beginTransaction​(XWikiContext context)
                                 throws XWikiException
        Begins a transaction if the context does not contains any.
        Parameters:
        context - the current XWikiContext
        Returns:
        true if a new transaction has been created, false otherwise.
        Throws:
        XWikiException - if an error occurs while retrieving or creating a new session and transaction.
      • beginTransaction

        @Deprecated
        public boolean beginTransaction​(boolean withTransaction,
                                        XWikiContext context)
                                 throws XWikiException
        Begins a transaction
        Parameters:
        withTransaction - this argument is unused
        context - the current XWikiContext
        Returns:
        true if a new transaction has been created, false otherwise.
        Throws:
        XWikiException - if an error occurs while retrieving or creating a new session and transaction.
      • beginTransaction

        @Deprecated
        public boolean beginTransaction​(org.hibernate.SessionFactory sfactory,
                                        boolean withTransaction,
                                        XWikiContext context)
                                 throws XWikiException
        Begins a transaction with a specific SessionFactory.
        Parameters:
        sfactory - the session factory used to begin a new session if none are available
        withTransaction - this argument is unused
        context - the current XWikiContext
        Returns:
        true if a new transaction has been created, false otherwise.
        Throws:
        XWikiException - if an error occurs while retrieving or creating a new session and transaction.
      • beginTransaction

        public boolean beginTransaction​(org.hibernate.SessionFactory sfactory,
                                        XWikiContext inputxcontext)
                                 throws XWikiException
        Begins a transaction with a specific SessionFactory.
        Parameters:
        sfactory - the session factory used to begin a new session if none are available
        inputxcontext - the current XWikiContext
        Returns:
        true if a new transaction has been created, false otherwise.
        Throws:
        XWikiException - if an error occurs while retrieving or creating a new session and transaction.
      • endTransaction

        @Deprecated
        public void endTransaction​(XWikiContext context,
                                   boolean commit,
                                   boolean withTransaction)
                            throws org.hibernate.HibernateException
        Deprecated.
        Ends a transaction and close the session.
        Parameters:
        context - the current XWikiContext
        commit - should we commit or not
        withTransaction -
        Throws:
        org.hibernate.HibernateException
      • endTransaction

        public void endTransaction​(XWikiContext inputxcontext,
                                   boolean commit)
        Ends a transaction and close the session.
        Parameters:
        inputxcontext - the current XWikiContext
        commit - should we commit or not
      • cleanUp

        public void cleanUp​(XWikiContext inputxcontext)
        Cleanup all sessions Used at the shutdown time
        Parameters:
        inputxcontext -
      • getSessionFactory

        public org.hibernate.SessionFactory getSessionFactory()
      • setSessionFactory

        @Deprecated
        public void setSessionFactory​(org.hibernate.SessionFactory sessionFactory)
        Deprecated.
        does not do anything since 11.5RC1
      • getConfiguration

        public org.hibernate.cfg.Configuration getConfiguration()
      • getMetadata

        public org.hibernate.boot.Metadata getMetadata()
        Since:
        11.5RC1
      • getNbConnections

        @Deprecated
        public int getNbConnections()
        Deprecated.
        since 9.9RC1
      • setNbConnections

        @Deprecated
        public void setNbConnections​(int nbConnections)
        Deprecated.
        since 9.9RC1
      • dynamicMappingTableName

        public String dynamicMappingTableName​(String className)
        Return the name generated for a dynamic mapped object.
        Parameters:
        className - the classname of the object.
        Returns:
        a name in the form xwikicustom_space_class
        Since:
        4.0M1
      • getMapping

        @Deprecated
        protected org.hibernate.cfg.Configuration getMapping​(String className,
                                                             String customMapping)
        Deprecated.
        since 11.5RC1
        Build a Configuration containing the provide mapping. Before 4.0M1, this function was called makeMapping. In 4.0M1, it enter in conflict with makeMapping(String, String)
        Parameters:
        className - the classname of the class to map.
        customMapping - the custom mapping
        Returns:
        a new Configuration containing this mapping alone.
        Since:
        4.0M1
      • makeMapping

        protected String makeMapping​(String className,
                                     String customMapping)
        Build a new XML string to define the provided mapping. Since 4.0M1, the ids are longs, and a conditional mapping is made for Oracle.
        Parameters:
        className - the name of the class to map.
        customMapping - the custom mapping
        Returns:
        a XML definition for the given mapping, using XWO_ID column for the object id.
      • failSafeExecute

        public <T> T failSafeExecute​(XWikiContext inputxcontext,
                                     boolean doCommit,
                                     XWikiHibernateBaseStore.HibernateCallback<T> cb)
        Execute method for operations in hibernate in an independent session (but not closing the current one if any). Never throw any error, but there is no warranty that the operation has been completed successfully.
        Parameters:
        inputxcontext - - used everywhere.
        doCommit - - should store commit changes(if any), or rollback it.
        cb - - callback to execute
        Returns:
        XWikiHibernateBaseStore.HibernateCallback.doInHibernate(Session), returns null if the callback throw an error.
      • isInSchemaMode

        protected boolean isInSchemaMode()
        Returns:
        true if the user has configured Hibernate to use XWiki in schema mode (vs database mode)
        Since:
        4.5M1
      • getExecution

        protected org.xwiki.context.Execution getExecution()
        We had to add this method because the Component Manager doesn't inject a field in the base class if a derived class defines a field with the same name.
        Returns:
        the execution
        Since:
        5.1M1
      • getDialect

        public org.hibernate.dialect.Dialect getDialect()
        Returns:
        a singleton instance of the configured Dialect
        Since:
        8.4RC1