Search in sources :

Example 6 with XWikiHibernateStore

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;
}
Also used : XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) ArrayList(java.util.ArrayList)

Example 7 with XWikiHibernateStore

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);
}
Also used : XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) XWikiException(com.xpn.xwiki.XWikiException) Session(org.hibernate.Session)

Example 8 with XWikiHibernateStore

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);
}
Also used : XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) EventStreamDeletedEvent(org.xwiki.eventstream.events.EventStreamDeletedEvent) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) XWikiException(com.xpn.xwiki.XWikiException) XWikiException(com.xpn.xwiki.XWikiException) MalformedURLException(java.net.MalformedURLException) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) Session(org.hibernate.Session)

Example 9 with XWikiHibernateStore

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());
    }
}
Also used : XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) Session(org.hibernate.Session)

Example 10 with XWikiHibernateStore

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));
}
Also used : XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) XWikiContext(com.xpn.xwiki.XWikiContext) MailStatus(org.xwiki.mail.MailStatus) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)18 XWikiException (com.xpn.xwiki.XWikiException)15 ArrayList (java.util.ArrayList)7 XWikiContext (com.xpn.xwiki.XWikiContext)6 Session (org.hibernate.Session)6 DocumentStats (com.xpn.xwiki.stats.impl.DocumentStats)4 ActivityStreamException (com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException)3 RefererStats (com.xpn.xwiki.stats.impl.RefererStats)2 VisitStats (com.xpn.xwiki.stats.impl.VisitStats)2 DataMigrationException (com.xpn.xwiki.store.migration.DataMigrationException)2 MalformedURLException (java.net.MalformedURLException)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 Test (org.junit.Test)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 XWikiRCSNodeInfo (com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 BaseObjectReference (com.xpn.xwiki.objects.BaseObjectReference)1 XWikiCacheStoreInterface (com.xpn.xwiki.store.XWikiCacheStoreInterface)1