Package com.xpn.xwiki.store.migration
Class AbstractDataMigrationManager
- java.lang.Object
-
- com.xpn.xwiki.store.migration.AbstractDataMigrationManager
-
- All Implemented Interfaces:
DataMigrationManager,org.xwiki.component.phase.Initializable
- Direct Known Subclasses:
HibernateDataMigrationManager
public abstract class AbstractDataMigrationManager extends Object implements DataMigrationManager, org.xwiki.component.phase.Initializable
Template forDataMigrationManager.- Since:
- 3.4M1
- Version:
- $Id: ba7dafe3b69b643242d961d78ea5cc1bcf7f27e7 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAbstractDataMigrationManager.XWikiMigrationInternal class used to find out the data migration that are being forced in the XWiki configuration file.
-
Field Summary
Fields Modifier and Type Field Description protected org.xwiki.component.manager.ComponentManagercomponentManagerComponent manager used to access stores and data migrations.protected com.xpn.xwiki.internal.store.hibernate.HibernateConfigurationhibernateConfigurationprotected org.slf4j.LoggerloggerLogger.protected Collection<AbstractDataMigrationManager.XWikiMigration>migrationsOrdered list of migrators that may be applied.protected org.xwiki.observation.ObservationManagerobservationManagerComponent manager used to access stores and data migrations.protected org.xwiki.job.event.status.JobProgressManagerprogress
-
Constructor Summary
Constructors Constructor Description AbstractDataMigrationManager()Unified constructor for all subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcheckDatabase()Check current database version and proceed to migrations.protected abstract List<? extends DataMigration>getAllMigrations()DataMigrationStatusgetDataMigrationStatus()XWikiDBVersiongetDBVersion()protected XWikiDBVersiongetDBVersionFromConfig()read data version from xwiki.cfg.protected XWikiDBVersiongetDBVersionFromDatabase()Read data version from database.protected Map<XWikiDBVersion,AbstractDataMigrationManager.XWikiMigration>getForcedMigrations()XWikiDBVersiongetLatestVersion()protected StringgetMainXWiki()protected Collection<AbstractDataMigrationManager.XWikiMigration>getNeededMigrations()protected List<String>getVirtualWikisDatabaseNames()Deprecated.protected XWikiConfiggetXWikiConfig()Deprecated.protected XWikiContextgetXWikiContext()voidinitialize()protected abstract voidinitializeEmptyDB()voidinitNewDB()Setup the schema of a new DB and set it to the latest version (not running migrations).protected booleanisVirtualMode()Deprecated.Virtual mode is on by default, starting with XWiki 5.0M2.protected voidsetDBVersion(XWikiDBVersion version)Update database version and status cache (not after a migration, use updateMigrationStatus).protected abstract voidsetDBVersionToDatabase(XWikiDBVersion version)protected voidstartMigrations()Start the migration process.protected voidstartMigrations(Collection<AbstractDataMigrationManager.XWikiMigration> migrations)protected abstract voidupdateSchema(Collection<AbstractDataMigrationManager.XWikiMigration> migrations)Update database schema to the latest structure.
-
-
-
Field Detail
-
componentManager
@Inject protected org.xwiki.component.manager.ComponentManager componentManager
Component manager used to access stores and data migrations.
-
observationManager
@Inject protected org.xwiki.observation.ObservationManager observationManager
Component manager used to access stores and data migrations.
-
progress
@Inject protected org.xwiki.job.event.status.JobProgressManager progress
-
hibernateConfiguration
@Inject protected com.xpn.xwiki.internal.store.hibernate.HibernateConfiguration hibernateConfiguration
-
migrations
protected Collection<AbstractDataMigrationManager.XWikiMigration> migrations
Ordered list of migrators that may be applied.
-
logger
@Inject protected org.slf4j.Logger logger
Logger.
-
-
Method Detail
-
getXWikiContext
protected XWikiContext getXWikiContext()
- Returns:
- XWikiContext
-
getXWikiConfig
@Deprecated protected XWikiConfig getXWikiConfig()
Deprecated.- Returns:
- XWikiConfig to read configuration from xwiki.cfg
-
isVirtualMode
@Deprecated protected boolean isVirtualMode()
Deprecated.Virtual mode is on by default, starting with XWiki 5.0M2.- Returns:
- true if running in virtual mode
-
getVirtualWikisDatabaseNames
@Deprecated protected List<String> getVirtualWikisDatabaseNames() throws DataMigrationException
Deprecated.- Returns:
- list of virtual database names
- Throws:
DataMigrationException- on error
-
getMainXWiki
protected String getMainXWiki()
- Returns:
- the main XWiki database name
-
initialize
public void initialize() throws org.xwiki.component.phase.InitializationException- Specified by:
initializein interfaceorg.xwiki.component.phase.Initializable- Throws:
org.xwiki.component.phase.InitializationException
-
getDBVersionFromConfig
protected XWikiDBVersion getDBVersionFromConfig()
read data version from xwiki.cfg.- Returns:
- data version if set, or null.
-
getDBVersionFromDatabase
protected XWikiDBVersion getDBVersionFromDatabase() throws DataMigrationException
Read data version from database.- Returns:
- data version or null if this is a new database
- Throws:
DataMigrationException- in case of an unexpected error
-
getDBVersion
public final XWikiDBVersion getDBVersion() throws DataMigrationException
- Specified by:
getDBVersionin interfaceDataMigrationManager- Returns:
- current DB version or null for a new database
- Throws:
DataMigrationException- if any error
-
getDataMigrationStatus
public DataMigrationStatus getDataMigrationStatus() throws DataMigrationException
- Specified by:
getDataMigrationStatusin interfaceDataMigrationManager- Returns:
- current DB migration status or null for a new database
- Throws:
DataMigrationException- if any error
-
getLatestVersion
public final XWikiDBVersion getLatestVersion()
- Specified by:
getLatestVersionin interfaceDataMigrationManager- Returns:
- latest DB version
-
initNewDB
public void initNewDB() throws DataMigrationExceptionDescription copied from interface:DataMigrationManagerSetup the schema of a new DB and set it to the latest version (not running migrations). This should be used on a newly created DB only- Specified by:
initNewDBin interfaceDataMigrationManager- Throws:
DataMigrationException- if any error
-
initializeEmptyDB
protected abstract void initializeEmptyDB() throws DataMigrationException- Throws:
DataMigrationException- if any error
-
setDBVersionToDatabase
protected abstract void setDBVersionToDatabase(XWikiDBVersion version) throws DataMigrationException
- Parameters:
version- to set- Throws:
DataMigrationException- if any error
-
setDBVersion
protected final void setDBVersion(XWikiDBVersion version) throws DataMigrationException
Update database version and status cache (not after a migration, use updateMigrationStatus).- Parameters:
version- database version to be stored- Throws:
DataMigrationException- if any error
-
updateSchema
protected abstract void updateSchema(Collection<AbstractDataMigrationManager.XWikiMigration> migrations) throws DataMigrationException
Update database schema to the latest structure.- Parameters:
migrations- the migration that will be executed (since 4.0M1)- Throws:
DataMigrationException- if any error
-
checkDatabase
public void checkDatabase() throws MigrationRequiredException, DataMigrationExceptionDescription copied from interface:DataMigrationManagerCheck current database version and proceed to migrations. Migration is processed only once, and depends on the following configuration:- Specified by:
checkDatabasein interfaceDataMigrationManager- Throws:
MigrationRequiredException- when version is incompatible with current versionDataMigrationException- when an error occurs during check.
-
startMigrations
protected void startMigrations() throws DataMigrationExceptionStart the migration process. This one is not thread safe and should be synchronized. The migrations field should not be null.- Throws:
DataMigrationException- in case of any error
-
getNeededMigrations
protected Collection<AbstractDataMigrationManager.XWikiMigration> getNeededMigrations() throws DataMigrationException
- Returns:
- collection of
DataMigrationin ascending order, which need be executed. - Throws:
DataMigrationException- if any error
-
getForcedMigrations
protected Map<XWikiDBVersion,AbstractDataMigrationManager.XWikiMigration> getForcedMigrations() throws DataMigrationException
- Returns:
- a map of forced
DataMigrationfor this manager - Throws:
DataMigrationException- id any error
-
startMigrations
protected void startMigrations(Collection<AbstractDataMigrationManager.XWikiMigration> migrations) throws DataMigrationException
- Parameters:
migrations- - run this migrations in order of collection- Throws:
DataMigrationException- if any error
-
getAllMigrations
protected abstract List<? extends DataMigration> getAllMigrations() throws DataMigrationException
- Returns:
- List of all
DataMigrationfor this manager - Throws:
DataMigrationException- if any error
-
-