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 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 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@Component |
46 |
|
@Named("Legacy") |
47 |
|
@Singleton |
|
|
| 10.5% |
Uncovered Elements: 17 (19) |
Complexity: 6 |
Complexity Density: 0.4 |
|
48 |
|
public class LegacyDataMigration extends AbstractHibernateDataMigration |
49 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
0 |
@Override... |
51 |
|
public String getDescription() |
52 |
|
{ |
53 |
0 |
return "Convert very old legacy databases"; |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
206 |
@Override... |
57 |
|
public XWikiDBVersion getVersion() |
58 |
|
{ |
59 |
206 |
return new XWikiDBVersion(1); |
60 |
|
} |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
0 |
@Override... |
63 |
|
public void hibernateMigrate() throws DataMigrationException, XWikiException |
64 |
|
{ |
65 |
|
|
66 |
0 |
getStore().executeWrite(getXWikiContext(), true, new XWikiHibernateBaseStore.HibernateCallback<Object>() |
67 |
|
{ |
68 |
|
|
69 |
|
private static final String UPDATE = "update "; |
70 |
|
|
71 |
|
|
72 |
|
private static final String DELETE_FROM = "delete from "; |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.25 |
|
74 |
0 |
@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 |
|
|
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 |
|
} |