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 |
|
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 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
|
47 |
|
@Component |
48 |
|
@Named("R15428XWIKI2977") |
49 |
|
@Singleton |
|
|
| 10% |
Uncovered Elements: 18 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
50 |
|
public class R15428XWIKI2977DataMigration extends AbstractHibernateDataMigration |
51 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
0 |
@Override... |
53 |
|
public String getDescription() |
54 |
|
{ |
55 |
0 |
return "Add a GUID to existing objects when upgrading from pre-1.8M1."; |
56 |
|
} |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
206 |
@Override... |
59 |
|
public XWikiDBVersion getVersion() |
60 |
|
{ |
61 |
206 |
return new XWikiDBVersion(15428); |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0 |
@Override... |
65 |
|
public void hibernateMigrate() throws DataMigrationException, XWikiException |
66 |
|
{ |
67 |
|
|
68 |
0 |
getStore().executeWrite(getXWikiContext(), true, new HibernateCallback<Object>() |
69 |
|
{ |
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
70 |
0 |
@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 |
|
} |