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;
}
Aggregations