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

File LegacyDataMigration.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart1.png
82% of files have more coverage

Code metrics

0
15
4
1
124
79
6
0.4
3.75
4
1.5

Classes

Class Line # Actions
LegacyDataMigration 48 15 0% 6 17
0.1052631610.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 javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.hibernate.HibernateException;
27    import org.hibernate.Session;
28    import org.xwiki.component.annotation.Component;
29   
30    import com.xpn.xwiki.XWikiException;
31    import com.xpn.xwiki.doc.XWikiDocument;
32    import com.xpn.xwiki.objects.BaseProperty;
33    import com.xpn.xwiki.objects.LongProperty;
34    import com.xpn.xwiki.store.XWikiHibernateBaseStore;
35    import com.xpn.xwiki.store.migration.DataMigrationException;
36    import com.xpn.xwiki.store.migration.XWikiDBVersion;
37   
38    /**
39    * Migration for XWIKI4396: Duplicate document ID. This dataMigration change document ID to use the new improved hash
40    * algorithm.
41    *
42    * @version $Id: c573918e591636171c329012aa0e0700842b27c5 $
43    * @since 3.4M1
44    */
45    @Component
46    @Named("Legacy")
47    @Singleton
 
48    public class LegacyDataMigration extends AbstractHibernateDataMigration
49    {
 
50  0 toggle @Override
51    public String getDescription()
52    {
53  0 return "Convert very old legacy databases";
54    }
55   
 
56  206 toggle @Override
57    public XWikiDBVersion getVersion()
58    {
59  206 return new XWikiDBVersion(1);
60    }
61   
 
62  0 toggle @Override
63    public void hibernateMigrate() throws DataMigrationException, XWikiException
64    {
65    // migrate data
66  0 getStore().executeWrite(getXWikiContext(), true, new XWikiHibernateBaseStore.HibernateCallback<Object>()
67    {
68    /** Update SQL command. */
69    private static final String UPDATE = "update ";
70   
71    /** Delete SQL command. */
72    private static final String DELETE_FROM = "delete from ";
73   
 
74  0 toggle @Override
75    public Object doInHibernate(Session session) throws HibernateException, XWikiException
76    {
77  0 String docClass = XWikiDocument.class.getName();
78  0 try {
79  0 session
80    .createQuery(
81    UPDATE + docClass + " doc set doc.translation = 0 where doc.translation is null")
82    .executeUpdate();
83   
84  0 session
85    .createQuery(UPDATE + docClass + " doc set doc.language = '' where doc.language is null")
86    .executeUpdate();
87   
88  0 session
89    .createQuery(UPDATE + docClass
90    + " doc set doc.defaultLanguage = '' where doc.defaultLanguage is null")
91    .executeUpdate();
92   
93  0 session
94    .createQuery(UPDATE + docClass
95    + " doc set doc.fullName = concat(doc.space,'.',doc.name) where doc.fullName is null")
96    .executeUpdate();
97   
98  0 session
99    .createQuery(UPDATE + docClass + " doc set doc.elements = 3 where doc.elements is null")
100    .executeUpdate();
101   
102  0 try {
103  0 session
104    .createQuery(DELETE_FROM + BaseProperty.class.getName() + " prop"
105    + " where prop.name like 'editbox_%'"
106    + " and prop.classType = 'com.xpn.xwiki.objects.LongProperty'")
107    .executeUpdate();
108   
109  0 session
110    .createQuery(
111    DELETE_FROM + LongProperty.class.getName() + " prop where prop.name like 'editbox_%'")
112    .executeUpdate();
113    } catch (Exception ignored) {
114    // Cleanup may fail, this is not important enough to break the whole stuff.
115    }
116    } catch (Exception e) {
117  0 throw new XWikiException(XWikiException.MODULE_XWIKI_STORE,
118    XWikiException.ERROR_XWIKI_STORE_MIGRATION, getName() + " migration failed", e);
119    }
120  0 return null;
121    }
122    });
123    }
124    }