use of com.xpn.xwiki.store.XWikiHibernateStore in project xwiki-platform by xwiki.
the class XWikiStatsReader method getRefMonthStats.
/**
* Gets monthly referer statistics.
*
* @param docName fully qualified document name.
* @param month the month.
* @param context the XWiki context.
* @return the monthly referer statistics.
* @throws XWikiException error when searching for referer statistics.
* @deprecated use {@link #getRefererStatistics(String, Scope, Period, Range, XWikiContext)} instead.
*/
@Deprecated
public List<?> getRefMonthStats(String docName, Date month, XWikiContext context) throws XWikiException {
XWikiHibernateStore store = context.getWiki().getHibernateStore();
List<?> solist;
if (store != null) {
List<Object> paramList = new ArrayList<Object>(1);
paramList.add(docName);
solist = store.search("from RefererStats as obj where obj.name=?", 0, 0, paramList, context);
} else {
solist = Collections.emptyList();
}
return solist;
}
use of com.xpn.xwiki.store.XWikiHibernateStore in project xwiki-platform by xwiki.
the class ActivityStreamImpl method addActivityEvent.
/**
* @param event event to add to the stream
* @param doc which fired the event
* @param context the XWiki context
* @throws ActivityStreamException if the addition to the stream fails
*/
public void addActivityEvent(ActivityEvent event, XWikiDocument doc, XWikiContext context) throws ActivityStreamException {
prepareEvent(event, doc, context);
if (useLocalStore()) {
// store event in the local database
XWikiHibernateStore localHibernateStore = context.getWiki().getHibernateStore();
try {
localHibernateStore.beginTransaction(context);
Session session = localHibernateStore.getSession(context);
session.save(event);
localHibernateStore.endTransaction(context, true);
} catch (XWikiException e) {
localHibernateStore.endTransaction(context, false);
}
}
if (useMainStore()) {
// store event in the main database
String oriDatabase = context.getWikiId();
context.setWikiId(context.getMainXWiki());
XWikiHibernateStore mainHibernateStore = context.getWiki().getHibernateStore();
try {
mainHibernateStore.beginTransaction(context);
Session session = mainHibernateStore.getSession(context);
session.save(event);
mainHibernateStore.endTransaction(context, true);
} catch (XWikiException e) {
mainHibernateStore.endTransaction(context, false);
} finally {
context.setWikiId(oriDatabase);
}
}
this.sendEventStreamEvent(new EventStreamAddedEvent(), event);
}
use of com.xpn.xwiki.store.XWikiHibernateStore in project xwiki-platform by xwiki.
the class ActivityStreamImpl method deleteActivityEvent.
@Override
public void deleteActivityEvent(ActivityEvent event, XWikiContext context) throws ActivityStreamException {
boolean bTransaction = true;
ActivityEventImpl evImpl = loadActivityEvent(event, true, context);
String oriDatabase = context.getWikiId();
if (useLocalStore()) {
XWikiHibernateStore hibstore;
// delete event from the local database
if (context.getWikiId().equals(event.getWiki())) {
hibstore = context.getWiki().getHibernateStore();
} else {
context.setWikiId(event.getWiki());
hibstore = context.getWiki().getHibernateStore();
}
try {
if (bTransaction) {
hibstore.checkHibernate(context);
bTransaction = hibstore.beginTransaction(context);
}
Session session = hibstore.getSession(context);
session.delete(evImpl);
if (bTransaction) {
hibstore.endTransaction(context, true);
}
} catch (XWikiException e) {
throw new ActivityStreamException();
} finally {
try {
if (bTransaction) {
hibstore.endTransaction(context, false);
}
if (context.getWikiId().equals(oriDatabase)) {
context.setWikiId(oriDatabase);
}
} catch (Exception e) {
// Do nothing.
}
}
}
if (useMainStore()) {
// delete event from the main database
context.setWikiId(context.getMainXWiki());
XWikiHibernateStore hibstore = context.getWiki().getHibernateStore();
try {
if (bTransaction) {
hibstore.checkHibernate(context);
bTransaction = hibstore.beginTransaction(context);
}
Session session = hibstore.getSession(context);
session.delete(evImpl);
if (bTransaction) {
hibstore.endTransaction(context, true);
}
} catch (XWikiException e) {
throw new ActivityStreamException();
} finally {
try {
if (bTransaction) {
hibstore.endTransaction(context, false);
}
context.setWikiId(oriDatabase);
} catch (Exception e) {
// Do nothing
}
}
}
this.sendEventStreamEvent(new EventStreamDeletedEvent(), event);
}
use of com.xpn.xwiki.store.XWikiHibernateStore in project xwiki-platform by xwiki.
the class RecordableEventMigrator method saveEvent.
private void saveEvent(ActivityEventImpl event) {
XWikiContext context = contextProvider.get();
XWikiHibernateStore hibernateStore = context.getWiki().getHibernateStore();
try {
hibernateStore.beginTransaction(context);
Session session = hibernateStore.getSession(context);
session.update(event);
hibernateStore.endTransaction(context, true);
} catch (XWikiException e) {
hibernateStore.endTransaction(context, false);
logger.warn("Failed to update the event [{}].", event.getEventId());
}
}
use of com.xpn.xwiki.store.XWikiHibernateStore in project xwiki-platform by xwiki.
the class DatabaseMailStatusStoreTest method logsForloadMailStatus.
@Test
public void logsForloadMailStatus() throws Exception {
Provider<XWikiContext> xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
XWikiContext xcontext = mock(XWikiContext.class);
when(xcontextProvider.get()).thenReturn(xcontext);
when(xcontext.getWikiId()).thenReturn("wiki");
when(xcontext.getMainXWiki()).thenReturn("mainwiki");
XWikiHibernateStore hibernateStore = mock(XWikiHibernateStore.class);
ReflectionUtils.setFieldValue(this.mocker.getComponentUnderTest(), "hibernateStore", hibernateStore);
MailStatus status = new MailStatus();
status.setBatchId("batchid");
status.setMessageId("messageid");
status.setState(MailState.PREPARE_SUCCESS);
status.setRecipients("recipients");
when(hibernateStore.executeRead(eq(xcontext), any())).thenReturn(Arrays.asList(status));
Map<String, Object> filterMap = new LinkedHashMap<>();
filterMap.put("status", "failed");
filterMap.put("wiki", "mywiki");
this.mocker.getComponentUnderTest().load(filterMap, 0, 0, null, false);
// The test is here, we verify that debug logs are correct
assertEquals(2, this.logRule.size());
assertEquals("Find mail statuses for query [from org.xwiki.mail.MailStatus where mail_status like :status " + "and mail_wiki like :wiki] and parameters [[status] = [failed], [wiki] = [mywiki]]", this.logRule.getMessage(0));
assertEquals("Loaded mail status [messageId = [messageid], batchId = [batchid], state = [prepare_success], " + "date = [<null>], recipients = [recipients]]", this.logRule.getMessage(1));
}
Aggregations