Author: sdumitriu
Date: 2008-02-07 20:26:51 +0100 (Thu, 07 Feb 2008)
New Revision: 7351

Added:
   
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R7350XWIKI2079Migrator.java
Removed:
   
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R6430XWIKI1954Migrator.java
Modified:
   
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/XWikiHibernateMigrationManager.java
Log:
XWIKI-2079: Fails to save document after migrating from a 1.0 or before 
database to 1.2
Fixed.
Merged from [EMAIL PROTECTED]


Deleted: 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R6430XWIKI1954Migrator.java
===================================================================
--- 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R6430XWIKI1954Migrator.java
    2008-02-07 19:26:16 UTC (rev 7350)
+++ 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R6430XWIKI1954Migrator.java
    2008-02-07 19:26:51 UTC (rev 7351)
@@ -1,97 +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 java.sql.SQLException;
-import java.sql.Statement;
-
-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;
-
-/**
- * Migration for XWIKI1954: When migrating the document archive format from 
1.1 to 1.2, delete the
- * contents of the old XWD_ARCHIVE field.
- * 
- * Note: This migrator should only be executed if the R4359XWIKI1459 one has 
already been executed
- * during a previous migration (i.e. if the database is in version >= 4359).
- *
- * @version $Id: $
- */
-public class R6430XWIKI1954Migrator extends AbstractXWikiHibernateMigrator
-{
-    /**
-     * [EMAIL PROTECTED]
-     * 
-     * @see 
com.xpn.xwiki.store.migration.hibernate.AbstractXWikiHibernateMigrator#getName()
-     */
-    public String getName()
-    {
-        return "R6430XWIKI1954";
-    }
-
-    /**
-     * [EMAIL PROTECTED]
-     * 
-     * @see AbstractXWikiHibernateMigrator#getDescription()
-     */
-    public String getDescription()
-    {
-        return "See http://jira.xwiki.org/jira/browse/XWIKI-1954";;
-    }
-
-    /** [EMAIL PROTECTED] */
-    public XWikiDBVersion getVersion()
-    {
-        return new XWikiDBVersion(6430);
-    }
-
-    /**
-     * [EMAIL PROTECTED]
-     * @see 
AbstractXWikiHibernateMigrator#shouldExecute(com.xpn.xwiki.store.migration.XWikiDBVersion)
-     */
-    public boolean shouldExecute(XWikiDBVersion startupVersion)
-    {
-        return (startupVersion.getVersion() >= 4359);
-    }
-
-    /** [EMAIL PROTECTED] */
-    public void migrate(XWikiHibernateMigrationManager manager, final 
XWikiContext context)
-        throws XWikiException
-    {
-        manager.getStore(context).executeWrite(context, true, new 
HibernateCallback() {
-            public Object doInHibernate(Session session) throws 
HibernateException, XWikiException
-            {
-                try {
-                    Statement stmt = session.connection().createStatement();
-                    stmt.executeUpdate("update xwikidoc set XWD_ARCHIVE=null");
-                    stmt.close();
-                } catch (SQLException e) {
-                    // Maybe the column doesn't exist.
-                }
-                return Boolean.TRUE;
-            }
-        });
-    }
-}

Copied: 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R7350XWIKI2079Migrator.java
 (from rev 7349, 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R7350XWIKI2079Migrator.java)
===================================================================
--- 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R7350XWIKI2079Migrator.java
                            (rev 0)
+++ 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/R7350XWIKI2079Migrator.java
    2008-02-07 19:26:51 UTC (rev 7351)
@@ -0,0 +1,108 @@
+/*
+ * 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 java.sql.SQLException;
+import java.sql.Statement;
+
+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;
+
+/**
+ * Migration for XWIKI2079: When migrating the document archive format from 
1.0 or before to 1.2,
+ * delete the old XWD_ARCHIVE field, as it will prevent saving documents, 
since that column used to
+ * have a NOT NULL constraint. Also, Hibernate does not delete columns/tables 
that don't appear in
+ * the mapping file, so the column must be manually dropped.
+ * 
+ * @version $Id: $
+ * @since 1.3M2
+ * @since 1.2.2
+ */
+public class R7350XWIKI2079Migrator extends AbstractXWikiHibernateMigrator
+{
+    /**
+     * [EMAIL PROTECTED]
+     * 
+     * @see 
com.xpn.xwiki.store.migration.hibernate.AbstractXWikiHibernateMigrator#getName()
+     */
+    public String getName()
+    {
+        return "R7345XWIKI2079";
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     * 
+     * @see AbstractXWikiHibernateMigrator#getDescription()
+     */
+    public String getDescription()
+    {
+        return "See http://jira.xwiki.org/jira/browse/XWIKI-2079";;
+    }
+
+    /** [EMAIL PROTECTED] */
+    public XWikiDBVersion getVersion()
+    {
+        return new XWikiDBVersion(7350);
+    }
+
+    /** [EMAIL PROTECTED] */
+    public void migrate(XWikiHibernateMigrationManager manager, final 
XWikiContext context)
+        throws XWikiException
+    {
+        manager.getStore(context).executeWrite(context, true, new 
HibernateCallback()
+        {
+            public Object doInHibernate(Session session) throws 
HibernateException,
+                XWikiException
+            {
+                try {
+                    Statement stmt = session.connection().createStatement();
+                    stmt.executeUpdate("ALTER TABLE xwikidoc DROP COLUMN 
XWD_ARCHIVE");
+                    stmt.close();
+                } catch (SQLException ex) {
+                    // Maybe the column doesn't exist. Anyway, in case we're 
using a DBMS which
+                    // doesn't support DROP COLUMN (such as Derby < 10.3.1.4), 
we can try to alter
+                    // the column to allow NULL values.
+                    // TODO Can we check the exception and see what is 
happening?
+                    try {
+                        Statement stmt = 
session.connection().createStatement();
+                        stmt.executeUpdate("ALTER TABLE xwikidoc ALTER COLUMN 
XWD_ARCHIVE "
+                            + "SET DEFAULT ' '");
+                        stmt.close();
+                    } catch (SQLException ex2) {
+                        // Maybe the column doesn't exist, after all.
+                        /*
+                         * TODO Can we check the exception and see what is 
happening? If the
+                         * statements failed because they are not supported by 
the DBMS, then this
+                         * is a fatal error, perhaps we should stop serving 
request and notify the
+                         * admin
+                         */
+                    }
+                }
+                return Boolean.TRUE;
+            }
+        });
+    }
+}

Modified: 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/XWikiHibernateMigrationManager.java
===================================================================
--- 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/XWikiHibernateMigrationManager.java
    2008-02-07 19:26:16 UTC (rev 7350)
+++ 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/store/migration/hibernate/XWikiHibernateMigrationManager.java
    2008-02-07 19:26:51 UTC (rev 7351)
@@ -89,7 +89,7 @@
         result.add(new R4359XWIKI1459Migrator());
         result.add(new R6079XWIKI1878Migrator());
         result.add(new R6405XWIKI1933Migrator());
-        result.add(new R6430XWIKI1954Migrator());
+        result.add(new R7350XWIKI2079Migrator());
         // 2nd way - via classloader
         
         return result;

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

Reply via email to