Search in sources :

Example 1 with MigrationRequiredException

use of com.xpn.xwiki.store.migration.MigrationRequiredException in project xwiki-platform by xwiki.

the class XWikiHibernateStore method isWikiNameAvailable.

@Override
public boolean isWikiNameAvailable(String wikiName, XWikiContext inputxcontext) throws XWikiException {
    XWikiContext context = getExecutionXContext(inputxcontext, false);
    boolean available;
    boolean bTransaction = true;
    String database = context.getWikiId();
    try {
        bTransaction = beginTransaction(context);
        Session session = getSession(context);
        // we don't want to pollute application logs with "normal errors"...
        if (!this.logger.isDebugEnabled()) {
            this.loggerManager.pushLogListener(null);
        }
        context.setWikiId(wikiName);
        try {
            setDatabase(session, context);
            available = false;
        } catch (XWikiException e) {
            // Failed to switch to database. Assume it means database does not exists.
            available = !(e.getCause() instanceof MigrationRequiredException);
        }
    } catch (Exception e) {
        Object[] args = { wikiName };
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_CHECK_EXISTS_DATABASE, "Exception while listing databases to search for {0}", e, args);
    } finally {
        context.setWikiId(database);
        try {
            if (bTransaction) {
                endTransaction(context, false);
            }
        } catch (Exception e) {
        }
        // Restore proper logging
        if (!this.logger.isDebugEnabled()) {
            this.loggerManager.popLogListener();
        }
    }
    return available;
}
Also used : MigrationRequiredException(com.xpn.xwiki.store.migration.MigrationRequiredException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) XWikiException(com.xpn.xwiki.XWikiException) InitializationException(org.xwiki.component.phase.InitializationException) MigrationRequiredException(com.xpn.xwiki.store.migration.MigrationRequiredException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) QueryException(org.xwiki.query.QueryException) UnexpectedException(org.xwiki.store.UnexpectedException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) SQLException(java.sql.SQLException) Session(org.hibernate.Session)

Aggregations

XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)1 SQLException (java.sql.SQLException)1 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)1 Session (org.hibernate.Session)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 InitializationException (org.xwiki.component.phase.InitializationException)1 QueryException (org.xwiki.query.QueryException)1 UnexpectedException (org.xwiki.store.UnexpectedException)1