@Test public void hibernateMigrateWhenQueryException() throws Exception { List<String> documentList = new ArrayList<>(); documentList.add("XWiki.XWikiServerSubwiki1"); Exception exception = new QueryException("error in queryManager.createQuery()", null, null); when(queryManager.createQuery(any(), eq(Query.HQL))).thenThrow(exception); mocker.getComponentUnderTest().hibernateMigrate(); verify(mocker.getMockedLogger()).error("Failed to perform a query on the main wiki.", exception); }
@Override protected void hibernateMigrate() throws DataMigrationException, XWikiException { String hql = "SELECT DISTINCT doc.fullName FROM XWikiDocument doc, BaseObject obj WHERE doc.fullName = obj.name" + " AND obj.className = :className AND doc.fullName <> :template AND doc.fullName NOT IN " + "(SELECT DISTINCT doc2.fullName FROM XWikiDocument doc2, BaseObject obj2, StringProperty propPrettyName" + " WHERE doc2.fullName = obj2.name AND obj2.className = :className" + " AND propPrettyName.id = obj2.id AND propPrettyName.name = :propertyName)"; try { Query query = queryManager.createQuery(hql, Query.HQL); query.bindValue("className", String.format("%s.%s", XWiki.SYSTEM_SPACE, XWikiServerClassDocumentInitializer.DOCUMENT_NAME)); query.bindValue("propertyName", XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME); query.bindValue("template", "XWiki.XWikiServerClassTemplate"); List<String> results = query.execute(); for (String result : results) { fixDocument(result); } } catch (QueryException e) { logger.error("Failed to perform a query on the main wiki.", e); } }
WikiDescriptorMigrator extends AbstractHibernateDataMigration { @Override protected void hibernateMigrate() throws DataMigrationException, XWikiException { String hql = "SELECT DISTINCT doc.fullName FROM XWikiDocument doc, BaseObject obj WHERE doc.fullName = obj.name" + " AND obj.className = :className AND doc.fullName <> :template AND doc.fullName NOT IN " + "(SELECT DISTINCT doc2.fullName FROM XWikiDocument doc2, BaseObject obj2, StringProperty propPrettyName" + " WHERE doc2.fullName = obj2.name AND obj2.className = :className" + " AND propPrettyName.id = obj2.id AND propPrettyName.name = :propertyName)"; try { Query query = queryManager.createQuery(hql, Query.HQL); query.bindValue("className", String.format("%s.%s", XWiki.SYSTEM_SPACE, XWikiServerClassDocumentInitializer.DOCUMENT_NAME)); query.bindValue("propertyName", XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME); query.bindValue("template", "XWiki.XWikiServerClassTemplate"); List<String> results = query.execute(); for (String result : results) { fixDocument(result); } } catch (QueryException e) { logger.error("Failed to perform a query on the main wiki.", e); } } }
WikiDescriptorMigrator extends AbstractHibernateDataMigration { @Override protected void hibernateMigrate() throws DataMigrationException, XWikiException { String hql = "SELECT DISTINCT doc.fullName FROM XWikiDocument doc, BaseObject obj WHERE doc.fullName = obj.name" + " AND obj.className = :className AND doc.fullName <> :template AND doc.fullName NOT IN " + "(SELECT DISTINCT doc2.fullName FROM XWikiDocument doc2, BaseObject obj2, StringProperty propPrettyName" + " WHERE doc2.fullName = obj2.name AND obj2.className = :className" + " AND propPrettyName.id = obj2.id AND propPrettyName.name = :propertyName)"; try { Query query = queryManager.createQuery(hql, Query.HQL); query.bindValue("className", String.format("%s.%s", XWiki.SYSTEM_SPACE, XWikiServerClassDocumentInitializer.DOCUMENT_NAME)); query.bindValue("propertyName", XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME); query.bindValue("template", "XWiki.XWikiServerClassTemplate"); List<String> results = query.execute(); for (String result : results) { fixDocument(result); } } catch (QueryException e) { logger.error("Failed to perform a query on the main wiki.", e); } }  }
WikiDescriptorMigrator extends AbstractHibernateDataMigration { @Override protected void hibernateMigrate() throws DataMigrationException, XWikiException { String hql = "SELECT DISTINCT doc.fullName FROM XWikiDocument doc, BaseObject obj WHERE doc.fullName = obj.name" + " AND obj.className = :className AND doc.fullName <> :template AND doc.fullName NOT IN " + "(SELECT DISTINCT doc2.fullName FROM XWikiDocument doc2, BaseObject obj2, StringProperty propPrettyName" + " WHERE doc2.fullName = obj2.name AND obj2.className = :className" + " AND propPrettyName.id = obj2.id AND propPrettyName.name = :propertyName)"; try { Query query = queryManager.createQuery(hql, Query.HQL); query.bindValue("className", String.format("%s.%s", XWiki.SYSTEM_SPACE, XWikiServerClassDocumentInitializer.DOCUMENT_NAME)); query.bindValue("propertyName", XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME); query.bindValue("template", "XWiki.XWikiServerClassTemplate"); List<String> results = query.execute(); for (String result : results) { fixDocument(result); } } catch (QueryException e) { logger.error("Failed to perform a query on the main wiki.", e); } }  @Override String getDescription(); @Override XWikiDBVersion getVersion(); @Override boolean shouldExecute(XWikiDBVersion startupVersion); }
WikiDescriptorMigrator extends AbstractHibernateDataMigration { @Override protected void hibernateMigrate() throws DataMigrationException, XWikiException { String hql = "SELECT DISTINCT doc.fullName FROM XWikiDocument doc, BaseObject obj WHERE doc.fullName = obj.name" + " AND obj.className = :className AND doc.fullName <> :template AND doc.fullName NOT IN " + "(SELECT DISTINCT doc2.fullName FROM XWikiDocument doc2, BaseObject obj2, StringProperty propPrettyName" + " WHERE doc2.fullName = obj2.name AND obj2.className = :className" + " AND propPrettyName.id = obj2.id AND propPrettyName.name = :propertyName)"; try { Query query = queryManager.createQuery(hql, Query.HQL); query.bindValue("className", String.format("%s.%s", XWiki.SYSTEM_SPACE, XWikiServerClassDocumentInitializer.DOCUMENT_NAME)); query.bindValue("propertyName", XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME); query.bindValue("template", "XWiki.XWikiServerClassTemplate"); List<String> results = query.execute(); for (String result : results) { fixDocument(result); } } catch (QueryException e) { logger.error("Failed to perform a query on the main wiki.", e); } }  @Override String getDescription(); @Override XWikiDBVersion getVersion(); @Override boolean shouldExecute(XWikiDBVersion startupVersion);  }