use of com.xpn.xwiki.store.XWikiHibernateBaseStore.HibernateCallback 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