Author: vmassol Date: 2007-11-15 11:37:41 +0100 (Thu, 15 Nov 2007) New Revision: 5879
Removed: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4326SampleMigrator.java Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/AbstractXWikiMigrationManager.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/XWikiMigratorInterface.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4340XWIKI883Migrator.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4359XWIKI1459Migrator.java xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/XWikiHibernateMigrationManager.java xwiki-platform/core/trunk/xwiki-core/src/main/resources/log4j.properties xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/store/migration/XWikiMigrationManagerTest.java Log: XWIKI-1854: Display information to users when the store migration system executes + Remove the sample migrator which is not required Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java 2007-11-15 09:45:37 UTC (rev 5878) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java 2007-11-15 10:37:41 UTC (rev 5879) @@ -657,7 +657,7 @@ // Run migrations if ("1".equals(Param("xwiki.store.migration", "0"))) { if (LOG.isInfoEnabled()) - LOG.info("Running migrations"); + LOG.info("Running storage migrations"); AbstractXWikiMigrationManager manager = (AbstractXWikiMigrationManager) createClassFromConfig( "xwiki.store.migration.manager.class", "com.xpn.xwiki.store.migration.hibernate.XWikiHibernateMigrationManager", context); @@ -2194,13 +2194,13 @@ if (bobj != null) { String host = bobj.getStringValue("server"); if ((host != null) && (!"".equals(host))) { - if (virtualWikiMap != null) { - try { - if (virtualWikiMap.getFromCache(host) != null) - virtualWikiMap.flushEntry(host); - } catch (XWikiCacheNeedsRefreshException e) { - virtualWikiMap.cancelUpdate(host); - } + if (virtualWikiMap != null) { + try { + if (virtualWikiMap.getFromCache(host) != null) + virtualWikiMap.flushEntry(host); + } catch (XWikiCacheNeedsRefreshException e) { + virtualWikiMap.cancelUpdate(host); + } } } } Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/AbstractXWikiMigrationManager.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/AbstractXWikiMigrationManager.java 2007-11-15 09:45:37 UTC (rev 5878) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/AbstractXWikiMigrationManager.java 2007-11-15 10:37:41 UTC (rev 5879) @@ -79,7 +79,7 @@ { XWikiDBVersion curversion = getDBVersion(context); if (LOG.isInfoEnabled()) { - LOG.info("current data version = " + curversion.toString()); + LOG.info("Current storage version = [" + curversion.toString() + "]"); } try { Collection neededMigrations = getNeededMigrations(context); @@ -99,12 +99,11 @@ { XWikiDBVersion curversion = getDBVersion(context); SortedMap neededMigrations = new TreeMap(); - String[] forcedMigrations = context.getWiki().getConfig() - .getPropertyAsList("xwiki.store.migration.force"); + String[] forcedMigrations = context.getWiki().getConfig().getPropertyAsList("xwiki.store.migration.force"); if (forcedMigrations.length > 0) { for (int i = 0; i < forcedMigrations.length; i++) { - XWikiMigratorInterface migrator = (XWikiMigratorInterface) - Class.forName(forcedMigrations[i]).newInstance(); + XWikiMigratorInterface migrator = + (XWikiMigratorInterface) Class.forName(forcedMigrations[i]).newInstance(); neededMigrations.put(migrator.getVersion(), migrator); } } else { @@ -112,10 +111,10 @@ .getPropertyAsList("xwiki.store.migration.ignored"))); List allMigrations = getAllMigrations(context); for (Iterator it = allMigrations.iterator(); it.hasNext();) { - XWikiMigratorInterface migrator = (XWikiMigratorInterface) - it.next(); + XWikiMigratorInterface migrator = (XWikiMigratorInterface) it.next(); if (ignoredMigrations.contains(migrator.getClass().getName()) - || ignoredMigrations.contains(migrator.getVersion().toString())) { + || ignoredMigrations.contains(migrator.getVersion().toString())) + { continue; } if (migrator.getVersion().compareTo(curversion) >= 0) { @@ -123,7 +122,17 @@ } } } - return neededMigrations.values(); + + Collection neededMigrationsAsCollection = neededMigrations.values(); + if (LOG.isInfoEnabled()) { + LOG.info("List of migrations that will be executed:"); + for (Iterator it = neededMigrationsAsCollection.iterator(); it.hasNext();) { + XWikiMigratorInterface migrator = (XWikiMigratorInterface) it.next(); + LOG.info(" " + migrator.getName() + " - " + migrator.getDescription()); + } + } + + return neededMigrationsAsCollection; } /** * @param migrations - run this migrations in order of collection @@ -137,8 +146,7 @@ for (Iterator it = migrations.iterator(); it.hasNext();) { XWikiMigratorInterface migrator = (XWikiMigratorInterface) it.next(); if (LOG.isInfoEnabled()) { - LOG.info("running migrator '" + migrator.getClass().getName() - + "' with version " + migrator.getVersion()); + LOG.info("Running migration [" + migrator.getName() + "] with version [" + migrator.getVersion() + "]"); } migrate(migrator, context); if (migrator.getVersion().compareTo(curversion) > 0) { @@ -158,7 +166,7 @@ } /** * @param context used everywhere - * @return List of all [EMAIL PROTECTED] AbstractXWikiMigrator} for this manager + * @return List of all [EMAIL PROTECTED] XWikiMigratorInterface} for this manager * @throws XWikiException if any error */ protected abstract List getAllMigrations(XWikiContext context) throws XWikiException; Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/XWikiMigratorInterface.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/XWikiMigratorInterface.java 2007-11-15 09:45:37 UTC (rev 5878) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/XWikiMigratorInterface.java 2007-11-15 10:37:41 UTC (rev 5879) @@ -30,6 +30,16 @@ public interface XWikiMigratorInterface { /** + * @return the migrator name. For example "R4340XWIKI883". + */ + String getName(); + + /** + * @return a description of what the migrator does + */ + String getDescription(); + + /** * @return data version which need migration. * before you commit stuff which needs migration, * you need write migrator with version = current svn revision number. Deleted: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4326SampleMigrator.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4326SampleMigrator.java 2007-11-15 09:45:37 UTC (rev 5878) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4326SampleMigrator.java 2007-11-15 10:37:41 UTC (rev 5879) @@ -1,54 +0,0 @@ -/* - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package com.xpn.xwiki.store.migration.hibernate; - -import org.hibernate.HibernateException; -import org.hibernate.Session; - -import com.xpn.xwiki.XWikiContext; -import com.xpn.xwiki.XWikiException; -import com.xpn.xwiki.store.XWikiHibernateBaseStore.HibernateCallback; -import com.xpn.xwiki.store.migration.XWikiDBVersion; - -/** - * Sample migrator which nothing does. - * It just set version to 4326+1. - * @version $Id: $ - */ -public class R4326SampleMigrator extends AbstractXWikiHibernateMigrator -{ - /** [EMAIL PROTECTED] */ - public XWikiDBVersion getVersion() - { - return new XWikiDBVersion(4326); - } - /** [EMAIL PROTECTED] */ - public void migrate(XWikiHibernateMigrationManager manager, XWikiContext context) - throws XWikiException - { - manager.getStore(context).executeWrite(context, true, new HibernateCallback() { - public Object doInHibernate(Session session) throws HibernateException - { - // here you can write migration - return null; - } - }); - } -} Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4340XWIKI883Migrator.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4340XWIKI883Migrator.java 2007-11-15 09:45:37 UTC (rev 5878) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4340XWIKI883Migrator.java 2007-11-15 10:37:41 UTC (rev 5879) @@ -20,6 +20,24 @@ */ public class R4340XWIKI883Migrator extends AbstractXWikiHibernateMigrator { + /** + * [EMAIL PROTECTED] + * @see AbstractXWikiHibernateMigrator#getName() + */ + public String getName() + { + return "R4340XWIKI883"; + } + + /** + * [EMAIL PROTECTED] + * @see com.xpn.xwiki.store.migration.hibernate.AbstractXWikiHibernateMigrator#getDescription() + */ + public String getDescription() + { + return "See http://jira.xwiki.org/jira/browse/XWIKI-883"; + } + /** [EMAIL PROTECTED] */ public XWikiDBVersion getVersion() { Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4359XWIKI1459Migrator.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4359XWIKI1459Migrator.java 2007-11-15 09:45:37 UTC (rev 5878) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4359XWIKI1459Migrator.java 2007-11-15 10:37:41 UTC (rev 5879) @@ -6,6 +6,8 @@ import org.hibernate.HibernateException; import org.hibernate.Session; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiException; @@ -19,6 +21,27 @@ */ public class R4359XWIKI1459Migrator extends AbstractXWikiHibernateMigrator { + /** logger. */ + private static final Log LOG = LogFactory.getLog(R4359XWIKI1459Migrator.class); + + /** + * [EMAIL PROTECTED] + * @see AbstractXWikiHibernateMigrator#getName() + */ + public String getName() + { + return "R4359XWIKI1459"; + } + + /** + * [EMAIL PROTECTED] + * @see com.xpn.xwiki.store.migration.hibernate.AbstractXWikiHibernateMigrator#getDescription() + */ + public String getDescription() + { + return "See http://jira.xwiki.org/jira/browse/XWIKI-1459"; + } + /** [EMAIL PROTECTED] */ public XWikiDBVersion getVersion() { @@ -35,13 +58,16 @@ Statement stmt = session.connection().createStatement(); ResultSet rs; try { - rs = stmt.executeQuery("select XWD_ID, XWD_ARCHIVE from xwikidoc"); + rs = stmt.executeQuery("select XWD_ID, XWD_ARCHIVE, XWD_FULLNAME from xwikidoc"); } catch (SQLException e) { // most likely there is no XWD_ARCHIVE column, so migration is not needed // is there easier way to find what column is not exist? return null; } while (rs.next()) { + if (LOG.isInfoEnabled()) { + LOG.info("Updating document [" + rs.getString(3) + "]..."); + } long docId = Long.parseLong(rs.getString(1)); String sArchive = rs.getString(2); if (sArchive==null) @@ -53,7 +79,7 @@ stmt.close(); } catch (SQLException e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, - XWikiException.ERROR_XWIKI_STORE_MIGRATION, "XWIKI-1459 migration failed", e); + XWikiException.ERROR_XWIKI_STORE_MIGRATION, getName() + " migration failed", e); } return Boolean.TRUE; } Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/XWikiHibernateMigrationManager.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/XWikiHibernateMigrationManager.java 2007-11-15 09:45:37 UTC (rev 5878) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/XWikiHibernateMigrationManager.java 2007-11-15 10:37:41 UTC (rev 5879) @@ -83,7 +83,6 @@ List result = new ArrayList(); // TODO: how to register migrations? // 1st way: - result.add(new R4326SampleMigrator()); result.add(new R4340XWIKI883Migrator()); result.add(new R4359XWIKI1459Migrator()); // 2nd way - via classloader Modified: xwiki-platform/core/trunk/xwiki-core/src/main/resources/log4j.properties =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/resources/log4j.properties 2007-11-15 09:45:37 UTC (rev 5878) +++ xwiki-platform/core/trunk/xwiki-core/src/main/resources/log4j.properties 2007-11-15 10:37:41 UTC (rev 5879) @@ -24,6 +24,7 @@ ### XWiki logging configuration log4j.logger.com.xpn.xwiki=warn log4j.logger.com.xpn.xwiki.render.XWikiRadeoxRenderEngine=warn +log4j.logger.com.xpn.xwiki.store.migration=info ### Deactive Radeox warnings log4j.logger.org.radeox.macro.BaseLocaleMacro=error Modified: xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/store/migration/XWikiMigrationManagerTest.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/store/migration/XWikiMigrationManagerTest.java 2007-11-15 09:45:37 UTC (rev 5878) +++ xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/store/migration/XWikiMigrationManagerTest.java 2007-11-15 10:37:41 UTC (rev 5879) @@ -58,10 +58,21 @@ } private XWikiMigratorInterface createMigrator(final int ver) { return new XWikiMigratorInterface() { + public String getName() + { + return "Test"; + } + + public String getDescription() + { + return "Test"; + } + public XWikiDBVersion getVersion() { return new XWikiDBVersion(ver); } + public void migrate(XWikiMigrationManagerInterface manager, XWikiContext context) throws XWikiException { @@ -108,6 +119,16 @@ } public static class TestForceMigratior implements XWikiMigratorInterface { + public String getName() + { + return "Test"; + } + + public String getDescription() + { + return "Test"; + } + public XWikiDBVersion getVersion() { return new XWikiDBVersion(567); _______________________________________________ notifications mailing list notifications@xwiki.org http://lists.xwiki.org/mailman/listinfo/notifications