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.hibernate; |
21 |
|
|
22 |
|
import javax.inject.Named; |
23 |
|
import javax.inject.Singleton; |
24 |
|
|
25 |
|
import org.hibernate.HibernateException; |
26 |
|
import org.hibernate.ObjectNotFoundException; |
27 |
|
import org.hibernate.Session; |
28 |
|
import org.slf4j.Logger; |
29 |
|
import org.slf4j.LoggerFactory; |
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
|
32 |
|
import com.xpn.xwiki.XWikiContext; |
33 |
|
import com.xpn.xwiki.XWikiException; |
34 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
35 |
|
import com.xpn.xwiki.doc.XWikiAttachmentArchive; |
36 |
|
import com.xpn.xwiki.store.AttachmentVersioningStore; |
37 |
|
import com.xpn.xwiki.store.XWikiHibernateBaseStore; |
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@Component |
46 |
|
@Named("hibernate") |
47 |
|
@Singleton |
|
|
| 75.8% |
Uncovered Elements: 8 (33) |
Complexity: 12 |
Complexity Density: 0.52 |
|
48 |
|
public class HibernateAttachmentVersioningStore extends XWikiHibernateBaseStore implements AttachmentVersioningStore |
49 |
|
{ |
50 |
|
|
51 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(HibernateAttachmentVersioningStore.class); |
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
@deprecated |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
0 |
@Deprecated... |
58 |
|
public HibernateAttachmentVersioningStore(XWikiContext context) |
59 |
|
{ |
60 |
0 |
super(context.getWiki(), context); |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
66 |
87 |
public HibernateAttachmentVersioningStore()... |
67 |
|
{ |
68 |
|
} |
69 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
70 |
455 |
@Override... |
71 |
|
public XWikiAttachmentArchive loadArchive(final XWikiAttachment attachment, XWikiContext context, |
72 |
|
boolean bTransaction) throws XWikiException |
73 |
|
{ |
74 |
455 |
try { |
75 |
455 |
final XWikiAttachmentArchive archive = new XWikiAttachmentArchive(); |
76 |
455 |
archive.setAttachment(attachment); |
77 |
455 |
executeRead(context, bTransaction, new HibernateCallback<Object>() |
78 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
79 |
455 |
@Override... |
80 |
|
public Object doInHibernate(Session session) throws HibernateException |
81 |
|
{ |
82 |
455 |
try { |
83 |
455 |
session.load(archive, archive.getId()); |
84 |
|
} catch (ObjectNotFoundException e) { |
85 |
|
|
86 |
|
} |
87 |
455 |
return null; |
88 |
|
} |
89 |
|
}); |
90 |
455 |
attachment.setAttachment_archive(archive); |
91 |
455 |
return archive; |
92 |
|
} catch (Exception e) { |
93 |
0 |
Object[] args = { attachment.getFilename(), attachment.getDoc() }; |
94 |
0 |
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, |
95 |
|
XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_ATTACHMENT, |
96 |
|
"Exception while loading attachment archive {0} of document {1}", e, args); |
97 |
|
} |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
423 |
@Override... |
101 |
|
public void saveArchive(final XWikiAttachmentArchive archive, XWikiContext context, boolean bTransaction) |
102 |
|
throws XWikiException |
103 |
|
{ |
104 |
423 |
executeWrite(context, bTransaction, new HibernateCallback<Object>() |
105 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
106 |
423 |
@Override... |
107 |
|
public Object doInHibernate(Session session) throws HibernateException, XWikiException |
108 |
|
{ |
109 |
423 |
session.saveOrUpdate(archive); |
110 |
423 |
return null; |
111 |
|
} |
112 |
|
}); |
113 |
|
} |
114 |
|
|
|
|
| 33.3% |
Uncovered Elements: 4 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
115 |
22 |
@Override... |
116 |
|
public void deleteArchive(final XWikiAttachment attachment, final XWikiContext context, boolean bTransaction) |
117 |
|
throws XWikiException |
118 |
|
{ |
119 |
22 |
try { |
120 |
22 |
executeWrite(context, bTransaction, new HibernateCallback<Object>() |
121 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
122 |
22 |
@Override... |
123 |
|
public Object doInHibernate(Session session) throws HibernateException, XWikiException |
124 |
|
{ |
125 |
22 |
XWikiAttachmentArchive archive = new XWikiAttachmentArchive(); |
126 |
22 |
archive.setAttachment(attachment); |
127 |
22 |
session.delete(archive); |
128 |
22 |
return null; |
129 |
|
} |
130 |
|
}); |
131 |
|
} catch (Exception e) { |
132 |
0 |
if (LOGGER.isWarnEnabled()) { |
133 |
0 |
LOGGER.warn(String.format("Error deleting attachment archive [%s] of doc [%s]", |
134 |
|
attachment.getFilename(), attachment.getDoc().getFullName()), e); |
135 |
|
} |
136 |
|
} |
137 |
|
} |
138 |
|
} |