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.io.BufferedReader; |
24 |
|
import java.io.IOException; |
25 |
|
import java.io.InputStreamReader; |
26 |
|
import java.io.UnsupportedEncodingException; |
27 |
|
import java.sql.BatchUpdateException; |
28 |
|
import java.sql.Connection; |
29 |
|
import java.sql.SQLException; |
30 |
|
import java.sql.Statement; |
31 |
|
|
32 |
|
import javax.inject.Named; |
33 |
|
import javax.inject.Singleton; |
34 |
|
|
35 |
|
import org.hibernate.HibernateException; |
36 |
|
import org.hibernate.Session; |
37 |
|
import org.hibernate.jdbc.Work; |
38 |
|
import org.xwiki.component.annotation.Component; |
39 |
|
|
40 |
|
import com.xpn.xwiki.XWikiException; |
41 |
|
import com.xpn.xwiki.store.DatabaseProduct; |
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 |
|
@version |
51 |
|
@since |
52 |
|
|
53 |
|
@Component |
54 |
|
@Named("R35100XWIKI7564") |
55 |
|
@Singleton |
|
|
| 12.5% |
Uncovered Elements: 14 (16) |
Complexity: 7 |
Complexity Density: 0.64 |
|
56 |
|
public class R35100XWIKI7564DataMigration extends AbstractHibernateDataMigration |
57 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
0 |
@Override... |
59 |
|
public String getDescription() |
60 |
|
{ |
61 |
0 |
return "See http://jira.xwiki.org/browse/XWIKI-7564"; |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
206 |
@Override... |
65 |
|
public XWikiDBVersion getVersion() |
66 |
|
{ |
67 |
206 |
return new XWikiDBVersion(35100); |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.5 |
|
70 |
0 |
@Override... |
71 |
|
public boolean shouldExecute(XWikiDBVersion startupVersion) |
72 |
|
{ |
73 |
0 |
boolean shouldExecute = false; |
74 |
0 |
try { |
75 |
0 |
getStore().beginTransaction(getXWikiContext()); |
76 |
|
|
77 |
0 |
shouldExecute = (startupVersion.getVersion() > 0 |
78 |
|
&& getStore().getDatabaseProductName() == DatabaseProduct.POSTGRESQL); |
79 |
0 |
getStore().endTransaction(getXWikiContext(), false); |
80 |
|
} catch (XWikiException ex) { |
81 |
|
|
82 |
|
} catch (DataMigrationException ex) { |
83 |
|
|
84 |
|
} |
85 |
0 |
return shouldExecute; |
86 |
|
} |
87 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
0 |
@Override... |
89 |
|
public void hibernateMigrate() throws DataMigrationException, XWikiException |
90 |
|
{ |
91 |
0 |
getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>() |
92 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
93 |
0 |
@Override... |
94 |
|
public Object doInHibernate(Session session) throws HibernateException, XWikiException |
95 |
|
{ |
96 |
0 |
session.doWork(new R35100Work()); |
97 |
0 |
return Boolean.TRUE; |
98 |
|
} |
99 |
|
}); |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
|
@link |
104 |
|
|
105 |
|
@version |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 7 |
Complexity Density: 0.7 |
|
107 |
|
private static class R35100Work implements Work |
108 |
|
{ |
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 7 |
Complexity Density: 0.7 |
|
109 |
0 |
@Override... |
110 |
|
public void execute(Connection connection) throws SQLException |
111 |
|
{ |
112 |
0 |
try { |
113 |
0 |
Statement stmt = connection.createStatement(); |
114 |
0 |
BufferedReader in = new BufferedReader(new InputStreamReader( |
115 |
|
this.getClass().getResourceAsStream("R35100XWIKI7564.sql"), "UTF-8")); |
116 |
0 |
String line; |
117 |
0 |
while ((line = in.readLine()) != null) { |
118 |
0 |
stmt.addBatch(line); |
119 |
|
} |
120 |
0 |
stmt.executeBatch(); |
121 |
|
} catch (BatchUpdateException ex) { |
122 |
0 |
if (ex.getNextException() != null |
123 |
|
&& ex.getNextException().getMessage().contains("function lowrite(integer, oid)")) { |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
0 |
return; |
128 |
|
} |
129 |
0 |
throw ex; |
130 |
|
} catch (UnsupportedEncodingException ex) { |
131 |
|
|
132 |
|
} catch (IOException ex) { |
133 |
|
|
134 |
|
} |
135 |
|
} |
136 |
|
} |
137 |
|
} |