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));
}
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));
}
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;
}
Aggregations