use of org.xwiki.mail.MailStoreException in project xwiki-platform by xwiki.
the class DatabaseMailStatusStore method save.
@Override
public void save(final MailStatus status, final Map<String, Object> parameters) throws MailStoreException {
XWikiHibernateBaseStore store = (XWikiHibernateBaseStore) this.hibernateStore;
XWikiContext xwikiContext = this.contextProvider.get();
// Save in the main wiki
String currentWiki = xwikiContext.getWikiId();
xwikiContext.setWikiId(xwikiContext.getMainXWiki());
try {
// Delete any previous state of the message
delete(status.getMessageId(), parameters);
store.executeWrite(xwikiContext, new XWikiHibernateBaseStore.HibernateCallback<Object>() {
@Override
public Object doInHibernate(Session session) throws HibernateException, XWikiException {
session.save(status);
return null;
}
});
// Log the save for debugging purpose
this.logger.debug("Saved mail status [{}]", status);
} catch (Exception e) {
throw new MailStoreException(String.format("Failed to save mail status [%s] to the database.", status), e);
} finally {
xwikiContext.setWikiId(currentWiki);
}
}
use of org.xwiki.mail.MailStoreException in project xwiki-platform by xwiki.
the class DatabaseMailStatusStore method delete.
@Override
public void delete(final String uniqueMessageId, Map<String, Object> parameters) throws MailStoreException {
XWikiHibernateBaseStore store = (XWikiHibernateBaseStore) this.hibernateStore;
XWikiContext xwikiContext = this.contextProvider.get();
// Delete from the main wiki
String currentWiki = xwikiContext.getWikiId();
xwikiContext.setWikiId(xwikiContext.getMainXWiki());
try {
store.executeWrite(xwikiContext, new XWikiHibernateBaseStore.HibernateCallback<Object>() {
@Override
public Object doInHibernate(Session session) throws HibernateException, XWikiException {
// Delete the message
String queryString = String.format("delete from %s where mail_id=:id", MailStatus.class.getName());
session.createQuery(queryString).setParameter(ID_PARAMETER_NAME, uniqueMessageId).executeUpdate();
return null;
}
});
} catch (Exception e) {
throw new MailStoreException(String.format("Failed to delete mail status (message id [%s]) " + "from the database.", uniqueMessageId), e);
} finally {
xwikiContext.setWikiId(currentWiki);
}
}
use of org.xwiki.mail.MailStoreException in project xwiki-platform by xwiki.
the class DatabaseMailStatusStore method count.
@Override
public long count(final Map<String, Object> filterMap) throws MailStoreException {
XWikiHibernateBaseStore store = (XWikiHibernateBaseStore) this.hibernateStore;
final XWikiContext xwikiContext = this.contextProvider.get();
// Count in the main wiki
String currentWiki = xwikiContext.getWikiId();
xwikiContext.setWikiId(xwikiContext.getMainXWiki());
// Compute the Query string based on the passed filter map
final String queryString = computeCountQueryString(filterMap);
try {
Long count = store.executeRead(xwikiContext, new XWikiHibernateBaseStore.HibernateCallback<Long>() {
@Override
public Long doInHibernate(Session session) throws HibernateException, XWikiException {
Query query = session.createQuery(queryString);
query.setProperties(filterMap);
return (Long) query.uniqueResult();
}
});
return count;
} catch (Exception e) {
throw new MailStoreException(String.format("Failed to count mail statuses matching the filter [%s] from the database.", filterMap), e);
} finally {
xwikiContext.setWikiId(currentWiki);
}
}
use of org.xwiki.mail.MailStoreException in project xwiki-platform by xwiki.
the class DatabaseMailStatusStore method load.
@Override
public List<MailStatus> load(final Map<String, Object> filterMap, final int offset, final int count, String sortField, boolean sortAscending) throws MailStoreException {
XWikiHibernateBaseStore store = (XWikiHibernateBaseStore) this.hibernateStore;
final XWikiContext xwikiContext = this.contextProvider.get();
// Load from the main wiki
String currentWiki = xwikiContext.getWikiId();
xwikiContext.setWikiId(xwikiContext.getMainXWiki());
// Compute the Query string based on the passed filter map
final String queryString = computeSelectQueryString(filterMap, sortField, sortAscending);
// Log query and parameters
logQuery(queryString, filterMap);
try {
List<MailStatus> mailStatuses = store.executeRead(xwikiContext, new XWikiHibernateBaseStore.HibernateCallback<List<MailStatus>>() {
@Override
public List<MailStatus> doInHibernate(Session session) throws HibernateException, XWikiException {
Query query = session.createQuery(queryString);
if (offset > 0) {
query.setFirstResult(offset);
}
if (count > 0) {
query.setMaxResults(count);
}
query.setProperties(filterMap);
List<MailStatus> queryResult = (List<MailStatus>) query.list();
return queryResult;
}
});
// Log loaded statuses
if (this.logger.isDebugEnabled()) {
for (MailStatus mailStatus : mailStatuses) {
this.logger.debug("Loaded mail status [{}]", mailStatus);
}
}
return mailStatuses;
} catch (Exception e) {
throw new MailStoreException(String.format("Failed to load mail statuses matching the filter [%s] from the database.", filterMap), e);
} finally {
xwikiContext.setWikiId(currentWiki);
}
}
use of org.xwiki.mail.MailStoreException in project xwiki-platform by xwiki.
the class FileSystemMailContentStore method delete.
@Override
public void delete(String batchId, String uniqueMessageId) throws MailStoreException {
File messageFile = null;
try {
messageFile = getMessageFile(batchId, uniqueMessageId);
messageFile.delete();
// Also remove the directory. Note that it'll succeed only the directory is empty which is what we want.
getBatchDirectory(batchId).delete();
} catch (Exception e) {
throw new MailStoreException(String.format("Failed to delete message (id [%s], batch id [%s]) file [%s]", uniqueMessageId, batchId, messageFile), e);
}
}
Aggregations