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: f007687060127f37e7691b614a66b3495d204f22 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractDataMigrationManager.XWikiMigration
Internal 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.ComponentManager
componentManager
Component manager used to access stores and data migrations.protected com.xpn.xwiki.internal.store.hibernate.HibernateConfiguration
hibernateConfiguration
protected org.slf4j.Logger
logger
Logger.protected Collection<AbstractDataMigrationManager.XWikiMigration>
migrations
Ordered list of migrators that may be applied.protected org.xwiki.observation.ObservationManager
observationManager
Component manager used to access stores and data migrations.protected org.xwiki.job.event.status.JobProgressManager
progress
-
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 void
checkDatabase()
Check current database version and proceed to migrations.protected abstract List<? extends DataMigration>
getAllMigrations()
DataMigrationStatus
getDataMigrationStatus()
XWikiDBVersion
getDBVersion()
protected XWikiDBVersion
getDBVersionFromConfig()
read data version from xwiki.cfg.protected XWikiDBVersion
getDBVersionFromDatabase()
Read data version from database.protected Map<XWikiDBVersion,AbstractDataMigrationManager.XWikiMigration>
getForcedMigrations()
XWikiDBVersion
getLatestVersion()
protected String
getMainXWiki()
protected Collection<AbstractDataMigrationManager.XWikiMigration>
getNeededMigrations()
protected List<String>
getVirtualWikisDatabaseNames()
Deprecated.protected XWikiConfig
getXWikiConfig()
Deprecated.protected XWikiContext
getXWikiContext()
void
initialize()
protected abstract void
initializeEmptyDB()
void
initNewDB()
Setup the schema of a new DB and set it to the latest version (not running migrations).protected boolean
isVirtualMode()
Deprecated.Virtual mode is on by default, starting with XWiki 5.0M2.protected void
setDBVersion(XWikiDBVersion version)
Update database version and status cache (not after a migration, use updateMigrationStatus).protected abstract void
setDBVersionToDatabase(XWikiDBVersion version)
protected void
startMigrations()
Start the migration process.protected void
startMigrations(Collection<AbstractDataMigrationManager.XWikiMigration> migrations)
protected abstract void
updateSchema(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:
initialize
in 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:
getDBVersion
in interfaceDataMigrationManager
- Returns:
- current DB version or null for a new database
- Throws:
DataMigrationException
- if any error
-
getDataMigrationStatus
public DataMigrationStatus getDataMigrationStatus() throws DataMigrationException
- Specified by:
getDataMigrationStatus
in interfaceDataMigrationManager
- Returns:
- current DB migration status or null for a new database
- Throws:
DataMigrationException
- if any error
-
getLatestVersion
public final XWikiDBVersion getLatestVersion()
- Specified by:
getLatestVersion
in interfaceDataMigrationManager
- Returns:
- latest DB version
-
initNewDB
public void initNewDB() throws DataMigrationException
Description copied from interface:DataMigrationManager
Setup 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:
initNewDB
in 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, DataMigrationException
Description copied from interface:DataMigrationManager
Check current database version and proceed to migrations. Migration is processed only once, and depends on the following configuration:- Specified by:
checkDatabase
in interfaceDataMigrationManager
- Throws:
MigrationRequiredException
- when version is incompatible with current versionDataMigrationException
- when an error occurs during check.
-
startMigrations
protected void startMigrations() throws DataMigrationException
Start 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
DataMigration
in 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
DataMigration
for 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
DataMigration
for this manager - Throws:
DataMigrationException
- if any error
-
-