1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.store.migration.hibernate

File R7350XWIKI2079DataMigration.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart2.png
81% of files have more coverage

Code metrics

0
12
4
1
100
52
6
0.5
3
4
1.5

Classes

Class Line # Actions
R7350XWIKI2079DataMigration 51 12 0% 6 14
0.12512.5%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20   
21    package com.xpn.xwiki.store.migration.hibernate;
22   
23    import java.sql.SQLException;
24    import java.sql.Statement;
25   
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.hibernate.HibernateException;
30    import org.hibernate.Session;
31    import org.xwiki.component.annotation.Component;
32   
33    import com.xpn.xwiki.XWikiException;
34    import com.xpn.xwiki.store.XWikiHibernateBaseStore.HibernateCallback;
35    import com.xpn.xwiki.store.migration.DataMigrationException;
36    import com.xpn.xwiki.store.migration.XWikiDBVersion;
37   
38    /**
39    * Migration for XWIKI2079: When migrating the document archive format from 1.0 or before to 1.2, delete the old
40    * XWD_ARCHIVE field, as it will prevent saving documents, since that column used to have a NOT NULL constraint. Also,
41    * Hibernate does not delete columns/tables that don't appear in the mapping file, so the column must be manually
42    * dropped.
43    *
44    * @version $Id: c555fd5da7f787a534f76cb2c7a5d8061a19ac95 $
45    * @since 1.3M2
46    * @since 1.2.2
47    */
48    @Component
49    @Named("R7345XWIKI2079")
50    @Singleton
 
51    public class R7350XWIKI2079DataMigration extends AbstractHibernateDataMigration
52    {
 
53  0 toggle @Override
54    public String getDescription()
55    {
56  0 return "See http://jira.xwiki.org/jira/browse/XWIKI-2079";
57    }
58   
 
59  206 toggle @Override
60    public XWikiDBVersion getVersion()
61    {
62  206 return new XWikiDBVersion(7350);
63    }
64   
 
65  0 toggle @Override
66    public void hibernateMigrate() throws DataMigrationException, XWikiException
67    {
68  0 getStore().executeWrite(getXWikiContext(), true, new HibernateCallback<Object>()
69    {
 
70  0 toggle @Override
71    public Object doInHibernate(Session session) throws HibernateException, XWikiException
72    {
73  0 try {
74  0 Statement stmt = session.connection().createStatement();
75  0 stmt.executeUpdate("ALTER TABLE xwikidoc DROP COLUMN XWD_ARCHIVE");
76  0 stmt.close();
77    } catch (SQLException ex) {
78    // Maybe the column doesn't exist. Anyway, in case we're using a DBMS which
79    // doesn't support DROP COLUMN (such as Derby < 10.3.1.4), we can try to alter
80    // the column to allow NULL values.
81    // TODO Can we check the exception and see what is happening?
82  0 try {
83  0 Statement stmt = session.connection().createStatement();
84  0 stmt.executeUpdate("ALTER TABLE xwikidoc ALTER COLUMN XWD_ARCHIVE " + "SET DEFAULT ' '");
85  0 stmt.close();
86    } catch (SQLException ex2) {
87    // Maybe the column doesn't exist, after all.
88    /*
89    * TODO Can we check the exception and see what is happening? If the statements failed because
90    * they are not supported by the DBMS, then this is a fatal error, perhaps we should stop
91    * serving request and notify the admin
92    */
93    }
94    }
95   
96  0 return Boolean.TRUE;
97    }
98    });
99    }
100    }