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

File R4340XWIKI883DataMigration.java

 

Coverage histogram

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

Code metrics

2
19
4
1
97
65
5
0.26
4.75
4
1.25

Classes

Class Line # Actions
R4340XWIKI883DataMigration 49 19 0% 5 23
0.088%
 

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   
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.hibernate.HibernateException;
30    import org.hibernate.Query;
31    import org.hibernate.Session;
32    import org.xwiki.component.annotation.Component;
33   
34    import com.xpn.xwiki.XWikiException;
35    import com.xpn.xwiki.objects.LargeStringProperty;
36    import com.xpn.xwiki.objects.StringProperty;
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 XWIKI-883: global access preferences cannot be updated.
43    *
44    * @version $Id: 09f2d8b36eacf0145b1a07df9b7070ea50ac268a $
45    */
46    @Component
47    @Named("R4340XWIKI883")
48    @Singleton
 
49    public class R4340XWIKI883DataMigration extends AbstractHibernateDataMigration
50    {
 
51  0 toggle @Override
52    public String getDescription()
53    {
54  0 return "See http://jira.xwiki.org/jira/browse/XWIKI-883";
55    }
56   
 
57  206 toggle @Override
58    public XWikiDBVersion getVersion()
59    {
60  206 return new XWikiDBVersion(4340);
61    }
62   
 
63  0 toggle @Override
64    public void hibernateMigrate() throws DataMigrationException, XWikiException
65    {
66  0 getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>()
67    {
 
68  0 toggle @Override
69    public Object doInHibernate(Session session) throws HibernateException
70    {
71  0 Query q = session.createQuery(
72    "select s from BaseObject o, StringProperty s where o.className like 'XWiki.XWiki%Rights'"
73    + " and o.id=s.id and (s.name='users' or s.name='groups')");
74  0 @SuppressWarnings("unchecked")
75    List<StringProperty> lst = q.list();
76  0 if (lst.size() == 0) {
77  0 return null;
78    }
79  0 List<LargeStringProperty> lst2 = new ArrayList<LargeStringProperty>(lst.size());
80  0 for (StringProperty sp : lst) {
81  0 LargeStringProperty lsp = new LargeStringProperty();
82  0 lsp.setId(sp.getId());
83  0 lsp.setName(sp.getName());
84  0 lsp.setValue(sp.getValue());
85  0 lst2.add(lsp);
86    }
87  0 for (StringProperty property : lst) {
88  0 session.delete(property);
89    }
90  0 for (LargeStringProperty property : lst2) {
91  0 session.save(property);
92    }
93  0 return null;
94    }
95    });
96    }
97    }