use of org.xwiki.store.UnexpectedException in project xwiki-platform by xwiki.
the class XWikiHibernateStore method releaseAllLocksForCurrentUser.
/**
* Release all of the locks held by the currently logged in user.
*
* @param ctx the XWikiContext, used to start the connection and get the user name.
*/
private void releaseAllLocksForCurrentUser(final XWikiContext ctx) {
try {
this.beginTransaction(ctx);
Session session = this.getSession(ctx);
final Query query = session.createQuery("delete from XWikiLock as lock where lock.userName=:userName");
// Using deprecated getUser() because this is how locks are created.
// It would be a maintainibility disaster to use different code paths
// for calculating names when creating and removing.
query.setString("userName", ctx.getUser());
query.executeUpdate();
this.endTransaction(ctx, true);
} catch (Exception e) {
String msg = "Error while deleting active locks held by user.";
try {
this.endTransaction(ctx, false);
} catch (Exception utoh) {
msg += " Failed to commit OR rollback [" + utoh.getMessage() + "]";
}
throw new UnexpectedException(msg, e);
}
// switch to the global wiki and delete locks held there.
if (!ctx.isMainWiki() && ctx.isMainWiki(ctx.getUserReference().getWikiReference().getName())) {
final String cdb = ctx.getWikiId();
try {
ctx.setWikiId(ctx.getMainXWiki());
this.releaseAllLocksForCurrentUser(ctx);
} finally {
ctx.setWikiId(cdb);
}
}
}
use of org.xwiki.store.UnexpectedException in project xwiki-platform by xwiki.
the class XWikiAttachmentContent method getNewFileItem.
/**
* @return a new FileItem for temporarily storing attachment content.
* @since 4.2M3
*/
private static FileItem getNewFileItem() {
final Environment env = Utils.getComponent(Environment.class);
final File dir = new File(env.getTemporaryDirectory(), "attachment-cache");
try {
if (!dir.mkdirs() && !dir.exists()) {
throw new UnexpectedException("Failed to create directory for attachments " + dir);
}
final DiskFileItem dfi = new DiskFileItem(null, null, false, null, 10000, dir);
// This causes the temp file to be created.
dfi.getOutputStream().close();
return dfi;
} catch (IOException e) {
throw new UnexpectedException("Failed to create new attachment temporary file.", e);
}
}
Aggregations