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

File R15428XWIKI2977DataMigration.java

 

Coverage histogram

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

Code metrics

2
14
4
1
90
56
5
0.36
3.5
4
1.25

Classes

Class Line # Actions
R15428XWIKI2977DataMigration 50 14 0% 5 18
0.110%
 

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.util.ArrayList;
24    import java.util.List;
25    import java.util.UUID;
26   
27    import javax.inject.Named;
28    import javax.inject.Singleton;
29   
30    import org.hibernate.HibernateException;
31    import org.hibernate.Query;
32    import org.hibernate.Session;
33    import org.xwiki.component.annotation.Component;
34   
35    import com.xpn.xwiki.XWikiException;
36    import com.xpn.xwiki.objects.BaseObject;
37    import com.xpn.xwiki.store.XWikiHibernateBaseStore.HibernateCallback;
38    import com.xpn.xwiki.store.migration.DataMigrationException;
39    import com.xpn.xwiki.store.migration.XWikiDBVersion;
40   
41    /**
42    * Migration for XWIKI2977: Add a Globally Unique Identifier (GUID) to objects. This data migration adds GUIDs to
43    * existing objects.
44    *
45    * @version $Id: 2ab32d0d64e10b5422124309128f5487f4f4c243 $
46    */
47    @Component
48    @Named("R15428XWIKI2977")
49    @Singleton
 
50    public class R15428XWIKI2977DataMigration extends AbstractHibernateDataMigration
51    {
 
52  0 toggle @Override
53    public String getDescription()
54    {
55  0 return "Add a GUID to existing objects when upgrading from pre-1.8M1.";
56    }
57   
 
58  206 toggle @Override
59    public XWikiDBVersion getVersion()
60    {
61  206 return new XWikiDBVersion(15428);
62    }
63   
 
64  0 toggle @Override
65    public void hibernateMigrate() throws DataMigrationException, XWikiException
66    {
67    // migrate data
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 Query q = session.createQuery("select o from BaseObject o where o.guid is null");
74  0 List<BaseObject> lst = q.list();
75  0 if (lst.size() == 0) {
76  0 return null;
77    }
78  0 List<BaseObject> lst2 = new ArrayList<BaseObject>(lst.size());
79  0 for (BaseObject o : lst) {
80  0 o.setGuid(UUID.randomUUID().toString());
81  0 lst2.add(o);
82    }
83  0 for (BaseObject o : lst2) {
84  0 session.update(o);
85    }
86  0 return null;
87    }
88    });
89    }
90    }