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.sql.Connection; |
24 |
|
import java.sql.PreparedStatement; |
25 |
|
import java.sql.ResultSet; |
26 |
|
import java.sql.SQLException; |
27 |
|
import java.sql.Statement; |
28 |
|
|
29 |
|
import javax.inject.Inject; |
30 |
|
import javax.inject.Named; |
31 |
|
import javax.inject.Singleton; |
32 |
|
|
33 |
|
import org.hibernate.HibernateException; |
34 |
|
import org.hibernate.Session; |
35 |
|
import org.hibernate.jdbc.Work; |
36 |
|
import org.xwiki.component.annotation.Component; |
37 |
|
import org.xwiki.model.EntityType; |
38 |
|
import org.xwiki.model.reference.EntityReference; |
39 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
40 |
|
|
41 |
|
import com.xpn.xwiki.XWikiException; |
42 |
|
import com.xpn.xwiki.store.XWikiHibernateBaseStore.HibernateCallback; |
43 |
|
import com.xpn.xwiki.store.migration.DataMigrationException; |
44 |
|
import com.xpn.xwiki.store.migration.XWikiDBVersion; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@version |
52 |
|
@since |
53 |
|
|
54 |
|
@Component |
55 |
|
@Named("R72000XWIKI12153") |
56 |
|
@Singleton |
|
|
| 8% |
Uncovered Elements: 23 (25) |
Complexity: 10 |
Complexity Density: 0.67 |
|
57 |
|
public class R72000XWIKI12153DataMigration extends AbstractHibernateDataMigration |
58 |
|
{ |
59 |
|
@Inject |
60 |
|
private EntityReferenceSerializer<String> serializer; |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
0 |
@Override... |
63 |
|
public String getDescription() |
64 |
|
{ |
65 |
0 |
return "Convert document space name into space reference"; |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
206 |
@Override... |
69 |
|
public XWikiDBVersion getVersion() |
70 |
|
{ |
71 |
206 |
return new XWikiDBVersion(72000); |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
0 |
@Override... |
75 |
|
public void hibernateMigrate() throws DataMigrationException, XWikiException |
76 |
|
{ |
77 |
0 |
getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>() |
78 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
79 |
0 |
@Override... |
80 |
|
public Object doInHibernate(Session session) throws HibernateException, XWikiException |
81 |
|
{ |
82 |
0 |
session.doWork(new R72000Work()); |
83 |
0 |
return Boolean.TRUE; |
84 |
|
} |
85 |
|
}); |
86 |
|
} |
87 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 5 |
Complexity Density: 1 |
|
88 |
|
private class R72000Work implements Work |
89 |
|
{ |
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 5 |
Complexity Density: 1 |
|
90 |
0 |
@Override... |
91 |
|
public void execute(Connection connection) throws SQLException |
92 |
|
{ |
93 |
|
|
94 |
0 |
try (Statement selectStatement = connection.createStatement()) { |
95 |
0 |
try (ResultSet result = |
96 |
|
selectStatement.executeQuery("select DISTINCT XWD_WEB from xwikidoc" |
97 |
|
+ " where XWD_WEB like '%.%' OR XWD_WEB like '%\\\\%' OR XWD_WEB like '%:%'")) { |
98 |
0 |
convert(connection, result); |
99 |
|
} |
100 |
|
} |
101 |
|
} |
102 |
|
} |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 5 |
Complexity Density: 0.83 |
|
104 |
0 |
private void convert(Connection connection, ResultSet result) throws SQLException... |
105 |
|
{ |
106 |
0 |
if (result.next()) { |
107 |
0 |
try (PreparedStatement statement = |
108 |
|
connection.prepareStatement("UPDATE xwikidoc set XWD_WEB = ? WHERE XWD_WEB = ?")) { |
109 |
0 |
do { |
110 |
0 |
addBatch(statement, result.getString(1)); |
111 |
0 |
} while (result.next()); |
112 |
|
|
113 |
|
|
114 |
0 |
statement.executeBatch(); |
115 |
|
} |
116 |
|
} |
117 |
|
} |
118 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
119 |
0 |
private void addBatch(PreparedStatement statement, String spaceName) throws SQLException... |
120 |
|
{ |
121 |
|
|
122 |
0 |
String spaceReference = this.serializer.serialize(new EntityReference(spaceName, EntityType.SPACE)); |
123 |
|
|
124 |
0 |
statement.setString(1, spaceReference); |
125 |
0 |
statement.setString(2, spaceName); |
126 |
|
|
127 |
|
|
128 |
0 |
statement.addBatch(); |
129 |
|
} |
130 |
|
} |