1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
|
46 |
|
@Component |
47 |
|
@Named("R4340XWIKI883") |
48 |
|
@Singleton |
|
|
| 8% |
Uncovered Elements: 23 (25) |
Complexity: 5 |
Complexity Density: 0.26 |
|
49 |
|
public class R4340XWIKI883DataMigration extends AbstractHibernateDataMigration |
50 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
0 |
@Override... |
52 |
|
public String getDescription() |
53 |
|
{ |
54 |
0 |
return "See http://jira.xwiki.org/jira/browse/XWIKI-883"; |
55 |
|
} |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
206 |
@Override... |
58 |
|
public XWikiDBVersion getVersion() |
59 |
|
{ |
60 |
206 |
return new XWikiDBVersion(4340); |
61 |
|
} |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
0 |
@Override... |
64 |
|
public void hibernateMigrate() throws DataMigrationException, XWikiException |
65 |
|
{ |
66 |
0 |
getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>() |
67 |
|
{ |
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 2 |
Complexity Density: 0.12 |
|
68 |
0 |
@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 |
|
} |