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 |
|
|
28 |
|
import javax.inject.Named; |
29 |
|
import javax.inject.Singleton; |
30 |
|
|
31 |
|
import org.hibernate.HibernateException; |
32 |
|
import org.hibernate.Session; |
33 |
|
import org.hibernate.jdbc.Work; |
34 |
|
import org.xwiki.component.annotation.Component; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWikiException; |
37 |
|
import com.xpn.xwiki.store.DatabaseProduct; |
38 |
|
import com.xpn.xwiki.store.XWikiHibernateBaseStore.HibernateCallback; |
39 |
|
import com.xpn.xwiki.store.migration.DataMigrationException; |
40 |
|
import com.xpn.xwiki.store.migration.XWikiDBVersion; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@version |
48 |
|
@since |
49 |
|
|
50 |
|
@Component |
51 |
|
@Named("R42000XWIKI7726") |
52 |
|
@Singleton |
|
|
| 15.4% |
Uncovered Elements: 11 (13) |
Complexity: 6 |
Complexity Density: 0.75 |
|
53 |
|
public class R42000XWIKI7726DataMigration extends AbstractHibernateDataMigration |
54 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
0 |
@Override... |
56 |
|
public String getDescription() |
57 |
|
{ |
58 |
0 |
return "Increase the size of the standard BLOB and CLOB columns which were created with the default 16M size."; |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
206 |
@Override... |
62 |
|
public XWikiDBVersion getVersion() |
63 |
|
{ |
64 |
206 |
return new XWikiDBVersion(42000); |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
67 |
0 |
@Override... |
68 |
|
public boolean shouldExecute(XWikiDBVersion startupVersion) |
69 |
|
{ |
70 |
|
|
71 |
0 |
try { |
72 |
0 |
return getStore().getDatabaseProductName() == DatabaseProduct.HSQLDB; |
73 |
|
} catch (DataMigrationException ex) { |
74 |
0 |
return false; |
75 |
|
} |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
0 |
@Override... |
79 |
|
public void hibernateMigrate() throws DataMigrationException, XWikiException |
80 |
|
{ |
81 |
0 |
getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>() |
82 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
83 |
0 |
@Override... |
84 |
|
public Object doInHibernate(Session session) throws HibernateException, XWikiException |
85 |
|
{ |
86 |
0 |
session.doWork(new R42000Work()); |
87 |
0 |
return Boolean.TRUE; |
88 |
|
} |
89 |
|
}); |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
@link |
94 |
|
|
95 |
|
@version |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 3 |
Complexity Density: 0.19 |
|
97 |
|
private static class R42000Work implements Work |
98 |
|
{ |
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
99 |
0 |
@Override... |
100 |
|
public void execute(Connection connection) throws SQLException |
101 |
|
{ |
102 |
0 |
processColumn("XWIKIRCS", "XWR_PATCH", connection); |
103 |
0 |
processColumn("XWIKIRECYCLEBIN", "XDD_XML", connection); |
104 |
0 |
processColumn("XWIKIATTRECYCLEBIN", "XDA_XML", connection); |
105 |
0 |
processColumn("XWIKIATTACHMENT_CONTENT", "XWA_CONTENT", connection); |
106 |
0 |
processColumn("XWIKIATTACHMENT_ARCHIVE", "XWA_ARCHIVE", connection); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
@param |
113 |
|
@param |
114 |
|
@param |
115 |
|
@throws |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
117 |
0 |
private void processColumn(String tableName, String columnName, Connection connection)... |
118 |
|
throws SQLException |
119 |
|
{ |
120 |
0 |
String command = "ALTER TABLE %s ALTER COLUMN %s SET DATA TYPE %s(%d)"; |
121 |
0 |
PreparedStatement getCurrentColumnType = connection.prepareStatement( |
122 |
|
"select DATA_TYPE from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND COLUMN_NAME=?"); |
123 |
0 |
getCurrentColumnType.setString(1, tableName); |
124 |
0 |
getCurrentColumnType.setString(2, columnName); |
125 |
0 |
ResultSet result = getCurrentColumnType.executeQuery(); |
126 |
0 |
if (!result.next()) { |
127 |
0 |
return; |
128 |
|
} |
129 |
0 |
String currentColumnType = result.getString(1); |
130 |
0 |
result.close(); |
131 |
0 |
getCurrentColumnType.close(); |
132 |
0 |
connection.createStatement().execute( |
133 |
|
String.format(command, tableName, columnName, currentColumnType, 1 << 30)); |
134 |
|
} |
135 |
|
} |
136 |
|
} |