1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.store; |
21 |
|
|
22 |
|
import java.util.Date; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.apache.commons.lang3.StringUtils; |
29 |
|
import org.hibernate.Criteria; |
30 |
|
import org.hibernate.HibernateException; |
31 |
|
import org.hibernate.Session; |
32 |
|
import org.hibernate.criterion.Order; |
33 |
|
import org.hibernate.criterion.Restrictions; |
34 |
|
import org.xwiki.component.annotation.Component; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWikiContext; |
37 |
|
import com.xpn.xwiki.XWikiException; |
38 |
|
import com.xpn.xwiki.doc.XWikiDeletedDocument; |
39 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
|
44 |
|
@version |
45 |
|
|
46 |
|
@Component |
47 |
|
@Named("hibernate") |
48 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 11 |
Complexity Density: 0.69 |
|
49 |
|
public class XWikiHibernateRecycleBinStore extends XWikiHibernateBaseStore implements XWikiRecycleBinStoreInterface |
50 |
|
{ |
51 |
|
|
52 |
|
@link |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
54 |
|
private static class DeletedDocumentsHibernateCallback implements HibernateCallback<XWikiDeletedDocument[]> |
55 |
|
{ |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
private XWikiDocument document; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@param |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
307 |
DeletedDocumentsHibernateCallback(XWikiDocument document)... |
67 |
|
{ |
68 |
307 |
this.document = document; |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
71 |
303 |
@Override... |
72 |
|
public XWikiDeletedDocument[] doInHibernate(Session session) throws HibernateException, XWikiException |
73 |
|
{ |
74 |
305 |
Criteria c = session.createCriteria(XWikiDeletedDocument.class); |
75 |
305 |
c.add(Restrictions.eq("fullName", this.document.getFullName())); |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
300 |
String language = this.document.getLanguage(); |
81 |
302 |
if (StringUtils.isEmpty(language)) { |
82 |
305 |
c.add(Restrictions.or(Restrictions.eq(LANGUAGE_PROPERTY_NAME, ""), |
83 |
|
Restrictions.isNull(LANGUAGE_PROPERTY_NAME))); |
84 |
|
} else { |
85 |
1 |
c.add(Restrictions.eq(LANGUAGE_PROPERTY_NAME, language)); |
86 |
|
} |
87 |
|
|
88 |
306 |
c.addOrder(Order.desc("date")); |
89 |
301 |
@SuppressWarnings("unchecked") |
90 |
|
List<XWikiDeletedDocument> deletedVersions = c.list(); |
91 |
307 |
XWikiDeletedDocument[] result = new XWikiDeletedDocument[deletedVersions.size()]; |
92 |
304 |
return deletedVersions.toArray(result); |
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
private static final String LANGUAGE_PROPERTY_NAME = "language"; |
100 |
|
|
101 |
|
|
102 |
|
@param |
103 |
|
@deprecated |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
7 |
@Deprecated... |
106 |
|
public XWikiHibernateRecycleBinStore(XWikiContext context) |
107 |
|
{ |
108 |
7 |
super(context.getWiki(), context); |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
114 |
89 |
public XWikiHibernateRecycleBinStore()... |
115 |
|
{ |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
118 |
153 |
@Override... |
119 |
|
public void saveToRecycleBin(XWikiDocument doc, String deleter, Date date, XWikiContext inputxcontext, |
120 |
|
boolean bTransaction) throws XWikiException |
121 |
|
{ |
122 |
153 |
XWikiContext context = getXWikiContext(inputxcontext); |
123 |
|
|
124 |
153 |
final XWikiDeletedDocument trashdoc = new XWikiDeletedDocument(doc, deleter, date, context); |
125 |
|
|
126 |
153 |
executeWrite(context, new HibernateCallback<Object>() |
127 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
128 |
153 |
@Override... |
129 |
|
public Object doInHibernate(Session session) throws HibernateException |
130 |
|
{ |
131 |
153 |
session.save(trashdoc); |
132 |
153 |
return null; |
133 |
|
} |
134 |
|
}); |
135 |
|
} |
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
137 |
3 |
@Override... |
138 |
|
public XWikiDocument restoreFromRecycleBin(final XWikiDocument doc, final long index, |
139 |
|
final XWikiContext inputxcontext, boolean bTransaction) throws XWikiException |
140 |
|
{ |
141 |
3 |
XWikiContext context = getXWikiContext(inputxcontext); |
142 |
|
|
143 |
3 |
return executeRead(context, new HibernateCallback<XWikiDocument>() |
144 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
145 |
3 |
@Override... |
146 |
|
public XWikiDocument doInHibernate(Session session) throws HibernateException, XWikiException |
147 |
|
{ |
148 |
3 |
XWikiDeletedDocument trashdoc = |
149 |
|
(XWikiDeletedDocument) session.load(XWikiDeletedDocument.class, Long.valueOf(index)); |
150 |
3 |
return trashdoc.restoreDocument(null, context); |
151 |
|
} |
152 |
|
}); |
153 |
|
} |
154 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
155 |
4 |
@Override... |
156 |
|
public XWikiDeletedDocument getDeletedDocument(XWikiDocument doc, final long index, XWikiContext context, |
157 |
|
boolean bTransaction) throws XWikiException |
158 |
|
{ |
159 |
4 |
return executeRead(context, new HibernateCallback<XWikiDeletedDocument>() |
160 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
161 |
4 |
@Override... |
162 |
|
public XWikiDeletedDocument doInHibernate(Session session) throws HibernateException, XWikiException |
163 |
|
{ |
164 |
4 |
return (XWikiDeletedDocument) session.get(XWikiDeletedDocument.class, Long.valueOf(index)); |
165 |
|
} |
166 |
|
}); |
167 |
|
} |
168 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
169 |
307 |
@Override... |
170 |
|
public XWikiDeletedDocument[] getAllDeletedDocuments(XWikiDocument doc, XWikiContext context, boolean bTransaction) |
171 |
|
throws XWikiException |
172 |
|
{ |
173 |
307 |
return executeRead(context, new DeletedDocumentsHibernateCallback(doc)); |
174 |
|
} |
175 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
176 |
4 |
@Override... |
177 |
|
public void deleteFromRecycleBin(XWikiDocument doc, final long index, XWikiContext context, boolean bTransaction) |
178 |
|
throws XWikiException |
179 |
|
{ |
180 |
4 |
executeWrite(context, new HibernateCallback<Object>() |
181 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
182 |
4 |
@Override... |
183 |
|
public Object doInHibernate(Session session) throws HibernateException, XWikiException |
184 |
|
{ |
185 |
4 |
session.createQuery("delete from " + XWikiDeletedDocument.class.getName() + " where id=?") |
186 |
|
.setLong(0, index).executeUpdate(); |
187 |
4 |
return null; |
188 |
|
} |
189 |
|
}); |
190 |
|
} |
191 |
|
} |