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.Named; |
30 |
|
import javax.inject.Singleton; |
31 |
|
|
32 |
|
import org.hibernate.HibernateException; |
33 |
|
import org.hibernate.Session; |
34 |
|
import org.hibernate.jdbc.Work; |
35 |
|
import org.xwiki.component.annotation.Component; |
36 |
|
|
37 |
|
import com.xpn.xwiki.XWiki; |
38 |
|
import com.xpn.xwiki.XWikiContext; |
39 |
|
import com.xpn.xwiki.XWikiException; |
40 |
|
import com.xpn.xwiki.store.DatabaseProduct; |
41 |
|
import com.xpn.xwiki.store.XWikiHibernateBaseStore.HibernateCallback; |
42 |
|
import com.xpn.xwiki.store.migration.DataMigrationException; |
43 |
|
import com.xpn.xwiki.store.migration.XWikiDBVersion; |
44 |
|
import com.xpn.xwiki.web.Utils; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@version |
55 |
|
@since |
56 |
|
|
57 |
|
@Component |
58 |
|
@Named("R35101XWIKI7645") |
59 |
|
@Singleton |
|
|
| 12.5% |
Uncovered Elements: 14 (16) |
Complexity: 7 |
Complexity Density: 0.64 |
|
60 |
|
public class R35101XWIKI7645DataMigration extends AbstractHibernateDataMigration |
61 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
0 |
@Override... |
63 |
|
public String getDescription() |
64 |
|
{ |
65 |
0 |
return "See http://jira.xwiki.org/browse/XWIKI-7645"; |
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(35101); |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.5 |
|
74 |
0 |
@Override... |
75 |
|
public boolean shouldExecute(XWikiDBVersion startupVersion) |
76 |
|
{ |
77 |
0 |
boolean shouldExecute = false; |
78 |
0 |
try { |
79 |
0 |
getStore().beginTransaction(getXWikiContext()); |
80 |
|
|
81 |
0 |
shouldExecute = getStore().getDatabaseProductName() == DatabaseProduct.ORACLE; |
82 |
0 |
getStore().endTransaction(getXWikiContext(), false); |
83 |
|
} catch (XWikiException ex) { |
84 |
|
|
85 |
|
} catch (DataMigrationException ex) { |
86 |
|
|
87 |
|
} |
88 |
0 |
return shouldExecute; |
89 |
|
} |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
0 |
@Override... |
92 |
|
public void hibernateMigrate() throws DataMigrationException, XWikiException |
93 |
|
{ |
94 |
0 |
getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>() |
95 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
96 |
0 |
@Override... |
97 |
|
public Object doInHibernate(Session session) throws HibernateException, XWikiException |
98 |
|
{ |
99 |
0 |
session.doWork(new R35101Work()); |
100 |
0 |
return Boolean.TRUE; |
101 |
|
} |
102 |
|
}); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
@link |
107 |
|
|
108 |
|
@version |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 40 (40) |
Complexity: 9 |
Complexity Density: 0.32 |
|
110 |
|
private static class R35101Work implements Work |
111 |
|
{ |
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 5 |
Complexity Density: 0.33 |
|
112 |
0 |
@Override... |
113 |
|
public void execute(Connection connection) throws SQLException |
114 |
|
{ |
115 |
0 |
String[][] tablesToFix = new String[][] { |
116 |
|
{ "XWIKIATTACHMENT_CONTENT", "XWA_CONTENT" }, |
117 |
|
{ "XWIKIATTACHMENT_ARCHIVE", "XWA_ARCHIVE" } }; |
118 |
0 |
Statement stmt = connection.createStatement(); |
119 |
0 |
PreparedStatement getIndexesQuery = connection.prepareStatement( |
120 |
|
"SELECT index_name FROM all_indexes WHERE table_owner=? AND table_name=? AND index_type='NORMAL'"); |
121 |
|
|
122 |
0 |
for (String[] table : tablesToFix) { |
123 |
0 |
try { |
124 |
0 |
stmt.execute("ALTER TABLE " + table[0] + " MODIFY (" + table[1] + " blob)"); |
125 |
|
} catch (SQLException ex) { |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
0 |
if (ex.getMessage().contains("ORA-22859") || ex.getMessage().contains("ORA-22858")) { |
131 |
0 |
return; |
132 |
|
} else { |
133 |
0 |
throw ex; |
134 |
|
} |
135 |
|
} |
136 |
0 |
getIndexesQuery.setString(1, getSchemaFromWikiName(Utils.getContext().getWikiId())); |
137 |
0 |
getIndexesQuery.setString(2, table[0]); |
138 |
0 |
ResultSet indexes = getIndexesQuery.executeQuery(); |
139 |
0 |
while (indexes.next()) { |
140 |
0 |
String index = indexes.getString(1); |
141 |
0 |
stmt.execute("ALTER INDEX " + index + " REBUILD"); |
142 |
|
} |
143 |
|
} |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
@param |
154 |
|
@return |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
156 |
0 |
private String getSchemaFromWikiName(String wikiName)... |
157 |
|
{ |
158 |
0 |
if (wikiName == null) { |
159 |
0 |
return null; |
160 |
|
} |
161 |
|
|
162 |
0 |
XWikiContext context = Utils.getContext(); |
163 |
0 |
XWiki wiki = context.getWiki(); |
164 |
|
|
165 |
0 |
String schema; |
166 |
0 |
if (context.isMainWiki(wikiName)) { |
167 |
|
|
168 |
0 |
schema = wiki.Param("xwiki.db"); |
169 |
0 |
if (schema == null) { |
170 |
0 |
schema = wikiName; |
171 |
|
} |
172 |
|
} else { |
173 |
|
|
174 |
0 |
schema = wikiName.replace('-', '_'); |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
0 |
String prefix = wiki.Param("xwiki.db.prefix", ""); |
179 |
0 |
schema = prefix + schema; |
180 |
|
|
181 |
|
|
182 |
0 |
return schema.toUpperCase(); |
183 |
|
} |
184 |
|
|
185 |
|
} |
186 |
|
} |