Search in sources :

Example 1 with XWikiDBVersion

use of com.xpn.xwiki.store.migration.XWikiDBVersion in project xwiki-platform by xwiki.

the class WikiTemplateMigrationTest method shouldExecuteTrue.

@Test
public void shouldExecuteTrue() throws Exception {
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("mainWiki");
    XWikiDBVersion version = new XWikiDBVersion(52000);
    assertTrue(mocker.getComponentUnderTest().shouldExecute(version));
}
Also used : XWikiDBVersion(com.xpn.xwiki.store.migration.XWikiDBVersion) Test(org.junit.Test)

Example 2 with XWikiDBVersion

use of com.xpn.xwiki.store.migration.XWikiDBVersion in project xwiki-platform by xwiki.

the class WikiTemplateMigrationTest method shouldExecuteFalse.

@Test
public void shouldExecuteFalse() throws Exception {
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("subwiki");
    XWikiDBVersion version = new XWikiDBVersion(52000);
    assertFalse(mocker.getComponentUnderTest().shouldExecute(version));
}
Also used : XWikiDBVersion(com.xpn.xwiki.store.migration.XWikiDBVersion) Test(org.junit.Test)

Example 3 with XWikiDBVersion

use of com.xpn.xwiki.store.migration.XWikiDBVersion in project xwiki-platform by xwiki.

the class HibernateDataMigrationManager method getDBVersionFromDatabase.

@Override
public XWikiDBVersion getDBVersionFromDatabase() throws DataMigrationException {
    XWikiDBVersion ver = getDBVersionFromConfig();
    if (ver != null) {
        return ver;
    }
    final XWikiContext context = getXWikiContext();
    final XWikiHibernateBaseStore store = getStore();
    // Try retrieving a version from the database
    ver = store.failSafeExecuteRead(context, new HibernateCallback<XWikiDBVersion>() {

        @Override
        public XWikiDBVersion doInHibernate(Session session) throws HibernateException {
            // Retrieve the version from the database
            return (XWikiDBVersion) session.createCriteria(XWikiDBVersion.class).uniqueResult();
        }
    });
    // if it fails, return version 0 if there is some documents in the database, else null (empty db?)
    if (ver == null) {
        ver = store.failSafeExecuteRead(getXWikiContext(), new HibernateCallback<XWikiDBVersion>() {

            @Override
            public XWikiDBVersion doInHibernate(Session session) throws HibernateException {
                if (((Number) session.createCriteria(XWikiDocument.class).setProjection(Projections.rowCount()).uniqueResult()).longValue() > 0) {
                    return new XWikiDBVersion(0);
                }
                return null;
            }
        });
    }
    return ver;
}
Also used : XWikiDBVersion(com.xpn.xwiki.store.migration.XWikiDBVersion) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiHibernateBaseStore(com.xpn.xwiki.store.XWikiHibernateBaseStore) HibernateCallback(com.xpn.xwiki.store.XWikiHibernateBaseStore.HibernateCallback) Session(org.hibernate.Session)

Aggregations

XWikiDBVersion (com.xpn.xwiki.store.migration.XWikiDBVersion)3 Test (org.junit.Test)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiHibernateBaseStore (com.xpn.xwiki.store.XWikiHibernateBaseStore)1 HibernateCallback (com.xpn.xwiki.store.XWikiHibernateBaseStore.HibernateCallback)1 Session (org.hibernate.Session)1