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.List; |
24 |
|
|
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.hibernate.HibernateException; |
29 |
|
import org.hibernate.Query; |
30 |
|
import org.hibernate.Session; |
31 |
|
import org.xwiki.component.annotation.Component; |
32 |
|
|
33 |
|
import com.xpn.xwiki.XWikiException; |
34 |
|
import com.xpn.xwiki.objects.BaseObject; |
35 |
|
import com.xpn.xwiki.objects.IntegerProperty; |
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 |
|
|
45 |
|
|
46 |
|
@version |
47 |
|
@since |
48 |
|
|
49 |
|
@Component |
50 |
|
@Named("R73000XWIKI12277") |
51 |
|
@Singleton |
|
|
| 5.3% |
Uncovered Elements: 36 (38) |
Complexity: 8 |
Complexity Density: 0.28 |
|
52 |
|
public class R73000XWIKI12277DataMigration extends AbstractHibernateDataMigration |
53 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
0 |
@Override... |
55 |
|
public String getDescription() |
56 |
|
{ |
57 |
0 |
return "Migrate TemplateProviderClass' removed 'type' property values to the new 'terminal' property."; |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
206 |
@Override... |
61 |
|
public XWikiDBVersion getVersion() |
62 |
|
{ |
63 |
206 |
return new XWikiDBVersion(73000); |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0 |
@Override... |
67 |
|
public void hibernateMigrate() throws DataMigrationException, XWikiException |
68 |
|
{ |
69 |
0 |
getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>() |
70 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0 |
@Override... |
72 |
|
public Object doInHibernate(Session session) throws HibernateException, XWikiException |
73 |
|
{ |
74 |
0 |
return doWork(session); |
75 |
|
} |
76 |
|
|
77 |
|
}); |
78 |
|
} |
79 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
80 |
0 |
private Object doWork(Session session) throws HibernateException... |
81 |
|
{ |
82 |
0 |
Query query = session.createQuery(createQueryString()); |
83 |
|
|
84 |
0 |
List results = query.list(); |
85 |
0 |
for (Object result : results) { |
86 |
0 |
Object[] resultLine = (Object[]) result; |
87 |
0 |
BaseObject object = (BaseObject) resultLine[0]; |
88 |
0 |
StringProperty typeProperty = (StringProperty) resultLine[1]; |
89 |
|
|
90 |
|
|
91 |
0 |
migrateProperty(typeProperty, object, session); |
92 |
|
} |
93 |
|
|
94 |
0 |
return Boolean.TRUE; |
95 |
|
} |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
97 |
0 |
private String createQueryString()... |
98 |
|
{ |
99 |
0 |
StringBuilder query = new StringBuilder(); |
100 |
0 |
query.append("SELECT templateProviderObj, typeProp "); |
101 |
0 |
query.append("FROM BaseObject templateProviderObj, StringProperty typeProp "); |
102 |
0 |
query.append("WHERE templateProviderObj.className='XWiki.TemplateProviderClass'"); |
103 |
0 |
query.append(" AND templateProviderObj.name<>'XWiki.TemplateProviderTemplate'"); |
104 |
0 |
query.append(" AND typeProp.id.id=templateProviderObj.id"); |
105 |
0 |
query.append(" AND typeProp.name='type'"); |
106 |
|
|
107 |
0 |
return query.toString(); |
108 |
|
} |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
110 |
0 |
private void migrateProperty(StringProperty typeProperty, BaseObject object, Session session)... |
111 |
|
throws HibernateException |
112 |
|
{ |
113 |
|
|
114 |
0 |
IntegerProperty terminalProperty = new IntegerProperty(); |
115 |
0 |
int value = 1; |
116 |
0 |
if ("space".equals(typeProperty.getValue())) { |
117 |
0 |
value = 0; |
118 |
|
} |
119 |
0 |
terminalProperty.setValue(value); |
120 |
0 |
terminalProperty.setName("terminal"); |
121 |
0 |
terminalProperty.setObject(object); |
122 |
|
|
123 |
|
|
124 |
0 |
session.saveOrUpdate(terminalProperty); |
125 |
|
|
126 |
0 |
session.delete(typeProperty); |
127 |
|
} |
128 |
|
} |