use of com.xpn.xwiki.store.XWikiHibernateBaseStore in project xwiki-platform by xwiki.
the class HibernateDataMigrationManager method liquibaseUpdate.
/**
* Run liquibase for a given set of change logs
*
* @param migrations the set of migration to visit
* @param preHibernate if true, use pre-hibernate schema update changelogs.
* @throws XWikiException
* @throws DataMigrationException
* @since 4.3
*/
private void liquibaseUpdate(Collection<XWikiMigration> migrations, boolean preHibernate) throws XWikiException, DataMigrationException {
String liquibaseChangeLogs = getLiquibaseChangeLogs(migrations, preHibernate);
if (liquibaseChangeLogs == null || liquibaseChangeLogs.length() == 0) {
return;
}
final String database = getXWikiContext().getWikiId();
if (this.logger.isInfoEnabled()) {
if (preHibernate) {
this.logger.info("Running early schema updates (using liquibase) for database [{}]", database);
} else {
this.logger.info("Running additional schema updates (using liquibase) for database [{}]", database);
}
}
final StringBuilder changeLogs = new StringBuilder(10000);
changeLogs.append(getLiquibaseChangeLogHeader());
changeLogs.append(liquibaseChangeLogs);
changeLogs.append(getLiquibaseChangeLogFooter());
final XWikiHibernateBaseStore store = getStore();
store.executeRead(getXWikiContext(), new HibernateCallback<Object>() {
@Override
public Object doInHibernate(Session session) throws XWikiException {
Liquibase lb;
try {
Database lbDatabase = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(session.connection()));
// Precise the schema name to liquibase, since it does not usually determine it
// properly (See XWIKI-8813).
lbDatabase.setDefaultSchemaName(store.getSchemaFromWikiName(getXWikiContext()));
lb = new Liquibase(MigrationResourceAccessor.CHANGELOG_NAME, new MigrationResourceAccessor(changeLogs.toString()), lbDatabase);
} catch (LiquibaseException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_MIGRATION, String.format("Unable to launch liquibase for database %s, schema update failed.", database), e);
}
try {
lb.update(null);
} catch (LiquibaseException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_MIGRATION, String.format("Unable to update schema of database %s.", database), e);
}
return null;
}
});
}
use of com.xpn.xwiki.store.XWikiHibernateBaseStore in project xwiki-platform by xwiki.
the class HibernateDataMigrationManager method startMigrations.
@Override
protected void startMigrations() throws DataMigrationException {
XWikiContext context = getXWikiContext();
XWikiHibernateBaseStore store = getStore();
Session originalSession = store.getSession(context);
Transaction originalTransaction = store.getTransaction(context);
store.setSession(null, context);
store.setTransaction(null, context);
try {
super.startMigrations();
} finally {
store.setSession(originalSession, context);
store.setTransaction(originalTransaction, context);
}
}
Aggregations