Search in sources :

Example 6 with DataMigrationException

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

the class RecordableEventMigrator method hibernateMigrate.

@Override
protected void hibernateMigrate() throws DataMigrationException, XWikiException {
    String hql = "select event from ActivityEventImpl event where event.page LIKE concat(event.wiki, ':%')";
    try {
        List<ActivityEventImpl> events;
        do {
            Query query = queryManager.createQuery(hql, Query.HQL);
            query.setLimit(50);
            events = query.execute();
            for (ActivityEventImpl event : events) {
                fixEvent(event);
            }
        } while (!events.isEmpty());
    } catch (QueryException e) {
        throw new DataMigrationException("Failed to fix RecordableEvent problems.", e);
    }
}
Also used : QueryException(org.xwiki.query.QueryException) Query(org.xwiki.query.Query) ActivityEventImpl(com.xpn.xwiki.plugin.activitystream.impl.ActivityEventImpl) DataMigrationException(com.xpn.xwiki.store.migration.DataMigrationException)

Example 7 with DataMigrationException

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

the class R40001XWIKI7540DataMigration method checkAnnotationsAndComments.

/**
 * Check if the migration can be executed by verifying if the current annotation class is the default one and that
 * the comments class does not have any custom mappings set up.
 * <p>
 * Note: We can not do this in {@link #shouldExecute(XWikiDBVersion)} because we need to read the database and we
 * can not do that until the previous migrations are executed.
 *
 * @return true if the migration can be executed, false otherwise.
 * @throws DataMigrationException if the annotation or comments class can not be properly retrieved
 */
protected boolean checkAnnotationsAndComments() throws DataMigrationException {
    XWikiContext context = getXWikiContext();
    String resultOfSkippingDatabase = "Comments and anotations will remain separated";
    try {
        EntityReference currentAnnotationClassReference = configuration.getAnnotationClassReference();
        currentAnnotationClassReference = currentAnnotationClassReference.removeParent(new WikiReference(context.getWikiId()));
        if (!XWIKI_ANNOTATION_CLASS_REFERENCE.equals(currentAnnotationClassReference)) {
            logger.warn("Skipping database [{}] because it uses a custom annotation class. " + resultOfSkippingDatabase, context.getWikiId());
            return false;
        }
        BaseClass commentsClass = context.getWiki().getCommentsClass(context);
        if (commentsClass.hasCustomMapping()) {
            logger.warn("Skipping database [{}] because it uses a custom mapping for comments. " + resultOfSkippingDatabase, context.getWikiId());
            return false;
        }
    } catch (Exception e) {
        // Should not happen
        String message = "Failed to check the current annotation and comments classes for customizations. " + "Migration will not execute";
        logger.error(message, e);
        throw new DataMigrationException(message, e);
    }
    return true;
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) XWikiContext(com.xpn.xwiki.XWikiContext) DataMigrationException(com.xpn.xwiki.store.migration.DataMigrationException) WikiReference(org.xwiki.model.reference.WikiReference) XWikiException(com.xpn.xwiki.XWikiException) DataMigrationException(com.xpn.xwiki.store.migration.DataMigrationException) HibernateException(org.hibernate.HibernateException)

Example 8 with DataMigrationException

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

the class HibernateDataMigrationManager method updateSchema.

@Override
protected void updateSchema(Collection<XWikiMigration> migrations) throws DataMigrationException {
    try {
        liquibaseUpdate(migrations, true);
        hibernateShemaUpdate();
        liquibaseUpdate(migrations, false);
    } catch (Exception e) {
        throw new DataMigrationException(String.format("Unable to update schema of wiki [%s]", getXWikiContext().getWikiId()), e);
    }
}
Also used : DataMigrationException(com.xpn.xwiki.store.migration.DataMigrationException) XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DataMigrationException(com.xpn.xwiki.store.migration.DataMigrationException) IOException(java.io.IOException) LiquibaseException(liquibase.exception.LiquibaseException) HibernateException(org.hibernate.HibernateException)

Aggregations

DataMigrationException (com.xpn.xwiki.store.migration.DataMigrationException)8 XWikiException (com.xpn.xwiki.XWikiException)7 XWikiContext (com.xpn.xwiki.XWikiContext)6 XWiki (com.xpn.xwiki.XWiki)3 HibernateException (org.hibernate.HibernateException)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 BaseObject (com.xpn.xwiki.objects.BaseObject)2 XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 Query (org.xwiki.query.Query)2 QueryException (org.xwiki.query.QueryException)2 XWikiRCSNodeInfo (com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)1 BaseObjectReference (com.xpn.xwiki.objects.BaseObjectReference)1 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)1 ActivityEventImpl (com.xpn.xwiki.plugin.activitystream.impl.ActivityEventImpl)1 XWikiHibernateBaseStore (com.xpn.xwiki.store.XWikiHibernateBaseStore)1