Author: vmassol
Date: 2008-02-05 23:50:54 +0100 (Tue, 05 Feb 2008)
New Revision: 7301

Modified:
   
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4359XWIKI1459Migrator.java
Log:
XWIKI-2074: Database Migration fails when migrating from 1.0 or older directly 
to 1.2 without going through a 1.1 upgrade


Modified: 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4359XWIKI1459Migrator.java
===================================================================
--- 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4359XWIKI1459Migrator.java
    2008-02-05 20:12:00 UTC (rev 7300)
+++ 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R4359XWIKI1459Migrator.java
    2008-02-05 22:50:54 UTC (rev 7301)
@@ -82,7 +82,13 @@
                     Statement stmt = session.connection().createStatement();
                     ResultSet rs;
                     try {
-                        rs = stmt.executeQuery("select XWD_ID, XWD_ARCHIVE, 
XWD_FULLNAME from xwikidoc where XWD_ARCHIVE is not null order by XWD_VERSION");
+                        // We place an empty character in archives for 
documents that have already been migrated so
+                        // that we can re-execute this migrator and not start 
over.
+                        // Note that we cannot use NULL since in old databases 
(prior to 1.1) the XWD_ARCHIVE column
+                        // had a not null constraint and since this column has 
disappeared in 1.2 and after, the
+                        // hibernate update script will not have modified the 
nullability of it...
+                        // (see http://jira.xwiki.org/jira/browse/XWIKI-2074).
+                        rs = stmt.executeQuery("select XWD_ID, XWD_ARCHIVE, 
XWD_FULLNAME from xwikidoc where (XWD_ARCHIVE is not null and XWD_ARCHIVE <> ' 
') order by XWD_VERSION");
                     } 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?
@@ -91,7 +97,7 @@
                     Transaction originalTransaction = 
((XWikiHibernateVersioningStore)context.getWiki().getVersioningStore()).getTransaction(context);
                     
((XWikiHibernateVersioningStore)context.getWiki().getVersioningStore()).setSession(null,
 context);
                     
((XWikiHibernateVersioningStore)context.getWiki().getVersioningStore()).setTransaction(null,
 context);
-                    PreparedStatement deleteStatement = 
session.connection().prepareStatement("update xwikidoc set XWD_ARCHIVE=null 
where XWD_ID=?");
+                    PreparedStatement deleteStatement = 
session.connection().prepareStatement("update xwikidoc set XWD_ARCHIVE=' ' 
where XWD_ID=?");
 
                     while (rs.next()) {
                         if (LOG.isInfoEnabled()) {

_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to